textbox.hpp

Go to the documentation of this file.
00001 /* $Id: textbox.hpp 26069 2008-04-24 18:28:15Z mordante $ */
00002 /*
00003    Copyright (C) 2003 - 2008 by David White <dave@whitevine.net>
00004    Part of the Battle for Wesnoth Project http://www.wesnoth.org/
00005 
00006    This program is free software; you can redistribute it and/or modify
00007    it under the terms of the GNU General Public License version 2
00008    or at your option any later version.
00009    This program is distributed in the hope that it will be useful,
00010    but WITHOUT ANY WARRANTY.
00011 
00012    See the COPYING file for more details.
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     //VC++ doesn't like a 'using scrollarea::set_location' directive here, so we declare
00049     //an inline forwarding function instead
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     // mutable unsigned int firstOnScreen_;
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     //records the time the cursor was shown at last
00079     //the cursor should be inverted every 500 ms.
00080     //this will be reset when keyboard input events occur
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     //make it so that only one textbox object can be receiving
00100     //events at a time.
00101     bool requires_event_focus(const SDL_Event *event=NULL) const;
00102 
00103     bool show_scrollbar() const;
00104 };
00105 
00106 }
00107 
00108 #endif

Generated by doxygen 1.5.5 on 23 May 2008 for The Battle for Wesnoth
Gna! | Forum | Wiki | CIA | devdocs