Colobot
control.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 "common/event.h"
23 
24 #include "graphics/engine/text.h"
25 
26 #include <string>
27 
28 class CRobotMain;
29 class CSoundInterface;
30 class CSettings;
31 
32 namespace Gfx
33 {
34 class CEngine;
35 class CParticle;
36 }
37 
38 
39 namespace Ui
40 {
41 
42 enum ControlState
43 {
44  STATE_ENABLE = (1<<0), // active
45  STATE_CHECK = (1<<1), // pressed
46  STATE_HILIGHT = (1<<2), // overflown by mouse
47  STATE_PRESS = (1<<3), // pressed by mouse
48  STATE_VISIBLE = (1<<4), // visible
49  STATE_DEAD = (1<<5), // inaccessible (x)
50  STATE_DEFAULT = (1<<6), // actuated by RETURN
51  STATE_OKAY = (1<<7), // green point at the bottom right
52  STATE_SHADOW = (1<<8), // shadow
53  STATE_GLINT = (1<<9), // dynamic reflection
54  STATE_CARD = (1<<10), // tab
55  STATE_EXTEND = (1<<11), // extended mode
56  STATE_SIMPLY = (1<<12), // undecorated
57  STATE_FRAME = (1<<13), // framework highlighting
58  STATE_WARNING = (1<<14), // framework hatched yellow / black
59  STATE_VALUE = (1<<15), // displays the value
60  STATE_RUN = (1<<16) // running program
61 };
62 
63 
64 
65 class CControl
66 {
67 public:
68  CControl();
69  virtual ~CControl();
70 
71  virtual bool Create(Math::Point pos, Math::Point dim, int icon, EventType eventType);
72 
73  virtual bool EventProcess(const Event &event);
74 
75  virtual void SetPos(Math::Point pos);
76  virtual Math::Point GetPos();
77  virtual void SetDim(Math::Point dim);
78  virtual Math::Point GetDim();
79  virtual bool SetState(int state, bool bState);
80  virtual bool SetState(int state);
81  virtual bool ClearState(int state);
82  virtual bool TestState(int state);
83  virtual int GetState();
84  virtual void SetIcon(int icon);
85  virtual int GetIcon();
86  virtual void SetName(std::string name, bool bTooltip=true);
87  virtual std::string GetName();
88  virtual void SetTextAlign(Gfx::TextAlign mode);
89  virtual int GetTextAlign();
90  virtual void SetFontSize(float size);
91  virtual float GetFontSize();
92  virtual void SetFontStretch(float stretch);
93  virtual float GetFontStretch();
94  virtual void SetFontType(Gfx::FontType font);
95  virtual Gfx::FontType GetFontType();
96  virtual bool SetTooltip(std::string name);
97  virtual bool GetTooltip(Math::Point pos, std::string &name);
98  virtual void SetFocus(CControl* focusControl);
99  virtual bool GetFocus();
100 
101  virtual EventType GetEventType();
102 
103  virtual void Draw();
104 
105 protected:
106  void GlintDelete();
107  void GlintCreate(Math::Point ref, bool bLeft=true, bool bUp=true);
108  void GlintFrame(const Event &event);
109  void DrawPart(int icon, float zoom, float ex);
110  void DrawIcon(Math::Point pos, Math::Point dim, Math::Point uv1, Math::Point uv2, float ex=0.0f);
111  void DrawIcon(Math::Point pos, Math::Point dim, Math::Point uv1, Math::Point uv2, Math::Point corner, float ex);
112  void DrawWarning(Math::Point pos, Math::Point dim);
113  void DrawShadow(Math::Point pos, Math::Point dim, float deep=1.0f);
114  virtual bool Detect(Math::Point pos);
115 
116  std::string GetResourceName(EventType eventType);
117 
118 protected:
119  Gfx::CEngine* m_engine;
120  Gfx::CParticle* m_particle;
121  CEventQueue* m_event;
122  CRobotMain* m_main;
123  CSoundInterface* m_sound;
124  CSettings* m_settings;
125 
126  Math::Point m_pos; // corner upper / left
127  Math::Point m_dim; // dimensions
128  int m_icon;
129  EventType m_eventType; // message to send when clicking
130  int m_state; // states (STATE_ *)
131  float m_fontSize; // size of the button name
132  float m_fontStretch; // stretch of the font
133  Gfx::FontType m_fontType; // type of font
134  Gfx::TextAlign m_textAlign; //type of alignment //comes in the place of m_justif
135  std::string m_name; // name of the button
136  std::string m_tooltip; // name of tooltip
137  bool m_bFocus;
138  bool m_bCapture;
139 
140  bool m_bGlint;
141  Math::Point m_glintCorner1;
142  Math::Point m_glintCorner2;
143  float m_glintProgress;
144  Math::Point m_glintMouse;
145 };
146 
147 } // namespace Ui
Definition: robotmain.h:108
Text rendering - CText class.
Global event queue.
Definition: event.h:866
Definition: robotmain.h:159
Particle engine.
Definition: particle.h:223
Definition: settings.h:32
2D point
Definition: point.h:50
Namespace for (new) graphics code.
Definition: app.h:49
The graphics engine.
Definition: engine.h:585
Event types, structs and event queue.
TextAlign
Type of text alignment.
Definition: text.h:54
EventType
Type of event message.
Definition: event.h:41
Event sent by system, interface or game.
Definition: event.h:735
Definition: control.h:65
FontType
Type of font.
Definition: text.h:72
Sound plugin interface.
Definition: sound.h:60