GLICT/window.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 
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         /*this->glictContainer::AddObject(&panel);
00053         panel.SetPos(0, 14);
00054         panel.SetHeight(100);
00055         panel.SetWidth(100);
00056         panel.SetBGColor(1,0,0,1);*/
00057 
00058         //printf("Window generated.\n");
00059 
00060 }
00061 glictWindow::~glictWindow() {
00062         //this->glictWindow::RemoveObject(&panel);
00063 }
00064 
00074 void glictWindow::Paint() {
00075         if (!GetVisible()) return;
00076         //printf("window\n");
00077 
00078     if (!glictGlobals.windowBodySkin) { // if not skinned
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) { // if there's no title skin, but there's body skin
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 { // if skinned both title and body
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 ; //- (glictGlobals.windowBodySkin ? glictGlobals.windowBodySkin->GetBottomSize()->h : 0) ;
00104         r.left = this->left + containeroffsetx;
00105         r.right = this->right - containeroffsetx;// - (glictGlobals.windowBodySkin ? glictGlobals.windowBodySkin->GetRightSize()->w : 0) ;
00106 
00107         c.top = max(this->cliptop, this->top + containeroffsety);
00108         c.bottom = min(this->clipbottom, this->bottom - containeroffsety); //- (glictGlobals.windowBodySkin ? glictGlobals.windowBodySkin->GetBottomSize()->h : 0) );
00109         c.left = max(this->clipleft, this->left + containeroffsetx);
00110         c.right = min(this->clipright, this->right - containeroffsetx); //- (glictGlobals.windowBodySkin ? glictGlobals.windowBodySkin->GetRightSize()->w : 0) );
00111 
00112         this->OnPaint(&r, &c, this);
00113 
00114     }
00115 
00116 
00117         this->CPaint();
00118         //panel.Paint();
00119 
00120 
00121         // this is here so that scissoring resumes properly
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         int er;
00138         if ((er =glGetError())!=GL_NO_ERROR) printf("1EROR!!!\n");
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         int er;
00149         if ((er =glGetError())!=GL_NO_ERROR) printf("2EROR!!!\n");
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         //this->panel.SetBGColor(r,g,b,a);
00159 }
00176 bool glictWindow::CastEvent(glictEvents evt, void* wparam, long lparam, void* returnvalue) {
00177         //printf("Event of type %s passing through %s (%s)\n", EvtTypeDescriptor(evt), objtype, parent ? parent->objtype : "NULL");
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             //printf("Within %s\n", this->GetCaption().c_str());
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                                         // dont to defaultcastevent as it might call a child that's below our titlebar
00198                     //printf("DRAG!\n");
00199                                         return true;
00200                                 }
00201                         }
00202 
00203 
00204                         if (evt == GLICT_MOUSEDOWN) {
00205                                 // we dont want any child to catch this one so return true
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                 // if mouse drag is done outside object...
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) {// revert to defaults
00247         this->containeroffsetx = 0;
00248         this->containeroffsety = 12;
00249     } else {
00250         if (!glictGlobals.windowTitleSkin) { // all is placed inside body
00251             this->containeroffsetx = glictGlobals.windowBodySkin->GetLeftSize()->w;
00252             this->containeroffsety = glictGlobals.windowBodySkin->GetTopSize()->h;
00253 
00254 
00255         } else { // there are separate body and titlebar skin
00256             this->containeroffsetx = glictGlobals.windowBodySkin->GetLeftSize()->w; // FIXME should not work this way
00257             this->containeroffsety = glictGlobals.windowBodySkin->GetTopSize()->h;
00258         }
00259     }
00260     //printf("%s container offsets %d %d\n", objtype,  containeroffsetx, containeroffsety);
00261 }

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