00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019 #include <stdlib.h>
00020 #include <stdio.h>
00021 #include "textbox.h"
00022 #include "globals.h"
00023 #include "fonts.h"
00024 glictTextbox::glictTextbox() {
00025 this->bgcolor.r = .7;
00026 this->bgcolor.g = .7;
00027 this->bgcolor.b = .7;
00028 this->bgcolor.a = 1.0;
00029 strcpy(this->objtype, "Textbox");
00030
00031 this->parent = NULL;
00032
00033
00034 this->focusable = true;
00035
00036 this->SetHeight(14);
00037 this->SetWidth(100);
00038
00039 this->passprotectchar = 0;
00040 this->allowedchr = "";
00041
00042 caption = "";
00043 }
00044 glictTextbox::~glictTextbox() {
00045
00046 }
00047 void glictTextbox::Paint() {
00048 if (!GetVisible()) return;
00049
00050
00051 if (!glictGlobals.textboxSkin) {
00052 glictGlobals.PaintRect(this->x+glictGlobals.translation.x, this->x+this->width+glictGlobals.translation.x,
00053 this->y+glictGlobals.translation.y, this->y+this->height+glictGlobals.translation.y, bgcolor);
00054
00055
00056
00057
00058
00059
00060
00061
00062 } else {
00063 glictSize s = {this->width, this->height};
00064
00065 glictGlobals.Translatef(this->x, this->y, 0);
00066 glictGlobals.textboxSkin->Paint(&s);
00067 glictGlobals.Translatef(-this->x, -this->y, 0);
00068
00069
00070 }
00071
00072
00073 std::string oldcaption;
00074 char* asterisked=NULL;
00075 if (passprotectchar) {
00076 asterisked = (char*)malloc(caption.size() + 1);
00077 for (int i = 0; i < caption.size() ; i++) {
00078 asterisked[i] = passprotectchar;
00079 }
00080 asterisked[caption.size()] = 0;
00081 }
00082 if (glictGlobals.topFocused==this) {
00083 oldcaption = caption;
00084 if (asterisked)
00085 this->SetCaption((std::string)(asterisked) + "_");
00086 else
00087 this->SetCaption(caption + "_");
00088 }
00089
00090
00091
00092
00093 glictGlobals.SetColor(glictGlobals.textboxTextColor.r, glictGlobals.textboxTextColor.g, glictGlobals.textboxTextColor.b, glictGlobals.textboxTextColor.a);
00094 if (asterisked && glictGlobals.topFocused != this)
00095 glictFontRender(asterisked, fontname.c_str(), fontsize, x+(glictGlobals.textboxSkin ? glictGlobals.textboxSkin->GetLeftSize()->w : 0) +glictGlobals.translation.x , y+(glictGlobals.textboxSkin ? glictGlobals.textboxSkin->GetTopSize()->h : 0) +glictGlobals.translation.y);
00096 else
00097 glictFontRender(this->caption.c_str(), fontname.c_str(), fontsize, x+(glictGlobals.textboxSkin ? glictGlobals.textboxSkin->GetLeftSize()->w : 0) +glictGlobals.translation.x, y+(glictGlobals.textboxSkin ? glictGlobals.textboxSkin->GetTopSize()->h : 0) + glictGlobals.translation.y);
00098 glictGlobals.SetColor(1., 1., 1., 1.);
00099
00100
00101 if (glictGlobals.topFocused==this) {
00102 caption = oldcaption;
00103 }
00104 if (asterisked) free(asterisked);
00105 this->CPaint();
00106
00107 }
00108 void glictTextbox::SetBGColor(float r, float g, float b, float a) {
00109 this->bgcolor.r = r;
00110 this->bgcolor.g = g;
00111 this->bgcolor.b = b;
00112 this->bgcolor.a = a;
00113 }
00118
00119 bool glictTextbox::CastEvent(glictEvents evt, void* wparam, long lparam, void* returnvalue) {
00120 if (!GetVisible() || !GetEnabled()) return false;
00121 switch (evt) {
00122 case GLICT_MOUSEUP:
00123 case GLICT_MOUSEDOWN:
00124 case GLICT_MOUSECLICK:
00125 if (((glictPos*)wparam)->x > this->clipleft &&
00126 ((glictPos*)wparam)->x < this->clipright &&
00127 ((glictPos*)wparam)->y > this->cliptop &&
00128 ((glictPos*)wparam)->y < this->clipbottom) {
00129
00130
00131
00132
00133
00134 return DefaultCastEvent(evt, wparam, lparam, returnvalue);
00135
00136
00137 }
00138
00139 break;
00140 case GLICT_KEYPRESS:
00141 switch (*((char*)wparam)) {
00142 default:
00143 if (allowedchr.size() == 0 || (allowedchr.find(*((char*)wparam))<allowedchr.size())) {
00144 this->SetCaption(caption + *((char*)wparam));
00145 }
00146 break;
00147 case 8:
00148 if (caption.size()) {
00149 char* Title = (char*)malloc(caption.size()+1);
00150 strcpy(Title, caption.c_str());
00151 Title[strlen(Title)-1]=0;
00152 caption = Title;
00153 free(Title);
00154
00155 }
00156 break;
00157 case 9:
00158 if (next)
00159 next->Focus(NULL);
00160 break;
00161 }
00162 break;
00163 }
00164
00165 return false;
00166 }
00175 void glictTextbox::SetPassProtectCharacter(char asterisk) {
00176 passprotectchar = asterisk;
00177 }
00178
00188 void glictTextbox::SetAllowedChars (std::string s) {
00189 allowedchr = s;
00190 }