]> git.saurik.com Git - wxWidgets.git/commitdiff
Some little additions to how wxBufferedDC is wrapped.
authorRobin Dunn <robin@alldunn.com>
Tue, 9 Apr 2002 01:25:47 +0000 (01:25 +0000)
committerRobin Dunn <robin@alldunn.com>
Tue, 9 Apr 2002 01:25:47 +0000 (01:25 +0000)
SHow how to use the wxBufferedDC in the demo.
Other demo tweaks

git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@15049 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775

wxPython/demo/template.py [new file with mode: 0644]
wxPython/demo/wxFileHistory.py
wxPython/demo/wxScrolledWindow.py
wxPython/src/gdi.i
wxPython/src/msw/gdi.cpp
wxPython/src/msw/gdi.py

diff --git a/wxPython/demo/template.py b/wxPython/demo/template.py
new file mode 100644 (file)
index 0000000..4ccfcd4
--- /dev/null
@@ -0,0 +1,25 @@
+
+from wxPython.wx import *
+
+#----------------------------------------------------------------------
+
+class TestPanel(wxPanel):
+    def __init__(self, parent, log):
+        self.log = log
+        wxPanel.__init__(self, parent, -1)
+
+#----------------------------------------------------------------------
+
+def runTest(frame, nb, log):
+    win = TestPanel(nb, log)
+    return win
+
+#----------------------------------------------------------------------
+
+
+
+overview = """<html><body>
+<h2><center>Say something nice here</center></h2>
+
+</body></html>
+"""
index bb90041bf789ab036d6cd739f3e463c4edda6bcd..9e0725705a7f22fd3b8bf61e6c7579c5afcfd40a 100644 (file)
@@ -21,8 +21,9 @@ class TestPanel(wxPanel):
         box = wxBoxSizer(wxVERTICAL)
 
         # Make and layout the controls
-        bf = wxFont(14, wxSWISS, wxNORMAL, wxBOLD)
-        nf = wxFont(11, wxSWISS, wxNORMAL, wxNORMAL)
+        fs = self.GetFont().GetPointSize()
+        bf = wxFont(fs+4, wxSWISS, wxNORMAL, wxBOLD)
+        nf = wxFont(fs+2, wxSWISS, wxNORMAL, wxNORMAL)
 
         t = wxStaticText(self, -1, "wxFileHistory")
         t.SetFont(bf)
index 76d83ee7146b82481d94081c539e1573e02f3712..ad1fa7becad7bd8fc19afb09d863fb3f0e6a4b04 100644 (file)
@@ -3,6 +3,8 @@ from wxPython.wx import *
 
 import images
 
+BUFFERED = 1
+
 #---------------------------------------------------------------------------
 
 class MyCanvas(wxScrolledWindow):
@@ -12,7 +14,9 @@ class MyCanvas(wxScrolledWindow):
         self.lines = []
         self.maxWidth  = 1000
         self.maxHeight = 1000
-        self.count = 0
+        self.x = self.y = 0
+        self.curLine = []
+        self.drawing = false
 
         self.SetBackgroundColour("WHITE")
         EVT_LEFT_DOWN(self, self.OnLeftButtonEvent)
@@ -28,6 +32,14 @@ class MyCanvas(wxScrolledWindow):
 
         self.SetScrollbars(20, 20, self.maxWidth/20, self.maxHeight/20)
 
+        if BUFFERED:
+            # Initialize the buffer bitmap.  No real DC is needed at this point.
+            self.buffer = wxEmptyBitmap(self.maxWidth, self.maxHeight)
+            dc = wxBufferedDC(None, self.buffer)
+            dc.SetBackground(wxBrush(self.GetBackgroundColour()))
+            dc.Clear()
+            self.DoDrawing(dc)
+
 
     def getWidth(self):
         return self.maxWidth
@@ -37,12 +49,18 @@ class MyCanvas(wxScrolledWindow):
 
 
     def OnPaint(self, event):
