Small cleanup.

- Added some comment.

- Made a separate function to update the canvasses.
This commit is contained in:
Mark de Wever 2008-04-06 08:41:23 +00:00
parent 7a53763c9b
commit 7fb7a01d26
6 changed files with 36 additions and 18 deletions

View file

@ -162,9 +162,7 @@ void tbutton::resolve_definition()
canvas(i) = definition_->state[i].canvas;
}
// FIXME also an ugly hack, maybe set the stuff correct
// just prior to draw... only need to find out when needed.
set_label(label());
set_canvas_text();
}
}

View file

@ -69,18 +69,27 @@ void tcontrol::set_height(const unsigned height)
// inherited
twidget::set_height(height);
}
void tcontrol::set_label(const std::string& label)
{
// set label in canvases
foreach(tcanvas& canvas, canvas_) {
canvas.set_variable("text", variant(label));
if(label == label_) {
return;
}
label_ = label;
set_canvas_text();
set_dirty();
}
//! Sets the text variable for the canvases.
void tcontrol::set_canvas_text()
{
// set label in canvases
foreach(tcanvas& canvas, canvas_) {
canvas.set_variable("text", variant(label_));
}
}
void tcontrol::draw(surface& surface)
{
SDL_Rect rect = get_rect();
@ -98,6 +107,7 @@ void tcontrol::draw(surface& surface)
set_dirty(false);
}
} // namespace gui2

View file

@ -31,11 +31,14 @@ public:
tcontrol(const unsigned canvas_count);
virtual ~tcontrol() {}
//! Inherited from twidget.
void set_width(const unsigned width);
//! Inherited from twidget.
void set_height(const unsigned height);
void set_visible(const bool visible) { visible_ = visible; set_dirty(); }
void set_visible(const bool visible)
{ if(visible_ != visible) { visible_ = visible; set_dirty();} }
bool get_visible() const { return visible_; }
void set_label(const std::string& label);
@ -57,10 +60,15 @@ public:
std::vector<tcanvas>& canvas() { return canvas_; }
tcanvas& canvas(const unsigned index) { return canvas_[index]; } // FIXME an assert would be nice
//! Draws the widget.
//! Inherited from twidget.
void draw(surface& surface);
//! Sets the control in the active state, when inactive a control can't be
//! used and doesn't react to events. (Note read-only for a ttext_ is a
//! different state.)
virtual void set_active(const bool active) = 0;
//! Gets the active state of the control.
virtual bool get_active() const = 0;
protected:
@ -71,11 +79,15 @@ protected:
//! Does the widget need to restore the surface before (re)painting?
virtual bool full_redraw() const = 0;
//! Sets the text variable for the canvases.
virtual void set_canvas_text();
private:
//! Visible state of the widget, invisible isn't drawn.
//! Visible state of the control, invisible isn't drawn.
bool visible_;
//! The label associated with a lot of widgets to show a (non editable) text.
std::string label_;
//! When hovering a tooltip with extra information can show up. (FIXME implement)
@ -91,7 +103,6 @@ private:
//! redrawing. This is needed for semi-tranparent items, the user
//! defines whether it's required or not.
surface restorer_;
};
} // namespace gui2

View file

@ -100,7 +100,7 @@ void tlabel::resolve_definition()
canvas(i) = definition_->state[i].canvas;
}
canvas(0).set_variable("text", variant(label()));
set_canvas_text();
}
}

View file

@ -220,9 +220,7 @@ void ttext_::resolve_definition()
canvas(i) = definition_->state[i].canvas;
}
// FIXME also an ugly hack, maybe set the stuff correct
// just prior to draw... only need to find out when needed.
set_label(label());
set_canvas_text();
}
}
@ -290,7 +288,7 @@ void ttext_::handle_key_backspace(SDLMod modifier, bool& handled)
handled = true;
if(sel_start_){
label().erase(--sel_start_, 1);
set_label(label());
set_canvas_text();
set_dirty();
set_cursor(sel_start_, false);
} else {
@ -309,7 +307,7 @@ void ttext_::handle_key_delete(SDLMod modifier, bool& handled)
assert(false); // FIXME implement
} else {
label().erase(sel_start_, 1);
set_label(label());
set_canvas_text();
set_dirty();
}
@ -322,7 +320,7 @@ void ttext_::handle_key_default(bool& handled, SDLKey key, SDLMod modifier, Uint
if(unicode >= 32 && unicode != 127) {
handled = true;
label().insert(label().begin() + sel_start_++, unicode);
set_label(label());
set_canvas_text();
set_dirty();
}
}

View file

@ -219,6 +219,7 @@ void twindow::resolve_definition()
}
}
SDL_Rect twindow::get_client_rect()
{
assert(definition_ != std::vector<twindow_definition::tresolution>::const_iterator());