00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
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
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
00085 HIDManager * hidmanager = HIDManager::get_instance();
00086
00087
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 }