-        #self.count += 1
-        #print self.count, "begin paint...",
-        dc = wxPaintDC(self)
-        self.PrepareDC(dc)
-        self.DoDrawing(dc)
-        #print "end paint"
+        if BUFFERED:
+            # Create a buffered paint DC.  It will create the real
+            # wxPaintDC and then blit the bitmap to it when dc is
+            # deleted.  Since we don't need to draw anything else
+            # here that's all there is to it.
+            dc = wxBufferedPaintDC(self, self.buffer)
+        else:
+            dc = wxPaintDC(self)
+            self.PrepareDC(dc)
+            # since we're not buffering in this case, we have to
+            # paint the whole window, potentially very time consuming.
+            self.DoDrawing(dc)
 
 
     def DoDrawing(self, dc):
@@ -107,7 +125,6 @@ class MyCanvas(wxScrolledWindow):
         dc.SetPen(old_pen)
         dc.DrawRectangle(490, 90, 20, 20)
 
-
         self.DrawSavedLines(dc)
         dc.EndDrawing()
 
@@ -133,10 +150,19 @@ class MyCanvas(wxScrolledWindow):
             self.SetXY(event)
             self.curLine = []
             self.CaptureMouse()
+            self.drawing = true
+
+        elif event.Dragging() and self.drawing:
+            if BUFFERED:
+                # If doing buffered drawing, create the buffered DC, giving it
+                # it a real DC to blit to when done.
+                cdc = wxClientDC(self)
+                self.PrepareDC(cdc)
+                dc = wxBufferedDC(cdc, self.buffer)
+            else:
+                dc = wxClientDC(self)
+                self.PrepareDC(dc)
 
-        elif event.Dragging():
-            dc = wxClientDC(self)
-            self.PrepareDC(dc)
             dc.BeginDrawing()
             dc.SetPen(wxPen('MEDIUM FOREST GREEN', 4))
             coords = (self.x, self.y) + self.ConvertEventCoords(event)
@@ -145,10 +171,12 @@ class MyCanvas(wxScrolledWindow):
             self.SetXY(event)
             dc.EndDrawing()
 
-        elif event.LeftUp():
+
+        elif event.LeftUp() and self.drawing:
             self.lines.append(self.curLine)
             self.curLine = []
             self.ReleaseMouse()
+            self.drawing = false
 
 
 ## This is an example of what to do for the EVT_MOUSEWHEEL event,
index f250e55540a48f9d00242327a45325c8857d85a2..349699d6d36731bb52165b5cb1e786057b628d3d 100644 (file)
@@ -878,6 +878,19 @@ public:
         // (where area is usually something like the size of the window
         // being buffered)
     %name(wxBufferedDCInternalBuffer)wxBufferedDC( wxDC *dc, const wxSize &area );
+
+        // Blits the buffer to the dc, and detaches the dc from
+        // the buffer.  Usually called in the dtor or by the dtor
+        // of derived classes if the BufferedDC must blit before
+        // the derived class (which may own the dc it's blitting
+        // to) is destroyed.
+    void UnMask();
+
+
+    %pragma(python) addtomethod =
+        "__init__:self._dc = _args[0] # save a ref so the other dc won't be deleted before self"
+    %pragma(python) addtomethod =
+        "wxBufferedDCInternalBuffer:val._dc = _args[0] # save a ref so the other dc won't be deleted before self"
 };
 
 
index 2a76d24c15d205531f8c59bdaa2fe67d737e7670..ea26ff17ff32e1dfcd07e81d0d7e9695689bc62c 100644 (file)
@@ -8633,6 +8633,34 @@ static PyObject *_wrap_new_wxBufferedDCInternalBuffer(PyObject *self, PyObject *
     return _resultobj;
 }
 
