The Battle for Wesnoth  1.15.2+dev
Public Member Functions | Protected Member Functions | Private Member Functions | Private Attributes | List of all members
gui::textbox Class Reference

#include <textbox.hpp>

Inheritance diagram for gui::textbox:
Inheritance graph

Public Member Functions

 textbox (CVideo &video, int width, const std::string &text="", bool editable=true, std::size_t max_size=256, int font_size=font::SIZE_PLUS, double alpha=0.4, double alpha_focus=0.2, const bool auto_join=true)
 
virtual ~textbox ()
 
const std::string text () const
 
void set_text (const std::string &text, const color_t &color=font::NORMAL_COLOR)
 
void append_text (const std::string &text, bool auto_scroll=false, const color_t &color=font::NORMAL_COLOR)
 
void clear ()
 
void set_selection (const int selstart, const int selend)
 
void set_cursor_pos (const int cursor_pos)
 
void set_editable (bool value)
 
bool editable () const
 
int font_size () const
 
void set_font_size (int fs)
 
void scroll_to_bottom ()
 
void set_wrap (bool val)
 
void set_edit_target (textbox *target)
 
- Public Member Functions inherited from gui::scrollarea
 scrollarea (CVideo &video, bool auto_join=true)
 Create a zone with automatic handling of scrollbar. More...
 
virtual void hide (bool value=true)
 
- Public Member Functions inherited from gui::widget
const SDL_Rect & location () const
 
virtual void set_location (const SDL_Rect &rect)
 
void set_location (int x, int y)
 
void set_width (int w)
 
void set_height (int h)
 
void set_measurements (int w, int h)
 
int width () const
 
int height () const
 
bool focus (const SDL_Event *event)
 
void set_focus (bool focus)
 
bool hidden () const
 
virtual void enable (bool new_val=true)
 
bool enabled () const
 
void set_clip_rect (const SDL_Rect &rect)
 
void set_volatile (bool val=true)
 
void set_dirty (bool dirty=true)
 
bool dirty () const
 
const std::string & id () const
 
void set_id (const std::string &id)
 
void set_help_string (const std::string &str)
 
void set_tooltip_string (const std::string &str)
 
virtual void process_help_string (int mousex, int mousey)
 
virtual void process_tooltip_string (int mousex, int mousey)
 
virtual void draw ()
 
- Public Member Functions inherited from events::sdl_handler
virtual void join ()
 
virtual void join (context &c)
 
virtual void join_same (sdl_handler *parent)
 
virtual void leave ()
 
virtual void join_global ()
 
virtual void leave_global ()
 
virtual bool has_joined ()
 
virtual bool has_joined_global ()
 
sdl_handleroperator= (sdl_handler &&)=delete
 Moving would require two instances' context membership to be handled, it's simpler to delete these and require the two instances to be separately constructed / destructed. More...
 
 sdl_handler (sdl_handler &&)=delete
 

Protected Member Functions

virtual void draw_contents ()
 
virtual void update_location (const SDL_Rect &rect)
 
virtual void set_inner_location (const SDL_Rect &)
 
virtual void scroll (unsigned int pos)
 
- Protected Member Functions inherited from gui::scrollarea
virtual sdl_handler_vector handler_members ()
 
virtual void process_event ()
 
SDL_Rect inner_location () const
 
unsigned scrollbar_width () const
 
unsigned get_position () const
 
unsigned get_max_position () const
 
void set_position (unsigned pos)
 
void adjust_position (unsigned pos)
 
void move_position (int dep)
 
void set_shown_size (unsigned h)
 
void set_full_size (unsigned h)
 
void set_scroll_rate (unsigned r)
 
bool has_scrollbar () const
 
- Protected Member Functions inherited from gui::widget
 widget (CVideo &video, const bool auto_join=true)
 
virtual ~widget ()
 
void bg_register (const SDL_Rect &rect)
 
void bg_restore () const
 
void bg_restore (const SDL_Rect &rect) const
 
void bg_update ()
 
void bg_cancel ()
 
CVideovideo () const
 
const SDL_Rect * clip_rect () const
 
virtual sdl_handler_vector member_handlers ()
 
virtual void handle_window_event (const SDL_Event &event)
 
bool mouse_locked () const
 
void aquire_mouse_lock ()
 
void free_mouse_lock ()
 
- Protected Member Functions inherited from events::sdl_handler
 sdl_handler (const bool auto_join=true)
 
 sdl_handler (const sdl_handler &)
 
sdl_handleroperator= (const sdl_handler &)
 
virtual ~sdl_handler ()
 

Private Member Functions

virtual void handle_text_changed (const std::u32string &)
 
void handle_event (const SDL_Event &event, bool was_forwarded)
 
void handle_event (const SDL_Event &event)
 
void pass_event_to_target (const SDL_Event &event)
 
void draw_cursor (int pos) const
 
void update_text_cache (bool reset=false, const color_t &color=font::NORMAL_COLOR)
 
surface add_text_line (const std::u32string &text, const color_t &color=font::NORMAL_COLOR)
 
bool is_selection ()
 
