00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020 #include <stdlib.h>
00021 #include <stdio.h>
00022 #include <GLICT/window.h>
00023 #include <GLICT/globals.h>
00024 #include <GLICT/fonts.h>
00025 glictWindow::glictWindow() {
00026
00027 this->containeroffsetx = 0;
00028 this->containeroffsety = 12;
00029
00030
00031 this->bgcolor.r = 0.75;
00032 this->bgcolor.g = 0.75;
00033 this->bgcolor.b = 0.75;
00034 this->bgcolor.a = 1.0;
00035 strcpy(this->objtype, "Window");
00036
00037 this->parent = NULL;
00038 this->SetCaption("Untitled Window");
00039
00040 this->focusable = true;
00041
00042 this->mousedown = false;
00043
00044 this->relmouse.x = 0;
00045 this->relmouse.y = 0;
00046
00047 this->SetHeight(100);
00048 this->SetWidth(100);
00049
00050 this->SetPos(0,0);
00051
00052
00053
00054
00055
00056
00057
00058
00059
00060 }
00061 glictWindow::~glictWindow() {
00062
00063 }
00064
00074 void glictWindow::Paint() {
00075 if (!GetVisible()) return;
00076
00077
00078 if (!glictGlobals.windowBodySkin) {
00079
00080 glictGlobals.PaintRect(this->x+glictGlobals.translation.x, this->x+this->width+glictGlobals.translation.x,
00081 this->y+12+glictGlobals.translation.y, this->y+12+this->height+glictGlobals.translation.y,
00082 bgcolor);
00083
00084 } else if (!glictGlobals.windowTitleSkin) {
00085 glictSize s = {this->width + glictGlobals.windowBodySkin->GetLeftSize()->w + glictGlobals.windowBodySkin->GetRightSize()->w, this->height + glictGlobals.windowBodySkin->GetTopSize()->h + glictGlobals.windowBodySkin->GetBottomSize()->h};
00086
00087 glictGlobals.Translatef(this->x, this->y, 0);
00088 glictGlobals.windowBodySkin->Paint(&s);
00089 glictGlobals.Translatef(-this->x, -this->y, 0);
00090 } else {
00091 glictSize s = {this->width, this->height};
00092
00093 glictGlobals.Translatef(this->x + this->containeroffsetx , this->y + this->containeroffsety, 0);
00094 glictGlobals.windowBodySkin->Paint(&s);
00095 glictGlobals.Translatef(-(this->x + this->containeroffsetx), -(this->y + this->containeroffsety), 0);
00096 }
00097
00098
00099 if (this->OnPaint) {
00100 glictRect r, c;
00101
00102 r.top = this->top + containeroffsety;
00103 r.bottom = this->bottom - containeroffsety ;
00104 r.left = this->left + containeroffsetx;
00105 r.right = this->right - containeroffsetx;
00106
00107 c.top = max(this->cliptop, this->top + containeroffsety);
00108 c.bottom = min(this->clipbottom, this->bottom - containeroffsety);
00109 c.left = max(this->clipleft, this->left + containeroffsetx);
00110 c.right = min(this->clipright, this->right - containeroffsetx);
00111
00112 this->OnPaint(&r, &c, this);
00113
00114 }
00115
00116
00117 this->CPaint();
00118
00119
00120
00121
00122 this->SetScissor();
00123
00124 if (!glictGlobals.windowBodySkin && !glictGlobals.windowTitleSkin) {
00125 glictColor c;
00126
00127 glictGlobals.PaintRect(this->x+glictGlobals.translation.x, this->x+this->width+glictGlobals.translation.x,
00128 this->y+glictGlobals.translation.y, this->y+12+glictGlobals.translation.y,
00129 glictGlobals.windowTitleBgColor);
00130
00131 }
00132
00133 glictGlobals.SetColor(glictGlobals.windowTitleColor.r, glictGlobals.windowTitleColor.g, glictGlobals.windowTitleColor.b, glictGlobals.windowTitleColor.a);
00134
00135
00136
00137
00138
00139
00140
00141
00142
00143 glictFontRender(this->caption.c_str(),"system", this->x + glictGlobals.translation.x + (this->width / 2 - glictFontSize(this->caption.c_str(), "system") / 2) + (glictGlobals.windowBodySkin ? glictGlobals.windowBodySkin->GetLeftSize()->w : 0) , this->y*+1. + (glictGlobals.windowBodySkin ? (glictGlobals.windowBodySkin->GetTopSize()->h/2 - 10./2.) : 0) + glictGlobals.translation.y );
00144
00145
00146
00147
00148
00149
00150
00151 }
00152
00153 void glictWindow::SetBGColor(float r, float g, float b, float a) {
00154 this->bgcolor.r = r;
00155 this->bgcolor.g = g;
00156 this->bgcolor.b = b;
00157 this->bgcolor.a = a;
00158
00159 }
00176 bool glictWindow::CastEvent(glictEvents evt, void* wparam, long lparam, void* returnvalue) {
00177
00178 if (!GetVisible()) return false;
00179 float oldx = this->x, oldy = this->y;
00180
00181 if (evt == GLICT_MOUSECLICK || evt == GLICT_MOUSEDOWN || evt == GLICT_MOUSEUP) {
00182 if (((glictPos*)wparam)->x > this->clipleft &&
00183 ((glictPos*)wparam)->x < this->clipright &&
00184 ((glictPos*)wparam)->y > this->cliptop &&
00185 ((glictPos*)wparam)->y < this->clipbottom) {
00186
00187
00188
00189
00190 if (((glictPos*)wparam)->y <= this->cliptop + containeroffsety) {
00191 if (evt == GLICT_MOUSEDOWN) {
00192
00193 this->Focus(NULL);
00194 this->mousedown = true;
00195 this->relmouse.x = ((glictPos*)wparam)->x-this->x ;
00196 this->relmouse.y = ((glictPos*)wparam)->y-this->y ;
00197
00198
00199 return true;
00200 }
00201 }
00202
00203
00204 if (evt == GLICT_MOUSEDOWN) {
00205
00206
00207 if (GetEnabled())
00208 DefaultCastEvent(evt,wparam,lparam,returnvalue);
00209
00210 return true;
00211 }
00212
00213 if (evt == GLICT_MOUSEUP && this->mousedown) {
00214 this->SetPos(
00215 ((glictPos*)wparam)->x - this->relmouse.x,
00216 ((glictPos*)wparam)->y - this->relmouse.y
00217 );
00218 this->mousedown = false;
00219
00220 return DefaultCastEvent(evt,wparam,lparam,returnvalue);
00221 }
00222
00223 if (GetEnabled())
00224 return DefaultCastEvent(evt, wparam, lparam, returnvalue);
00225 else
00226 return false;
00227 } else
00228
00229 if (evt == GLICT_MOUSEUP && this->mousedown) {
00230 this->SetPos(
00231 ((glictPos*)wparam)->x - this->relmouse.x,
00232 ((glictPos*)wparam)->y - this->relmouse.y
00233 );
00234 this->mousedown = false;
00235 return true;
00236 }
00237
00238
00239 return DefaultCastEvent(evt, wparam, lparam, returnvalue);
00240 }
00241
00242 return false;
00243 }
00244
00245 void glictWindow::FixContainerOffsets() {
00246 if (!glictGlobals.windowBodySkin && !glictGlobals.windowTitleSkin) {
00247 this->containeroffsetx = 0;
00248 this->containeroffsety = 12;
00249 } else {
00250 if (!glictGlobals.windowTitleSkin) {
00251 this->containeroffsetx = glictGlobals.windowBodySkin->GetLeftSize()->w;
00252 this->containeroffsety = glictGlobals.windowBodySkin->GetTopSize()->h;
00253
00254
00255 } else {
00256 this->containeroffsetx = glictGlobals.windowBodySkin->GetLeftSize()->w;
00257 this->containeroffsety = glictGlobals.windowBodySkin->GetTopSize()->h;
00258 }
00259 }
00260
00261 }