+#define wxBufferedDC_UnMask(_swigobj)  (_swigobj->UnMask())
+static PyObject *_wrap_wxBufferedDC_UnMask(PyObject *self, PyObject *args, PyObject *kwargs) {
+    PyObject * _resultobj;
+    wxBufferedDC * _arg0;
+    PyObject * _argo0 = 0;
+    char *_kwnames[] = { "self", NULL };
+
+    self = self;
+    if(!PyArg_ParseTupleAndKeywords(args,kwargs,"O:wxBufferedDC_UnMask",_kwnames,&_argo0)) 
+        return NULL;
+    if (_argo0) {
+        if (_argo0 == Py_None) { _arg0 = NULL; }
+        else if (SWIG_GetPtrObj(_argo0,(void **) &_arg0,"_wxBufferedDC_p")) {
+            PyErr_SetString(PyExc_TypeError,"Type error in argument 1 of wxBufferedDC_UnMask. Expected _wxBufferedDC_p.");
+        return NULL;
+        }
+    }
+{
+    PyThreadState* __tstate = wxPyBeginAllowThreads();
+    wxBufferedDC_UnMask(_arg0);
+
+    wxPyEndAllowThreads(__tstate);
+    if (PyErr_Occurred()) return NULL;
+}    Py_INCREF(Py_None);
+    _resultobj = Py_None;
+    return _resultobj;
+}
+
 static void *SwigwxBufferedPaintDCTowxBufferedDC(void *ptr) {
     wxBufferedPaintDC *src;
     wxBufferedDC *dest;
@@ -11180,6 +11208,7 @@ static PyMethodDef gdicMethods[] = {
         { "wxScreenDC_StartDrawingOnTopWin", (PyCFunction) _wrap_wxScreenDC_StartDrawingOnTopWin, METH_VARARGS | METH_KEYWORDS },
         { "new_wxScreenDC", (PyCFunction) _wrap_new_wxScreenDC, METH_VARARGS | METH_KEYWORDS },
         { "new_wxBufferedPaintDC", (PyCFunction) _wrap_new_wxBufferedPaintDC, METH_VARARGS | METH_KEYWORDS },
+        { "wxBufferedDC_UnMask", (PyCFunction) _wrap_wxBufferedDC_UnMask, METH_VARARGS | METH_KEYWORDS },
         { "new_wxBufferedDCInternalBuffer", (PyCFunction) _wrap_new_wxBufferedDCInternalBuffer, METH_VARARGS | METH_KEYWORDS },
         { "new_wxBufferedDC", (PyCFunction) _wrap_new_wxBufferedDC, METH_VARARGS | METH_KEYWORDS },
         { "wxMemoryDC_SelectObject", (PyCFunction) _wrap_wxMemoryDC_SelectObject, METH_VARARGS | METH_KEYWORDS },
index 58affdf548437755b77730f7c602ec298ca0530b..eda13bc5eca978c642ac79d6b14bbcd609b476b4 100644 (file)
@@ -857,18 +857,23 @@ class wxBufferedDCPtr(wxMemoryDCPtr):
     def __init__(self,this):
         self.this = this
         self.thisown = 0
+    def UnMask(self, *_args, **_kwargs):
+        val = apply(gdic.wxBufferedDC_UnMask,(self,) + _args, _kwargs)
+        return val
     def __repr__(self):
         return "<C wxBufferedDC instance at %s>" % (self.this,)
 class wxBufferedDC(wxBufferedDCPtr):
     def __init__(self,*_args,**_kwargs):
         self.this = apply(gdic.new_wxBufferedDC,_args,_kwargs)
         self.thisown = 1
+        self._dc = _args[0] # save a ref so it won't be deleted before self
 
 
 
 def wxBufferedDCInternalBuffer(*_args,**_kwargs):
     val = wxBufferedDCPtr(apply(gdic.new_wxBufferedDCInternalBuffer,_args,_kwargs))
     val.thisown = 1
+    val._dc = _args[0] # save a ref so it won't be deleted before self
     return val