BindGump.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 "BindGump.h"
00021 
00022 #include "Font.h"
00023 #include "RenderSurface.h"
00024 #include "TextWidget.h"
00025 #include "Mouse.h"
00026 
00027 #include "HIDManager.h"
00028 
00029 #include "IDataSource.h"
00030 #include "ODataSource.h"
00031 
00032 DEFINE_RUNTIME_CLASSTYPE_CODE(BindGump,ModalGump);
00033 
00034 BindGump::BindGump(Pentagram::istring * b, Gump * g): ModalGump(0, 0, 160, 80), binding(b), invoker(g)
00035 {
00036 }
00037 
00038 BindGump::~BindGump()
00039 {
00040 }
00041 
00042 void BindGump::InitGump(Gump* newparent, bool take_focus)
00043 {
00044         ModalGump::InitGump(newparent, take_focus);
00045 
00047         std::string bindtext = "Press any key or button.\n\nPress ESCAPE to cancel\nor BACKSPACE to clear";
00048         Gump * widget = new TextWidget(0, 0, bindtext, true, 6, 0, 0,
00049                                                                    Pentagram::Font::TEXT_CENTER);
00050         widget->InitGump(this);
00051         widget->setRelativePosition(TOP_CENTER, 0, 8);
00052 }
00053 
00054 
00055 void BindGump::PaintThis(RenderSurface* surf, sint32 lerp_factor, bool scaled)
00056 {
00057         uint32 rgb = 0x000000;
00058         surf->Fill32(rgb, 0, 0, dims.w, dims.h);
00059 
00060         Gump::PaintThis(surf, lerp_factor, scaled);
00061 }
00062 
00063 bool BindGump::OnKeyDown(int key, int mod)
00064 {
00065         if (key != SDLK_ESCAPE && binding)
00066         {
00067                 HIDManager * hidmanager = HIDManager::get_instance();
00068                 if (key == SDLK_BACKSPACE) {
00069                         hidmanager->unbind(*binding);
00070                 }
00071                 else {
00072                         Pentagram::istring control = SDL_GetKeyName(static_cast<SDLKey>(key));
00073 //                      hidmanager->bind(control, *binding);
00074                 }
00075                 if (invoker)
00076                         invoker->ChildNotify(this, UPDATE);
00077         }
00078         Close();        
00079         return true;
00080 }
00081 
00082 Gump * BindGump::OnMouseDown(int button, int mx, int my)
00083 {
00084         //Pentagram::istring control = GetMouseButtonName(static_cast<MouseButton>(button));
00085         HIDManager * hidmanager = HIDManager::get_instance();
00086 //      if (binding)
00087 //              hidmanager->bind(control, *binding);
00088         if (invoker)
00089                 invoker->ChildNotify(this, UPDATE);
00090         Close();
00091         return this;
00092 }
00093 
00094 bool BindGump::loadData(IDataSource* ids)
00095 {
00096         CANT_HAPPEN_MSG("Trying to load ModalGump");
00097         return true;
00098 }
00099 
00100 void BindGump::saveData(ODataSource* ods)
00101 {
00102         CANT_HAPPEN_MSG("Trying to save ModalGump");
00103 }

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