Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016 #ifndef TEXTBOX_HPP_INCLUDED
00017 #define TEXTBOX_HPP_INCLUDED
00018
00019 #include "../serialization/string_utils.hpp"
00020 #include "font.hpp"
00021
00022 #include "scrollarea.hpp"
00023
00024 namespace gui {
00025
00026 class textbox : public scrollarea
00027 {
00028 public:
00029 textbox(CVideo &video, int width, const std::string& text="", bool editable=true, size_t max_size = 256, double alpha = 0.4, double alpha_focus = 0.2, const bool auto_join = true);
00030 virtual ~textbox();
00031
00032 const std::string text() const;
00033 void set_text(const std::string& text, const SDL_Color& color =font::NORMAL_COLOR);
00034 void append_text(const std::string& text,bool auto_scroll = false, const SDL_Color& color =font::NORMAL_COLOR);
00035 void clear();
00036
00037 void set_editable(bool value);
00038 bool editable() const;
00039
00040 void scroll_to_bottom();
00041
00042 void set_wrap(bool val);
00043
00044 protected:
00045 virtual void draw_contents();
00046 virtual void set_inner_location(SDL_Rect const &);
00047 virtual void scroll(unsigned int pos);
00048
00049 private:
00050 virtual void handle_text_changed(const wide_string&) {}
00051
00052 size_t max_size_;
00053
00054 wide_string text_;
00055
00056
00057 int cursor_;
00058 int selstart_;
00059 int selend_;
00060 bool grabmouse_;
00061
00062 int text_pos_;
00063 int cursor_pos_;
00064 std::vector<int> char_x_, char_y_;
00065
00066 bool editable_;
00067
00068 bool show_cursor_;
00069
00070
00071
00072
00073 int show_cursor_at_;
00074 surface text_image_;
00075
00076 bool wrap_;
00077
00078 size_t line_height_, yscroll_;
00079
00080 double alpha_;
00081 double alpha_focus_;
00082
00083 void handle_event(const SDL_Event& event);
00084
00085 void draw_cursor(int pos, CVideo &video) const;
00086 void update_text_cache(bool reset = false, const SDL_Color& color =font::NORMAL_COLOR);
00087 surface add_text_line(const wide_string& text, const SDL_Color& color =font::NORMAL_COLOR);
00088 bool is_selection();
00089 void erase_selection();
00090
00091
00092
00093 bool requires_event_focus(const SDL_Event *event=NULL) const;
00094
00095 bool show_scrollbar() const;
00096 };
00097
00098 }
00099
00100 #endif