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