widgets/textbox.hpp

Go to the documentation of this file.
00001 /* $Id: textbox.hpp 52533 2012-01-07 02:35:17Z shadowmaster $ */
00002 /*
00003    Copyright (C) 2003 - 2012 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 as published by
00008    the Free Software Foundation; either version 2 of the License, or
00009    (at your option) any later version.
00010    This program is distributed in the hope that it will be useful,
00011    but WITHOUT ANY WARRANTY.
00012 
00013    See the COPYING file for more details.
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     // mutable unsigned int firstOnScreen_;
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     //records the time the cursor was shown at last
00071     //the cursor should be inverted every 500 ms.
00072     //this will be reset when keyboard input events occur
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     //make it so that only one textbox object can be receiving
00092     //events at a time.
00093     bool requires_event_focus(const SDL_Event *event=NULL) const;
00094 
00095     bool show_scrollbar() const;
00096 };
00097 
00098 }
00099 
00100 #endif
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines

Generated by doxygen 1.7.1 on Fri May 25 2012 01:03:15 for The Battle for Wesnoth
Gna! | Forum | Wiki | CIA | devdocs