#include <textbox.hpp>
Public Member Functions | |
textbox (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) |
virtual void | layout () override |
Called by draw_manager to validate layout. More... | |
Public Member Functions inherited from gui::scrollarea | |
scrollarea (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 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 | queue_redraw () |
Indicate that the widget should be redrawn. More... | |
void | queue_redraw (const rect &) |
Indicate that a specific region of the screen should be redrawn. More... | |
void | set_dirty (bool dirty=true) |
bool | dirty () const |
const std::string & | id () const |
void | set_id (const std::string &id) |
void | set_tooltip_string (const std::string &str) |
virtual void | process_tooltip_string (int mousex, int mousey) override |
virtual bool | expose (const rect ®ion) override |
Called by draw_manager when it believes a redraw is necessary. More... | |
virtual rect | screen_location () override |
The current draw location of the display, on the screen. More... | |
Public Member Functions inherited from events::sdl_handler | |
virtual void | handle_window_event (const SDL_Event &) |
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_handler & | operator= (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 | |
Public Member Functions inherited from gui2::top_level_drawable | |
virtual void | update () |
Update state and any parameters that may effect layout, or any of the later stages. More... | |
virtual void | render () |
Perform any internal rendering necessary to prepare the drawable. More... | |
Protected Member Functions | |
virtual void | draw_contents () override |
virtual void | update_location (const SDL_Rect &rect) override |
virtual void | set_inner_location (const SDL_Rect &) override |
virtual void | scroll (unsigned int pos) override |
Protected Member Functions inherited from gui::scrollarea | |
virtual sdl_handler_vector | handler_members () |
virtual void | process_event () |
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 (const bool auto_join=true) | |
virtual | ~widget () |
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_handler & | operator= (const sdl_handler &) |
virtual | ~sdl_handler () |
Protected Member Functions inherited from gui2::top_level_drawable | |
top_level_drawable () | |
virtual | ~top_level_drawable () |
top_level_drawable (const top_level_drawable &) | |
top_level_drawable & | operator= (const top_level_drawable &) |
top_level_drawable (top_level_drawable &&) | |
top_level_drawable & | operator= (top_level_drawable &&) |
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) override |
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) |
texture | 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 override |
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_ |
texture | text_image_ |
bool | wrap_ |
std::size_t | line_height_ |
std::size_t | yscroll_ |
double | alpha_ |
double | alpha_focus_ |
textbox * | edit_target_ |
bool | listening_ |
Additional Inherited Members | |
Protected Attributes inherited from gui::widget | |
bool | focus_ |
Definition at line 26 of file textbox.hpp.
gui::textbox::textbox | ( | 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 |
||
) |
Definition at line 35 of file textbox.cpp.
References font_size_, font::get_max_height(), gui::widget::set_measurements(), gui::scrollarea::set_scroll_rate(), update_text_cache(), and gui::widget::width().
|
virtual |
Definition at line 51 of file textbox.cpp.
References cursor::get(), cursor::IBEAM, cursor::NORMAL, and cursor::set().
|
private |
Definition at line 291 of file textbox.cpp.
References char_x_, char_y_, font_size_, font::get_max_height(), gui::scrollarea::inner_location(), line_height_, font::pango_line_width(), font::pango_render_text(), s, text(), w, and wrap_.
Referenced by append_text(), and update_text_cache().
void gui::textbox::append_text | ( | const std::string & | text, |
bool | auto_scroll = false , |
||
const color_t & | color = font::NORMAL_COLOR |
||
) |
Definition at line 92 of file textbox.cpp.
References add_text_line(), gui::scrollarea::get_max_position(), gui::scrollarea::get_position(), handle_text_changed(), utils::isnewline(), gui::widget::queue_redraw(), scroll_to_bottom(), set_text(), text(), text_, text_image_, update_text_cache(), and wrap_.
void gui::textbox::clear | ( | ) |
Definition at line 116 of file textbox.cpp.
References cursor_, cursor_pos_, handle_text_changed(), gui::widget::queue_redraw(), selend_, selstart_, text_, text_pos_, and update_text_cache().
|
overrideprotectedvirtual |
Reimplemented from gui::widget.
Definition at line 180 of file textbox.cpp.
References alpha_, alpha_focus_, draw::blit(), c, char_x_, char_y_, texture::clear_src(), cursor_pos_, draw_cursor(), gui::widget::enabled(), draw::fill(), gui::widget::focus(), texture::h(), gui::scrollarea::inner_location(), is_selection(), line_height_, loc, draw::reduce_clip(), selend_, selstart_, texture::set_alpha_mod(), texture::set_src(), src, editor::start(), text_image_, text_pos_, texture::w(), map_location::x, map_location::y, and yscroll_.
|
private |
Definition at line 159 of file textbox.cpp.
References editable_, gui::widget::enabled(), draw::fill(), gui::widget::location(), and show_cursor_.
Referenced by draw_contents().
bool gui::textbox::editable | ( | ) | const |
Definition at line 256 of file textbox.cpp.
References editable_.
Referenced by handle_key_down(), and pass_event_to_target().
|
private |
Definition at line 388 of file textbox.cpp.
References cursor_, is_selection(), selend_, selstart_, and text_.
Referenced by handle_key_down(), and handle_text_input().
int gui::textbox::font_size | ( | ) | const |
Definition at line 261 of file textbox.cpp.
References font_size_.
|
overrideprivatevirtual |
Reimplemented from gui::scrollarea.
Definition at line 437 of file textbox.cpp.
References gui::widget::handle_event(), and handle_event().
|
private |
Definition at line 618 of file textbox.cpp.
References char_x_, char_y_, cursor_, gui::widget::enabled(), gui::widget::focus(), events::focus_handler(), cursor::get(), sdl::get_mouse_state(), grabmouse_, gui::scrollarea::handle_event(), handle_key_down(), handle_text_changed(), handle_text_input(), gui::widget::hidden(), i, cursor::IBEAM, gui::scrollarea::inner_location(), is_selection(), line_height_, listening_, loc, gui::widget::mouse_locked(), cursor::NORMAL, gui::widget::queue_redraw(), texture::reset(), selend_, selstart_, cursor::set(), gui::widget::set_focus(), show_cursor_, show_cursor_at_, text_, text_image_, text_pos_, update_text_cache(), WRN_DP, map_location::x, gui::scrollarea::x, map_location::y, gui::scrollarea::y, and yscroll_.
Referenced by handle_event(), and pass_event_to_target().
|
private |
Definition at line 467 of file textbox.cpp.
References c, desktop::clipboard::copy_from_clipboard(), desktop::clipboard::copy_to_clipboard(), cursor_, editable(), editable_, erase_selection(), is_selection(), utils::isnewline(), listening_, max_size_, pass_event_to_target(), s, selend_, selstart_, set_selection(), and text_.
Referenced by handle_event().
|
inlineprivatevirtual |
Definition at line 63 of file textbox.hpp.
Referenced by append_text(), clear(), handle_event(), and set_text().
|
private |
Definition at line 443 of file textbox.cpp.
References cursor_, DBG_G, editable_, erase_selection(), is_selection(), max_size_, pass_event_to_target(), s, and text_.
Referenced by handle_event().
|
private |
Definition at line 383 of file textbox.cpp.
References selend_, and selstart_.
Referenced by draw_contents(), erase_selection(), handle_event(), handle_key_down(), and handle_text_input().
|
overridevirtual |
Called by draw_manager to validate layout.
Reimplemented from gui::widget.
Definition at line 173 of file textbox.cpp.
References text_image_, and update_text_cache().
|
private |
Definition at line 734 of file textbox.cpp.
References edit_target_, editable(), and handle_event().
Referenced by handle_key_down(), and handle_text_input().
|
overrideprivatevirtual |
Reimplemented from events::sdl_handler.
Definition at line 409 of file textbox.cpp.
References gui::widget::enabled(), gui::widget::focus_, and gui::widget::hidden().
|
overrideprotectedvirtual |
Implements gui::scrollarea.
Definition at line 285 of file textbox.cpp.
References gui::widget::queue_redraw(), and yscroll_.
void gui::textbox::scroll_to_bottom | ( | ) |
Definition at line 271 of file textbox.cpp.
References gui::scrollarea::get_max_position(), and gui::scrollarea::set_position().
Referenced by append_text().
void gui::textbox::set_cursor_pos | ( | const int | cursor_pos | ) |
Definition at line 144 of file textbox.cpp.
References cursor_, editable_, gui::widget::queue_redraw(), text_, update_text_cache(), and WRN_DP.
void gui::textbox::set_edit_target | ( | textbox * | target | ) |
Definition at line 741 of file textbox.cpp.
References edit_target_.
void gui::textbox::set_editable | ( | bool | value | ) |
Definition at line 251 of file textbox.cpp.
References editable_.
void gui::textbox::set_font_size | ( | int | fs | ) |
Definition at line 266 of file textbox.cpp.
References font_size_.
|
overrideprotectedvirtual |
Implements gui::scrollarea.
Definition at line 66 of file textbox.cpp.
References text_image_, text_pos_, and update_text_cache().
void gui::textbox::set_selection | ( | const int | selstart, |
const int | selend | ||
) |
Definition at line 129 of file textbox.cpp.
References editable_, gui::widget::queue_redraw(), selend_, selstart_, text_, and WRN_DP.
Referenced by handle_key_down().
void gui::textbox::set_text | ( | const std::string & | text, |
const color_t & | color = font::NORMAL_COLOR |
||
) |
Definition at line 80 of file textbox.cpp.
References cursor_, handle_text_changed(), gui::widget::queue_redraw(), selend_, selstart_, text(), text_, text_pos_, and update_text_cache().
Referenced by append_text().
void gui::textbox::set_wrap | ( | bool | val | ) |
Definition at line 276 of file textbox.cpp.
References gui::widget::queue_redraw(), update_text_cache(), and wrap_.
|
private |
const std::string gui::textbox::text | ( | ) | const |
Definition at line 73 of file textbox.cpp.
References text_.
Referenced by add_text_line(), append_text(), and set_text().
|
overrideprotectedvirtual |
Reimplemented from gui::scrollarea.
Definition at line 59 of file textbox.cpp.
References gui::widget::queue_redraw(), gui::scrollarea::update_location(), and update_text_cache().
|
private |
Definition at line 359 of file textbox.cpp.
References add_text_line(), char_x_, char_y_, cursor_, cursor_pos_, texture::h(), h, gui::widget::location(), gui::scrollarea::set_full_size(), gui::scrollarea::set_shown_size(), text_, text_image_, text_pos_, and w.
Referenced by append_text(), clear(), handle_event(), layout(), set_cursor_pos(), set_inner_location(), set_text(), set_wrap(), textbox(), and update_location().
|
private |
Definition at line 95 of file textbox.hpp.
Referenced by draw_contents().
|
private |
Definition at line 96 of file textbox.hpp.
Referenced by draw_contents().
|
private |
Definition at line 79 of file textbox.hpp.
Referenced by add_text_line(), draw_contents(), handle_event(), and update_text_cache().
|
private |
Definition at line 79 of file textbox.hpp.
Referenced by add_text_line(), draw_contents(), handle_event(), and update_text_cache().
|
private |
Definition at line 72 of file textbox.hpp.
Referenced by clear(), erase_selection(), handle_event(), handle_key_down(), handle_text_input(), set_cursor_pos(), set_text(), and update_text_cache().
|
private |
Definition at line 78 of file textbox.hpp.
Referenced by clear(), draw_contents(), and update_text_cache().
|
private |
Definition at line 98 of file textbox.hpp.
Referenced by pass_event_to_target(), and set_edit_target().
|
private |
Definition at line 81 of file textbox.hpp.
Referenced by draw_cursor(), editable(), handle_key_down(), handle_text_input(), set_cursor_pos(), set_editable(), and set_selection().
|
private |
Definition at line 67 of file textbox.hpp.
Referenced by add_text_line(), font_size(), set_font_size(), and textbox().
|
private |
Definition at line 75 of file textbox.hpp.
Referenced by handle_event().
|
private |
Definition at line 93 of file textbox.hpp.
Referenced by add_text_line(), draw_contents(), and handle_event().
|
private |
Definition at line 104 of file textbox.hpp.
Referenced by handle_event(), and handle_key_down().
|
private |
Definition at line 65 of file textbox.hpp.
Referenced by handle_key_down(), and handle_text_input().
|
private |
Definition at line 74 of file textbox.hpp.
Referenced by clear(), draw_contents(), erase_selection(), handle_event(), handle_key_down(), is_selection(), set_selection(), and set_text().
|
private |
Definition at line 73 of file textbox.hpp.
Referenced by clear(), draw_contents(), erase_selection(), handle_event(), handle_key_down(), is_selection(), set_selection(), and set_text().
|
private |
Definition at line 83 of file textbox.hpp.
Referenced by draw_cursor(), and handle_event().
|
private |
Definition at line 88 of file textbox.hpp.
Referenced by handle_event().
|
private |
Definition at line 69 of file textbox.hpp.
Referenced by append_text(), clear(), erase_selection(), handle_event(), handle_key_down(), handle_text_input(), set_cursor_pos(), set_selection(), set_text(), text(), and update_text_cache().
|
private |
Definition at line 89 of file textbox.hpp.
Referenced by append_text(), draw_contents(), handle_event(), layout(), set_inner_location(), and update_text_cache().
|
private |
Definition at line 77 of file textbox.hpp.
Referenced by clear(), draw_contents(), handle_event(), set_inner_location(), set_text(), and update_text_cache().
|
private |
Definition at line 91 of file textbox.hpp.
Referenced by add_text_line(), append_text(), and set_wrap().
|
private |
Definition at line 93 of file textbox.hpp.
Referenced by draw_contents(), handle_event(), and scroll().