File: ui.pkg

package info (click to toggle)
boswars 2.7%2Bsvn160110-5
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, bullseye
  • size: 97,132 kB
  • sloc: cpp: 57,441; python: 1,759; makefile: 34; sh: 26
file content (568 lines) | stat: -rw-r--r-- 12,283 bytes parent folder | download | duplicates (5)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
$using std::string;
$using std::vector;

$using namespace gcn;


class LuaActionListener
{
	LuaActionListener(lua_State *lua, lua_Object luaref);
};

class CUIButton
{
	CUIButton();
	~CUIButton();

	int X;
	int Y;
	string Text;
	ButtonStyle *Style;
	LuaActionListener *Callback;
};

$[
_uiButtonCallbacks = {}
CUIButton.SetCallback = function(w, f)
  w.Callback = LuaActionListener(f)
  table.insert(_uiButtonCallbacks, w.Callback)
end
$]

class CMapArea
{
	int X;
	int Y;
	int EndX;
	int EndY;
	int ScrollPaddingLeft;
	int ScrollPaddingRight;
	int ScrollPaddingTop;
	int ScrollPaddingBottom;
};

class CViewport
{
	int Viewport2MapX(int x);
	int Viewport2MapY(int y);
};

class CFiller
{
	CFiller();
	
	CGraphic *G;
	int X;
	int Y;
};

class vector
{
	TOLUA_TEMPLATE_BIND(T, CFiller, CUIButton, string)

	vector();
	~vector();

	const T& operator[](int index) const;
	T& operator[](int index);
	const T& at(int index) const;
	T& at(int index);

	const T& front() const;
	T& front();
	const T& back() const;
	T& back();

	void push_back(T val);
	void pop_back();

	void assign(int num, const T& val);
	void clear();
	bool empty() const;
	int size() const;
};


class CButtonPanel
{
	int X;
	int Y;
	vector<CUIButton> Buttons;
	CColor AutoCastBorderColorRGB;
	bool ShowCommandKey;
};

class CPieMenu
{
	CGraphic *G;
	int MouseButton;
	int X[8];
	int Y[8];
	
	void SetRadius(int radius);
};

class CResourceInfo
{
	CGraphic *G;
	int IconFrame;
	int IconX;
	int IconY;
	int TextX;
	int TextY;
};

class CInfoPanel
{
	int X;
	int Y;
};

class CStatusLine
{
	void Set(const std::string status);
	const std::string &Get();
	void Clear();

	int Width;
	int TextX;
	int TextY;
	CFont *Font;
};

class CUITimer
{
	int X;
	int Y;
	CFont *Font;
};

class CUserInterface
{
	string NormalFontColor;
	string ReverseFontColor;
	
	vector<CFiller> Fillers;

	CResourceInfo Resources[MaxCosts];
	CInfoPanel InfoPanel;
	CUIButton *SingleSelectedButton;

	vector<CUIButton> SelectedButtons;
	CFont *MaxSelectedFont;
	int MaxSelectedTextX;
	int MaxSelectedTextY;

	CUIButton *SingleTrainingButton;
	vector<CUIButton> TrainingButtons;
	vector<CUIButton> TransportingButtons;

	CColor CompletedBarColorRGB;
	bool CompletedBarShadow;

	CButtonPanel ButtonPanel;
	
	CPieMenu PieMenu;

	CViewport *MouseViewport;
	CMapArea MapArea;

	CFont *MessageFont;
	int MessageScrollSpeed;

	CUIButton MenuButton;
	CUIButton NetworkMenuButton;
	CUIButton NetworkDiplomacyButton;

	CMinimap Minimap;
	CStatusLine StatusLine;
	CUITimer Timer;
};

extern CUserInterface UI;

class CIcon
{
	static CIcon *New(const std::string ident);
	static CIcon *Get(const std::string ident);

	tolua_readonly tolua_property__s std::string Ident;
	CGraphic *G;
	int Frame;
};

extern ButtonStyle *FindButtonStyle(const std::string style);

extern bool GetMouseScroll(void);
extern void SetMouseScroll(bool enabled);
extern bool GetKeyScroll(void);
extern void SetKeyScroll(bool enabled);
extern bool GetGrabMouse(void);
extern void SetGrabMouse(bool enabled);
extern bool GetLeaveStops(void);
extern void SetLeaveStops(bool enabled);
extern void SetSavedMapPosition(int index, int x, int y);
extern int GetDoubleClickDelay(void);
extern void SetDoubleClickDelay(int delay);
extern int GetHoldClickDelay(void);
extern void SetHoldClickDelay(int delay);

extern int CursorX;
extern int CursorY;


//
//  Guichan
//

