Update of /cvsroot/planeshift/planeshift/src/client/gui/base In directory usw-pr-cvs1:/tmp/cvs-serv4045/src/client/gui/base Modified Files: psbutton.cpp psbutton.h pscomp.cpp pscomp.h psdialog.cpp psdialog.h pstext.cpp pstextin.cpp pstextin.h Log Message: GUI changes Index: psbutton.cpp =================================================================== RCS file: /cvsroot/planeshift/planeshift/src/client/gui/base/psbutton.cpp,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** psbutton.cpp 2001/11/20 23:24:59 1.1 --- psbutton.cpp 2002/01/28 03:58:31 1.2 *************** *** 80,83 **** --- 80,84 ---- void psButton::DrawFrame() { + CalculatePosition(); if(!idle || !pressed) return; *************** *** 85,92 **** if(pushed) pressed->DrawScaled(dialog->GetDialogManager()->GetG3D(), ! x, y, width, height); else idle->DrawScaled(dialog->GetDialogManager()->GetG3D(), ! x, y, width, height); } --- 86,93 ---- if(pushed) pressed->DrawScaled(dialog->GetDialogManager()->GetG3D(), ! actualX, actualY, width, height); else idle->DrawScaled(dialog->GetDialogManager()->GetG3D(), ! actualX, actualY, width, height); } *************** *** 96,100 **** { pushed = psComponent::HandleMouseDown(ix, iy, ibutton); - return pushed; } --- 97,100 ---- Index: psbutton.h =================================================================== RCS file: /cvsroot/planeshift/planeshift/src/client/gui/base/psbutton.h,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** psbutton.h 2001/11/20 23:24:59 1.1 --- psbutton.h 2002/01/28 03:58:31 1.2 *************** *** 24,28 **** #include "pscomp.h" ! class psManager; class psDialog; class csSimplePixmap; --- 24,28 ---- #include "pscomp.h" ! //class psManager; class psDialog; class csSimplePixmap; Index: pscomp.cpp =================================================================== RCS file: /cvsroot/planeshift/planeshift/src/client/gui/base/pscomp.cpp,v retrieving revision 1.3 retrieving revision 1.4 diff -C2 -d -r1.3 -r1.4 *** pscomp.cpp 2002/01/20 01:28:09 1.3 --- pscomp.cpp 2002/01/28 03:58:31 1.4 *************** *** 60,64 **** bool psComponent::HandleMouseUp(int ix, int iy, int) { ! if(ix >= x && ix <= x + width && iy >= y && iy <= y + height) return true; return false; --- 60,65 ---- bool psComponent::HandleMouseUp(int ix, int iy, int) { ! CalculatePosition(); ! if(ix >= actualX && ix <= actualX + width && iy >= actualY && iy <= actualY + height) return true; return false; *************** *** 69,73 **** bool psComponent::HandleMouseDown(int ix, int iy, int) { ! if(ix >= x && ix <= x + width && iy >= y && iy <= y + height) return true; return false; --- 70,75 ---- bool psComponent::HandleMouseDown(int ix, int iy, int) { ! CalculatePosition(); ! if(ix >= actualX && ix <= (actualX + width) && iy >= actualY && iy <= (actualY + height)) return true; return false; *************** *** 89,90 **** --- 91,97 ---- //------------------------------------------------------------------- + void psComponent::CalculatePosition() + { + actualX = dialog->GetX() + x; + actualY = dialog->GetY() + y; + } Index: pscomp.h =================================================================== RCS file: /cvsroot/planeshift/planeshift/src/client/gui/base/pscomp.h,v retrieving revision 1.3 retrieving revision 1.4 diff -C2 -d -r1.3 -r1.4 *** pscomp.h 2002/01/20 01:28:09 1.3 --- pscomp.h 2002/01/28 03:58:31 1.4 *************** *** 61,64 **** --- 61,66 ---- void Hide(){ invis = true; } void Show(){ invis = false; } + int GetID() { return ID; } + void CalculatePosition(); protected: *************** *** 73,76 **** --- 75,80 ---- int x, y; bool invis; + int actualX; + int actualY; }; Index: psdialog.cpp =================================================================== RCS file: /cvsroot/planeshift/planeshift/src/client/gui/base/psdialog.cpp,v retrieving revision 1.7 retrieving revision 1.8 diff -C2 -d -r1.7 -r1.8 *** psdialog.cpp 2002/01/20 01:28:09 1.7 --- psdialog.cpp 2002/01/28 03:58:31 1.8 *************** *** 43,47 **** iGraphics2D* g2d = dmanager->GetG2D(); g2d->IncRef(); ! width = g2d->GetWidth(); height = g2d->GetHeight(); x = y = 0; --- 43,47 ---- iGraphics2D* g2d = dmanager->GetG2D(); g2d->IncRef(); ! width = g2d->GetWidth(); height = g2d->GetHeight(); x = y = 0; *************** *** 50,57 **** bg = NULL; bgcolor = -1; - compList = NULL; - totalCompArray = 0; - totalComp = 0; tiledBackground = false; } --- 50,65 ---- bg = NULL; bgcolor = -1; tiledBackground = false; + + isVisible = false; + + mouseButtonsDown[0] = false; + mouseButtonsDown[1] = false; + mouseButtonsDown[2] = false; + + isMoveable = false; + clickY = clickX = 1; + tiledBackground = false; + alpha = 0; } *************** *** 62,67 **** if(bg) delete bg; ! if(compList) ! delete [] compList; } --- 70,79 ---- if(bg) delete bg; ! ! while ( components.Length() > 0 ) ! { ! delete components[0]; ! components.Delete(0); ! } } *************** *** 80,90 **** else bg->DrawScaled(dmanager->GetG3D(), x, y, ! width, height); } ! if(compList) { ! for(int i = 0; i < totalComp; i++) ! if(compList[i] != NULL && !compList[i]->IsInvis()) compList[i]->DrawFrame(); } } --- 92,105 ---- else bg->DrawScaled(dmanager->GetG3D(), x, y, ! width, height,alpha); } ! for ( int i = 0; i < components.Length(); i++ ) { ! if ( !components[i]->IsInvis() ) ! { ! components[i]->CalculatePosition(); ! components[i]->DrawFrame(); ! } } } *************** *** 92,141 **** //------------------------------------------------------------------- ! bool psDialog::HandleMouseDown(int x, int y, int button) { ! bool retval = false; ! if(compList) { ! for(int i = 0; i < totalComp; i++) ! { ! if(compList[i] !=NULL && compList[i]->HandleMouseDown(x, y, button)) ! retval = true; ! } ! } - return retval; - } ! //------------------------------------------------------------------- ! bool psDialog::HandleMouseUp(int x, int y, int button) ! { ! bool retval = false; ! if(compList) { ! for(int i = 0; i < totalComp; i++) ! { ! if(compList[i] !=NULL && compList[i]->HandleMouseUp(x, y, button)) ! retval = true; ! } } ! ! return retval; } //------------------------------------------------------------------- ! bool psDialog::HandleKeyDown(int key, char c, int modifier) { bool retval = false; - if(compList) - { - for(int i = 0; i < totalComp; i++) - { ! if(compList[i]!=NULL && compList[i]->HandleKeyDown(key, c, modifier)) ! retval = true; ! } } --- 107,148 ---- //------------------------------------------------------------------- ! bool psDialog::HandleMouseDown(int X, int Y, int button) { ! if (!(( X >= x && X < (x + width)) && ! ( Y >= y && Y < (y + height))) ) { ! return false; ! } ! mouseButtonsDown[button] = true; ! if ( isMoveable && mouseButtonsDown[2] ) { ! clickX = X; ! clickY = Y; } ! bool retval = false; ! for ( int z = 0; z < components.Length(); z++ ) ! { ! if (components[z]->HandleMouseDown(X,Y,button)) ! retval = true; ! } ! ! return retval; } //------------------------------------------------------------------- ! bool psDialog::HandleMouseUp(int x, int y, int button) { + mouseButtonsDown[button] = false; bool retval = false; ! for ( int z = 0; z < components.Length(); z++ ) ! { ! retval = components[z]->HandleMouseUp(x,y,button); ! components[z]->CalculatePosition(); } *************** *** 143,322 **** } - //------------------------------------------------------------------- - - void psDialog::ExpandComponentsArray(int total) - { - // never shrink the array below the total of already registered - // datas - if(total < totalComp) - return; - - psComponent** temp = new psComponent*[total]; - - // the array is not necessarily full of data. It could contain - // nothingness. So copy only registered data instead of the - // whole array - for(int i = 0; i < totalComp; i++) - temp[i] = compList[i]; - - if(compList) - delete [] compList; - compList = new psComponent*[total]; - compList = temp; - totalCompArray = total; - } //------------------------------------------------------------------- ! psButton* psDialog::AddButton(int ix, int iy, int iwidth, int iheight, ! const char* pixmapUpName, ! const char* pixmapDownName, ! void (*action)(psDialog* idialog, int iID)) { ! if((totalComp + 1) > totalCompArray) ! ExpandComponentsArray(totalCompArray + ! COMPONENT_EXPANSION_SIZE); ! ! csSimplePixmap *buttonu = NULL, *buttond = NULL; ! // load other necessary images ! if(pixmapUpName) ! if(!(buttonu = dmanager->CreateSprite(pixmapUpName))) ! return NULL; ! ! if(pixmapDownName) ! if(!(buttond = dmanager->CreateSprite(pixmapDownName))) ! return NULL; ! ! compList[totalComp] = new psButton(this, totalComp); ! psButton* caster = (psButton*)compList[totalComp]; ! if(!(caster->Initialize(ix + x, iy + y, iwidth, iheight, ! buttonu, buttond, action))) { ! delete compList[totalComp]; ! compList[totalComp] = NULL; ! return NULL; } ! totalComp++; ! return (psButton*)compList[totalComp-1]; } //------------------------------------------------------------------- ! psDragPlane *psDialog::AddDragPlane(int ix, int iy, int iwidth, int iheight, ! const char* bg, ! void (*action)(psDialog* idialog, int iID), ! uint8 alpha) { ! if((totalComp + 1) > totalCompArray) ! ExpandComponentsArray(totalCompArray + ! COMPONENT_EXPANSION_SIZE); ! ! csSimplePixmap *plane = NULL; ! // load other necessary images ! if(bg) ! if(!(plane = dmanager->CreateSprite(bg))) ! return NULL; ! ! compList[totalComp] = new psDragPlane(this, totalComp, 5); ! psDragPlane* caster = (psDragPlane*)compList[totalComp]; ! if(!(caster->Initialize(ix + x, iy + y, iwidth, iheight, ! plane,action,alpha))) { ! delete compList[totalComp]; ! compList[totalComp] = NULL; ! return NULL; } ! totalComp++; ! return (psDragPlane *)compList[totalComp-1]; } //------------------------------------------------------------------- ! bool psDialog::AddButton(int ix, int iy, int iwidth, int iheight, ! const char* pixmapUpName, ! const char* pixmapDownName, ! int itx, int ity, ! void (*action)(psDialog* idialog, int iID)) { ! if((totalComp + 1) > totalCompArray) ! ExpandComponentsArray(totalCompArray + ! COMPONENT_EXPANSION_SIZE); ! ! csSimplePixmap *buttonu = NULL, *buttond = NULL; ! // load other necessary images ! if(pixmapUpName) ! { ! if(!(buttonu = dmanager->CreateSprite(pixmapUpName))) ! return false; ! else ! buttonu->SetTextureRectangle(itx, ity, iwidth, iheight); ! } ! ! if(pixmapDownName) ! { ! if(!(buttond = dmanager->CreateSprite(pixmapDownName))) ! return false; ! else ! buttond->SetTextureRectangle(itx, ity, iwidth, iheight); ! } ! ! compList[totalComp] = new psButton(this, totalComp); ! psButton* caster = (psButton*)compList[totalComp]; ! if(!(caster->Initialize(ix + x, iy + y, iwidth, iheight, ! buttonu, buttond, action))) ! { ! delete compList[totalComp]; ! compList[totalComp] = NULL; ! return false; ! } - totalComp++; - return true; } - //------------------------------------------------------------------- - - psText* psDialog::AddText(int ix, int iy, int iwidth, int iheight, - const char* text, int color) - { - if((totalComp + 1) > totalCompArray) - ExpandComponentsArray(totalCompArray + - COMPONENT_EXPANSION_SIZE); - - compList[totalComp] = new psText(this, totalComp); - psText* tcaster = (psText*)compList[totalComp]; - if(!(tcaster->Initialize(ix + x, iy + y, iwidth, iheight))) - return NULL; ! tcaster->SetText(text, color); ! totalComp++; ! return tcaster; } ! //------------------------------------------------------------------- ! psTextInput* psDialog::AddTextInput(int ix, int iy, int iwidth, int color, ! bool focused) { ! if((totalComp + 1) > totalCompArray) ! ExpandComponentsArray(totalCompArray + ! COMPONENT_EXPANSION_SIZE); ! ! compList[totalComp] = new psTextInput(this, totalComp); ! psTextInput* tcaster = (psTextInput*)compList[totalComp]; ! if(!(tcaster->Initialize(ix + x, iy + y, iwidth, 0))) ! return NULL; ! ! tcaster->SetColor(color); ! if(focused) ! tcaster->SetFocused(true); ! totalComp++; - return tcaster; } - //------------------------------------------------------------------- --- 150,223 ---- } //------------------------------------------------------------------- ! bool psDialog::HandleMouseMove( int ix, int iy ) { ! if ( mouseButtonsDown[2] && isMoveable ) { ! SetPos(x+(ix-clickX), y+(iy-clickY)); ! ! clickY = iy; ! clickX = ix; ! return true; } ! return false; } //------------------------------------------------------------------- ! bool psDialog::HandleKeyDown(int key, char c, int modifier) { ! bool retval = false; ! for(int i = 0; i < components.Length(); i++) { ! retval = components[i]->HandleKeyDown(key, c, modifier); } ! return retval; } + //------------------------------------------------------------------- ! bool psDialog::AddComp(psComponent* cmp) { ! components.Push(cmp); } ! //----------------------------------------------------------------------------- ! bool psDialog::DelComp(int id) ! { ! for ( int i = 0; i < components.Length(); i++ ) ! { ! if ( components[i]->GetID() == id ) ! { ! delete components[i]; ! components.Delete(i); ! return true; ! } ! } ! return false; } ! //----------------------------------------------------------------------------- ! psComponent* psDialog::GetComp(int id) { ! for ( int i = 0; i < components.Length(); i++ ) ! { ! if ( components[i]->GetID() == id ) ! { ! return components[i]; ! } ! } ! return NULL; } Index: psdialog.h =================================================================== RCS file: /cvsroot/planeshift/planeshift/src/client/gui/base/psdialog.h,v retrieving revision 1.9 retrieving revision 1.10 diff -C2 -d -r1.9 -r1.10 *** psdialog.h 2002/01/19 19:08:02 1.9 --- psdialog.h 2002/01/28 03:58:31 1.10 *************** *** 21,28 **** #define PS_DIALOG_H ! class psManager; class psDialogManager; class csSimplePixmap; - class psButton; class psComponent; --- 21,27 ---- #define PS_DIALOG_H ! //class psManager; class psDialogManager; class csSimplePixmap; class psComponent; *************** *** 30,39 **** #define COMPONENT_EXPANSION_SIZE 8 ! #include "psdragplane.h" ! #include "psbutton.h" ! #include "pstextin.h" ! #include "pstext.h" ! #include "../psgwchat.h" class psDialog { --- 29,38 ---- #define COMPONENT_EXPANSION_SIZE 8 ! #include "csutil/garray.h" ! //CS vector class ! CS_TYPEDEF_GROWING_ARRAY(vect, psComponent*); + + class psDialog { *************** *** 61,67 **** /// This is where we actually handle the action virtual bool HandleMouseUp(int x, int y, int button); ! virtual bool HandleMouseMove(int , int ) ! { return true;} ! --- 60,64 ---- /// This is where we actually handle the action virtual bool HandleMouseUp(int x, int y, int button); ! virtual bool HandleMouseMove(int x, int y); *************** *** 75,132 **** */ psDialogManager* GetDialogManager() { return dmanager; }; - - /// manual expansion is recommended - void ExpandComponentsArray(int total); - - /** - * this function expands array automatically by EXPAND_SIZE - * if the array cannot hold the button. Otherwise, it just - * add another button to the list - */ - psButton* AddButton(int ix, int iy, int iwidth, int iheight, - const char* pixmapUpName, - const char* pixmapDownName, - void (*action)(psDialog* idialog, int iID)); - - - psDragPlane *AddDragPlane(int ix, int iy, int iwidth, int iheight, - const char* bg , - void (*action)(psDialog* idialog, int iID), - uint8 alpha=0); - - /** - * this function overload the other AddButton and with 2 - * additional int coordinates to specify the SetRectangle - * coordinates of the textures (width and height will be - * the same as the iwidth and iheight) - */ - bool AddButton(int ix, int iy, int iwidth, int iheight, - const char* pixmapUpName, - const char* pixmapDownName, - int itx, int ity, - void (*action)(psDialog* idialog, int iID)); - - - /** - * this function expands array automatically by EXPAND_SIZE - * if the array cannot hold the text. Otherwise, it just - * add another text to the list - */ - - psText* AddText(int ix, int iy, int iwidth, int iheight, - const char* text, int color = -1); - - - - psTextInput* AddTextInput(int ix, int iy, int iwidth, int color = -1, - bool focused = false); - void SetTiledBackground(bool b) { tiledBackground = b; }; - psComponent *operator[](int index) - { - return (index < totalComp) ? compList[index] : NULL; - }; - /** * this function allows the desktop to forward chat messages to the --- 72,77 ---- *************** *** 136,139 **** --- 81,104 ---- { }; + //Attributes + char* GetName() { return name; } + void SetName(const char* Name) { strcpy(name, Name); } + void SetVisible( int state ) { isVisible = state; } + bool IsVisible() { return isVisible; } + bool IsMoveable() { return isMoveable; } + void SetMoveable(bool state) { isMoveable = state; } + + //Component manipulation + bool AddComp(psComponent* com); + bool DelComp(int ID); + psComponent* GetComp(int ID); + + // Positional data + void SetPos( int ix, int iy) { x = ix; y = iy;} + int GetX() { return x;} + int GetY() { return y;} + int GetWidth() { return width; } + int GetHeight() { return height; } + protected: /// pointer to dialog manager *************** *** 155,167 **** int bgcolor; - /// pointer to component list - psComponent** compList; - - /// how many components the array can hold - int totalCompArray; - /// how many components present - int totalComp; bool tiledBackground; }; --- 120,135 ---- int bgcolor; bool tiledBackground; + + char name[16]; + bool isVisible; + bool mouseButtonsDown[3]; + bool isMoveable; + + int clickX, clickY; + + vect components; + int alpha; }; Index: pstext.cpp =================================================================== RCS file: /cvsroot/planeshift/planeshift/src/client/gui/base/pstext.cpp,v retrieving revision 1.8 retrieving revision 1.9 diff -C2 -d -r1.8 -r1.9 *** pstext.cpp 2002/01/19 23:25:06 1.8 --- pstext.cpp 2002/01/28 03:58:31 1.9 *************** *** 86,98 **** bool psText::HandleMouseDown(int ix, int iy, int ibutton) { bool change = false; ! if(ix >= (x + width) && ix <= (x + width + 15) && ibutton == 1 && scrollbar) { ! if(iy >= y && iy <= (y + 15)) { currentTopLine--; } ! if(iy >= (y + height - 15) && iy <= (y + height)) { currentTopLine++; --- 86,99 ---- bool psText::HandleMouseDown(int ix, int iy, int ibutton) { + CalculatePosition(); bool change = false; ! if(ix >= (actualX + width) && ix <= (actualX + width + 15) && ibutton == 1 && scrollbar) { ! if(iy >= actualY && iy <= (actualY + 15)) { currentTopLine--; } ! if(iy >= (actualY + height - 15) && iy <= (actualY + height)) { currentTopLine++; *************** *** 260,270 **** { iGraphics2D *g2d = dialog->GetDialogManager()->GetG2D(); ! if(scrollbar) { up->DrawScaled(dialog->GetDialogManager()->GetG3D(), ! x + width, y, 15, 15); down->DrawScaled(dialog->GetDialogManager()->GetG3D(), ! x + width, y + height - 15, 15, 15); } --- 261,271 ---- { iGraphics2D *g2d = dialog->GetDialogManager()->GetG2D(); ! CalculatePosition(); if(scrollbar) { up->DrawScaled(dialog->GetDialogManager()->GetG3D(), ! actualX + width, actualY, 15, 15); down->DrawScaled(dialog->GetDialogManager()->GetG3D(), ! actualX + width, actualY + height - 15, 15, 15); } *************** *** 273,277 **** if((i * lineHeight) <= height) g2d->Write(dialog->GetDialogManager()->GetDefaultFont(), ! x, y + (i * lineHeight), text[i + currentTopLine].color, -1, text[i + currentTopLine].text); --- 274,278 ---- if((i * lineHeight) <= height) g2d->Write(dialog->GetDialogManager()->GetDefaultFont(), ! actualX, actualY + (i * lineHeight), text[i + currentTopLine].color, -1, text[i + currentTopLine].text); Index: pstextin.cpp =================================================================== RCS file: /cvsroot/planeshift/planeshift/src/client/gui/base/pstextin.cpp,v retrieving revision 1.6 retrieving revision 1.7 diff -C2 -d -r1.6 -r1.7 *** pstextin.cpp 2002/01/19 19:08:02 1.6 --- pstextin.cpp 2002/01/28 03:58:31 1.7 *************** *** 50,53 **** --- 50,55 ---- focused = false; blink = true; + + background = NULL; } *************** *** 111,116 **** g2d->IncRef(); if(text) ! g2d->Write(font, x, y, color, -1, text); csTicks currentTime = csGetTicks(); --- 113,122 ---- g2d->IncRef(); + if ( background ) + background->DrawScaled(dialog->GetDialogManager()->GetG3D(), + actualX, actualY, width, height, 0); + if(text) ! g2d->Write(font, actualX, actualY, color, -1, text); csTicks currentTime = csGetTicks(); *************** *** 121,125 **** } ! if(focused && blink) { int tempx, tempy; --- 127,131 ---- } ! if(focused && blink && dialog->GetDialogManager()->GetCurrentDialog() == dialog ) { int tempx, tempy; *************** *** 131,135 **** tempy = height; } ! g2d->DrawBox(x + tempx, y, 3, tempy, color); } --- 137,141 ---- tempy = height; } ! g2d->DrawBox(actualX + tempx, actualY, 3, tempy, color); } Index: pstextin.h =================================================================== RCS file: /cvsroot/planeshift/planeshift/src/client/gui/base/pstextin.h,v retrieving revision 1.3 retrieving revision 1.4 diff -C2 -d -r1.3 -r1.4 *** pstextin.h 2002/01/18 02:51:44 1.3 --- pstextin.h 2002/01/28 03:58:31 1.4 *************** *** 63,66 **** --- 63,68 ---- void SetText(const char* iText); + void SetBackGround(csSimplePixmap* bg) { background = bg; } + protected: /// holds the string *************** *** 79,82 **** --- 81,86 ---- csTicks initialTime; bool blink; + + csSimplePixmap* background; }; |