void erase_selection ()
 
bool requires_event_focus (const SDL_Event *event=nullptr) const
 
bool show_scrollbar () const
 
bool handle_text_input (const SDL_Event &event)
 
bool handle_key_down (const SDL_Event &event)
 

Private Attributes

std::size_t max_size_
 
int font_size_
 
std::u32string text_
 
int cursor_
 
int selstart_
 
int selend_
 
bool grabmouse_
 
int text_pos_
 
int cursor_pos_
 
std::vector< int > char_x_
 
std::vector< int > char_y_
 
bool editable_
 
bool show_cursor_
 
int show_cursor_at_
 
surface text_image_
 
bool wrap_
 
std::size_t line_height_
 
std::size_t yscroll_
 
double alpha_
 
double alpha_focus_
 
textboxedit_target_
 
bool listening_
 

Additional Inherited Members

- Protected Attributes inherited from gui::widget
bool focus_
 

Detailed Description

Definition at line 25 of file textbox.hpp.

Constructor & Destructor Documentation

◆ textbox()

gui::textbox::textbox ( CVideo video,
int  width,
const std::string &  text = "",
bool  editable = true,
std::size_t  max_size = 256,
int  font_size = font::SIZE_PLUS,
double  alpha = 0.4,
double  alpha_focus = 0.2,
const bool  auto_join = true 
)

◆ ~textbox()

gui::textbox::~textbox ( )
virtual

Definition at line 50 of file textbox.cpp.

References cursor::get(), cursor::IBEAM, cursor::NORMAL, and cursor::set().

Member Function Documentation

◆ add_text_line()

surface gui::textbox::add_text_line ( const std::u32string &  text,
const color_t color = font::NORMAL_COLOR 
)
private

◆ append_text()

void gui::textbox::append_text ( const std::string &  text,
bool  auto_scroll = false,
const color_t color = font::NORMAL_COLOR 
)

◆ clear()

void gui::textbox::clear ( )

◆ draw_contents()

void gui::textbox::draw_contents ( )
protectedvirtual

◆ draw_cursor()

void gui::textbox::draw_cursor ( int  pos) const
private

◆ editable()

bool gui::textbox::editable ( ) const

Definition at line 268 of file textbox.cpp.

References editable_.

Referenced by handle_key_down(), and pass_event_to_target().

◆ erase_selection()

void gui::textbox::erase_selection ( )
private

Definition at line 402 of file textbox.cpp.

References cursor_, is_selection(), selend_, selstart_, and text_.

Referenced by handle_key_down(), and handle_text_input().

◆ font_size()

int gui::textbox::font_size ( ) const

Definition at line 273 of file textbox.cpp.

References font_size_.

◆ handle_event() [1/2]

void gui::textbox::handle_event ( const SDL_Event &  event,
bool  was_forwarded 
)
private

◆ handle_event() [2/2]

void gui::textbox::handle_event ( const SDL_Event &  event)
privatevirtual

Reimplemented from gui::scrollarea.

Definition at line 451 of file textbox.cpp.

References gui::widget::handle_event(), and handle_event().

◆ handle_key_down()

bool gui::textbox::handle_key_down ( const SDL_Event &  event)
private

◆ handle_text_changed()

virtual void gui::textbox::handle_text_changed ( const std::u32string &  )
inlineprivatevirtual

Definition at line 58 of file textbox.hpp.

Referenced by append_text(), clear(), handle_event(), and set_text().

◆ handle_text_input()

bool gui::textbox::handle_text_input ( const SDL_Event &  event)
private

◆ is_selection()

bool gui::textbox::is_selection ( )
private

Definition at line 397 of file textbox.cpp.

References selend_, and selstart_.

Referenced by draw_contents(), erase_selection(), handle_event(), handle_key_down(), and handle_text_input().

◆ pass_event_to_target()

void gui::textbox::pass_event_to_target ( const SDL_Event &  event)
private

Definition at line 756 of file textbox.cpp.

References edit_target_, editable(), and handle_event().

Referenced by handle_key_down(), and handle_text_input().

◆ requires_event_focus()

bool gui::textbox::requires_event_focus ( const SDL_Event *  event = nullptr) const
privatevirtual

Reimplemented from events::sdl_handler.

Definition at line 423 of file textbox.cpp.

References gui::widget::enabled(), gui::widget::focus_, and gui::widget::hidden().

◆ scroll()

void gui::textbox::scroll ( unsigned int  pos)
protectedvirtual

Implements gui::scrollarea.

Definition at line 297 of file textbox.cpp.

References gui::widget::set_dirty(), and yscroll_.

◆ scroll_to_bottom()

void gui::textbox::scroll_to_bottom ( )

Definition at line 283 of file textbox.cpp.

References gui::scrollarea::get_max_position(), and gui::scrollarea::set_position().

Referenced by append_text().

◆ set_cursor_pos()

void gui::textbox::set_cursor_pos ( const int  cursor_pos)

Definition at line 161 of file textbox.cpp.

References cursor_, editable_, gui::widget::set_dirty(), text_, update_text_cache(), and WRN_DP.

