ControlsGump.cpp

Go to the documentation of this file.
00001 /*
00002  *  Copyright (C) 2004-2005  The Pentagram Team
00003  *
00004  *  This program is free software; you can redistribute it and/or modify
00005  *  it under the terms of the GNU General Public License as published by
00006  *  the Free Software Foundation; either version 2 of the License, or
00007  *  (at your option) any later version.
00008  *
00009  *  This program is distributed in the hope that it will be useful,
00010  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
00011  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00012  *  GNU General Public License for more details.
00013  *
00014  *  You should have received a copy of the GNU General Public License
00015  *  along with this program; if not, write to the Free Software
00016  *  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
00017  */
00018 
00019 #include "pent_include.h"
00020 #include "ControlsGump.h"
00021 
00022 #include "RenderSurface.h"
00023 #include "DesktopGump.h"
00024 #include "ButtonWidget.h"
00025 #include "TextWidget.h"
00026 #include "BindGump.h"
00027 #include "PagedGump.h"
00028 #include "HIDManager.h"
00029 
00030 #include "IDataSource.h"
00031 #include "ODataSource.h"
00032 
00033 static const int font = 9;
00034 
00035 class ControlEntryGump : public Gump
00036 {
00037 public:
00038         ENABLE_RUNTIME_CLASSTYPE();
00039         ControlEntryGump(int x, int y, int width, char * binding, char * name);
00040         virtual ~ControlEntryGump(void);
00041         virtual void InitGump(Gump* newparent, bool take_focus=true);
00042         virtual void ChildNotify(Gump *child, uint32 message);
00043         void init();
00044 protected:
00045         Pentagram::istring bindingName;
00046         std::string displayedName;
00047         Gump * button;
00048 };
00049 
00050 DEFINE_RUNTIME_CLASSTYPE_CODE(ControlEntryGump,Gump);
00051 
00052 ControlEntryGump::ControlEntryGump(int x, int y, int width, char * binding, char * name)
00053         :Gump(x, y, width, 5), bindingName(binding), displayedName(name)
00054 {
00055 }
00056 
00057 ControlEntryGump::~ControlEntryGump()
00058 {
00059 }
00060 
00061 void ControlEntryGump::InitGump(Gump* newparent, bool take_focus)
00062 {
00063         Gump::InitGump(newparent, take_focus);
00064 
00065         init();
00066 }
00067 
00068 void ControlEntryGump::init()
00069 {
00070         // close all children so we can simply use this method to re init
00071         std::list<Gump*>::iterator it;
00072         for (it = children.begin(); it != children.end(); ++it)
00073         {
00074                 Gump *g = *it;
00075                 if (! g->IsClosing())
00076                         g->Close();
00077         }
00078 
00079         std::vector<const char *> controls;
00080         HIDManager * hidmanager = HIDManager::get_instance();
00081 
00082         Pentagram::Rect rect;
00083         button = new ButtonWidget(0, 0, displayedName, true, font, 0x80D000D0);
00084         button->InitGump(this);
00085         button->GetDims(rect);
00086 
00087         dims.h = rect.h;
00088 
00089         //hidmanager->getBindings(bindingName, controls);
00090 /*      int x = 120;
00091         std::vector<const char *>::iterator i;
00092         for (i = controls.begin(); i != controls.end(); ++i)
00093         {
00094                 Gump * widget;
00095                 widget = new TextWidget(x, 0, *i, true, font);
00096                 widget->InitGump(this, false);
00097                 widget->GetDims(rect);
00098                 x += rect.w + 5;
00099         }
00100 */
00101 }
00102 
00103 void ControlEntryGump::ChildNotify(Gump *child, uint32 message)
00104 {
00105         ObjId cid = child->getObjId();
00106         if (message == ButtonWidget::BUTTON_CLICK)
00107         {
00108                 if (cid == button->getObjId())
00109                 {
00110                         ModalGump* gump = new BindGump(&bindingName, parent);
00111                         gump->InitGump(0);
00112                         gump->setRelativePosition(CENTER);
00113                 }
00114         }
00115         else if (message == BindGump::UPDATE)
00116         {
00117                 parent->ChildNotify(child, message);
00118         }
00119 }
00120 
00121 DEFINE_RUNTIME_CLASSTYPE_CODE(ControlsGump,Gump);
00122 
00123 ControlsGump::ControlsGump(): Gump(0, 0, 5, 5)
00124 {
00125 }
00126 
00127 ControlsGump::~ControlsGump()
00128 {
00129 }
00130 
00131 void ControlsGump::InitGump(Gump* newparent, bool take_focus)
00132 {
00133         Gump::InitGump(newparent, take_focus);
00134 
00135         dims.w = 220;
00136         dims.h = 120;
00137 
00138         Gump * widget = new TextWidget(0, 0, "Controls", true, font);
00139         widget->InitGump(this, false);
00140         widget = new TextWidget(120, 0, "Keys", true, font);
00141         widget->InitGump(this, false);
00142 }
00143 
00144 void ControlsGump::addEntry(char * binding, char * name, int & x, int & y)
00145 {
00146         Pentagram::Rect rect;
00147         Gump * widget = new ControlEntryGump(x, y, dims.w - x, binding, name);
00148         widget->InitGump(this);
00149         widget->GetDims(rect);
00150         y += rect.h;
00151 }
00152 
00153 void ControlsGump::ChildNotify(Gump *child, uint32 message)
00154 {
00155         if (message == BindGump::UPDATE)
00156         {
00157                 std::list<Gump*>::iterator it;
00158                 for (it = children.begin(); it != children.end(); ++it)
00159                 {
00160                         ControlEntryGump *g =  p_dynamic_cast<ControlEntryGump*>(*it);
00161                         if (g)
00162                                 g->init();
00163                 }
00164         }
00165 }
00166 
00167 void ControlsGump::PaintThis(RenderSurface* surf, sint32 lerp_factor, bool scaled)
00168 {
00169         Gump::PaintThis(surf, lerp_factor, scaled);
00170 }
00171 
00172 bool ControlsGump::OnKeyDown(int key, int mod)
00173 {
00174         return false;
00175 }
00176 
00177 //static
00178 void ControlsGump::showEngineMenu(PagedGump* pagedgump)
00179 {
00180         ControlsGump* gump = new ControlsGump();
00181         gump->InitGump(pagedgump, false);
00182         int x = 4;
00183         int y = 12;
00184         gump->addEntry("quickSave", "Quick Save", x, y);
00185         gump->addEntry("quickLoad", "Quick Save", x, y);
00186         gump->addEntry("avatarInStasis", "Stasis Mode", x, y);
00187         gump->addEntry("engineStats", "Engine Stats", x, y);
00188         gump->addEntry("paintEditorItems", "View Editor Items", x, y);
00189         gump->addEntry("itemLocator", "Locate Item", x, y);
00190         gump->addEntry("toggleFrameByFrame", "Single Frame Mode", x, y);
00191         gump->addEntry("advanceFrameByFrame", "Next Frame", x, y);
00192         gump->addEntry("toggleConsole", "Console", x, y);
00193 
00194         pagedgump->addPage(gump);
00195 }
00196 
00197 // static
00198 void ControlsGump::showU8Menu(PagedGump* pagedgump)
00199 {
00200         ControlsGump* gump = new ControlsGump();
00201         gump->InitGump(pagedgump, false);
00202         int x = 4;
00203         int y = 12;
00204         gump->addEntry("toggleCombat", "Combat Mode", x, y);
00205         gump->addEntry("openInventory", "Open Inventory", x, y);
00206         gump->addEntry("openBackpack", "Open Backpack", x, y);
00207         gump->addEntry("recall", "Recall", x, y);
00208         gump->addEntry("runFirstEgg", "First Scene", x, y);
00209         gump->addEntry("runExecutionEgg", "Execution Scene", x, y);
00210         gump->addEntry("u8ShapeViewer", "Shape Viewer", x, y);
00211         gump->addEntry("showMenu", "Menu", x, y);
00212         gump->addEntry("quit", "Quit", x, y);
00213 
00214         pagedgump->addPage(gump);
00215 }
00216 
00217 bool ControlsGump::loadData(IDataSource* ids)
00218 {
00219         return true;
00220 }
00221 
00222 void ControlsGump::saveData(ODataSource* ods)
00223 {
00224 }
00225 

Generated on Fri Jul 27 22:27:12 2007 for pentagram by  doxygen 1.4.7