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