void MyCanvas::OnPaint( wxPaintEvent &WXUNUSED(event) ) { wxPaintDC dc( this ); PrepareDC( dc ); DrawShapes(dc); }
// Save drawing to file void PaintModel::SaveImage(wxString filename, wxSize size) { wxBitmap bitmap; // Create the bitmap of the specified wxSize bitmap.Create(size); // Create a memory DC to draw to the bitmap wxMemoryDC dc(bitmap); // Clear the background color dc.SetBackground(*wxWHITE_BRUSH); dc.Clear(); // Draw all the shapes DrawShapes(dc, false); // Get the type of image file wxBitmapType type = wxBITMAP_TYPE_JPEG; if (filename.substr(filename.size() - PNG_EXT.length()) == PNG_EXT) { std::cout << "Saving PNG image: " << filename << std::endl; type = wxBITMAP_TYPE_PNG; } else if (filename.substr(filename.size() - BMP_EXT.length()) == BMP_EXT) { std::cout << "Saving BMP image: " << filename << std::endl; type = wxBITMAP_TYPE_BMP; } else { std::cout << "Saving JPG/JPEG image: " << filename << std::endl; } // Write the bitmap with the specified file name and wxBitmapType bitmap.SaveFile(filename, type); }
void cDrawSimCharacter::Draw(const cSimCharacter& character, const tVector& fill_tint, const tVector& line_col, bool enable_draw_shape) { bool has_draw_shapes = character.HasDrawShapes(); if (has_draw_shapes && enable_draw_shape) { DrawShapes(character, fill_tint, line_col); } else { DrawSimBody(character, fill_tint, line_col); } }
static void DrawShapes(R3Scene *scene, R3SceneNode *node, RNFlags draw_flags = R3_DEFAULT_DRAW_FLAGS) { // Push transformation node->Transformation().Push(); // Draw elements for (int i = 0; i < node->NElements(); i++) { R3SceneElement *element = node->Element(i); element->Draw(draw_flags); } // Draw children for (int i = 0; i < node->NChildren(); i++) { R3SceneNode *child = node->Child(i); DrawShapes(scene, child, draw_flags); } // Pop transformation node->Transformation().Pop(); }
void MyCanvas::OnMouseEvent(wxMouseEvent& event) { if (event.LeftDown()) { DragShape* shape = FindShape(event.GetPosition()); if (shape) { // We tentatively start dragging, but wait for // mouse movement before dragging properly. m_dragMode = TEST_DRAG_START; m_dragStartPos = event.GetPosition(); m_draggedShape = shape; } } else if (event.LeftUp() && m_dragMode != TEST_DRAG_NONE) { // Finish dragging m_dragMode = TEST_DRAG_NONE; if (!m_draggedShape || !m_dragImage) return; m_draggedShape->SetPosition(m_draggedShape->GetPosition() + event.GetPosition() - m_dragStartPos); m_dragImage->Hide(); m_dragImage->EndDrag(); delete m_dragImage; m_dragImage = NULL; wxClientDC dc(this); if (m_currentlyHighlighted) { m_currentlyHighlighted->Draw(dc); } m_draggedShape->SetShow(true); m_draggedShape->Draw(dc); m_currentlyHighlighted = (DragShape*) NULL; m_draggedShape = (DragShape*) NULL; } else if (event.Dragging() && m_dragMode != TEST_DRAG_NONE) { if (m_dragMode == TEST_DRAG_START) { // We will start dragging if we've moved beyond a couple of pixels int tolerance = 2; int dx = abs(event.GetPosition().x - m_dragStartPos.x); int dy = abs(event.GetPosition().y - m_dragStartPos.y); if (dx <= tolerance && dy <= tolerance) return; // Start the drag. m_dragMode = TEST_DRAG_DRAGGING; if (m_dragImage) delete m_dragImage; // Erase the dragged shape from the canvas m_draggedShape->SetShow(false); wxClientDC dc(this); EraseShape(m_draggedShape, dc); DrawShapes(dc); switch (m_draggedShape->GetDragMethod()) { case SHAPE_DRAG_BITMAP: { m_dragImage = new wxDragImage(m_draggedShape->GetBitmap(), wxCursor(wxCURSOR_HAND)); break; } case SHAPE_DRAG_TEXT: { m_dragImage = new wxDragImage(wxString(_T("Dragging some test text")), wxCursor(wxCURSOR_HAND)); break; } case SHAPE_DRAG_ICON: { m_dragImage = new wxDragImage(wxICON(dragicon), wxCursor(wxCURSOR_HAND)); break; } } bool fullScreen = wxGetApp().GetUseScreen(); // The offset between the top-left of the shape image and the current shape position wxPoint beginDragHotSpot = m_dragStartPos - m_draggedShape->GetPosition(); // Now we do this inside the implementation: always assume // coordinates relative to the capture window (client coordinates) //if (fullScreen) // beginDragHotSpot -= ClientToScreen(wxPoint(0, 0)); if (!m_dragImage->BeginDrag(beginDragHotSpot, this, fullScreen)) { delete m_dragImage; m_dragImage = (wxDragImage*) NULL; m_dragMode = TEST_DRAG_NONE; } else { m_dragImage->Move(event.GetPosition()); m_dragImage->Show(); } } else if (m_dragMode == TEST_DRAG_DRAGGING) { // We're currently dragging. See if we're over another shape. DragShape* onShape = FindShape(event.GetPosition()); bool mustUnhighlightOld = false; bool mustHighlightNew = false; if (m_currentlyHighlighted) { if ((onShape == (DragShape*) NULL) || (m_currentlyHighlighted != onShape)) mustUnhighlightOld = true; } if (onShape && (onShape != m_currentlyHighlighted) && onShape->IsShown()) mustHighlightNew = true; if (mustUnhighlightOld || mustHighlightNew) m_dragImage->Hide(); // Now with the drag image switched off, we can change the window contents. if (mustUnhighlightOld) { wxClientDC clientDC(this); m_currentlyHighlighted->Draw(clientDC); m_currentlyHighlighted = (DragShape*) NULL; } if (mustHighlightNew) { wxClientDC clientDC(this); m_currentlyHighlighted = onShape; m_currentlyHighlighted->Draw(clientDC, wxINVERT); } // Move and show the image again m_dragImage->Move(event.GetPosition()); if (mustUnhighlightOld || mustHighlightNew) m_dragImage->Show(); } } }
void GLUTRedraw(void) { // Check scene if (!scene) return; // Set viewing transformation viewer->Camera().Load(); // Clear window RNRgb background = scene->Background(); glClearColor(background.R(), background.G(), background.B(), 1.0); glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); // Load lights LoadLights(scene); // Draw camera if (show_camera) { glDisable(GL_LIGHTING); glColor3d(1.0, 1.0, 1.0); glLineWidth(5); DrawCamera(scene); glLineWidth(1); } // Draw lights if (show_lights) { glDisable(GL_LIGHTING); glColor3d(1.0, 1.0, 1.0); glLineWidth(5); DrawLights(scene); glLineWidth(1); } // Draw rays if (show_rays) { glDisable(GL_LIGHTING); glColor3d(0.0, 1.0, 0.0); glLineWidth(3); DrawRays(scene); glLineWidth(1); } // Draw rays if (show_photons) { glDisable(GL_LIGHTING); glColor3d(1.0, 1.0, 1.0); glLineWidth(1); DrawPhotonPaths(scene); glLineWidth(1); } // Draw rays if (show_global_samples) { glDisable(GL_LIGHTING); glColor3d(1.0, 1.0, 1.0); glLineWidth(1); DrawGlobalSamples(scene); glLineWidth(1); } // Draw rays if (show_caustic_samples) { glDisable(GL_LIGHTING); glColor3d(1.0, 1.0, 1.0); glLineWidth(1); DrawCausticSamples(scene); glLineWidth(1); } // Draw scene nodes if (show_shapes) { glEnable(GL_LIGHTING); R3null_material.Draw(); DrawShapes(scene, scene->Root()); R3null_material.Draw(); } // Draw bboxes if (show_bboxes) { glDisable(GL_LIGHTING); glColor3d(1.0, 0.0, 0.0); DrawBBoxes(scene, scene->Root()); } // Draw frame time if (show_frame_rate) { char buffer[128]; static RNTime last_time; double frame_time = last_time.Elapsed(); last_time.Read(); if ((frame_time > 0) && (frame_time < 10)) { glDisable(GL_LIGHTING); glColor3d(1.0, 1.0, 1.0); sprintf(buffer, "%.1f fps", 1.0 / frame_time); DrawText(R2Point(100, 100), buffer); } } // Capture screenshot image if (screenshot_image_name) { if (print_verbose) printf("Creating image %s\n", screenshot_image_name); R2Image image(GLUTwindow_width, GLUTwindow_height, 3); image.Capture(); image.Write(screenshot_image_name); screenshot_image_name = NULL; } // Swap buffers glutSwapBuffers(); }