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 "panel.h"
00022 #include "globals.h"
00023 #include "fonts.h"
00024 glictPanel::glictPanel() {
00025 this->bgcolor.r = 0.75;
00026 this->bgcolor.g = 0.75;
00027 this->bgcolor.b = 0.75;
00028 this->bgcolor.a = 1.0;
00029
00030 strcpy(this->objtype, "Panel");
00031
00032 this->parent = NULL;
00033
00034
00035 this->focusable = false;
00036
00037 this->bgactive = true;
00038
00039 virtualsize.x = 0;
00040 virtualsize.y = 0;
00041
00042 this->AddObject(&sbVertical);
00043
00044 sbVertical.SetVisible(false);
00045
00046
00047 skin = NULL;
00048 }
00049 glictPanel::~glictPanel() {
00050
00051 }
00052 void glictPanel::Paint() {
00053 if (!GetVisible()) return;
00054
00055
00056
00057
00058
00059
00060
00061
00062
00063
00064
00065
00066
00067
00068
00069
00070 if (virtualsize.h > height) {
00071 sbVertical.SetWidth(10);
00072 sbVertical.SetHeight(height );
00073 sbVertical.SetPos(width - 10, +sbVertical.GetValue());
00074 sbVertical.SetVisible(true);
00075
00076 sbVertical.SetMin(0);
00077 sbVertical.SetMax((int)(virtualsize.h - height));
00078 if (sbVertical.GetValue() > virtualsize.h - height) sbVertical.SetValue((int)(virtualsize.h - height));
00079 }
00080
00081 this->virtualpos.x = 0;
00082 this->virtualpos.y = sbVertical.GetValue();
00083
00084 if ( this->virtualsize.h != this->height )
00085 SetPos(x,y);
00086
00087 if (this->bgactive) {
00088 if (!skin) {
00089 glictGlobals.PaintRect(this->x+glictGlobals.translation.x, this->x+this->width+glictGlobals.translation.x,
00090 this->y+glictGlobals.translation.y, this->y+this->height+glictGlobals.translation.y, bgcolor);
00091
00092 } else {
00093 glictSize s;
00094 s.h = height, s.w = width;
00095 glictGlobals.Translatef(x,y,0);
00096 skin->Paint(&s);
00097 glictGlobals.Translatef(-x,-y,0);
00098
00099 }
00100 }
00101
00102
00103
00104
00105 glictGlobals.SetColor(glictGlobals.panelTextColor.r , glictGlobals.panelTextColor.g, glictGlobals.panelTextColor.b, glictGlobals.panelTextColor.a);
00106 glictFontRender(this->caption.c_str(), fontname.c_str(), x+glictGlobals.translation.x , y + glictGlobals.translation.y);
00107 glictGlobals.SetColor(1., 1., 1., 1.);
00108
00109
00110 if (this->OnPaint) {
00111 glictRect r, c;
00112
00113 r.top = this->top+containeroffsety;
00114 r.bottom = this->bottom;
00115 r.left = this->left+containeroffsetx;
00116 r.right = this->right;
00117
00118 c.top = max(this->cliptop, this->top+containeroffsety);
00119 c.bottom = this->clipbottom;
00120 c.left = max(this->clipleft, this->left+containeroffsetx);
00121 c.right = this->clipright;
00122 this->OnPaint(&r, &c, this);
00123 }
00124
00125
00126
00127
00128 this->CPaint();
00129
00130
00131 if (virtualsize.h > height) {
00132 sbVertical.SetPos(width - 10, 0);
00133 }
00134
00135
00136
00137 }
00138 void glictPanel::SetBGColor(float r, float g, float b, float a) {
00139 this->bgcolor.r = r;
00140 this->bgcolor.g = g;
00141 this->bgcolor.b = b;
00142 this->bgcolor.a = a;
00143 }
00145 bool glictPanel::CastEvent(glictEvents evt, void* wparam, long lparam, void* returnvalue) {
00146 if (!GetVisible() || !GetEnabled()) return false;
00147 switch (evt) {
00148
00149 case GLICT_MOUSEUP:
00150 case GLICT_MOUSEDOWN:
00151 case GLICT_MOUSECLICK: {
00152
00153 glictPos p;
00154 p.x = ((glictPos*)wparam)->x;
00155 p.y = ((glictPos*)wparam)->y - sbVertical.GetValue();
00156
00157 if (((glictPos*)wparam)->x > this->clipleft &&
00158 ((glictPos*)wparam)->x < this->clipright &&
00159 ((glictPos*)wparam)->y > this->cliptop &&
00160 ((glictPos*)wparam)->y < this->clipbottom) {
00161
00162
00163 if (evt == GLICT_MOUSEDOWN && this->OnMouseDown) {
00164 if (this->OnMouseDown) {
00165
00166 glictPos relpos;
00167 relpos.x = ((glictPos*)wparam)->x - this->left - this->containeroffsetx + this->virtualpos.x;
00168 relpos.y = ((glictPos*)wparam)->y - this->top - this->containeroffsety + this->virtualpos.y;
00169 this->OnMouseDown(&relpos, this);
00170 }
00171
00172 }
00173 sbVertical.SetPos(sbVertical.GetX(), sbVertical.GetY() + sbVertical.GetValue());
00174 if (sbVertical.CastEvent(evt, wparam, lparam, returnvalue)) {
00175 sbVertical.SetPos(sbVertical.GetX(), sbVertical.GetY() - sbVertical.GetValue());
00176
00177 return true;
00178 }
00179 sbVertical.SetPos(sbVertical.GetX(), sbVertical.GetY() - sbVertical.GetValue());
00180
00181
00182
00183 return DefaultCastEvent(evt, wparam, lparam, returnvalue);
00184
00185
00186
00187
00188 } else {
00189
00190 return DefaultCastEvent(evt, wparam, lparam, returnvalue);
00191 }
00192
00193 break;
00194 }
00195 }
00196
00197 return false;
00198 }
00199
00208 void glictPanel::SetBGActiveness(bool bg) {
00209 bgactive = bg;
00210 }
00211
00212
00216 void glictPanel::VirtualScrollBottom() {
00217 if (virtualsize.h > height) {
00218 sbVertical.SetMax((int)(virtualsize.h - height));
00219 sbVertical.SetValue(sbVertical.GetMax());
00220 } else {
00221 sbVertical.SetValue(0);
00222 }
00223 }
00224
00230 void glictPanel::SetVirtualSize(float w, float h) {
00231
00232 bool newheightbigger = h <= height;
00233
00234 glictContainer::SetVirtualSize(w,h);
00235
00236
00237 sbVertical.SetStep(10);
00238 sbHorizontal.SetStep(10);
00239
00240 if (newheightbigger) {
00241 VirtualScrollBottom();
00242 }
00243
00244 }
00245
00246
00252 #include <stdlib.h>
00253 void glictPanel::SetSkin(glictSkinner* skin) {
00254
00255 this->skin = skin;
00256 }