Author: mordante
Date: Sun Apr 6 10:41:23 2008
New Revision: 25617
URL: http://svn.gna.org/viewcvs/wesnoth?rev=25617&view=rev
Log:
Small cleanup.
- Added some comment.
- Made a separate function to update the canvasses.
Modified:
trunk/src/gui/widgets/button.cpp
trunk/src/gui/widgets/control.cpp
trunk/src/gui/widgets/control.hpp
trunk/src/gui/widgets/label.cpp
trunk/src/gui/widgets/text_box.cpp
trunk/src/gui/widgets/window.cpp
Modified: trunk/src/gui/widgets/button.cpp
URL:
http://svn.gna.org/viewcvs/wesnoth/trunk/src/gui/widgets/button.cpp?rev=25617&r1=25616&r2=25617&view=diff
==============================================================================
--- trunk/src/gui/widgets/button.cpp (original)
+++ trunk/src/gui/widgets/button.cpp Sun Apr 6 10:41:23 2008
@@ -162,9 +162,7 @@
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();
}
}
Modified: trunk/src/gui/widgets/control.cpp
URL:
http://svn.gna.org/viewcvs/wesnoth/trunk/src/gui/widgets/control.cpp?rev=25617&r1=25616&r2=25617&view=diff
==============================================================================
--- trunk/src/gui/widgets/control.cpp (original)
+++ trunk/src/gui/widgets/control.cpp Sun Apr 6 10:41:23 2008
@@ -69,16 +69,25 @@
// 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)
@@ -98,6 +107,7 @@
set_dirty(false);
}
+
} // namespace gui2
Modified: trunk/src/gui/widgets/control.hpp
URL:
http://svn.gna.org/viewcvs/wesnoth/trunk/src/gui/widgets/control.hpp?rev=25617&r1=25616&r2=25617&view=diff
==============================================================================
--- trunk/src/gui/widgets/control.hpp (original)
+++ trunk/src/gui/widgets/control.hpp Sun Apr 6 10:41:23 2008
@@ -31,11 +31,14 @@
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 @@
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 @@
//! 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 @@
//! redrawing. This is needed for semi-tranparent items, the user
//! defines whether it's required or not.
surface restorer_;
-
};
} // namespace gui2
Modified: trunk/src/gui/widgets/label.cpp
URL:
http://svn.gna.org/viewcvs/wesnoth/trunk/src/gui/widgets/label.cpp?rev=25617&r1=25616&r2=25617&view=diff
==============================================================================
--- trunk/src/gui/widgets/label.cpp (original)
+++ trunk/src/gui/widgets/label.cpp Sun Apr 6 10:41:23 2008
@@ -100,7 +100,7 @@
canvas(i) = definition_->state[i].canvas;
}
- canvas(0).set_variable("text", variant(label()));
+ set_canvas_text();
}
}
Modified: trunk/src/gui/widgets/text_box.cpp
URL:
http://svn.gna.org/viewcvs/wesnoth/trunk/src/gui/widgets/text_box.cpp?rev=25617&r1=25616&r2=25617&view=diff
==============================================================================
--- trunk/src/gui/widgets/text_box.cpp (original)
+++ trunk/src/gui/widgets/text_box.cpp Sun Apr 6 10:41:23 2008
@@ -220,9 +220,7 @@
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 @@
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 @@
assert(false); // FIXME implement
} else {
label().erase(sel_start_, 1);
- set_label(label());
+ set_canvas_text();
set_dirty();
}
@@ -322,7 +320,7 @@
if(unicode >= 32 && unicode != 127) {
handled = true;
label().insert(label().begin() + sel_start_++, unicode);
- set_label(label());
+ set_canvas_text();
set_dirty();
}
}
Modified: trunk/src/gui/widgets/window.cpp
URL:
http://svn.gna.org/viewcvs/wesnoth/trunk/src/gui/widgets/window.cpp?rev=25617&r1=25616&r2=25617&view=diff
==============================================================================
--- trunk/src/gui/widgets/window.cpp (original)
+++ trunk/src/gui/widgets/window.cpp Sun Apr 6 10:41:23 2008
@@ -219,6 +219,7 @@
}
}
+
SDL_Rect twindow::get_client_rect()
{
assert(definition_ !=
std::vector<twindow_definition::tresolution>::const_iterator());
_______________________________________________
Wesnoth-commits mailing list
[email protected]
https://mail.gna.org/listinfo/wesnoth-commits