class Color
{
	Color(int r, int g, int b, int a = 255);
	int r;
	int g;
	int b;
	int a;
};

class Graphics
{
	enum {
		LEFT = 0,
		CENTER,
		RIGHT
	};
};

class Widget 
{
	virtual void setWidth(int width);
	virtual int getWidth() const;
	virtual void setHeight(int height);
	virtual int getHeight() const;
	virtual void setSize(int width, int height);
	virtual void setX(int x);
	virtual int getX() const;
	virtual void setY(int y);
	virtual int getY() const;
	virtual void setPosition(int x, int y);
	virtual void setBorderSize(int width);
	virtual unsigned int getBorderSize() const;
	virtual void setEnabled(bool enabled);
	virtual bool isEnabled() const;
	virtual void setVisible(bool visible);
	virtual bool isVisible() const;

	virtual void setBaseColor(const Color color);
	virtual const Color &getBaseColor() const;
	virtual void setForegroundColor(const Color color);
	virtual const Color &getForegroundColor() const;
	virtual void setBackgroundColor(const Color color);
	virtual const Color &getBackgroundColor() const;
	virtual void setDisabledColor(const Color color);
	virtual const Color &getDisabledColor() const;

	static void setGlobalFont(CFont *font);
	virtual void setFont(CFont *font);

	virtual int getHotKey() const;
	virtual void setHotKey(const int key);
	virtual void setHotKey(const char *key);

	virtual void addActionListener(LuaActionListener *actionListener);
	virtual void requestFocus();
};

$[
Widget.setActionCallback = function(w, f)
  w._actioncb = LuaActionListener(f)
  w:addActionListener(w._actioncb)
end
$]

class BasicContainer : public Widget
{
};

class ScrollArea : public BasicContainer
{
	ScrollArea();
	virtual void setContent(Widget *widget);
	virtual Widget *getContent();
	virtual void setScrollbarWidth(int width);
	virtual int getScrollbarWidth();
};

class ImageWidget : public Widget
{
	ImageWidget(CGraphic *image);
};

class Button : public Widget
{
};

class ButtonWidget : public Button
{
	ButtonWidget(const std::string caption);
	virtual void setCaption(const std::string caption);
	virtual const std::string &getCaption() const;
	virtual void adjustSize();
};

class ImageButton : public Button
{
	ImageButton();
	ImageButton(const std::string caption);

	void setNormalImage(CGraphic *image);
	void setPressedImage(CGraphic *image);
	void setDisabledImage(CGraphic *image);
};

class RadioButton : public Widget
{
	RadioButton();
	RadioButton(const std::string caption, const std::string group, bool marked = false);

	virtual bool isMarked();
	virtual void setMarked(bool marked);
	virtual const std::string &getCaption() const;
	virtual void setCaption(const std::string caption);
	virtual void setGroup(const std::string group);
	virtual const std::string &getGroup() const;
	virtual void adjustSize();
};

class ImageRadioButton : public RadioButton
{
	ImageRadioButton();
	ImageRadioButton(const std::string caption, const std::string group, bool marked = false);

	void setUncheckedNormalImage(CGraphic *image);
	void setUncheckedPressedImage(CGraphic *image);
	void setCheckedNormalImage(CGraphic *image);
	void setCheckedPressedImage(CGraphic *image);
};

class CheckBox : public Widget
{
	CheckBox();
	CheckBox(const std::string caption, bool marked = false);

	virtual bool isMarked() const;
	virtual void setMarked(bool marked);
	virtual const std::string &getCaption() const;
	virtual void setCaption(const std::string caption);
	virtual void adjustSize();
};

class ImageCheckBox : public CheckBox
{
	ImageCheckBox();
	ImageCheckBox(const std::string caption, bool marked = false);

	void setUncheckedNormalImage(CGraphic *image);
	void setUncheckedPressedImage(CGraphic *image);
	void setCheckedNormalImage(CGraphic *image);
	void setCheckedPressedImage(CGraphic *image);
};

class Slider : public Widget
{
	Slider(double scaleEnd = 1.0);
	Slider(double scaleStart, double scaleEnd);
	virtual void setScale(double scaleStart, double scaleEnd);
	virtual double getScaleStart() const;
	virtual void setScaleStart(double scaleStart);
	virtual double getScaleEnd() const;
	virtual void setScaleEnd(double scaleEnd);
	virtual double getValue();
	virtual void setValue(double value);
	virtual void setMarkerLength(int length);
	virtual int getMarkerLength() const;
	virtual void setOrientation(unsigned int orientation);
	virtual unsigned int getOrientation() const;
	virtual void setStepLength(double length);
	virtual double getStepLength() const;

	enum { HORIZONTAL = 0, VERTICAL };
};

