1$using namespace gcn;
2
3#include "font.h"
4
5enum ViewportModeType {
6	VIEWPORT_SINGLE = 0,
7	VIEWPORT_SPLIT_HORIZ,
8	VIEWPORT_SPLIT_HORIZ3,
9	VIEWPORT_SPLIT_VERT,
10	VIEWPORT_QUAD
11};
12
13class LuaActionListener
14{
15	LuaActionListener(lua_State *lua, lua_Object luaref);
16};
17
18class CUIButton
19{
20	CUIButton();
21
22	int X;
23	int Y;
24	string Text;
25	ButtonStyle *Style;
26	LuaActionListener *Callback;
27};
28
29$[
30_uiButtonCallbacks = {}
31CUIButton.SetCallback = function(w, f)
32  w.Callback = LuaActionListener(f)
33  table.insert(_uiButtonCallbacks, w.Callback)
34end
35$]
36
37class CMapArea
38{
39	int X;
40	int Y;
41	int EndX;
42	int EndY;
43	int ScrollPaddingLeft;
44	int ScrollPaddingRight;
45	int ScrollPaddingTop;
46	int ScrollPaddingBottom;
47};
48
49class CViewport
50{
51};
52
53class CFiller
54{
55	CFiller();
56
57	CGraphic *G;
58	int X;
59	int Y;
60};
61
62class vector
63{
64	TOLUA_TEMPLATE_BIND(T, CFiller, CUIButton, CUIUserButton, string)
65
66	vector();
67	~vector();
68
69	const T& operator[](int index) const;
70	T& operator[](int index);
71	const T& at(int index) const;
72	T& at(int index);
73
74	const T& front() const;
75	T& front();
76	const T& back() const;
77	T& back();
78
79	void push_back(T val);
80	void pop_back();
81
82	void assign(int num, const T& val);
83	void clear();
84	bool empty() const;
85	int size() const;
86};
87
88
89class CButtonPanel
90{
91	int X;
92	int Y;
93	vector<CUIButton> Buttons;
94	CColor AutoCastBorderColorRGB;
95	bool ShowCommandKey;
96};
97
98class CPieMenu
99{
100	CGraphic *G;
101	int MouseButton;
102	int X[8];
103	int Y[8];
104
105	void SetRadius(int radius);
106};
107
108class CResourceInfo
109{
110	CGraphic *G;
111	int IconFrame;
112	int IconX;
113	int IconY;
114	int IconWidth;
115	int TextX;
116	int TextY;
117};
118
119class CInfoPanel
120{
121	CGraphic *G;
122	int X;
123	int Y;
124};
125
126class CUIUserButton
127{
128	CUIUserButton();
129
130	bool Clicked;
131	CUIButton Button;
132};
133
134class CStatusLine
135{
136	void Set(const std::string status);
137	const std::string &Get();
138	void Clear();
139
140	int Width;
141	int TextX;
142	int TextY;
143	CFont *Font;
144};
145
146class CUITimer
147{
148	int X;
149	int Y;
150	CFont *Font;
151};
152
153class CUserInterface
154{
155	string NormalFontColor;
156	string ReverseFontColor;
157
158	vector<CFiller> Fillers;
159
160	CResourceInfo Resources[MaxResourceInfo];
161	CInfoPanel InfoPanel;
162	CUIButton *SingleSelectedButton;
163
164	vector<CUIButton> SelectedButtons;
165	CFont *MaxSelectedFont;
166	int MaxSelectedTextX;
167	int MaxSelectedTextY;
168
169	CUIButton *SingleTrainingButton;
170	vector<CUIButton> TrainingButtons;
171	CUIButton *UpgradingButton;
172	CUIButton *ResearchingButton;
173	vector<CUIButton> TransportingButtons;
174
175        vector<string> LifeBarColorNames;
176        vector<int> LifeBarPercents;
177        int LifeBarYOffset;
178		int LifeBarPadding;
179        bool LifeBarBorder;
180
181	CColor CompletedBarColorRGB;
182	bool CompletedBarShadow;
183
184	CButtonPanel ButtonPanel;
185
186	CPieMenu PieMenu;
187
188	CViewport *MouseViewport;
189	CMapArea MapArea;
190
191	CFont *MessageFont;
192	int MessageScrollSpeed;
193
194	CUIButton MenuButton;
195	CUIButton NetworkMenuButton;
196	CUIButton NetworkDiplomacyButton;
197
198	vector<CUIUserButton> UserButtons;
199
200	CMinimap Minimap;
201	CStatusLine StatusLine;
202	CUITimer Timer;
203
204	Vec2i EditorSettingsAreaTopLeft;
205	Vec2i EditorSettingsAreaBottomRight;
206	Vec2i EditorButtonAreaTopLeft;
207	Vec2i EditorButtonAreaBottomRight;
208};
209
210extern CUserInterface UI;
211
212class CIcon
213{
214	static CIcon *New(const std::string ident);
215	static CIcon *Get(const std::string ident);
216
217	tolua_readonly tolua_property__s std::string Ident;
218	CPlayerColorGraphic *G;
219	int Frame;
220};
221
222extern ButtonStyle *FindButtonStyle(const std::string style);
223
224extern bool GetMouseScroll(void);
225extern void SetMouseScroll(bool enabled);
226extern bool GetKeyScroll(void);
227extern void SetKeyScroll(bool enabled);
228extern bool GetGrabMouse(void);
229extern void SetGrabMouse(bool enabled);
230extern bool GetLeaveStops(void);
231extern void SetLeaveStops(bool enabled);
232extern int GetDoubleClickDelay(void);
233extern void SetDoubleClickDelay(int delay);
234extern int GetHoldClickDelay(void);
235extern void SetHoldClickDelay(int delay);
236
237extern PixelPos CursorScreenPos;
238
239//
240//  Guichan
241//
242
243class Color
244{
245	Color(int r, int g, int b, int a = 255);
246	int r;
247	int g;
248	int b;
249	int a;
250};
251
252class Graphics
253{
254	enum {
255		LEFT = 0,
256		CENTER,
257		RIGHT
258	};
259};
260
261class Widget
262{
263	virtual void setWidth(int width);
264	virtual int getWidth() const;
265	virtual void setHeight(int height);
266	virtual int getHeight() const;
267	virtual void setSize(int width, int height);
268	virtual void setX(int x);
269	virtual int getX() const;
270	virtual void setY(int y);
271	virtual int getY() const;
272	virtual void setPosition(int x, int y);
273	virtual void setBorderSize(int width);
274	virtual unsigned int getBorderSize() const;
275	virtual void setEnabled(bool enabled);
276	virtual bool isEnabled() const;
277	virtual void setVisible(bool visible);
278	virtual bool isVisible() const;
279
280	virtual void setBaseColor(const Color color);
281	virtual const Color &getBaseColor() const;
282	virtual void setForegroundColor(const Color color);
283	virtual const Color &getForegroundColor() const;
284	virtual void setBackgroundColor(const Color color);
285	virtual const Color &getBackgroundColor() const;
286	virtual void setDisabledColor(const Color color);
287	virtual const Color &getDisabledColor() const;
288
289	static void setGlobalFont(CFont *font);
290	virtual void setForegroundColor(const Color color);
291	virtual void setBackgroundColor(const Color color);
292	virtual void setBaseColor(const Color color);
293	virtual void setSize(int width, int height);
294	virtual void setBorderSize(int width);
295	virtual void setFont(CFont *font);
296
297	virtual int getHotKey() const;
298	virtual void setHotKey(const int key);
299	virtual void setHotKey(const char *key);
300
301        virtual void requestFocus();
302
303	virtual void addActionListener(LuaActionListener *actionListener);
304        virtual void addMouseListener(LuaActionListener *actionListener);
305        virtual void addKeyListener(LuaActionListener *actionListener);
306};
307
308$[
309Widget.setActionCallback = function(w, f)
310  w._actioncb = LuaActionListener(f)
311  w:addActionListener(w._actioncb)
312end
313
314Widget.setMouseCallback = function(w, f)
315  w._mousecb = LuaActionListener(f)
316  w:addMouseListener(w._mousecb)
317end
318
319Widget.setKeyCallback = function(w, f)
320  w._keycb = LuaActionListener(f)
321  w:addKeyListener(w._keycb)
322end
323$]
324
325class BasicContainer : public Widget
326{
327};
328
329class ScrollArea : public BasicContainer
330{
331	ScrollArea();
332	virtual void setContent(Widget *widget);
333	virtual Widget *getContent();
334	virtual void setScrollbarWidth(int width);
335	virtual int getScrollbarWidth();
336        virtual void scrollToBottom();
337        virtual void scrollToTop();
338};
339
340class ImageWidget : public Widget
341{
342	ImageWidget(CGraphic *image);
343        ImageWidget(Mng *image);
344        ImageWidget(Movie *image);
345};
346
347class Button : public Widget
348{
349};
350
351class ButtonWidget : public Button
352{
353	ButtonWidget(const std::string caption);
354	virtual void setCaption(const std::string caption);
355	virtual const std::string &getCaption() const;
356	virtual void adjustSize();
357};
358
359class ImageButton : public Button
360{
361	ImageButton();
362	ImageButton(const std::string caption);
363
364	void setNormalImage(CGraphic *image);
365	void setPressedImage(CGraphic *image);
366	void setDisabledImage(CGraphic *image);
367};
368
369class RadioButton : public Widget
370{
371	RadioButton();
372	RadioButton(const std::string caption, const std::string group, bool marked = false);
373
374	virtual bool isMarked();
375	virtual void setMarked(bool marked);
376	virtual const std::string &getCaption() const;
377	virtual void setCaption(const std::string caption);
378	virtual void setGroup(const std::string group);
379	virtual const std::string &getGroup() const;
380	virtual void adjustSize();
381};
382
383class ImageRadioButton : public RadioButton
384{
385	ImageRadioButton();
386	ImageRadioButton(const std::string caption, const std::string group, bool marked = false);
387
388	void setUncheckedNormalImage(CGraphic *image);
389	void setUncheckedPressedImage(CGraphic *image);
390	void setUncheckedDisabledImage(CGraphic *image);
391	void setCheckedNormalImage(CGraphic *image);
392	void setCheckedPressedImage(CGraphic *image);
393	void setCheckedDisabledImage(CGraphic *image);
394};
395
396class CheckBox : public Widget
397{
398	CheckBox();
399	CheckBox(const std::string caption, bool marked = false);
400
401	virtual bool isMarked() const;
402	virtual void setMarked(bool marked);
403	virtual const std::string &getCaption() const;
404	virtual void setCaption(const std::string caption);
405	virtual void adjustSize();
406};
407
408class ImageCheckBox : public CheckBox
409{
410	ImageCheckBox();
411	ImageCheckBox(const std::string caption, bool marked = false);
412
413	void setUncheckedNormalImage(CGraphic *image);
414	void setUncheckedPressedImage(CGraphic *image);
415	void setUncheckedDisabledImage(CGraphic *image);
416	void setCheckedNormalImage(CGraphic *image);
417	void setCheckedPressedImage(CGraphic *image);
418	void setCheckedDisabledImage(CGraphic *image);
419};
420
421class Slider : public Widget
422{
423	Slider(double scaleEnd = 1.0);
424	Slider(double scaleStart, double scaleEnd);
425	virtual void setScale(double scaleStart, double scaleEnd);
426	virtual double getScaleStart() const;
427	virtual void setScaleStart(double scaleStart);
428	virtual double getScaleEnd() const;
429	virtual void setScaleEnd(double scaleEnd);
430	virtual double getValue();
431	virtual void setValue(double value);
432	virtual void setMarkerLength(int length);
433	virtual int getMarkerLength() const;
434	virtual void setOrientation(unsigned int orientation);
435	virtual unsigned int getOrientation() const;
436	virtual void setStepLength(double length);
437	virtual double getStepLength() const;
438
439	enum { HORIZONTAL = 0, VERTICAL };
440};
441
442class ImageSlider : public Slider
443{
444	ImageSlider(double scaleEnd = 1.0);
445	ImageSlider(double scaleStart, double scaleEnd);
446	void setMarkerImage(CGraphic *image);
447	void setBackgroundImage(CGraphic *image);
448	void setDisabledBackgroundImage(CGraphic *image);
449};
450
451class Label : public Widget
452{
453	Label(const std::string caption);
454	const std::string &getCaption() const;
455	void setCaption(const std::string caption);
456	virtual void setAlignment(unsigned int alignment);
457	virtual unsigned int getAlignment();
458	virtual void adjustSize();
459};
460
461class MultiLineLabel : public Widget
462{
463	MultiLineLabel();
464	MultiLineLabel(const std::string caption);
465
466	virtual void setCaption(const std::string caption);
467	virtual const std::string &getCaption() const;
468	virtual void setAlignment(unsigned int alignment);
469	virtual unsigned int getAlignment();
470	virtual void setVerticalAlignment(unsigned int alignment);
471	virtual unsigned int getVerticalAlignment();
472	virtual void setLineWidth(int width);
473	virtual int getLineWidth();
474	virtual void adjustSize();
475	virtual void draw(gcn::Graphics *graphics);
476
477	enum {
478		LEFT = 0,
479		CENTER,
480		RIGHT,
481		TOP,
482		BOTTOM
483	};
484};
485
486class TextBox : public Widget
487{
488	TextBox(const std::string text);
489        virtual void setEditable(bool editable);
490        virtual std::string getText();
491};
492
493class TextField : public Widget
494{
495	TextField(const std::string text);
496	virtual void setText(const std::string text);
497	virtual std::string &getText();
498};
499
500class ImageTextField : public Widget
501{
502	ImageTextField(const std::string text);
503	virtual void setText(const std::string text);
504	virtual std::string &getText();
505	void setItemImage(CGraphic *image);
506};
507
508class ListBox : public Widget
509{
510};
511
512class ImageListBox : public ListBox
513{
514};
515
516class ListBoxWidget : public ScrollArea
517{
518	ListBoxWidget(unsigned int width, unsigned int height);
519	void setList(lua_State *lua, lua_Object *lo);
520	void setSelected (int selected);
521	int getSelected();
522};
523
524class ImageListBoxWidget : public ListBoxWidget
525{
526	ImageListBoxWidget(unsigned int width, unsigned int height);
527	void setList(lua_State *lua, lua_Object *lo);
528	void setSelected (int selected);
529	int getSelected();
530	void setItemImage(CGraphic *image);
531	void setUpButtonImage(CGraphic *image);
532	void setUpPressedButtonImage(CGraphic *image);
533	void setDownButtonImage(CGraphic *image);
534	void setDownPressedButtonImage(CGraphic *image);
535	void setLeftButtonImage(CGraphic *image);
536	void setLeftPressedButtonImage(CGraphic *image);
537	void setRightButtonImage(CGraphic *image);
538	void setRightPressedButtonImage(CGraphic *image);
539	void setHBarImage(CGraphic *image);
540	void setVBarImage(CGraphic *image);
541	void setMarkerImage(CGraphic *image);
542};
543
544class Window : public BasicContainer
545{
546	Window();
547	Window(const std::string caption);
548	Window(Widget *content, const std::string caption = "");
549
550	virtual void setCaption(const std::string caption);
551	virtual const std::string &getCaption() const;
552	virtual void setAlignment(unsigned int alignment);
553	virtual unsigned int getAlignment() const;
554	virtual void setContent(Widget* widget);
555	virtual Widget* getContent() const;
556	virtual void setPadding(unsigned int padding);
557	virtual unsigned int getPadding() const;
558	virtual void setTitleBarHeight(unsigned int height);
559	virtual unsigned int getTitleBarHeight();
560	virtual void setMovable(bool movable);
561	virtual bool isMovable() const;
562	virtual void resizeToContent();
563	virtual void setOpaque(bool opaque);
564	virtual bool isOpaque();
565};
566
567class Windows : public Window
568{
569	Windows(const std::string text, int width, int height);
570	void add(Widget *widget, int x, int y);
571};
572
573class ScrollingWidget : public ScrollArea
574{
575	ScrollingWidget(int width, int height);
576	void add(Widget *widget, int x, int y);
577	void restart();
578	void setSpeed(float speed);
579	float getSpeed();
580};
581
582class DropDown : public BasicContainer
583{
584	virtual int getSelected();
585	virtual void setSelected(int selected);
586	virtual void setScrollArea(ScrollArea* scrollArea);
587	virtual ScrollArea *getScrollArea();
588	virtual void setListBox(ListBox* listBox);
589	virtual ListBox *getListBox();
590};
591
592class DropDownWidget : public DropDown
593{
594	DropDownWidget();
595	void setList(lua_State *lua, lua_Object *lo);
596	virtual ListBox *getListBox();
597	virtual void setSize(int width, int height);
598};
599
600class ImageDropDownWidget : public DropDown
601{
602	ImageDropDownWidget();
603	void setList(lua_State *lua, lua_Object *lo);
604	virtual ListBox *getListBox();
605	virtual void setSize(int width, int height);
606	void setItemImage(CGraphic *image);
607	void setDownNormalImage(CGraphic *image);
608	void setDownPressedImage(CGraphic *image);
609};
610
611class StatBoxWidget : public Widget
612{
613	StatBoxWidget(int width, int height);
614
615	void setCaption(const std::string s);
616	const std::string &getCaption() const;
617	void setPercent(const int percent);
618	int getPercent() const;
619};
620
621class Container : public BasicContainer
622{
623	Container();
624	virtual void setOpaque(bool opaque);
625	virtual bool isOpaque() const;
626	virtual void add(Widget *widget, int x, int y);
627	virtual void remove(Widget *widget);
628	virtual void clear();
629};
630
631class MenuScreen : public Container
632{
633	MenuScreen();
634
635	int run(bool loop = true);
636	void stop(int result = 0);
637	void stopAll(int result = 0);
638	void addLogicCallback(LuaActionListener *actionListener);
639	void setDrawMenusUnder(bool drawunder);
640	bool getDrawMenusUnder();
641};
642$renaming MenuScreen @ CMenuScreen
643
644$[
645function MenuScreen()
646  local menu = CMenuScreen()
647
648  -- Store the widget in the container. This way we keep a reference
649  -- to the widget until the container gets deleted.
650  local guichanadd = Container.add
651  function menu:add(widget, x, y)
652    if not self._addedWidgets then
653       self._addedWidgets = {}
654    end
655    self._addedWidgets[widget] = true
656    guichanadd(self, widget, x, y)
657  end
658
659  return menu
660end
661$]
662
663void CenterOnMessage();
664void ToggleShowMessages();
665void UiFindIdleWorker();
666void CycleViewportMode(int step);
667void UiToggleTerrain();
668void UiTrackUnit();
669void SetNewViewportMode(ViewportModeType new_mode);
670
671void SetDefaultTextColors(const std::string &normal, const std::string &reverse);
672