15 #define GETTEXT_DOMAIN "wesnoth-lib"
28 #define WRN_DP LOG_STREAM(warn, log_display)
29 #define DBG_G LOG_STREAM(debug, lg::general())
35 cursor_(
text_.
size()), selstart_(-1), selend_(-1),
36 grabmouse_(false), text_pos_(0), editable_(editable),
37 show_cursor_(true), show_cursor_at_(0), text_image_(nullptr),
38 wrap_(false), line_height_(0), yscroll_(0), alpha_(alpha),
39 alpha_focus_(alpha_focus),
107 SDL_SetSurfaceBlendMode(
text_image_, SDL_BLENDMODE_NONE);
109 SDL_SetSurfaceBlendMode(
text_image_, SDL_BLENDMODE_BLEND);
115 SDL_SetSurfaceBlendMode(new_text, SDL_BLENDMODE_NONE);
116 sdl_blit(new_text,
nullptr,new_surface,&target);
119 text_.insert(
text_.end(), wtext.begin(), wtext.end());
145 if (selstart < 0 || selend < 0 ||
size_t(selstart) >
text_.size() ||
146 size_t(selend) >
text_.size()) {
147 WRN_DP <<
"out-of-boundary selection" << std::endl;
160 if (cursor_pos < 0 ||
size_t(cursor_pos) >
text_.size()) {
161 WRN_DP <<
"out-of-boundary selection" << std::endl;
179 sdl::fill_rect(frame_buffer,&rect,SDL_MapRGB(frame_buffer->format,255,255,255));
215 while(starty <= endy) {
217 if(right <=
size_t(startx)) {
222 , loc.y + starty - src.y
228 Uint32
color = SDL_MapRGB(surf->format, 0, 0, 160);
311 ucs4::string::const_iterator backup_itor = text.end();
313 ucs4::string::const_iterator
itor = text.begin();
314 while(itor != text.end()) {
316 if(
char(*itor) ==
' ') {
319 visible_string.append(unicode_cast<utf8::string>(*itor));
321 if(
char(*itor) ==
'\n') {
322 backup_itor = text.end();
329 if(backup_itor != text.end()) {
330 int backup = itor - backup_itor;
331 itor = backup_itor + 1;
335 wrapped_text.erase(wrapped_text.end()-backup, wrapped_text.end());
338 if (visible_string ==
std::string(
"").append(unicode_cast<utf8::string>(*itor))) {
342 backup_itor = text.end();
348 wrapped_text.push_back(*itor);
403 const unsigned int copypaste_modifier =
417 if(event ==
nullptr) {
422 if(event->type == SDL_KEYDOWN) {
423 SDLKey key =
event->key.keysym.sym;
448 bool changed =
false;
452 DBG_G <<
"Char: " << str <<
"\n";
472 bool changed =
false;
474 const SDL_keysym& key =
reinterpret_cast<const SDL_KeyboardEvent&
>(
event).keysym;
475 const SDLMod modifiers = SDL_GetModState();
477 const int c = key.sym;
478 const int old_cursor =
cursor_;
483 if(c == SDLK_LEFT &&
cursor_ > 0)
486 if(c == SDLK_RIGHT &&
cursor_ < static_cast<int>(
text_.size()))
490 if(c == SDLK_END || (c == SDLK_e && (modifiers & KMOD_CTRL)))
493 if(c == SDLK_HOME || (c == SDLK_a && (modifiers & KMOD_CTRL)))
496 if((old_cursor !=
cursor_) && (modifiers & KMOD_SHIFT)) {
501 }
else if(c == SDLK_LEFT || c == SDLK_RIGHT || c == SDLK_END || c == SDLK_HOME) {
506 if(c == SDLK_BACKSPACE) {
516 if(c == SDLK_u && (modifiers & KMOD_CTRL)) {
522 if(c == SDLK_DELETE && !
text_.empty()) {
532 }
else if(c == SDLK_BACKSPACE || c == SDLK_DELETE || (c == SDLK_u && (modifiers & KMOD_CTRL))) {
538 if(!(c == SDLK_UP || c == SDLK_DOWN || c == SDLK_LEFT || c == SDLK_RIGHT ||
539 c == SDLK_DELETE || c == SDLK_BACKSPACE || c == SDLK_END || c == SDLK_HOME ||
540 c == SDLK_PAGEUP || c == SDLK_PAGEDOWN)) {
541 if((event.key.keysym.mod & copypaste_modifier)
544 && !(event.key.keysym.mod & KMOD_ALT)
610 bool changed =
false;
613 const int old_selend =
selend_;
618 WRN_DP <<
"out-of-boundary selection" << std::endl;
623 const Uint8 mousebuttons = SDL_GetMouseState(&mousex,&mousey);
624 if(!(mousebuttons & SDL_BUTTON(1))) {
629 bool clicked_inside = !
mouse_locked() && (
event.type == SDL_MOUSEBUTTONDOWN
630 && (mousebuttons & SDL_BUTTON(1))
637 const int y = mousey - loc.y;
641 for(
unsigned int i = 1;
i <
char_x_.size(); ++
i) {
650 distance = abs(x -
char_x_[i]);
661 if(!
grabmouse_ && (mousebuttons & SDL_BUTTON(1))) {
664 }
else if (! (mousebuttons & SDL_BUTTON(1))) {
673 if(!was_forwarded &&
focus(&event) ==
false) {
680 const int old_cursor =
cursor_;
682 if (event.type == SDL_TEXTINPUT &&
listening_) {
685 if (event.type == SDL_KEYDOWN) {
689 if(event.type != SDL_KEYDOWN || (!was_forwarded &&
focus(&event) !=
true)) {
static unsigned int max_size_
std::vector< int > char_x_
std::vector< char_t > string
virtual void handle_text_changed(const ucs4::string &)
SDL_Surface * get() const
void fill_rect(surface &dst, SDL_Rect *dst_rect, const Uint32 color)
Fill a rectangle on a given surface.
void set_edit_target(textbox *target)
void draw_cursor(int pos, CVideo &video) const
std::string copy_from_clipboard(const bool)
Copies text from the clipboard.
void pass_event_to_target(const SDL_Event &event)
ucs4_convert_impl::enableif< TD, typename TS::value_type >::type unicode_cast(const TS &source)
GLuint const GLfloat * val
void set_text(const std::string &text, const SDL_Color &color=font::NORMAL_COLOR)
virtual void draw_contents()
GLint GLint GLint GLint GLint GLint y
const std::string text() const
textbox(CVideo &video, int width, const std::string &text="", bool editable=true, 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)
std::vector< int > char_y_
void update_text_cache(bool reset=false, const SDL_Color &color=font::NORMAL_COLOR)
tformula< t_string > text_
The text to draw.
void set_cursor_pos(const int cursor_pos)
void focus_handler(const sdl_handler *ptr)
void draw_solid_tinted_rectangle(int x, int y, int w, int h, int r, int g, int b, double alpha, surface target)
Fills a specified rectangle area of a surface with a given color and opacity.
bool handle_text_input(const SDL_Event &event)
GLubyte GLubyte GLubyte GLubyte w
GLsizei const GLfloat * value
surface adjust_surface_alpha(const surface &surf, fixed_t amount, bool optimize)
void set_editable(bool value)
bool handle_key_down(const SDL_Event &event)
GLclampf GLclampf GLclampf alpha
void set_font_size(int fs)
static lg::log_domain log_display("display")
typedef int(WINAPI *PFNWGLRELEASEPBUFFERDCARBPROC)(HPBUFFERARB hPbuffer
void append_text(const std::string &text, bool auto_scroll=false, const SDL_Color &color=font::NORMAL_COLOR)
int get_max_height(int size)
bool point_in_rect(int x, int y, const SDL_Rect &rect)
Tests whether a point is inside a rectangle.
void handle_event(const SDL_Event &event, bool was_forwarded)
surface add_text_line(const ucs4::string &text, const SDL_Color &color=font::NORMAL_COLOR)
void set_selection(const int selstart, const int selend)
std::map< std::string, tfilter >::iterator itor
virtual void update_location(SDL_Rect const &rect)
GLfloat GLfloat GLfloat GLfloat h
GLint GLint GLint GLint GLint x
virtual void scroll(unsigned int pos)
bool isnewline(const char c)
SDL_Rect create_rect(const int x, const int y, const int w, const int h)
Creates an empty SDL_Rect.
virtual void set_inner_location(SDL_Rect const &)
void copy_to_clipboard(const std::string &text, const bool)
Copies text to the clipboard.
Contains the SDL_Rect helper code.
void fill_rect_alpha(SDL_Rect &rect, Uint32 color, Uint8 alpha, surface target)
Fills a specified area of a surface with a given color and opacity.
Standard logging facilities (interface).
void assign(const surface &o)
surface create_compatible_surface(const surface &surf, int width, int height)
bool requires_event_focus(const SDL_Event *event=nullptr) const
GLint GLint GLint GLint GLint GLint GLsizei width
void sdl_blit(const surface &src, SDL_Rect *src_rect, surface &dst, SDL_Rect *dst_rect)
int SDL_SetAlpha(SDL_Surface *surface, Uint32 flag, Uint8 alpha)
surface get_rendered_text(const std::string &str, int size, const SDL_Color &color, int style)
Compatibility layer for using SDL 1.2 and 2.0.
void update_rect(const SDL_Rect &)
GLsizei const GLcharARB ** string
int line_width(const std::string &line, int font_size, int style)
Determine the width of a line of text given a certain font size.
#define ftofxp(x)
IN: float or int - OUT: fixed_t.