cgv
text_editor.h
1 #pragma once
2 
3 #include <cgv/base/named.h>
4 #include <cgv/data/ref_ptr.h>
5 #include <cgv/media/font/font.h>
6 
7 #include "lib_begin.h"
8 
9 namespace cgv {
10  namespace gui {
11 
14 {
16  virtual void on_close_editor();
18  virtual void after_read();
20  virtual void after_save();
22  virtual void on_text_insertion(int text_pos, int nr_inserted);
24  virtual void on_text_deletion(int text_pos, int nr_deleted, const char* deleted_text);
26  virtual void on_update_callback();
27 };
28 
30 struct text_style
31 {
33  int color;
37  float font_size;
38 };
39 
41 class CGV_API text_editor : public base::named
42 {
43 protected:
46 public:
48  text_editor(const std::string& name, text_editor_callback_handler* _handler = 0);
50  void set_callback_handler(text_editor_callback_handler* _handler);
52  const text_editor_callback_handler* get_callback_handler() const;
54  virtual ~text_editor();
56  virtual void set_base_path(const std::string& path) = 0;
58  virtual void set_filter(const std::string& filter) = 0;
60  virtual bool read(const std::string& file_name) = 0;
62  virtual bool is_modified() const = 0;
64  virtual bool save() = 0;
66  virtual void show() = 0;
68  virtual void hide() = 0;
70  virtual bool is_visible() const = 0;
72  virtual const char* get_text() const = 0;
74  virtual void set_text(const std::string& new_text) = 0;
76  virtual const char* get_style() const = 0;
78  virtual void set_style(int text_pos, int length, const char* style) = 0;
80  virtual unsigned int get_length() const = 0;
82  virtual void set_text_styles(const text_style* table, int nr_styles) = 0;
83 };
84 
87 
88 #if _MSC_VER >= 1400
89 CGV_TEMPLATE template class CGV_API data::ref_ptr<text_editor_ptr>;
90 #endif
91 
93 extern CGV_API text_editor_ptr create_text_editor(unsigned int w, unsigned int h, const std::string& title, int x=-1, int y=-1);
94 
95  }
96 }
97 
98 #include <cgv/config/lib_end.h>
cgv::gui::text_style
Definition: text_editor.h:31
cgv::gui::text_editor::handler
text_editor_callback_handler * handler
store a callback handler
Definition: text_editor.h:45
cgv::gui::text_style::font_face
cgv::media::font::font_face_ptr font_face
font face string with font name first, followed by +bold and or +italic
Definition: text_editor.h:35
cgv::gui::text_editor::is_visible
virtual bool is_visible() const =0
return whether editor is visible
cgv::gui::text_editor_callback_handler
Definition: text_editor.h:14
cgv::gui::text_editor::read
virtual bool read(const std::string &file_name)=0
read a new text file
cgv::gui::text_editor_ptr
data::ref_ptr< text_editor > text_editor_ptr
ref counted pointer to abst control
Definition: text_editor.h:86
cgv::gui::text_editor::save
virtual bool save()=0
save the current file
cgv::data::ref_ptr< font_face >
cgv::gui::text_editor::show
virtual void show()=0
show editor
cgv::base::named
Definition: named.h:17
cgv::gui::text_style::color
int color
rgb color packed into one integer, i.e. 0xff00ff corresponds to magenta
Definition: text_editor.h:33
cgv::gui::text_editor::set_base_path
virtual void set_base_path(const std::string &path)=0
set a different base path used for the file open and save dialog
cgv::gui::text_editor::is_modified
virtual bool is_modified() const =0
check if the current file is modified
cgv::gui::text_editor::set_filter
virtual void set_filter(const std::string &filter)=0
set a file filter for the file open and save dialog, default is "*"
cgv::gui::text_editor
abstract base class for text editors
Definition: text_editor.h:42
cgv::gui::text_editor::hide
virtual void hide()=0
hide editor
cgv::gui::create_text_editor
text_editor_ptr create_text_editor(unsigned int w, unsigned int h, const std::string &title, int x, int y)
construct a new text editor in a separate window of given size, title and position
Definition: text_editor.cxx:9
cgv::gui::text_editor::set_style
virtual void set_style(int text_pos, int length, const char *style)=0
set the style of a given text portion
cgv::gui::text_style::font_size
float font_size
font size in pixels
Definition: text_editor.h:37
cgv::gui::text_editor::get_style
virtual const char * get_style() const =0
return pointer to style buffer
cgv::gui::text_editor::get_text
virtual const char * get_text() const =0
return pointer to text buffer
cgv::gui::text_editor::get_length
virtual unsigned int get_length() const =0
return length of text and style buffer
cgv
the cgv namespace
Definition: vr_calib.cxx:9
cgv::gui::text_editor::set_text
virtual void set_text(const std::string &new_text)=0
replace the complete text
cgv::gui::text_editor::set_text_styles
virtual void set_text_styles(const text_style *table, int nr_styles)=0
set text styles from a table, where the first style is labeled with the character A,...