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