GLICT/panel.cpp

00001 /*
00002         GLICT - Graphics Library Interface Creation Toolkit
00003         Copyright (C) 2006-2007 OBJECT Networks
00004 
00005         This library is free software; you can redistribute it and/or
00006         modify it under the terms of the GNU Library General Public
00007         License as published by the Free Software Foundation; either
00008         version 2 of the License, or (at your option) any later version.
00009 
00010         This library is distributed in the hope that it will be useful,
00011         but WITHOUT ANY WARRANTY; without even the implied warranty of
00012         MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00013         Library General Public License for more details.
00014 
00015         You should have received a copy of the GNU Library General Public
00016         License along with this library; if not, write to the Free
00017         Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
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         //printf("Panel generated.\n");
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         //sbHorizontal.SetVisible(false);// FIXME horizontal scrollbar widget must be done in order to be implemented here
00046 
00047         skin = NULL;
00048 }
00049 glictPanel::~glictPanel() {
00050 
00051 }
00052 void glictPanel::Paint() {
00053         if (!GetVisible()) return;
00054 
00055 
00056 /*
00057     if (virtualsize.w > width) {
00058         sbHorizontal.SetHeight(10);
00059         sbHorizontal.SetWidth(width - (virtualsize.h > height ? 10 : 0));
00060         sbHorizontal.SetPos(0, height - 10);
00061         sbHorizontal.SetVisible(true);
00062 
00063 
00064         sbHorizontal.SetMin(0);
00065         sbHorizontal.SetMax(virtualsize.w);
00066     }*/
00067 
00068 
00069 
00070     if (virtualsize.h > height) {
00071         sbVertical.SetWidth(10);
00072         sbVertical.SetHeight(height );//- (virtualsize.w > width ? 10 : 0));
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; // scrollbar related begin
00154             p.x = ((glictPos*)wparam)->x;
00155             p.y = ((glictPos*)wparam)->y - sbVertical.GetValue(); // scrollbar related end
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                 //printf("EVENT WITHIN PANEL %s (%s)...!\n", objtype, parent ? parent->objtype : "NULL");
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)) { // scrollbar related begin
00175                     sbVertical.SetPos(sbVertical.GetX(), sbVertical.GetY() - sbVertical.GetValue());
00176 
00177                     return true;
00178                 } // scrollbar related end
00179                 sbVertical.SetPos(sbVertical.GetX(), sbVertical.GetY() - sbVertical.GetValue());
00180 
00181 
00182                                 // if a child caught click, we dont handle it otherwise
00183                                 return DefaultCastEvent(evt, wparam, lparam, returnvalue);
00184 
00185                                 //return DefaultCastEvent(evt, wparam, lparam, returnvalue); // replace &p with wparam
00186                                 // otherwise we could handle it mroe but we'll simply tell we didnt proces it
00187 
00188                         } else {
00189                             //printf("PANEL DID NOT FIND THIS THING. X, Y: %d %d Clip: %d %d %d %d\n", ((glictPos*)wparam)->x, ((glictPos*)wparam)->y, clipleft, clipright, cliptop, clipbottom);
00190                             return DefaultCastEvent(evt, wparam, lparam, returnvalue);
00191                         }
00192                         //printf("It occured outside the panel, ignored.\n");
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 }

SourceForge.net Logo
generated with doxygen 1.5.3 on Mon Oct 29 18:09:26 2007