]> git.saurik.com Git - wxWidgets.git/blobdiff - utils/ogl/samples/ogledit/view.cpp
Corrected grey scrolling windows; added C++Builder 3.0 fixes
[wxWidgets.git] / utils / ogl / samples / ogledit / view.cpp
index 485392c833fb900d22458521130c1a1f38499fd9..0d8e58232b9c552d26da423005c13ce388c2d440 100644 (file)
@@ -26,8 +26,8 @@
 
 #include <wx/colordlg.h>
 
-#if !USE_DOC_VIEW_ARCHITECTURE
-#error You must set USE_DOC_VIEW_ARCHITECTURE to 1 in wx_setup.h!
+#if !wxUSE_DOC_VIEW_ARCHITECTURE
+#error You must set wxUSE_DOC_VIEW_ARCHITECTURE to 1 in wx_setup.h!
 #endif
 
 #include "ogledit.h"
@@ -66,10 +66,81 @@ bool DiagramView::OnCreate(wxDocument *doc, long flags)
   return TRUE;
 }
 
+#define CENTER  FALSE // Place the drawing to the center of the page
+
+
 // Sneakily gets used for default print/preview
-// as well as drawing on the screen.
-void DiagramView::OnDraw(wxDC *dc)
-{
+// as well as drawing on the screen. 
+void DiagramView::OnDraw(wxDC *dc) 
+{ 
+
+  /* You might use THIS code if you were scaling 
+   * graphics of known size to fit on the page. 
+   */ 
+  int w, h; 
+
+  // We need to adjust for the graphic size, a formula will be added 
+  float maxX = 900; 
+  float maxY = 700; 
+  // A better way of find the maxium values would be to search through 
+  // the linked list 
+
+  // Let's have at least 10 device units margin 
+  float marginX = 10; 
+  float marginY = 10; 
+
+  // Add the margin to the graphic size 
+  maxX += (2 * marginX); 
+  maxY += (2 * marginY); 
+
+  // Get the size of the DC in pixels 
+  dc->GetSize (&w, &h); 
+
+  // Calculate a suitable scaling factor 
+  float scaleX = (float) (w / maxX); 
+  float scaleY = (float) (h / maxY); 
+
+  // Use x or y scaling factor, whichever fits on the DC 
+  float actualScale = wxMin (scaleX, scaleY); 
+
+  float posX, posY; 
+  // Calculate the position on the DC for centring the graphic 
+  if (CENTER == TRUE) // center the drawing 
+    { 
+      posX = (float) ((w - (200 * actualScale)) / 2.0); 
+      posY = (float) ((h - (200 * actualScale)) / 2.0); 
+    } 
+  else    // Use defined presets 
+    { 
+      posX = 10; 
+      posY = 35; 
+    } 
+  
+
+  // Set the scale and origin 
+  dc->SetUserScale (actualScale, actualScale); 
+  dc->SetDeviceOrigin ((long) posX, (long) posY); 
+
+  // This part was added to preform the print preview and printing functions 
+
+  dc->BeginDrawing(); // Allows optimization of drawing code under MS Windows. 
+  wxDiagram *diagram_p=((DiagramDocument*)GetDocument())->GetDiagram();  // Get the current diagram
+  if (diagram_p->GetShapeList()) 
+  { 
+    wxCursor *old_cursor = NULL; 
+    wxNode *current = diagram_p->GetShapeList()->First();
+
+    while (current) // Loop through the entire list of shapes 
+    {
+        wxShape *object = (wxShape *)current->Data();
+        if (!object->GetParent())
+        {
+            object->Draw(* dc); // Draw the shape onto our printing dc
+        }
+        current = current->Next();  // Procede to the next shape in the list
+    }
+  }
+  dc->EndDrawing(); // Allows optimization of drawing code under MS Windows. 
 }
 
 void DiagramView::OnUpdate(wxView *sender, wxObject *hint)
@@ -167,6 +238,7 @@ void DiagramView::OnEditLabel(wxCommandEvent& event)
       }
 }
 
+
 /*
  * Window implementations
  */
@@ -181,6 +253,7 @@ MyCanvas::MyCanvas(wxView *v, wxWindow *parent, wxWindowID id, const wxPoint& po
     const wxSize& size, long style):
  wxShapeCanvas(parent, id, pos, size, style)
 {
+  SetBackgroundColour(*wxWHITE);
   view = v;
 }
 
@@ -188,7 +261,7 @@ MyCanvas::~MyCanvas(void)
 {
 }
 
-void MyCanvas::OnLeftClick(float x, float y, int keys)
+void MyCanvas::OnLeftClick(double x, double y, int keys)
 {
   EditorToolPalette *palette = wxGetApp().frame->palette;
   wxClassInfo *info = NULL;
@@ -224,31 +297,31 @@ void MyCanvas::OnLeftClick(float x, float y, int keys)
   }
 }
 
-void MyCanvas::OnRightClick(float x, float y, int keys)
+void MyCanvas::OnRightClick(double x, double y, int keys)
 {
 }
 
-void MyCanvas::OnDragLeft(bool draw, float x, float y, int keys)
+void MyCanvas::OnDragLeft(bool draw, double x, double y, int keys)
 {
 }
 
-void MyCanvas::OnBeginDragLeft(float x, float y, int keys)
+void MyCanvas::OnBeginDragLeft(double x, double y, int keys)
 {
 }
 
-void MyCanvas::OnEndDragLeft(float x, float y, int keys)
+void MyCanvas::OnEndDragLeft(double x, double y, int keys)
 {
 }
 
-void MyCanvas::OnDragRight(bool draw, float x, float y, int keys)
+void MyCanvas::OnDragRight(bool draw, double x, double y, int keys)
 {
 }
 
-void MyCanvas::OnBeginDragRight(float x, float y, int keys)
+void MyCanvas::OnBeginDragRight(double x, double y, int keys)
 {
 }
 
-void MyCanvas::OnEndDragRight(float x, float y, int keys)
+void MyCanvas::OnEndDragRight(double x, double y, int keys)
 {
 }