(svn r9091) [cpp_gui] -Codechange: Widgets now use container's coordinate space instead of window's space
--- a/src/misc/rect.hpp Sat Mar 10 04:52:01 2007 +0000
+++ b/src/misc/rect.hpp Sat Mar 10 08:53:59 2007 +0000
@@ -132,6 +132,10 @@
: top_left(left, top), bottom_right(right, bottom)
{}
+ template <typename Ta> RectT(const PointT<Ta> &tl, const PointT<Ta> &br)
+ : top_left(tl), bottom_right(br)
+ {}
+
template <typename Ta> RectT(const RectT<Ta> &src)
: top_left(src.top_left), bottom_right(src.bottom_right)
{}
--- a/src/widget/widget.h Sat Mar 10 04:52:01 2007 +0000
+++ b/src/widget/widget.h Sat Mar 10 08:53:59 2007 +0000
@@ -112,6 +112,7 @@
Point16 Size() const;
Point16 CenterPt() const;
const Rect16& GetRect() const;
+ Rect16 GetLocalRect() const;
void SetLeft(int16 val);
void SetTop(int16 val);
--- a/src/widget/widget_base.cpp Sat Mar 10 04:52:01 2007 +0000
+++ b/src/widget/widget_base.cpp Sat Mar 10 08:53:59 2007 +0000
@@ -74,6 +74,11 @@
return m_rect;
}
+Rect16 Widget::GetLocalRect() const
+{
+ return Rect16(Point16(0, 0), BottomRight() - TopLeft());
+}
+
void Widget::SetLeft(int16 val)
{
m_rect.SetRight(Right() + val - Left());
@@ -212,13 +217,12 @@
void Widget::DrawFrameRect(int ctab, FrameFlags flags)
{
- DrawFrameRect(Left(), Top(), Right(), Bottom(), ctab, flags);
+ DrawFrameRect(0, 0, Width() - 1, Height() - 1, ctab, flags);
}
void Widget::DrawSprite(SpriteID img, SpriteID pal, const Point16 &local_pos)
{
- Point16 window_space_pos = TopLeft() + local_pos;
- ::DrawSprite(img, pal, window_space_pos.x, window_space_pos.y);
+ ::DrawSprite(img, pal, local_pos.x, local_pos.y);
}
--- a/src/widget/widget_button_txt.cpp Sat Mar 10 04:52:01 2007 +0000
+++ b/src/widget/widget_button_txt.cpp Sat Mar 10 08:53:59 2007 +0000
@@ -23,7 +23,7 @@
/*virtual*/ void TextButton::OnPaint(EvtPaint &ev)
{
DrawBackground(ev);
- Point center = CenterPt();
+ Point center = Size() / 2;
if (m_pushed) center += Point(1, 1);
DrawStringCentered(center.x, center.y - 5, m_text, 0);
ev.SetHandled();
--- a/src/widget/widget_caption.cpp Sat Mar 10 04:52:01 2007 +0000
+++ b/src/widget/widget_caption.cpp Sat Mar 10 08:53:59 2007 +0000
@@ -29,7 +29,7 @@
bool make_close_box = ((m_feature_flags & FF_NO_CLOSE_BOX ) == FF_NONE);
bool make_sticky_box = ((m_feature_flags & FF_NO_STICKY_BOX) == FF_NONE);
- Rect16 rc_caption = GetRect();
+ Rect16 rc_caption = GetLocalRect();
/* add close box */
if (make_close_box) {
@@ -58,10 +58,10 @@
byte caption_color = w->caption_color;
assert(Height() == 14); // XXX - to ensure the same sizes are used everywhere!
- DrawFrameRect(Left(), Top(), Right(), Bottom(), m_color, FR_BORDERONLY);
- DrawFrameRect(Left() + 1, Top() + 1, Right() - 1, Bottom() - 1, m_color, (caption_color == 0xFF) ? FR_LOWERED | FR_DARKENED : FR_LOWERED | FR_DARKENED | FR_BORDERONLY);
+ DrawFrameRect(m_color, FR_BORDERONLY);
+ DrawFrameRect(1, 1, Width() - 2, Height() - 2, m_color, (caption_color == 0xFF) ? FR_LOWERED | FR_DARKENED : FR_LOWERED | FR_DARKENED | FR_BORDERONLY);
if (caption_color != 0xFF) {
- GfxFillRect(Left() + 2, Top() + 2, Right() - 2, Bottom() - 2, _colour_gradient[_player_colors[caption_color]][4]);
+ GfxFillRect(2, 2, Width() - 3, Height() - 3, _colour_gradient[_player_colors[caption_color]][4]);
}
}
@@ -71,7 +71,7 @@
assert(w != NULL);
DrawBackground(ev);
- DrawStringCenteredTruncated(Left() + 2, Right() - 2, Top() + 2, w->m_caption_text, 0x84);
+ DrawStringCenteredTruncated(2, Width() - 3, 2, w->m_caption_text, 0x84);
ev.SetHandled();
}
--- a/src/widget/widget_composite.cpp Sat Mar 10 04:52:01 2007 +0000
+++ b/src/widget/widget_composite.cpp Sat Mar 10 08:53:59 2007 +0000
@@ -112,8 +112,9 @@
WidgetIterator it = it_next++;
/* get child */
Widget *wd_child = (*it).second;
- /* tell him we are closing */
- wd_child->OnPaint(ev);
+ /* tell him we are painting */
+ ClipDrawContext ctx(wd_child->Left(), wd_child->Top(), wd_child->Width(), wd_child->Height());
+ if (!ctx.IsEmpty()) wd_child->OnPaint(ev);
}
}
--- a/src/widget/widget_label.cpp Sat Mar 10 04:52:01 2007 +0000
+++ b/src/widget/widget_label.cpp Sat Mar 10 08:53:59 2007 +0000
@@ -30,7 +30,7 @@
/*virtual*/ void Label::OnPaint(EvtPaint &ev)
{
DrawBackground(ev);
- Point center = CenterPt();
+ Point center = Size() / 2;
DrawStringCentered(center.x, center.y - 5, m_text, 0);
ev.SetHandled();
}
--- a/src/widget/widget_resizebox.cpp Sat Mar 10 04:52:01 2007 +0000
+++ b/src/widget/widget_resizebox.cpp Sat Mar 10 08:53:59 2007 +0000
@@ -23,7 +23,7 @@
/*virtual*/ void ResizeBox::DrawBackground(EvtPaint &ev)
{
bool sizing = m_ticket_sizing.IsActive();
- DrawFrameRect(Left(), Top(), Right(), Bottom(), m_color, sizing ? FR_LOWERED : FR_NONE);
+ DrawFrameRect(m_color, sizing ? FR_LOWERED : FR_NONE);
}
void ResizeBox::OnCaptureSizing(EvtMouseOver &e)
--- a/src/window.cpp Sat Mar 10 04:52:01 2007 +0000
+++ b/src/window.cpp Sat Mar 10 08:53:59 2007 +0000
@@ -295,7 +295,7 @@
/*virtual*/ void BaseWindow::OnPaint(gui::EvtPaint &ev)
{
ClipDrawContext ctx(0, 0, Width(), Height());
- super::OnPaint(ev);
+ if (!ctx.IsEmpty()) super::OnPaint(ev);
}
/**