Colobot
window.h
1 /*
2  * This file is part of the Colobot: Gold Edition source code
3  * Copyright (C) 2001-2016, 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 #include "ui/controls/control.h"
23 
24 #include "graphics/engine/engine.h" // TODO: only needed for EngineMouseType
25 
26 #include <memory>
27 #include <string>
28 #include <vector>
29 
30 namespace Ui
31 {
32 
33 class CButton;
34 class CColor;
35 class CCheck;
36 class CKey;
37 class CGroup;
38 class CImage;
39 class CLabel;
40 class CEdit;
41 class CEditValue;
42 class CScroll;
43 class CSlider;
44 class CEnumSlider;
45 class CList;
46 class CShortcut;
47 class CMap;
48 class CGauge;
49 class CTarget;
50 
51 class CWindow : public CControl
52 {
53 public:
54  CWindow();
55  ~CWindow();
56 
57  void Flush();
58  bool Create(Math::Point pos, Math::Point dim, int icon, EventType eventMsg) override;
59  CButton* CreateButton(Math::Point pos, Math::Point dim, int icon, EventType eventMsg);
60  CColor* CreateColor(Math::Point pos, Math::Point dim, int icon, EventType eventMsg);
61  CCheck* CreateCheck(Math::Point pos, Math::Point dim, int icon, EventType eventMsg);
62  CKey* CreateKey(Math::Point pos, Math::Point dim, int icon, EventType eventMsg);
63  CGroup* CreateGroup(Math::Point pos, Math::Point dim, int icon, EventType eventMsg);
64  CImage* CreateImage(Math::Point pos, Math::Point dim, int icon, EventType eventMsg);
65  CLabel* CreateLabel(Math::Point pos, Math::Point dim, int icon, EventType eventMsg, std::string name);
66  CEdit* CreateEdit(Math::Point pos, Math::Point dim, int icon, EventType eventMsg);
67  CEditValue* CreateEditValue(Math::Point pos, Math::Point dim, int icon, EventType eventMsg);
68  CScroll* CreateScroll(Math::Point pos, Math::Point dim, int icon, EventType eventMsg);
69  CSlider* CreateSlider(Math::Point pos, Math::Point dim, int icon, EventType eventMsg);
70  CEnumSlider* CreateEnumSlider(Math::Point pos, Math::Point dim, int icon, EventType eventMsg);
71  CList* CreateList(Math::Point pos, Math::Point dim, int icon, EventType eventMsg, float expand=1.2f);
72  CShortcut* CreateShortcut(Math::Point pos, Math::Point dim, int icon, EventType eventMsg);
73  CMap* CreateMap(Math::Point pos, Math::Point dim, int icon, EventType eventMsg);
74  CGauge* CreateGauge(Math::Point pos, Math::Point dim, int icon, EventType eventMsg);
75  CTarget* CreateTarget(Math::Point pos, Math::Point dim, int icon, EventType eventMsg);
76  bool DeleteControl(EventType eventMsg);
77  CControl* SearchControl(EventType eventMsg);
78 
79  EventType GetEventTypeReduce();
80  EventType GetEventTypeFull();
81  EventType GetEventTypeClose();
82 
83  void SetName(std::string name, bool tooltip = true) override;
84 
85  void SetTrashEvent(bool bTrash);
86  bool GetTrashEvent();
87 
88  void SetPos(Math::Point pos) override;
89  void SetDim(Math::Point dim) override;
90 
91  void SetMinDim(Math::Point dim);
92  void SetMaxDim(Math::Point dim);
93  Math::Point GetMinDim();
94  Math::Point GetMaxDim();
95 
96  void SetMovable(bool bMode);
97  bool GetMovable();
98 
99  void SetRedim(bool bMode);
100  bool GetRedim();
101 
102  void SetClosable(bool bMode);
103  bool GetClosable();
104 
105  void SetMaximized(bool bMaxi);
106  bool GetMaximized();
107  void SetMinimized(bool bMini);
108  bool GetMinimized();
109  void SetFixed(bool bFix);
110  bool GetFixed();
111 
112  bool GetTooltip(Math::Point pos, std::string &name) override;
113 
114  bool EventProcess(const Event &event) override;
115 
116  void Draw() override;
117 
118  void SetFocus(CControl* focusControl) override;
119 
120 protected:
121  int BorderDetect(Math::Point pos);
122  void AdjustButtons();
123  void MoveAdjust();
124  void DrawVertex(Math::Point pos, Math::Point dim, int icon);
125  void DrawHach(Math::Point pos, Math::Point dim);
126  template<typename ControlClass>
127  ControlClass* CreateControl(Math::Point pos, Math::Point dim, int icon, EventType eventMsg);
128 
129 protected:
130  std::vector<std::unique_ptr<CControl>> m_controls;
131 
132  bool m_bTrashEvent;
133  bool m_bMaximized;
134  bool m_bMinimized;
135  bool m_bFixed;
136 
137  Math::Point m_minDim;
138  Math::Point m_maxDim;
139 
140  std::unique_ptr<CButton> m_buttonReduce;
141  std::unique_ptr<CButton> m_buttonFull;
142  std::unique_ptr<CButton> m_buttonClose;
143 
144  bool m_bMovable;
145  bool m_bRedim;
146  bool m_bClosable;
147  bool m_bCapture;
148  Math::Point m_pressPos;
149  int m_pressFlags;
150  Gfx::EngineMouseType m_pressMouse;
151 };
152 
153 
154 } // namespace Ui
Definition: gauge.h:27
Main graphics engine - CEngine class.
Definition: map.h:69
Definition: shortcut.h:29
Definition: robotmain.h:108
Definition: list.h:41
Definition: group.h:27
Definition: target.h:34
Definition: editvalue.h:42
Definition: button.h:29
Definition: color.h:29
Definition: label.h:29
Definition: slider.h:31
2D point
Definition: point.h:50
Definition: check.h:27
Image loaded from file.
Definition: image.h:54
Definition: image.h:27
EngineMouseType
Type of mouse cursor displayed in-game.
Definition: engine.h:444
Definition: edit.h:112
Definition: enumslider.h:30
Definition: key.h:39
Definition: scroll.h:37
EventType
Type of event message.
Definition: event.h:41
Event sent by system, interface or game.
Definition: event.h:735
Definition: window.h:51
Definition: control.h:65