(svn r9087) [cpp_gui] -Codechange: Window is now clipping its widgets in OnPaint()
-Add: ClipDrawContext class to simplify draw clipping
-Fix: ResizeBox now can't resize window to negative width/height
--- a/src/gfx.h Tue Mar 06 20:18:17 2007 +0000
+++ b/src/gfx.h Sat Mar 10 02:39:51 2007 +0000
@@ -205,6 +205,8 @@
int DrawStringTruncated(int x, int y, StringID str, uint16 color, uint maxw);
int DoDrawString(const char *string, int x, int y, uint16 color);
+typedef uint32 WChar;
+int DoDrawStringW(const WChar *string, int x, int y, uint16 color);
int DoDrawStringTruncated(const char *str, int x, int y, uint16 color, uint maxw);
void DrawStringCenterUnderline(int x, int y, StringID str, uint16 color);
@@ -295,6 +297,34 @@
IS_PALETTE_COLOR = 0x100, ///< color value is already a real palette color index, not an index of a StringColor
} StringColorFlags;
+/**
+ * Create instance of this class on the stack (as local var) to set new clipping
+ * context. The original clipping context gets restored automatically when this
+ * variable is destroyed (comes out of scope).
+ */
+struct ClipDrawContext {
+ DrawPixelInfo m_dpi;
+ DrawPixelInfo *m_old_dpi;
+
+ ClipDrawContext(int left, int top, int width, int height)
+ {
+ if (FillDrawPixelInfo(&m_dpi, left, top, width, height)) {
+ m_old_dpi = _cur_dpi;
+ _cur_dpi = &m_dpi;
+ } else {
+ m_old_dpi = NULL;
+ }
+ }
+ ~ClipDrawContext()
+ {
+ if (m_old_dpi != NULL) _cur_dpi = m_old_dpi;
+ }
+ bool IsEmpty()
+ {
+ return m_old_dpi == NULL;
+ }
+};
+
#ifdef _DEBUG
extern bool _dbg_screen_rect;
--- a/src/widget/widget_resizebox.cpp Tue Mar 06 20:18:17 2007 +0000
+++ b/src/widget/widget_resizebox.cpp Sat Mar 10 02:39:51 2007 +0000
@@ -38,7 +38,10 @@
}
BaseWindow *w = GetWindow();
w->SetDirty();
- w->SetSize(e.m_pt - w->TopLeft() + m_sizing_offset);
+ Point16 size = e.m_pt - w->TopLeft() + m_sizing_offset;
+ size.x = max(size.x, DEFAULT_WIDTH);
+ size.y = max(size.y, DEFAULT_HEIGHT);
+ w->SetSize(size);
e.SetHandled();
w->SetDirty();
}
--- a/src/window.cpp Tue Mar 06 20:18:17 2007 +0000
+++ b/src/window.cpp Sat Mar 10 02:39:51 2007 +0000
@@ -292,6 +292,12 @@
assert(widget != NULL);
}
+/*virtual*/ void BaseWindow::OnPaint(gui::EvtPaint &ev)
+{
+ ClipDrawContext ctx(0, 0, Width(), Height());
+ super::OnPaint(ev);
+}
+
/**
* Open a new window. If there is no space for a new window, close an open
* window. Try to avoid stickied windows, but if there is no else, close one of
--- a/src/window.h Tue Mar 06 20:18:17 2007 +0000
+++ b/src/window.h Sat Mar 10 02:39:51 2007 +0000
@@ -456,6 +456,9 @@
/*virtual*/ void CreateNcWidgets();
/*virtual*/ void CreateWidgets(); ///< @TODO remove it when old gui infrastructure will no longer be used
+ /*virtual*/ void OnPaint(gui::EvtPaint &ev);
+
+
static BaseWindow* Allocate(int x, int y, int width, int height, WindowProc *proc, WindowClass cls, const OldWidget *widget);
static BaseWindow* Allocate(const WindowDesc *desc, int window_number = 0);
static BaseWindow* AllocateFront(const WindowDesc *desc, int window_number = 0);