fixed problem with textbox not processing properly

This commit is contained in:
uid68803 2004-02-20 16:45:51 +00:00
parent cda417bc99
commit 6c6725ceae
4 changed files with 27 additions and 24 deletions

View file

@ -51,7 +51,7 @@ void textbox::clear()
firstOnScreen_ = 0;
}
void textbox::draw_cursor(int pos, display &disp)
void textbox::draw_cursor(int pos, display &disp) const
{
const bool show_cursor = (SDL_GetTicks()%1000) > 500;
@ -62,7 +62,7 @@ void textbox::draw_cursor(int pos, display &disp)
}
}
void textbox::draw(display &disp)
void textbox::draw() const
{
if(location().x == 0)
return;
@ -70,14 +70,14 @@ void textbox::draw(display &disp)
bg_restore();
gui::draw_solid_tinted_rectangle(location().x,location().y,location().w,location().h,0,0,0,
focus() ? 0.2 : 0.4, disp.video().getSurface());
focus() ? 0.2 : 0.4, disp().video().getSurface());
if(cursor_ == 0)
draw_cursor(0, disp);
draw_cursor(0, disp());
int pos = 1;
std::string str(1,'x');
const SDL_Rect clip = disp.screen_area();
const SDL_Rect clip = disp().screen_area();
//draw the text
for(size_t i = firstOnScreen_; i < text_.size(); ++i) {
@ -93,13 +93,13 @@ void textbox::draw(display &disp)
break;
}
font::draw_text(&disp,clip,font_size,font::NORMAL_COLOUR,str,
font::draw_text(&disp(),clip,font_size,font::NORMAL_COLOUR,str,
location().x + pos, location().y, NULL, false, font::NO_MARKUP);
pos += area.w;
if(cursor_ == i+1)
draw_cursor(pos-1, disp);
draw_cursor(pos-1, disp());
}
update_rect(location());

View file

@ -45,8 +45,8 @@ private:
void handle_event(const SDL_Event& event);
void draw(display &disp);
void draw_cursor(int pos, display &disp);
void draw() const;
void draw_cursor(int pos, display &disp) const;
};
}

View file

@ -7,12 +7,12 @@ namespace {
namespace gui {
widget::widget(display& disp) : disp_(disp), rect_(EmptyRect)
widget::widget(display& disp) : disp_(disp), rect_(EmptyRect), focus_(true)
{
bg_backup();
}
widget::widget(display& disp, const SDL_Rect& rect) : disp_(disp), rect_(rect)
widget::widget(display& disp, const SDL_Rect& rect) : disp_(disp), rect_(rect), focus_(true)
{
bg_backup();
}
@ -22,7 +22,7 @@ void widget::set_location(const SDL_Rect& rect)
bg_restore();
rect_ = rect;
bg_backup();
draw(disp_);
draw();
}
void widget::set_position(int x, int y)
@ -31,7 +31,7 @@ void widget::set_position(int x, int y)
SDL_Rect rect = {x,y,location().w,location().h};
rect_ = rect;
bg_backup();
draw(disp_);
draw();
}
void widget::set_width(int w)
@ -40,7 +40,7 @@ void widget::set_width(int w)
SDL_Rect rect = {location().x,location().y,w,location().h};
rect_ = rect;
bg_backup();
draw(disp_);
draw();
}
void widget::set_height(int h)
@ -49,7 +49,7 @@ void widget::set_height(int h)
SDL_Rect rect = {location().x,location().y,location().w,h};
rect_ = rect;
bg_backup();
draw(disp_);
draw();
}
const SDL_Rect& widget::location() const
@ -72,14 +72,14 @@ void widget::bg_backup()
restorer_ = surface_restorer(&disp_.video(), rect_);
}
void widget::bg_restore()
void widget::bg_restore() const
{
restorer_.restore();
}
void widget::update()
void widget::update() const
{
draw(disp_);
draw();
}
void widget::handle_event(const SDL_Event& event)
@ -87,7 +87,7 @@ void widget::handle_event(const SDL_Event& event)
if (!focus_)
return;
draw(disp_);
draw();
}
}

View file

@ -23,18 +23,21 @@ public:
protected:
widget(display& disp);
widget(display& disp, const SDL_Rect& rect);
virtual ~widget() {}
void bg_restore();
void update();
void bg_restore() const;
void update() const;
display& disp() const { return disp_; }
private:
display& disp_;
surface_restorer restorer_;
mutable display& disp_;
mutable surface_restorer restorer_;
SDL_Rect rect_;
bool focus_;
void bg_backup();
virtual void draw(display &disp) = 0;
virtual void handle_event(const SDL_Event& event);
};