◆ set_edit_target()

void gui::textbox::set_edit_target ( textbox target)

Definition at line 763 of file textbox.cpp.

References edit_target_.

◆ set_editable()

void gui::textbox::set_editable ( bool  value)

Definition at line 263 of file textbox.cpp.

References editable_.

◆ set_font_size()

void gui::textbox::set_font_size ( int  fs)

Definition at line 278 of file textbox.cpp.

References font_size_.

◆ set_inner_location()

void gui::textbox::set_inner_location ( const SDL_Rect &  rect)
protectedvirtual

Implements gui::scrollarea.

Definition at line 65 of file textbox.cpp.

References gui::widget::bg_register(), text_image_, text_pos_, and update_text_cache().

◆ set_selection()

void gui::textbox::set_selection ( const int  selstart,
const int  selend 
)

Definition at line 146 of file textbox.cpp.

References editable_, selend_, selstart_, gui::widget::set_dirty(), text_, and WRN_DP.

Referenced by handle_key_down().

◆ set_text()

void gui::textbox::set_text ( const std::string &  text,
const color_t color = font::NORMAL_COLOR 
)

◆ set_wrap()

void gui::textbox::set_wrap ( bool  val)

Definition at line 288 of file textbox.cpp.

References gui::widget::set_dirty(), update_text_cache(), and wrap_.

◆ show_scrollbar()

bool gui::textbox::show_scrollbar ( ) const
private

◆ text()

const std::string gui::textbox::text ( ) const

Definition at line 73 of file textbox.cpp.

References text_, and unicode_cast().

Referenced by append_text(), and set_text().

◆ update_location()

void gui::textbox::update_location ( const SDL_Rect &  rect)
protectedvirtual

Reimplemented from gui::scrollarea.

Definition at line 58 of file textbox.cpp.

References gui::widget::set_dirty(), gui::scrollarea::update_location(), and update_text_cache().

◆ update_text_cache()

void gui::textbox::update_text_cache ( bool  reset = false,
const color_t color = font::NORMAL_COLOR 
)
private

Member Data Documentation

◆ alpha_

double gui::textbox::alpha_
private

Definition at line 90 of file textbox.hpp.

Referenced by draw_contents().

◆ alpha_focus_

double gui::textbox::alpha_focus_
private

Definition at line 91 of file textbox.hpp.

Referenced by draw_contents().

◆ char_x_

std::vector<int> gui::textbox::char_x_
private

Definition at line 74 of file textbox.hpp.

Referenced by add_text_line(), draw_contents(), handle_event(), and update_text_cache().

◆ char_y_

std::vector<int> gui::textbox::char_y_
private

Definition at line 74 of file textbox.hpp.

Referenced by add_text_line(), draw_contents(), handle_event(), and update_text_cache().

◆ cursor_

int gui::textbox::cursor_
private

◆ cursor_pos_

int gui::textbox::cursor_pos_
private

Definition at line 73 of file textbox.hpp.

Referenced by clear(), draw_contents(), and update_text_cache().

◆ edit_target_

textbox* gui::textbox::edit_target_
private

Definition at line 93 of file textbox.hpp.

Referenced by pass_event_to_target(), and set_edit_target().

◆ editable_

bool gui::textbox::editable_
private

◆ font_size_

int gui::textbox::font_size_
private

Definition at line 62 of file textbox.hpp.

Referenced by add_text_line(), font_size(), set_font_size(), and textbox().

◆ grabmouse_

bool gui::textbox::grabmouse_
private

Definition at line 70 of file textbox.hpp.

Referenced by handle_event().

◆ line_height_

std::size_t gui::textbox::line_height_
private

Definition at line 88 of file textbox.hpp.

Referenced by add_text_line(), draw_contents(), and handle_event().

◆ listening_

bool gui::textbox::listening_
private

Definition at line 99 of file textbox.hpp.

Referenced by handle_event(), and handle_key_down().

◆ max_size_

std::size_t gui::textbox::max_size_
private

Definition at line 60 of file textbox.hpp.

Referenced by handle_key_down(), and handle_text_input().

◆ selend_

int gui::textbox::selend_
private

◆ selstart_

int gui::textbox::selstart_
private

◆ show_cursor_

bool gui::textbox::show_cursor_
private

Definition at line 78 of file textbox.hpp.

Referenced by draw_cursor(), and handle_event().

◆ show_cursor_at_

int gui::textbox::show_cursor_at_
private

Definition at line 83 of file textbox.hpp.

Referenced by handle_event().

◆ text_

std::u32string gui::textbox::text_
private

◆ text_image_

surface gui::textbox::text_image_
private

◆ text_pos_

int gui::textbox::text_pos_
private

◆ wrap_

bool gui::textbox::wrap_
private

Definition at line 86 of file textbox.hpp.

Referenced by add_text_line(), append_text(), and set_wrap().

◆ yscroll_

std::size_t gui::textbox::yscroll_
private

Definition at line 88 of file textbox.hpp.

Referenced by draw_contents(), handle_event(), and scroll().


The documentation for this class was generated from the following files: