Colobot
list.h
1 /*
2  * This file is part of the Colobot: Gold Edition source code
3  * Copyright (C) 2001-2015, Daniel Roux, EPSITEC SA & TerranovaTeam
4  * http://epsitec.ch; http://colobot.info; http://github.com/colobot
5  *
6  * This program is free software: you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License as published by
8  * the Free Software Foundation, either version 3 of the License, or
9  * (at your option) any later version.
10  *
11  * This program is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
14  * See the GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with this program. If not, see http://gnu.org/licenses
18  */
19 
20 #pragma once
21 
22 
23 #include "ui/controls/control.h"
24 
25 #include "common/event.h"
26 #include "common/misc.h"
27 
28 #include "graphics/engine/text.h"
29 
30 #include "ui/controls/button.h"
31 #include "ui/controls/scroll.h"
32 
33 #include <array>
34 #include <memory>
35 
36 namespace Ui
37 {
38 
39 const int LISTMAXDISPLAY = 20; // maximum number of visible lines
40 const int LISTMAXTOTAL = 100; // maximum total number of lines
41 
42 
43 
44 class CList : public CControl
45 {
46 public:
47  CList();
48  ~CList();
49 
50  bool Create(Math::Point pos, Math::Point dim, int icon, EventType eventMsg, float expand);
51 
52  void SetPos(Math::Point pos) override;
53  void SetDim(Math::Point dim) override;
54 
55  bool SetState(int state, bool bState) override;
56  bool SetState(int state) override;
57  bool ClearState(int state) override;
58 
59  bool EventProcess(const Event &event) override;
60  void Draw() override;
61 
62  void Flush();
63 
64  void SetTotal(int i);
65  int GetTotal();
66 
67  void SetSelect(int i);
68  int GetSelect();
69 
70  void SetSelectCap(bool bEnable);
71  bool GetSelectCap();
72 
73  void SetBlink(bool bEnable);
74  bool GetBlink();
75 
76  void SetItemName(int i, const char* name);
77  char* GetItemName(int i);
78 
79  void SetCheck(int i, bool bMode);
80  bool GetCheck(int i);
81 
82  void SetEnable(int i, bool bEnable);
83  bool GetEnable(int i);
84 
85  void SetTabs(int i, float pos, Gfx::TextAlign justif=Gfx::TEXT_ALIGN_LEFT);
86  float GetTabs(int i);
87 
88  void ShowSelect(bool bFixed);
89 
90  EventType GetEventMsgButton(int i);
91  EventType GetEventMsgScroll();
92 
93 protected:
94  bool MoveAdjust();
95  void UpdateButton();
96  void UpdateScroll();
97  void MoveScroll();
98  void DrawCase(char *text, Math::Point pos, float width, Gfx::TextAlign justif);
99 
100 private:
101  // Overridden to avoid warning about hiding the virtual function
102  bool Create(Math::Point pos, Math::Point dim, int icon, EventType eventType) override;
103 
104 protected:
105  std::array<std::unique_ptr<CButton>, LISTMAXDISPLAY> m_buttons;
106  std::unique_ptr<CScroll> m_scroll;
107 
108  float m_expand;
109  int m_totalLine; // total number of lines
110  int m_displayLine; // number of visible lines
111  int m_selectLine; // selected line
112  int m_firstLine; // first visible line
113  bool m_bBlink;
114  bool m_bSelectCap;
115  float m_blinkTime;
116  float m_tabs[10];
117  Gfx::TextAlign m_justifs[10];
118 
119  struct Item
120  {
121  char text[100] = {};
122  bool check = false;
123  bool enable = true;
124  };
125  std::array<Item, LISTMAXTOTAL> m_items;
126 };
127 
128 
129 } // namespace Ui
Definition: robotmain.h:107
Text rendering - CText class.
Definition: list.h:44
2D point
Definition: point.h:50
Definition: list.h:119
Event types, structs and event queue.
TextAlign
Type of text alignment.
Definition: text.h:53
EventType
Type of event message.
Definition: event.h:41
Event sent by system, interface or game.
Definition: event.h:709
Definition: control.h:64