class ImageSlider : public Slider
{
	ImageSlider(double scaleEnd = 1.0);
	ImageSlider(double scaleStart, double scaleEnd);
	void setMarkerImage(CGraphic *image);
	void setBackgroundImage(CGraphic *image);
};

class Label : public Widget
{
	Label(const std::string caption);
	const std::string &getCaption() const;
	void setCaption(const std::string caption);
	virtual void setAlignment(unsigned int alignment);
	virtual unsigned int getAlignment();
	virtual void adjustSize();
};

class MultiLineLabel : public Widget
{
	MultiLineLabel();
	MultiLineLabel(const std::string caption);

	virtual void setCaption(const std::string caption);
	virtual const std::string &getCaption() const;
	virtual void setAlignment(unsigned int alignment);
	virtual unsigned int getAlignment();
	virtual void setVerticalAlignment(unsigned int alignment);
	virtual unsigned int getVerticalAlignment();
	virtual void setLineWidth(int width);
	virtual int getLineWidth();
	virtual void adjustSize();
	virtual void draw(gcn::Graphics *graphics);

	enum {
		LEFT = 0,
		CENTER,
		RIGHT,
		TOP,
		BOTTOM
	};
};

// FIXME Combine with ScrollArea in our own widget
//class TextBox : public Widget
//{
//	TextBox(const std::string text);
//};

class TextField : public Widget
{
	TextField(const std::string text);
	virtual void setText(const std::string text);
	virtual std::string &getText();
	void setMaxLengthBytes(int maxLengthBytes);
	int getMaxLengthBytes() const;
};

class ListBox : public Widget
{
};

class ListBoxWidget : public ScrollArea
{
	ListBoxWidget(unsigned int width, unsigned int height);
	void setList(lua_State *lua, lua_Object *lo);
	void setSelected (int selected);
	int getSelected();
};

class Window : public BasicContainer
{
	Window();
	Window(const std::string caption);
	Window(Widget *content, const std::string caption = "");
	
	virtual void setCaption(const std::string caption);
	virtual const std::string &getCaption() const;
	virtual void setAlignment(unsigned int alignment);
	virtual unsigned int getAlignment() const;
	virtual void setContent(Widget* widget);
	virtual Widget* getContent() const;
	virtual void setPadding(unsigned int padding);
	virtual unsigned int getPadding() const;
	virtual void setTitleBarHeight(unsigned int height);
	virtual unsigned int getTitleBarHeight();
	virtual void setMovable(bool movable);
	virtual bool isMovable() const;
	virtual void resizeToContent();
	virtual void setOpaque(bool opaque);
	virtual bool isOpaque();
};

class Windows : public Window
{
	Windows(const std::string text, int width, int height);
	void add(Widget *widget, int x, int y);
};

class ScrollingWidget : public ScrollArea
{
	ScrollingWidget(int width, int height);
	void add(Widget *widget, int x, int y);
	void restart();
	void setSpeed(float speed);
	float getSpeed();
};

class DropDown : public BasicContainer
{
	virtual int getSelected();
	virtual void setSelected(int selected);
	virtual void setScrollArea(ScrollArea* scrollArea);
	virtual ScrollArea *getScrollArea();
	virtual void setListBox(ListBox* listBox);
	virtual ListBox *getListBox();
};

class DropDownWidget : public DropDown
{
	DropDownWidget();
	void setList(lua_State *lua, lua_Object *lo);
	virtual ListBox *getListBox();
	virtual void setSize(int width, int height);
};

class StatBoxWidget : public Widget
{
	StatBoxWidget(int width, int height);

	void setCaption(const std::string s);
	const std::string &getCaption() const;
	void setPercent(const int percent);
	int getPercent() const;
};

class Container : public BasicContainer
{
	Container();
	virtual void setOpaque(bool opaque);
	virtual bool isOpaque() const;
	virtual void add(Widget *widget, int x, int y);
	virtual void remove(Widget *widget);
	virtual void clear();
};

class MenuScreen : public Container
{
	MenuScreen();

	int run(bool loop = true);
	void stop(int result = 0);
	void stopAll(int result = 0);
	void addLogicCallback(LuaActionListener *actionListener);
	void setDrawMenusUnder(bool drawunder);
	bool getDrawMenusUnder();
};
$renaming MenuScreen @ CMenuScreen

$[
function MenuScreen()
  local menu = CMenuScreen()

  -- Store the widget in the container. This way we keep a reference
  -- to the widget until the container gets deleted.
  local guichanadd = Container.add
  function menu:add(widget, x, y)
    if not self._addedWidgets then
       self._addedWidgets = {}
    end
    self._addedWidgets[widget] = true
    guichanadd(self, widget, x, y)
  end

  return menu
end
$]