Colobot
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Pages
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-2014, Daniel Roux, EPSITEC SA & TerranovaTeam
4  * http://epsiteс.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 
29 #include "ui/control.h"
30 #include "ui/scroll.h"
31 
32 #include "graphics/engine/engine.h"
33 #include "graphics/engine/text.h"
34 
35 #include "common/event.h"
36 #include "common/misc.h"
37 #include "common/restext.h"
38 
39 #include <set>
40 #include <string>
41 #include <cstdlib>
42 
43 #include <boost/filesystem.hpp>
44 #include <boost/algorithm/string.hpp>
45 
46 namespace fs = boost::filesystem;
47 
48 
49 namespace Ui {
50 
51 
52 
54 const int EDITSTUDIOMAX = 20000;
56 const int EDITLINEMAX = 1000;
58 const int EDITIMAGEMAX = 100;
60 const int EDITLINKMAX = 100;
62 const int EDITHISTORYMAX = 50;
63 
65 const int EDITUNDOMAX = 20;
66 
67 struct EditUndo
68 {
70  char* text;
72  int len;
74  int cursor1;
76  int cursor2;
78  int lineFirst;
79 
80 };
81 
82 enum OperUndo
83 {
85  OPERUNDO_SPEC = 0,
87  OPERUNDO_INSERT = 1,
89  OPERUNDO_DELETE = 2,
90 };
91 
92 struct ImageLine
93 {
95  std::string name;
97  float offset;
99  float height;
101  float width;
102 };
103 
104 struct HyperLink
105 {
107  std::string name;
109  std::string marker;
110 };
111 
113 {
115  std::string name;
117  int pos;
118 };
119 
121 {
123  std::string filename;
126 };
127 
128 
129 
130 
131 class CEdit : public CControl
132 {
133 public:
134  CEdit ();
135 
136  virtual ~CEdit();
137 
138  bool Create(Math::Point pos, Math::Point dim, int icon, EventType eventType);
139 
140  void SetPos(Math::Point pos);
141  void SetDim(Math::Point dim);
142 
143  bool EventProcess(const Event &event);
144  void Draw();
145 
146  void SetText(const char *text, bool bNew=true);
147  void GetText(char *buffer, int max);
148  char* GetText();
149  int GetTextLength();
150 
151  bool ReadText(std::string filename, int addSize=0);
152  bool WriteText(std::string filename);
153 
154  void SetMaxChar(int max);
155  int GetMaxChar();
156 
157  void SetEditCap(bool bMode);
158  bool GetEditCap();
159 
160  void SetHighlightCap(bool bEnable);
161  bool GetHighlightCap();
162 
163  void SetInsideScroll(bool bInside);
164  bool GetInsideScroll();
165 
166  void SetSoluceMode(bool bSoluce);
167  bool GetSoluceMode();
168 
169  void SetGenericMode(bool bGeneric);
170  bool GetGenericMode();
171 
172  void SetAutoIndent(bool bMode);
173  bool GetAutoIndent();
174 
175  void SetCursor(int cursor1, int cursor2);
176  void GetCursor(int &cursor1, int &cursor2);
177 
178  void SetFirstLine(int rank);
179  int GetFirstLine();
180  void ShowSelect();
181 
182  void SetDisplaySpec(bool bDisplay);
183  bool GetDisplaySpec();
184 
185  void SetMultiFont(bool bMulti);
186  bool GetMultiFont();
187 
188  bool Cut();
189  bool Copy(bool memorize_cursor = false);
190  bool Paste();
191  bool Undo();
192 
193  void HyperFlush();
194  void HyperHome(std::string filename);
195  bool HyperTest(EventType event);
196  bool HyperGo(EventType event);
197 
198  void SetFontSize(float size);
199 
200  bool ClearFormat();
201  bool SetFormat(int cursor1, int cursor2, int format);
202 
203 protected:
204  void SendModifEvent();
205  bool IsLinkPos(Math::Point pos);
206  void MouseDoubleClick(Math::Point mouse);
207  void MouseClick(Math::Point mouse);
208  void MouseMove(Math::Point mouse);
209  void MouseRelease(Math::Point mouse);
210  int MouseDetect(Math::Point mouse);
211  void MoveAdjust();
212 
213  void HyperJump(std::string name, std::string marker);
214  bool HyperAdd(std::string filename, int firstLine);
215 
216  void DrawImage(Math::Point pos, std::string name, float width, float offset, float height, int nbLine);
217  void DrawBack(Math::Point pos, Math::Point dim);
218  void DrawPart(Math::Point pos, Math::Point dim, int icon);
219 
220  void FreeImage();
221  void LoadImage(std::string name);
222  void Scroll(int pos, bool bAdjustCursor);
223  void Scroll();
224  void MoveChar(int move, bool bWord, bool bSelect);
225  void MoveLine(int move, bool bWord, bool bSelect);
226  void MoveHome(bool bWord, bool bSelect);
227  void MoveEnd(bool bWord, bool bSelect);
228  void ColumnFix();
229  void Insert(char character);
230  void InsertOne(char character);
231  void Delete(int dir);
232  void DeleteOne(int dir);
233  int IndentCompute();
234  int IndentTabCount();
235  void IndentTabAdjust(int number);
236  bool Shift(bool bLeft);
237  bool MinMaj(bool bMaj);
238  void Justif();
239  int GetCursorLine(int cursor);
240 
241  void UndoFlush();
242  void UndoMemorize(OperUndo oper);
243  bool UndoRecall();
244 
245  void UpdateScroll();
246 
247 protected:
248  CScroll* m_scroll; // vertical scrollbar on the right
249 
250  int m_maxChar; // max length of the buffer m_text
251  char* m_text; // text (without zero terminator)
252  std::vector<Gfx::FontMetaChar> m_format; // format characters
253  int m_len; // length used in m_text
254  int m_cursor1; // offset cursor
255  int m_cursor2; // offset cursor
256 
257  bool m_bMulti; // true -> multi-line
258  bool m_bEdit; // true -> editable
259  bool m_bHilite; // true -> hilitable
260  bool m_bInsideScroll; // true -> lift as part
261  bool m_bDisplaySpec; // true -> displays the special characters
262  bool m_bMultiFont; // true -> more fonts possible
263  bool m_bSoluce; // true -> shows the links-solution
264  bool m_bGeneric; // true -> generic that defile
265  bool m_bAutoIndent; // true -> automatic indentation
266  float m_lineHeight; // height of a row
267  float m_lineAscent; // height above the baseline
268  float m_lineDescent; // height below the baseline
269  int m_lineVisible; // total number of viewable lines
270  int m_lineFirst; // the first line displayed
271  int m_lineTotal; // number lines used (in m_lineOffset)
272  int m_lineOffset[EDITLINEMAX];
273  char m_lineIndent[EDITLINEMAX];
274  int m_imageTotal;
275  ImageLine m_image[EDITIMAGEMAX];
276  HyperLink m_link[EDITLINKMAX];
277  int m_markerTotal;
278  HyperMarker m_marker[EDITLINKMAX];
279  int m_historyTotal;
280  int m_historyCurrent;
281  HyperHistory m_history[EDITHISTORYMAX];
282  float m_time; // absolute time
283  float m_timeBlink;
284  float m_timeLastClick;
285  float m_timeLastScroll;
286  Math::Point m_mouseFirstPos;
287  Math::Point m_mouseLastPos;
288  float m_column;
289 
290  bool m_bCapture;
291 
292  bool m_bUndoForce;
293  OperUndo m_undoOper;
294  EditUndo m_undo[EDITUNDOMAX];
295 };
296 
297 
298 }
299 
Definition: edit.h:67
Main graphics engine - CEngine class.
int firstLine
rank of the first displayed line
Definition: edit.h:125
float width
width
Definition: edit.h:101
Definition: controller.h:32
Text rendering - CText class.
std::string name
name of the image (without icons/)
Definition: edit.h:95
int pos
position in the text
Definition: edit.h:117
Definition: edit.h:120
std::string name
name of the marker
Definition: edit.h:115
Translation and string resource utilities.
int cursor2
offset cursor
Definition: edit.h:76
CEdit()
Object's constructor.
Definition: edit.cpp:87
2D point
Definition: point.h:49
float height
height of the part (dv texture)
Definition: edit.h:99
int lineFirst
the first line displayed.
Definition: edit.h:78
char * text
original text
Definition: edit.h:70
float offset
vertical offset (v texture)
Definition: edit.h:97
Event types, structs and event queue.
Definition: edit.h:131
Definition: edit.h:112
Definition: scroll.h:37
EventType
Type of event message.
Definition: event.h:38
Event sent by system, interface or game.
Definition: event.h:678
int cursor1
offset cursor
Definition: edit.h:74
int len
length of the text
Definition: edit.h:72
Definition: edit.h:92
std::string filename
full file name text
Definition: edit.h:123
Definition: control.h:66