1 /*--License: 2 Kyra Sprite Engine 3 Copyright Lee Thomason (Grinning Lizard Software) 2001-2005 4 www.grinninglizard.com/kyra 5 www.sourceforge.net/projects/kyra 6 7 Kyra is provided under the LGPL. 8 9 I kindly request you display a splash screen (provided in the HTML documentation) 10 to promote Kyra and acknowledge the software and everyone who has contributed to it, 11 but it is not required by the license. 12 13 --- LGPL License -- 14 15 This library is free software; you can redistribute it and/or 16 modify it under the terms of the GNU Lesser General Public 17 License as published by the Free Software Foundation; either 18 version 2.1 of the License, or (at your option) any later version. 19 20 This library is distributed in the hope that it will be useful, 21 but WITHOUT ANY WARRANTY; without even the implied warranty of 22 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 23 Lesser General Public License for more details. 24 25 You should have received a copy of the GNU Lesser General Public 26 License along with this library; if not, write to the Free Software 27 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 28 29 The full text of the license can be found in lgpl.txt 30 */ 31 32 #ifndef KYRA_ED_STATEMACINE_INCLUDED 33 #define KYRA_ED_STATEMACINE_INCLUDED 34 35 #include "../engine/krmath.h" 36 #include "../util/gllist.h" 37 #include "../engine/rle.h" 38 #include "../gui/console.h" 39 #include "states.h" 40 #include "sharedstate.h" 41 42 43 class Editor; 44 class KrAction; 45 46 enum { 47 COMMAND_HELP = 1, // Processed by the editor, not the states. 48 COMMAND_LOAD, 49 COMMAND_IMAGE, 50 COMMAND_SAVE, 51 COMMAND_NAME, 52 COMMAND_ACTION, 53 COMMAND_TILE, 54 COMMAND_DELETE_CURRENT_FRAME, 55 COMMAND_EXIT, 56 COMMAND_FPS, 57 COMMAND_DISPERSE, 58 COMMAND_SET_UPPERLEFT, 59 COMMAND_SET_LOWERRIGHT 60 }; 61 62 63 class CommandArgument 64 { 65 public: 66 enum 67 { 68 UNKNOWN, 69 STRING, 70 INTEGER 71 }; 72 CommandArgument()73 CommandArgument() : type( UNKNOWN ), integer( 0 ) {} 74 Type()75 int Type() const { return type; } String()76 const std::string& String() const { return str; } CharString()77 const char* CharString() const { return str.c_str(); } Integer()78 int Integer() const { return integer; } 79 SetString(const std::string & _str)80 void SetString( const std::string& _str ) { str = _str; type = STRING; } SetInteger(int i)81 void SetInteger( int i ) { integer = i; type = INTEGER; } 82 83 private: 84 int type; 85 std::string str; 86 int integer; 87 }; 88 89 90 class Editor : public IKrWidgetListener 91 { 92 public: 93 // The current state will construct itself as a child of the node. 94 Editor( SDL_Surface* surface ); 95 virtual ~Editor(); 96 97 // For use by the command processor and event loop: 98 // Inputs (mouse and command key) 99 void MouseDown( int x, int y, int button, int keymod ); 100 void MouseUp( int x, int y, int button, int keymod ); 101 void MouseMove( int x, int y ); 102 ZoomIn()103 virtual void ZoomIn() { state[currentState]->ZoomIn(); } ZoomOut()104 virtual void ZoomOut() { state[currentState]->ZoomOut(); } RightClick(int x,int y)105 virtual void RightClick( int x, int y ) { state[currentState]->RightClick(x,y); } 106 CommandDown()107 void CommandDown() { commandDown = true; MouseMove( mouseX, mouseY ); } CommandUp()108 void CommandUp() { commandDown = false; MouseMove( mouseX, mouseY ); } 109 MotionKey(int key)110 void MotionKey( int key ) { state[ currentState ]->MotionKey( key ); } 111 112 // Commands: 113 void Command( int index, CommandArgument* arg, int nArg ); 114 FrameTick()115 void FrameTick() { state[ currentState ]->FrameTick(); } 116 117 // General control: 118 void Draw(); 119 120 // For use by the states: State()121 int State() { return currentState; } 122 void ChangeState( int state ); 123 SharedState()124 SharedStateData* SharedState() { return shared; } IsDragging()125 bool IsDragging() { return mouseDown && !commandDown; } IsFreeMove()126 bool IsFreeMove() { return !mouseDown; } IsCommand()127 bool IsCommand() { return commandDown; } MouseX()128 int MouseX() { return mouseX; } MouseY()129 int MouseY() { return mouseY; } MouseDownX()130 int MouseDownX() { return mouseDownX; } MouseDownY()131 int MouseDownY() { return mouseDownY; } 132 133 // void HandleCommand( const std::string& commang, const std::string& arg ); 134 135 virtual bool HandleWidgetEvent( KrWidget* source, const KrWidgetEvent& event ); 136 137 private: 138 enum { MOUSE_CLICK = 2 }; 139 140 void LoadDef( const char* filename ); 141 void LoadImage( const char* filename, int nTrans, KrRGBA* trans ); 142 143 EdState* state[ EdState::NUMSTATES ]; 144 145 // Data about the inputs and statemachine: 146 // bool refresh; 147 int mouseX, mouseY; 148 int mouseDownX, mouseDownY; 149 int rightMouseDownX, rightMouseDownY; 150 bool mouseDown; 151 int rightMouseLastX, rightMouseLastY; 152 bool rightButtonDown; 153 154 bool commandDown; // Does the mouseclick have the command flag set? 155 bool commandClick; 156 157 int currentState; 158 159 // Data for the states to use: 160 SharedStateData* shared; 161 162 int nTrans; 163 KrRGBA trans[16]; 164 }; 165 166 167 // inline SharedStateData* EdState::SharedState() 168 // { 169 // GLASSERT( machine ); 170 // return machine->SharedState(); 171 // } 172 // 173 174 #endif 175