void MyFrame::DoChangeFont(const wxFont& font, const wxColour& col) { m_canvas->SetTextFont(font); if ( col.IsOk() ) m_canvas->SetColour(col); m_canvas->Refresh(); m_textctrl->SetFont(font); if ( col.IsOk() ) m_textctrl->SetForegroundColour(col); m_textctrl->Refresh(); // update the state of the bold/italic/underlined menu items wxMenuBar *mbar = GetMenuBar(); if ( mbar ) { mbar->Check(Font_Light, font.GetWeight() == wxFONTWEIGHT_LIGHT); mbar->Check(Font_Bold, font.GetWeight() == wxFONTWEIGHT_BOLD); mbar->Check(Font_Italic, font.GetStyle() == wxFONTSTYLE_ITALIC); #ifndef __WXMSW__ mbar->Check(Font_Slant, font.GetStyle() == wxFONTSTYLE_SLANT); #endif mbar->Check(Font_Underlined, font.GetUnderlined()); mbar->Check(Font_Strikethrough, font.GetStrikethrough()); } }
void MyFrame::OnNewWindow(wxCommandEvent& WXUNUSED(event) ) { // Make another frame, containing a canvas MyChild *subframe = new MyChild(frame, _T("Canvas Frame")); wxString title; title.Printf(_T("Canvas Frame %d"), ++gs_nFrames); subframe->SetTitle(title); // Give it an icon #ifdef __WXMSW__ subframe->SetIcon(wxIcon(_T("chrt_icn"))); #else subframe->SetIcon(wxIcon( mondrian_xpm )); #endif // Make a menubar wxMenu *file_menu = new wxMenu; file_menu->Append(MDI_NEW_WINDOW, _T("&New window")); file_menu->Append(MDI_CHILD_QUIT, _T("&Close child"), _T("Close this window")); file_menu->Append(MDI_QUIT, _T("&Exit")); wxMenu *option_menu = new wxMenu; option_menu->Append(MDI_REFRESH, _T("&Refresh picture")); option_menu->Append(MDI_CHANGE_TITLE, _T("Change &title...\tCtrl-T")); option_menu->AppendSeparator(); option_menu->Append(MDI_CHANGE_POSITION, _T("Move frame\tCtrl-M")); option_menu->Append(MDI_CHANGE_SIZE, _T("Resize frame\tCtrl-S")); wxMenu *help_menu = new wxMenu; help_menu->Append(MDI_ABOUT, _T("&About")); wxMenuBar *menu_bar = new wxMenuBar; menu_bar->Append(file_menu, _T("&File")); menu_bar->Append(option_menu, _T("&Child")); menu_bar->Append(help_menu, _T("&Help")); // Associate the menu bar with the frame subframe->SetMenuBar(menu_bar); #if wxUSE_STATUSBAR subframe->CreateStatusBar(); subframe->SetStatusText(title); #endif // wxUSE_STATUSBAR int width, height; subframe->GetClientSize(&width, &height); MyCanvas *canvas = new MyCanvas(subframe, wxPoint(0, 0), wxSize(width, height)); canvas->SetCursor(wxCursor(wxCURSOR_PENCIL)); subframe->canvas = canvas; // Give it scrollbars canvas->SetScrollbars(20, 20, 50, 50); subframe->Show(true); }
wxFrame *MyApp::CreateFrame() { MyChild *subframe = new MyChild(NULL, _T("Canvas Frame"), wxPoint(10, 10), wxSize(300, 300), wxDEFAULT_FRAME_STYLE); subframe->SetTitle(_T("wxWidgets canvas frame")); // Give it a status line subframe->CreateStatusBar(); // Make a menubar wxMenu *file_menu = new wxMenu; file_menu->Append(HELLO_NEW, _T("&New MFC Window")); file_menu->Append(HELLO_QUIT, _T("&Close")); wxMenuBar *menu_bar = new wxMenuBar; menu_bar->Append(file_menu, _T("&File")); // Associate the menu bar with the frame subframe->SetMenuBar(menu_bar); int width, height; subframe->GetClientSize(&width, &height); MyCanvas *canvas = new MyCanvas(subframe, wxPoint(0, 0), wxSize(width, height)); canvas->SetCursor(wxCursor(wxCURSOR_PENCIL)); subframe->canvas = canvas; subframe->Show(true); // Return the main frame window return subframe; }
void MyFrame::OnNewWindow(wxCommandEvent& WXUNUSED(event)) { // Make another frame, containing a canvas MyChild *subframe = new MyChild(frame, wxT("Canvas Frame"), wxPoint(10, 10), wxSize(300, 300), wxDEFAULT_FRAME_STYLE | wxNO_FULL_REPAINT_ON_RESIZE); subframe->SetTitle(wxString::Format(wxT("Canvas Frame %d"), winNumber)); winNumber ++; // Give it an icon (this is ignored in MDI mode: uses resources) #ifdef __WXMSW__ subframe->SetIcon(wxIcon(wxT("sashtest_icn"))); #endif #if wxUSE_STATUSBAR // Give it a status line subframe->CreateStatusBar(); #endif // wxUSE_STATUSBAR // Make a menubar wxMenu *file_menu = new wxMenu; file_menu->Append(SASHTEST_NEW_WINDOW, wxT("&New window")); file_menu->Append(SASHTEST_CHILD_QUIT, wxT("&Close child")); file_menu->Append(SASHTEST_QUIT, wxT("&Exit")); wxMenu *option_menu = new wxMenu; // Dummy option option_menu->Append(SASHTEST_REFRESH, wxT("&Refresh picture")); wxMenu *help_menu = new wxMenu; help_menu->Append(SASHTEST_ABOUT, wxT("&About")); wxMenuBar *menu_bar = new wxMenuBar; menu_bar->Append(file_menu, wxT("&File")); menu_bar->Append(option_menu, wxT("&Options")); menu_bar->Append(help_menu, wxT("&Help")); // Associate the menu bar with the frame subframe->SetMenuBar(menu_bar); int width, height; subframe->GetClientSize(&width, &height); MyCanvas *canvas = new MyCanvas(subframe, wxPoint(0, 0), wxSize(width, height)); canvas->SetCursor(wxCursor(wxCURSOR_PENCIL)); subframe->canvas = canvas; // Give it scrollbars canvas->SetScrollbars(20, 20, 50, 50); subframe->Show(true); }
// The `main program' equivalent, creating the windows and returning the // main frame bool MyApp::OnInit() { // Create the main frame window MyFrame* frame = new MyFrame(NULL, _T("Tree Test"), wxDefaultPosition, wxSize(400, 550)); #if wxUSE_STATUSBAR // Give it a status line frame->CreateStatusBar(2); #endif // wxUSE_STATUSBAR // Give it an icon #ifdef __WINDOWS__ wxIcon icon(_T("tree_icn")); frame->SetIcon(icon); #endif // Make a menubar wxMenu *file_menu = new wxMenu; file_menu->Append(TEST_LEFT_RIGHT, _T("&Left to right"), _T("Redraw left to right")); file_menu->Append(TEST_TOP_BOTTOM, _T("&Top to bottom"), _T("Redraw top to bottom")); file_menu->AppendSeparator(); file_menu->Append(TEST_QUIT, _T("E&xit"), _T("Quit program")); wxMenu *help_menu = new wxMenu; help_menu->Append(TEST_ABOUT, _T("&About"), _T("About Tree Test")); wxMenuBar* menu_bar = new wxMenuBar; menu_bar->Append(file_menu, _T("&File")); menu_bar->Append(help_menu, _T("&Help")); // Associate the menu bar with the frame frame->SetMenuBar(menu_bar); MyCanvas *canvas = new MyCanvas(frame); // Give it scrollbars: the virtual canvas is 20 * 50 = 1000 pixels in each direction canvas->SetScrollbars(20, 20, 50, 50); frame->canvas = canvas; myTree = new wxTreeLayoutStored(); wxClientDC dc(canvas); wxFont font(10, wxROMAN, wxNORMAL, wxBOLD); dc.SetFont(font); TreeTest(*myTree, dc); frame->Show(true); #if wxUSE_STATUSBAR frame->SetStatusText(_T("Hello, tree!")); #endif // wxUSE_STATUSBAR // Return the main frame window return true; }
// Creates a canvas. Called from view.cpp when a new drawing // view is created. MyCanvas *MyFrame::CreateCanvas(wxView *view, wxMDIChildFrame *parent) { int width, height; parent->GetClientSize(&width, &height); // Non-retained canvas MyCanvas *canvas = new MyCanvas(view, parent, wxPoint(0, 0), wxSize(width, height), 0); canvas->SetCursor(wxCursor(wxCURSOR_PENCIL)); // Give it scrollbars canvas->SetScrollbars(20, 20, 50, 50); return canvas; }
void MyFrame::OnSelectFont(wxCommandEvent& WXUNUSED(event)) { wxFontData data; data.SetInitialFont(m_canvas->GetTextFont()); data.SetColour(m_canvas->GetColour()); wxFontDialog dialog(this, data); if ( dialog.ShowModal() == wxID_OK ) { wxFontData retData = dialog.GetFontData(); wxFont font = retData.GetChosenFont(); wxColour colour = retData.GetColour(); DoChangeFont(font, colour); } }
void MyEvtHandler::OnEndDragRight(double x, double y, int WXUNUSED(keys), int WXUNUSED(attachment)) { GetShape()->GetCanvas()->ReleaseMouse(); MyCanvas *canvas = (MyCanvas *)GetShape()->GetCanvas(); // Check if we're on an object int new_attachment; wxShape *otherShape = canvas->FindFirstSensitiveShape(x, y, &new_attachment, OP_DRAG_RIGHT); if (otherShape && !otherShape->IsKindOf(CLASSINFO(wxLineShape))) { canvas->view->GetDocument()->GetCommandProcessor()->Submit( new DiagramCommand(_T("wxLineShape"), OGLEDIT_ADD_LINE, (DiagramDocument *)canvas->view->GetDocument(), CLASSINFO(wxLineShape), 0.0, 0.0, false, NULL, GetShape(), otherShape)); } }
void MyFrame::OnUnderline(wxCommandEvent& event) { wxFont font = m_canvas->GetTextFont(); font.SetUnderlined(event.IsChecked()); DoChangeFont(font); }
void MyFrame::OnSlant(wxCommandEvent& event) { wxFont font = m_canvas->GetTextFont(); font.SetStyle(event.IsChecked() ? wxFONTSTYLE_SLANT : wxFONTSTYLE_NORMAL); DoChangeFont(font); }
void MyFrame::OnLight(wxCommandEvent& event) { wxFont font = m_canvas->GetTextFont(); font.SetWeight(event.IsChecked() ? wxFONTWEIGHT_LIGHT : wxFONTWEIGHT_NORMAL); DoChangeFont(font); }
void MyFrame::DoResizeFont(int diff) { wxFont font = m_canvas->GetTextFont(); font.SetPointSize(font.GetPointSize() + diff); DoChangeFont(font); }
void MyFrame::OnSetFamily(wxCommandEvent& WXUNUSED(event)) { wxFontFamily f = GetFamilyFromUser(); wxFont font = m_canvas->GetTextFont(); font.SetFamily(f); DoChangeFont(font); }
void MyFrame::OnSetEncoding(wxCommandEvent& WXUNUSED(event)) { wxFontEncoding enc = GetEncodingFromUser(); if ( enc == wxFONTENCODING_SYSTEM ) return; wxFont font = m_canvas->GetTextFont(); font.SetEncoding(enc); DoChangeFont(font); }
void MyFrame::OnSetNativeDesc(wxCommandEvent& WXUNUSED(event)) { wxString fontInfo = wxGetTextFromUser ( wxT("Enter native font string"), wxT("Input font description"), m_canvas->GetTextFont().GetNativeFontInfoDesc(), this ); if ( fontInfo.empty() ) return; // user clicked "Cancel" - do nothing wxFont font; font.SetNativeFontInfo(fontInfo); if ( !font.IsOk() ) { wxLogError(wxT("Font info string \"%s\" is invalid."), fontInfo.c_str()); return; } DoChangeFont(font); }
void ShadowMap::computeAsTexture(vcg::Point3f L, bool makeboth, MyCanvas &canvas){ if (lastL!=L) { canvas.SetAsOutput(); setMatrices(L, canvas.GetSoftRes(),canvas.GetHardRes(), true); glClearDepth(1); glClear( GL_DEPTH_BUFFER_BIT ); glDisable(GL_SCISSOR_TEST); glDepthFunc(GL_LESS); m.DrawShadowmap(false); restoreMatrices(); if (hardSettings.doubleSM && makeboth) { setMatrices(L, canvas.GetSoftRes(), canvas.GetHardRes(), false); glClearDepth(-10000); glClear( GL_DEPTH_BUFFER_BIT); glDepthFunc(GL_GREATER); glDisable(GL_SCISSOR_TEST); m.DrawShadowmap(false); restoreMatrices(); } glClearDepth(1); glDepthFunc(GL_LESS); mainCanvas.SetAsOutput(); lastL=L; } glActiveTextureARB(GL_TEXTURE1_ARB); canvas.SetAsTexture(); }
bool MyApp::OnInit(void) { wxInitAllImageHandlers(); // Set the font path and working directory wxFileName exePath = wxStandardPaths::Get().GetExecutablePath(); #ifdef __WXMAC__ wxString fontPath = exePath.GetPathWithSep() + wxT("../../../../../lib/fonts"); wxString cwdPath = exePath.GetPathWithSep() + wxT("../../.."); #else wxString fontPath = exePath.GetPathWithSep() + wxT("../../lib/fonts"); wxString cwdPath = exePath.GetPath(); #endif wxPdfFontManager::GetFontManager()->AddSearchPath(fontPath); wxSetWorkingDirectory(cwdPath); #if wxCHECK_VERSION(2,9,0) m_testFont.Create(10, wxFONTFAMILY_SWISS, wxFONTSTYLE_NORMAL, wxFONTWEIGHT_NORMAL); #else m_testFont.Create(10, wxSWISS, wxNORMAL, wxNORMAL); #endif g_printData = new wxPrintData; // You could set an initial paper size here // g_printData->SetPaperId(wxPAPER_LETTER); // for Americans // g_printData->SetPaperId(wxPAPER_A4); // for everyone else g_pageSetupData = new wxPageSetupDialogData; // copy over initial paper size from print record (*g_pageSetupData) = *g_printData; // Set some initial page margins in mm. g_pageSetupData->SetMarginTopLeft(wxPoint(15, 15)); g_pageSetupData->SetMarginBottomRight(wxPoint(15, 15)); // Create the main frame window frame = new MyFrame((wxFrame *) NULL, _T("wxWidgets Printing Demo"), wxPoint(0, 0), wxSize(400, 400)); #if wxUSE_STATUSBAR // Give it a status line frame->CreateStatusBar(2); #endif // wxUSE_STATUSBAR // Load icon and bitmap frame->SetIcon( wxICON( mondrian) ); // Make a menubar wxMenu *file_menu = new wxMenu; file_menu->Append(WXPRINT_PRINT, _T("&Print..."), _T("Print")); file_menu->Append(WXPRINT_PDF, _T("PDF..."), _T("PDF")); file_menu->Append(WXPRINT_PAGE_SETUP, _T("Page Set&up..."), _T("Page setup")); #ifdef __WXMAC__ file_menu->Append(WXPRINT_PAGE_MARGINS, _T("Page Margins..."), _T("Page margins")); #endif file_menu->Append(WXPRINT_PREVIEW, _T("Print Pre&view"), _T("Preview")); #if wxUSE_ACCEL // Accelerators wxAcceleratorEntry entries[1]; entries[0].Set(wxACCEL_CTRL, (int) 'V', WXPRINT_PREVIEW); wxAcceleratorTable accel(1, entries); frame->SetAcceleratorTable(accel); #endif #if defined(__WXMSW__) && wxTEST_POSTSCRIPT_IN_MSW file_menu->AppendSeparator(); file_menu->Append(WXPRINT_PRINT_PS, _T("Print PostScript..."), _T("Print (PostScript)")); file_menu->Append(WXPRINT_PAGE_SETUP_PS, _T("Page Setup PostScript..."), _T("Page setup (PostScript)")); file_menu->Append(WXPRINT_PREVIEW_PS, _T("Print Preview PostScript"), _T("Preview (PostScript)")); #endif file_menu->AppendSeparator(); file_menu->Append(WXPRINT_ANGLEUP, _T("Angle up\tAlt-U"), _T("Raise rotated text angle")); file_menu->Append(WXPRINT_ANGLEDOWN, _T("Angle down\tAlt-D"), _T("Lower rotated text angle")); file_menu->AppendSeparator(); file_menu->Append(WXPRINT_QUIT, _T("E&xit"), _T("Exit program")); wxMenu *help_menu = new wxMenu; help_menu->Append(WXPRINT_ABOUT, _T("&About"), _T("About this demo")); wxMenuBar *menu_bar = new wxMenuBar; menu_bar->Append(file_menu, _T("&File")); menu_bar->Append(help_menu, _T("&Help")); // Associate the menu bar with the frame frame->SetMenuBar(menu_bar); MyCanvas *canvas = new MyCanvas(frame, wxPoint(0, 0), wxSize(100, 100), wxRETAINED|wxHSCROLL|wxVSCROLL); // Give it scrollbars: the virtual canvas is 20 * 50 = 1000 pixels in each direction canvas->SetScrollbars(20, 20, 50, 50); frame->canvas = canvas; frame->Centre(wxBOTH); frame->Show(); #if wxUSE_STATUSBAR frame->SetStatusText(_T("Printing demo")); #endif // wxUSE_STATUSBAR SetTopWindow(frame); return true; }
void MyFrame::OnStrikethrough(wxCommandEvent& event) { wxFont font = m_canvas->GetTextFont(); font.SetStrikethrough(event.IsChecked()); DoChangeFont(font); }
void MyChild::OnActivate(wxActivateEvent& event) { if ( event.GetActive() && m_canvas ) m_canvas->SetFocus(); }
bool MyChild::OnSave(wxString filename) { wxSVGFileDC svgDC (filename, 600, 650); m_canvas->OnDraw (svgDC); return svgDC.IsOk(); }