Colobot
edit.h
Go to the documentation of this file.
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 
26 #pragma once
27 
28 #include "ui/controls/control.h"
29 
30 #include <memory>
31 
32 namespace Ui
33 {
34 
35 class CScroll;
36 
38 const int EDITHISTORYMAX = 50;
40 const int EDITUNDOMAX = 20;
41 
42 struct EditUndo
43 {
45  std::string text;
47  int len = 0;
49  int cursor1 = 0;
51  int cursor2 = 0;
53  int lineFirst = 0;
54 
55 };
56 
58 {
65 };
66 
67 struct ImageLine
68 {
70  std::string name;
72  float offset = 0.0f;
74  float height = 0.0f;
76  float width = 0.0f;
77 };
78 
79 struct HyperLink
80 {
82  std::string name;
84  std::string marker;
85 };
86 
88 {
90  std::string name;
92  int pos = 0;
93 };
94 
96 {
98  std::string filename;
100  int firstLine = 0;
101 };
102 
103 
104 
105 
106 class CEdit : public CControl
107 {
108 public:
109  CEdit ();
110 
111  virtual ~CEdit();
112 
113  bool Create(Math::Point pos, Math::Point dim, int icon, EventType eventType) override;
114 
115  void SetPos(Math::Point pos) override;
116  void SetDim(Math::Point dim) override;
117 
118  bool EventProcess(const Event &event) override;
119  void Draw() override;
120 
121  void SetText(const std::string& text, bool bNew=true);
122  std::string GetText(int max);
123  const std::string& GetText();
124  int GetTextLength();
125 
126  bool ReadText(std::string filename);
127  bool WriteText(std::string filename);
128 
129  void SetMaxChar(int max);
130  int GetMaxChar();
131 
132  void SetEditCap(bool bMode);
133  bool GetEditCap();
134 
135  void SetHighlightCap(bool bEnable);
136  bool GetHighlightCap();
137 
138  void SetInsideScroll(bool bInside);
139  bool GetInsideScroll();
140 
141  void SetSoluceMode(bool bSoluce);
142  bool GetSoluceMode();
143 
144  void SetGenericMode(bool bGeneric);
145  bool GetGenericMode();
146 
147  void SetAutoIndent(bool bMode);
148  bool GetAutoIndent();
149 
150  void SetCursor(int cursor1, int cursor2);
151  void GetCursor(int &cursor1, int &cursor2);
152 
153  void SetFirstLine(int rank);
154  int GetFirstLine();
155  void ShowSelect();
156 
157  void SetDisplaySpec(bool bDisplay);
158  bool GetDisplaySpec();
159 
160  void SetMultiFont(bool bMulti);
161  bool GetMultiFont();
162 
163  bool Cut();
164  bool Copy(bool memorize_cursor = false);
165  bool Paste();
166  bool Undo();
167 
168  void HyperFlush();
169  void HyperHome(std::string filename);
170  bool HyperTest(EventType event);
171  bool HyperGo(EventType event);
172 
173  void SetFontSize(float size) override;
174 
175  bool ClearFormat();
176  bool SetFormat(int cursor1, int cursor2, int format);
177 
178 protected:
179  void SendModifEvent();
180  bool IsLinkPos(Math::Point pos);
181  void MouseDoubleClick(Math::Point mouse);
182  void MouseClick(Math::Point mouse);
183  void MouseMove(Math::Point mouse);
184  void MouseRelease(Math::Point mouse);
185  int MouseDetect(Math::Point mouse);
186  void MoveAdjust();
187 
188  void HyperJump(std::string name, std::string marker);
189  bool HyperAdd(std::string filename, int firstLine);
190 
191  void DrawImage(Math::Point pos, std::string name, float width, float offset, float height, int nbLine);
192  void DrawBack(Math::Point pos, Math::Point dim);
193 
194  void DrawHorizontalGradient(Math::Point pos, Math::Point dim, Gfx::Color color1, Gfx::Color color2);
195  void DrawColor(Math::Point pos, Math::Point dim, Gfx::Color color);
196 
197  void FreeImage();
198  void Scroll(int pos, bool bAdjustCursor);
199  void Scroll();
200  void MoveChar(int move, bool bWord, bool bSelect);
201  void MoveLine(int move, bool bWord, bool bSelect);
202  void MoveHome(bool bWord, bool bSelect);
203  void MoveEnd(bool bWord, bool bSelect);
204  void ColumnFix();
205  void Insert(char character);
206  void InsertOne(char character);
207  void Delete(int dir);
208  void DeleteOne(int dir);
209  int IndentCompute();
210  int IndentTabCount();
211  void IndentTabAdjust(int number);
212  bool Shift(bool bLeft);
213  bool MinMaj(bool bMaj);
214  void Justif();
215  int GetCursorLine(int cursor);
216 
217  void UndoFlush();
218  void UndoMemorize(OperUndo oper);
219  bool UndoRecall();
220 
221  void UpdateScroll();
222 
223  void SetFocus(CControl* control) override;
224  void UpdateFocus(); // Start/stop text input mode, this toggles the on-screen keyboard
225 
226  void GetIndentedText(std::ostream& stream, unsigned int start, unsigned int end);
227 
228 protected:
229  std::unique_ptr<CScroll> m_scroll; // vertical scrollbar on the right
230 
231  int m_maxChar;
232  std::string m_text; // text (without zero terminator)
233  std::vector<Gfx::FontMetaChar> m_format; // format characters
234  int m_len; // length used in m_text
235  int m_cursor1; // offset cursor
236  int m_cursor2; // offset cursor
237 
238  bool m_bMulti; // true -> multi-line
239  bool m_bEdit; // true -> editable
240  bool m_bHilite; // true -> hilitable
241  bool m_bInsideScroll; // true -> lift as part
242  bool m_bDisplaySpec; // true -> displays the special characters
243  bool m_bMultiFont; // true -> more fonts possible
244  bool m_bSoluce; // true -> shows the links-solution
245  bool m_bGeneric; // true -> generic that defile
246  bool m_bAutoIndent; // true -> automatic indentation
247  float m_lineHeight; // height of a row
248  float m_lineAscent; // height above the baseline
249  float m_lineDescent; // height below the baseline
250  int m_lineVisible; // total number of viewable lines
251  int m_lineFirst; // the first line displayed
252  int m_lineTotal; // number lines used (in m_lineOffset)
253  std::vector<int> m_lineOffset;
254  std::vector<char> m_lineIndent;
255  std::vector<ImageLine> m_image;
256  std::vector<HyperLink> m_link;
257  std::vector<HyperMarker> m_marker;
258  int m_historyTotal;
259  int m_historyCurrent;
260  std::array<HyperHistory, EDITHISTORYMAX> m_history;
261  float m_time; // absolute time
262  float m_timeBlink;
263  float m_timeLastClick;
264  float m_timeLastScroll;
265  Math::Point m_mouseFirstPos;
266  Math::Point m_mouseLastPos;
267  float m_column;
268 
269  bool m_bCapture;
270 
271  bool m_bUndoForce;
272  OperUndo m_undoOper;
273  std::array<EditUndo, EDITUNDOMAX> m_undo;
274 };
275 
276 
277 }
Definition: edit.h:42
special operation
Definition: edit.h:60
deleting characters
Definition: edit.h:64
Definition: robotmain.h:108
std::string name
name of the image (without icons/)
Definition: edit.h:70
Definition: edit.h:95
OperUndo
Definition: edit.h:57
std::string name
name of the marker
Definition: edit.h:90
int cursor2
offset cursor
Definition: edit.h:51
2D point
Definition: point.h:50
int lineFirst
the first line displayed.
Definition: edit.h:53
const int EDITHISTORYMAX
max number of levels preserves
Definition: edit.h:38
std::string text
original text
Definition: edit.h:45
inserting characters
Definition: edit.h:62
Definition: edit.h:106
Definition: edit.h:87
RGBA color.
Definition: color.h:39
EventType
Type of event message.
Definition: event.h:41
Event sent by system, interface or game.
Definition: event.h:735
int cursor1
offset cursor
Definition: edit.h:49
int len
length of the text
Definition: edit.h:47
Definition: edit.h:67
std::string filename
full file name text
Definition: edit.h:98
Definition: control.h:65
const int EDITUNDOMAX
max number of successive undo
Definition: edit.h:40