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 
33 #ifndef KYRA_SHARED_STATE_INCLUDED
34 #define KYRA_SHARED_STATE_INCLUDED
35 
36 #ifdef _MSC_VER
37 // Disable the no-exception handling warning.
38 #pragma warning( disable : 4530 )
39 #pragma warning( disable : 4786 )
40 #endif
41 
42 #include <string>
43 #include "../../tinyxml/tinyxml.h"
44 #include "SDL.h"
45 #include "SDL_image.h"
46 
47 #include "../engine/color.h"
48 
49 class KrAction;
50 class KrEngine;
51 class KrCanvasResource;
52 class KrImageTree;
53 class KrImNode;
54 class KrConsole;
55 class EdWidget;
56 class EdWidgetFrame;
57 class EdWidgetTile;
58 class EdWidgetSprite;
59 class EdWidgetAction;
60 class KrFontResource;
61 class KrTextBox;
62 class KrBox;
63 
64 
65 
66 enum
67 {
68 	INFO_CLEAR_START = 0,
69 	INFO_CLEAR_END = 4,
70 
71 	INFO_SPRITE = 0,
72 	INFO_ACTION = 1,
73 	INFO_FRAME  = 2,
74 	INFO_FRAME_SIZE = 3,
75 
76 	INFO_TILE = 0,
77 	INFO_TILE_SIZE = 1,
78 
79 	INFO_CREATING = 4,
80 	INFO_MOUSE = 5,
81 };
82 
83 
84 class SharedStateData
85 {
86   public:
87 	SharedStateData( SDL_Surface* surface );
88 	~SharedStateData();
89 
90 	// Clear the widgets and filenames
91 	void Clear();
92 
SetFilenames(const std::string & def,const std::string & surface)93 	void SetFilenames( const std::string& def, const std::string& surface )	{ defFileName = def; surfaceFileName = surface; }
94 	const std::string&	DefFileName();
95 	const std::string&	SurfaceFileName();
96 
97 	/* The image that backs the screen is kept as a canvas
98 		resource so it can be used with the sprite engine. The
99 		sprite engine is faster and it's a good test of the engine
100 		code.
101 	*/
CanvasResource()102 	KrCanvasResource*	CanvasResource()		{ return canvasResource; }
103 
104 	// The engine we are using:
Engine()105 	KrEngine* Engine()		{ return engine; }
106 
107 	// The console to output to:
Console()108 	KrConsole* Console()	{ return console; }
109 
110 	// The console in contained in this node:
ConsoleNode()111 	KrImNode*  ConsoleNode()	{ return consoleHolder; }
112 
113 	// The image node that states should be a child of:
ImNode()114 	KrImNode* ImNode()		{ return imnode; }
115 
116 	// The view state tosses its (considerable) widget set in
117 	// this node:
WidgetNode()118 	KrImNode* WidgetNode()	{ return widgetNode; }
119 
120 	// The base widget, once the XML stuff is parsed to widgets.
Widget()121 	EdWidget* Widget()		{ return widget; }
122 
FontResource()123 	KrFontResource*		FontResource()	{ return fontResource; }
BackgroundRes()124 	KrCanvasResource*	BackgroundRes()	{ return backgroundRes; }
125 
126 	void SetInfoBox( bool on );
127 	void SetInfoBoxMouse( int x, int y );
128 
129 	enum {
130 		SPRITE,
131 		TILE
132 	};
133 
CurrentObject()134 	int				CurrentObject()		{ return currentObject; }
CurrentFrame()135 	EdWidgetFrame*	CurrentFrame()		{ return currentFrame; }
CurrentAction()136 	EdWidgetAction*	CurrentAction()		{ return currentAction; }
CurrentSprite()137 	EdWidgetSprite*	CurrentSprite()		{ return currentSprite; }
CurrentTile()138 	EdWidgetTile*	CurrentTile()		{ return currentTile; }
139 
140 	// Sets both the current tile/sprite and switches to that mode.
141 	void SetCurrentTile( EdWidget* tile );
142 	void SetCurrentFrame( EdWidget* frame );
143 	void SetCurrentAction( EdWidget* action );
144 	void SetCurrentSprite( EdWidget* sprite );
145 
146 	// Converts the current action into a KrAction, and returns
147 	// the object. Used to feed to the engine for rendering.
148 	KrAction* CreateAnimationAction();
149 
150 	// SetFilenames must be set before calling LoadSurface.
151 	bool LoadSurface( int nTransparency, const KrRGBA* rgba );
152 
153 	// Transparency values for non-32 bit surfaces.
154 	enum {
155 		MAX_TRANS = 10
156 	};
157   private:
158 	enum {
159 		MAIN_IMNODE_DEPTH,
160 		WIDGET_DEPTH,
161 		CONSOLE_DEPTH,
162 		INFO_BACKGROUND_DEPTH,
163 		INFO_DEPTH,
164 	};
165 
166 	KrEngine*		engine;
167 	KrImNode*		imnode;		// The node where states hang there data from
168 	KrImNode*		widgetNode;	// Special container for the view state.
169 	KrImNode*		consoleHolder;
170 	KrConsole*		console;
171 	KrTextBox*		infoBox;
172 	KrBox*			infoBoxBack;
173 	EdWidget*		widget;
174 	KrFontResource*		fontResource;
175 	KrCanvasResource*	backgroundRes;
176 
177 	std::string		surfaceFileName;
178 	std::string		defFileName;
179 
180 	KrAction*		animAction;
181 	int				currentObject;
182 	EdWidgetTile*	currentTile;
183 	EdWidgetFrame*	currentFrame;
184 	EdWidgetAction*	currentAction;
185 	EdWidgetSprite*	currentSprite;
186 	KrCanvasResource* canvasResource;
187 
188  	KrRGBA			trans[MAX_TRANS];
189 	int				nTrans;
190 };
191 
192 
193 #endif
194