00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00027 #include <stdlib.h>
00028 #include <stdio.h>
00029 #include "button.h"
00030 #include "globals.h"
00031 #include "fonts.h"
00032
00036 glictButton::glictButton() {
00037
00038 this->bgcolor.r = 0.0;
00039 this->bgcolor.g = 0.0;
00040 this->bgcolor.b = 0.0;
00041 this->bgcolor.a = 1.0;
00042
00043 this->fgcolor.r = 1.0;
00044 this->fgcolor.g = 1.0;
00045 this->fgcolor.b = 1.0;
00046 this->fgcolor.a = 1.0;
00047
00048
00049 strcpy(this->objtype, "Button");
00050
00051 this->highlighted = false;
00052 this->parent = NULL;
00053
00054 this->focusable = true;
00055
00056 this->caption = "Button";
00057 }
00058
00062 glictButton::~glictButton() {
00063
00064 }
00065
00082 bool glictButton::CastEvent(glictEvents evt, void* wparam, long lparam, void* returnvalue) {
00083 if (!GetVisible() || !GetEnabled()) return false;
00084
00085
00086 switch (evt) {
00087 case GLICT_KEYPRESS:
00088 switch (*((char*)wparam)) {
00089 case 9:
00090 if (next)
00091 next->Focus(NULL);
00092 break;
00093 }
00094 break;
00095 case GLICT_MOUSEUP:
00096 case GLICT_MOUSEDOWN:
00097 case GLICT_MOUSECLICK:
00098 if (((glictPos*)wparam)->x >= this->clipleft &&
00099 ((glictPos*)wparam)->x <= this->clipright &&
00100 ((glictPos*)wparam)->y >= this->cliptop &&
00101 ((glictPos*)wparam)->y <= this->clipbottom) {
00102
00103 if (evt == GLICT_MOUSECLICK) {
00104
00105
00106 }
00107
00108 if (evt == GLICT_MOUSEUP) {
00109
00110 highlighted = false;
00111 }
00112 if (evt == GLICT_MOUSEDOWN) {
00113
00114 highlighted = true;
00115 }
00116
00117 if (DefaultCastEvent(evt, wparam, lparam, returnvalue)) {
00118
00119 return true;
00120 }
00121
00122
00123 return true;
00124 } else {
00125
00126 }
00127
00128
00129 if (evt == GLICT_MOUSEUP) {
00130
00131 highlighted = false;
00132 return false;
00133 }
00134 break;
00135 }
00136
00137
00138
00139 return false;
00140 }
00141
00148 void glictButton::Paint() {
00149 if (!GetVisible()) return;
00150
00151
00152 if (glictGlobals.debugCallback) {
00153 glictGlobals.debugCallback(strlen("glictButton::Paint()"), "glictButton::Paint()");
00154 }
00155
00156 this->SetScissor();
00157
00158 if (!((glictGlobals.buttonSkin && !highlighted) || (glictGlobals.buttonHighlightSkin && highlighted))) {
00159
00160 glictColor col;
00161 if (!highlighted) {
00162 col = bgcolor;
00163 } else {
00164 col.r = this->bgcolor.r < .5 ? (float)this->bgcolor.r * 1.5 : (float)this->bgcolor.r / 1.5;
00165 col.g = this->bgcolor.g < .5 ? (float)this->bgcolor.g * 1.5 : (float)this->bgcolor.g / 1.5;
00166 col.b = this->bgcolor.b < .5 ? (float)this->bgcolor.b * 1.5 : (float)this->bgcolor.b / 1.5;
00167 col.a = this->bgcolor.a;
00168 }
00169 glictGlobals.PaintRect(this->x+glictGlobals.translation.x, this->x+this->width+glictGlobals.translation.x,
00170 this->y+glictGlobals.translation.y, this->y+this->height+glictGlobals.translation.y,
00171 col);
00172
00173 } else {
00174
00175 glictSize s = {this->width, this->height};
00176
00177 glictGlobals.Translatef(this->x, this->y, 0);
00178 if (!highlighted)
00179 glictGlobals.buttonSkin->Paint(&s);
00180 else
00181 glictGlobals.buttonHighlightSkin->Paint(&s);
00182 glictGlobals.Translatef(-this->x, -this->y, 0);
00183 }
00184
00185
00186 if (!highlighted) {
00187 glictGlobals.SetColor(
00188 glictGlobals.buttonTextColor.r,
00189 glictGlobals.buttonTextColor.g,
00190 glictGlobals.buttonTextColor.b,
00191 glictGlobals.buttonTextColor.a
00192 );
00193 } else {
00194 glictGlobals.SetColor(
00195 glictGlobals.buttonHighlightTextColor.r,
00196 glictGlobals.buttonHighlightTextColor.g,
00197 glictGlobals.buttonHighlightTextColor.b,
00198 glictGlobals.buttonHighlightTextColor.a
00199 );
00200 }
00201
00202
00203 {
00204
00205 glictColor col;
00206
00207 col.r = this->bgcolor.r < .5 ? (float)this->bgcolor.r * 1.6 : (float)this->bgcolor.r / 1.6;
00208 col.g = this->bgcolor.g < .5 ? (float)this->bgcolor.g * 1.6 : (float)this->bgcolor.g / 1.6;
00209 col.b = this->bgcolor.b < .5 ? (float)this->bgcolor.b * 1.6 : (float)this->bgcolor.b / 1.6;
00210 col.a = this->bgcolor.a;
00211
00212 glictGlobals.PaintRectLines(this->x+glictGlobals.translation.x, this->x+this->width+glictGlobals.translation.x,
00213 this->y+glictGlobals.translation.y, this->y+this->height+glictGlobals.translation.y,
00214 col);
00215 }
00216
00217
00218 if (highlighted) glictGlobals.Translatef(2.,2.,0.);
00219
00220
00221
00222 glictFontRender(
00223 this->caption.c_str(),
00224 fontname.c_str(),
00225 fontsize,
00226 this->x + this->width / 2. - glictFontSize(this->caption.c_str(), fontname.c_str(), fontsize) / 2. +glictGlobals.translation.x,
00227 (this->y + this->height / 2. - (fontsize/2.)*((float)glictFontNumberOfLines(this->caption.c_str())))*+1. +glictGlobals.translation.y
00228 );
00229
00230
00231 if (highlighted) glictGlobals.Translatef(-2.,-2.,0.);
00232
00233
00234 this->CPaint();
00235 }
00245 void glictButton::SetBGColor(float r, float g, float b, float a) {
00246 this->bgcolor.r = r;
00247 this->bgcolor.g = g;
00248 this->bgcolor.b = b;
00249 this->bgcolor.a = a;
00250 }
00251
00261 void glictButton::SetFGColor(float r, float g, float b, float a) {
00262 this->fgcolor.r = r;
00263 this->fgcolor.g = g;
00264 this->fgcolor.b = b;
00265 this->fgcolor.a = a;
00266 }