GLICT/messagebox.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 "messagebox.h"
00020 #include "globals.h"
00021 
00022 void _glictMessageBox_Closer(glictPos* relmousepos, glictContainer* caller) {
00023         void(*UponClick)(glictPos* relmousepos, glictContainer* callerclass);
00024         glictContainer* parent=caller->GetParent(); // this gets the messagebox
00025         glictContainer* parent2=parent->GetParent(); // this gets the parent of messagebox
00026         UponClick = dynamic_cast<glictMessageBox*>(parent)->OnDismissFunction;
00027         parent2->RemoveObject(parent);
00028         if (UponClick) UponClick(relmousepos, parent);
00029 
00030 }
00031 
00032 glictMessageBox::glictMessageBox() {
00033         //printf("MessageBox generated.\n");
00034 
00035 
00036 
00037         this->AddObject(&pnlMessage);
00038         pnlMessage.SetHeight(90);
00039         pnlMessage.SetWidth(300);
00040         pnlMessage.SetPos(0,0);//containeroffsety);
00041         pnlMessage.SetBGColor(0.75,0.75,0.75,1.);
00042     pnlMessage.SetBGActiveness(false);
00043 
00044         this->AddObject(&btnOk);
00045         btnOk.SetBGColor(0.6,0.6,0.6,1.0);
00046         btnOk.SetOnClick(_glictMessageBox_Closer);
00047         btnOk.SetCaption("Ok");
00048         btnOk.SetHeight(16);
00049         btnOk.SetWidth(64);
00050         btnOk.SetPos(300/2 - 32, 100 - 21);
00051         btnOk.Focus(NULL);
00052 
00053         SetWidth(300);
00054         SetHeight(100);
00055 
00056         this->SetCaption("Message Box");
00057         this->SetMessage("Sample message box.");
00058         strcpy(objtype, "MessageBox");
00059 
00060         this->focusable = true;
00061 
00062         this->OnDismissFunction = NULL;
00063 
00064         FixContainerOffsets();
00065 }
00066 
00067 
00068 glictMessageBox::~glictMessageBox() {
00069         this->RemoveObject(&btnOk);
00070 }
00071 
00072 void glictMessageBox::Paint() {
00073         if (!GetVisible()) return;
00074 
00075         glictWindow::Paint();
00076 }
00077 
00078 void glictMessageBox::SetMessage(std::string msg) {
00079         this->mesg = msg;
00080         pnlMessage.SetCaption(msg);
00081 }
00082 
00083 void glictMessageBox::SetOnDismiss(void(*OnDism)(glictPos* relmousepos, glictContainer* callerclass)) {
00084         OnDismissFunction = OnDism;
00085 }
00086 
00087 void glictMessageBox::SetHeight(int h) {
00088         glictWindow::SetHeight(h);
00089 
00090         btnOk.SetPos(width/2 - 32, height - 21);
00091         if (this->GetEnabled())
00092                 pnlMessage.SetHeight(h-10 - (glictGlobals.windowBodySkin ? glictGlobals.windowBodySkin->GetBottomSize()->h : 0));
00093         else
00094                 pnlMessage.SetHeight(h - (glictGlobals.windowBodySkin ? glictGlobals.windowBodySkin->GetBottomSize()->h : 0));
00095         pnlMessage.SetPos(0,0);//containeroffsety);
00096 
00097 }
00098 void glictMessageBox::SetWidth(int w) {
00099         glictWindow::SetWidth(w);
00100 
00101         btnOk.SetPos(width/2 - 32, height - 21);
00102         pnlMessage.SetWidth(w);
00103 
00104 }
00105 void glictMessageBox::SetEnabled(bool enabled) {
00106         glictContainer::SetEnabled(enabled);
00107         btnOk.SetVisible(enabled);
00108         this->SetHeight(this->height);
00109 }
00110 void glictMessageBox::SetBGColor(float r, float g, float b, float a) {
00111         glictWindow::SetBGColor(r,g,b,a);
00112         pnlMessage.SetBGColor(r,g,b,a);
00113 }

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