made textbox accept more characters

This commit is contained in:
Dave White 2003-10-19 01:52:17 +00:00
parent c0aa537d8d
commit 3841692996
5 changed files with 31 additions and 24 deletions

View file

@ -28,7 +28,7 @@ resize_lock::~resize_lock()
std::vector<handler*> event_handlers;
handler::handler()
handler::handler() : unicode_(SDL_EnableUNICODE(1))
{
SDL_EnableKeyRepeat(SDL_DEFAULT_REPEAT_DELAY,SDL_DEFAULT_REPEAT_INTERVAL);
event_handlers.push_back(this);
@ -43,6 +43,8 @@ handler::~handler()
event_handlers.erase(std::find(event_handlers.begin(),
event_handlers.end(),this));
}
SDL_EnableUNICODE(unicode_);
}
void pump()

View file

@ -19,6 +19,9 @@ public:
protected:
handler();
virtual ~handler();
private:
const int unicode_;
};
void pump();

View file

@ -177,7 +177,7 @@ SDL_Rect draw_text_line(display* gui, const SDL_Rect& area, int size,
SDL_Rect draw_text(display* gui, const SDL_Rect& area, int size,
COLOUR colour, const std::string& txt, int x, int y,
SDL_Surface* bg, bool use_tooltips)
SDL_Surface* bg, bool use_tooltips, MARKUP use_markup)
{
//make sure there's always at least a space, so we can ensure
//that we can return a rectangle for height
@ -196,18 +196,20 @@ SDL_Rect draw_text(display* gui, const SDL_Rect& area, int size,
if(i1 != i2) {
COLOUR col = colour;
int sz = size;
if(*i1 == '#') {
col = BAD_COLOUR;
++i1;
} else if(*i1 == '@') {
col = GOOD_COLOUR;
++i1;
} else if(*i1 == '+') {
sz += 2;
++i1;
} else if(*i1 == '-') {
sz -= 2;
++i1;
if(use_markup == USE_MARKUP) {
if(*i1 == '#') {
col = BAD_COLOUR;
++i1;
} else if(*i1 == '@') {
col = GOOD_COLOUR;
++i1;
} else if(*i1 == '+') {
sz += 2;
++i1;
} else if(*i1 == '-') {
sz -= 2;
++i1;
}
}
if(i1 != i2) {

View file

@ -30,9 +30,11 @@ struct manager {
enum COLOUR { NORMAL_COLOUR, GOOD_COLOUR, BAD_COLOUR, BLACK_COLOUR,
BUTTON_COLOUR };
enum MARKUP { USE_MARKUP, NO_MARKUP };
SDL_Rect draw_text(display* gui, const SDL_Rect& area, int size, COLOUR colour,
const std::string& text, int x, int y, SDL_Surface* bg=NULL,
bool use_tooltips=false);
bool use_tooltips=false, MARKUP use_markup=USE_MARKUP);
}

View file

@ -95,7 +95,8 @@ void textbox::draw() const
for(size_t i = firstOnScreen_; i < text_.size(); ++i) {
str[0] = text_[i];
const SDL_Rect area =
font::draw_text(NULL,clip,font_size,font::NORMAL_COLOUR,str,0,0);
font::draw_text(NULL,clip,font_size,font::NORMAL_COLOUR,str,0,0,
NULL,false,font::NO_MARKUP);
//if we can't fit the next character on screen
if(pos + area.w > width()) {
@ -103,7 +104,7 @@ void textbox::draw() const
}
font::draw_text(&disp_,clip,font_size,font::NORMAL_COLOUR,str,
x_ + pos, y_);
x_ + pos, y_, NULL, false, font::NO_MARKUP);
pos += area.w;
@ -122,7 +123,7 @@ void textbox::handle_event(const SDL_Event& event)
const SDL_keysym& key
= reinterpret_cast<const SDL_KeyboardEvent&>(event).keysym;
int c = key.sym;
const int c = key.sym;
if(c == SDLK_LEFT && cursor_ > 0) {
--cursor_;
@ -150,13 +151,10 @@ void textbox::handle_event(const SDL_Event& event)
}
}
if(c >= INPUT_CHAR_START && c < INPUT_CHAR_END) {
if(islower(c) && (key_[SDLK_LSHIFT] || key_[SDLK_RSHIFT])) {
c = toupper(c);
}
const char character = static_cast<char>(key.unicode);
text_.insert(text_.begin()+cursor_,c);
if(character >= INPUT_CHAR_START && character < INPUT_CHAR_END) {
text_.insert(text_.begin()+cursor_,character);
++cursor_;
}
}