|
From: <sm...@us...> - 2008-12-09 08:57:33
|
Revision: 9060
http://plplot.svn.sourceforge.net/plplot/?rev=9060&view=rev
Author: smekal
Date: 2008-12-09 08:57:24 +0000 (Tue, 09 Dec 2008)
Log Message:
-----------
The size of the image is now asked in a dialog when selecting image file types from the "Save Plot..." menu (tested on Linux wx 2.6 and 2.8).
Modified Paths:
--------------
trunk/drivers/wxwidgets.h
trunk/drivers/wxwidgets_app.cpp
Modified: trunk/drivers/wxwidgets.h
===================================================================
--- trunk/drivers/wxwidgets.h 2008-12-08 20:58:53 UTC (rev 9059)
+++ trunk/drivers/wxwidgets.h 2008-12-09 08:57:24 UTC (rev 9060)
@@ -22,6 +22,9 @@
#ifndef __WXWIDGETS_H__
#define __WXWIDGETS_H__
+/* some special wxWidgets headers */
+#include <wx/spinctrl.h>
+
/* freetype headers and macros */
#ifdef HAVE_FREETYPE
#include "plfreetype.h"
@@ -343,6 +346,7 @@
wxString dev_menu_short;
wxString dev_menu_long;
wxString dev_file_app;
+ bool pixelDevice;
};
@@ -405,8 +409,8 @@
DECLARE_EVENT_TABLE()
};
-/* definition of the actual window/frame shown */
+/* declaration of the actual window/frame shown */
class wxPLplotFrame : public wxFrame
{
public:
@@ -429,6 +433,30 @@
enum { wxPL_Save=10000, wxPL_Next=10100, wxPL_Locate, wxPL_Orientation_0, wxPL_Orientation_90,
wxPL_Orientation_180, wxPL_Orientation_270 };
+
+/* Pixel size dialog */
+class wxGetSizeDialog: public wxDialog
+{
+public:
+ // constructors and destructors
+ wxGetSizeDialog( wxWindow *parent, wxWindowID id, const wxString &title,
+ const wxPoint& pos = wxDefaultPosition,
+ const wxSize& size = wxDefaultSize,
+ long style = wxDEFAULT_DIALOG_STYLE,
+ int width=800, int height=600 );
+
+ int getWidth() { return spinControlWidth->GetValue(); }
+ int getHeight() { return spinControlHeight->GetValue(); }
+
+private:
+ wxSpinCtrl* spinControlWidth;
+ wxSpinCtrl* spinControlHeight;
+
+private:
+ DECLARE_EVENT_TABLE()
+};
+
+
/* Use this macro if you want to define your own main() or WinMain() function
and call wxEntry() from there. */
#define IMPLEMENT_PLAPP_NO_MAIN(appname) \
Modified: trunk/drivers/wxwidgets_app.cpp
===================================================================
--- trunk/drivers/wxwidgets_app.cpp 2008-12-08 20:58:53 UTC (rev 9059)
+++ trunk/drivers/wxwidgets_app.cpp 2008-12-09 08:57:24 UTC (rev 9060)
@@ -68,20 +68,20 @@
};
struct dev_entry dev_entries[] = {
- { wxT("wxbmp"), wxT("bmp (wx)..."), wxT("Save this plot as bmp!"), wxT("bmp files (*.bmp)|*.bmp") },
- { wxT("wxpng"), wxT("png (wx)..."), wxT("Save this plot as png"), wxT("png files (*.png)|*.png") },
- { wxT("wxpcx"), wxT("pcx (wx)..."), wxT("Save this plot as pcx!"), wxT("pcx files (*.pcx)|*.pcx") },
- { wxT("wxjpeg"), wxT("jpeg (wx)..."), wxT("Save this plot as jpeg!"), wxT("jpg files (*.jpg;*.jpeg)|*.jpg;*.jpeg") },
- { wxT("wxtiff"), wxT("tiff (wx)..."), wxT("Save this plot as tiff!"), wxT("tiff files (*.tif;*.tiff)|*.tif;*.tiff") },
- { wxT("wxpnm"), wxT("pnm (wx)..."), wxT("Save this plot as pnm!"), wxT("pnm files (*.pnm)|*.pnm") },
- { wxT("pngcairo"), wxT("png (cairo)..."), wxT("Save this plot as png using cairo!"), wxT("png files (*.png)|*.png") },
- { wxT("pdfcairo"), wxT("pdf (cairo)..."), wxT("Save this plot as pdf using cairo!"), wxT("pdf files (*.pdf)|*.pdf") },
- { wxT("ps"), wxT("postscript..."), wxT("Save this plot as postscript!"), wxT("ps files (*.ps)|*.ps") },
- { wxT("psc"), wxT("color postscript..."), wxT("Save this plot as color postscript!"), wxT("ps files (*.ps;*.psc)|*.ps;*.psc") },
- { wxT("pscairo"), wxT("color postscript (cairo)..."), wxT("Save this plot as color postscript using cairo!"), wxT("ps files (*.ps;*.psc)|*.ps;*.psc") },
- { wxT("svg"), wxT("svg..."), wxT("Save this plot as svg!"), wxT("svg files (*.svg)|*.svg") },
- { wxT("svgcairo"), wxT("svg (cairo)..."), wxT("Save this plot as svg using cairo!"), wxT("svg files (*.svg)|*.svg") },
- { wxT("xfig"), wxT("xfig..."), wxT("Save this plot as xfig!"), wxT("fig files (*.fig)|*.fig") }
+ { wxT("wxbmp"), wxT("bmp (wx)..."), wxT("Save this plot as bmp!"), wxT("bmp files (*.bmp)|*.bmp"), true },
+ { wxT("wxpng"), wxT("png (wx)..."), wxT("Save this plot as png"), wxT("png files (*.png)|*.png"), true },
+ { wxT("wxpcx"), wxT("pcx (wx)..."), wxT("Save this plot as pcx!"), wxT("pcx files (*.pcx)|*.pcx"), true },
+ { wxT("wxjpeg"), wxT("jpeg (wx)..."), wxT("Save this plot as jpeg!"), wxT("jpg files (*.jpg;*.jpeg)|*.jpg;*.jpeg"), true },
+ { wxT("wxtiff"), wxT("tiff (wx)..."), wxT("Save this plot as tiff!"), wxT("tiff files (*.tif;*.tiff)|*.tif;*.tiff"), true },
+ { wxT("wxpnm"), wxT("pnm (wx)..."), wxT("Save this plot as pnm!"), wxT("pnm files (*.pnm)|*.pnm"), true },
+ { wxT("pngcairo"), wxT("png (cairo)..."), wxT("Save this plot as png using cairo!"), wxT("png files (*.png)|*.png"), true },
+ { wxT("pdfcairo"), wxT("pdf (cairo)..."), wxT("Save this plot as pdf using cairo!"), wxT("pdf files (*.pdf)|*.pdf"), false },
+ { wxT("ps"), wxT("postscript..."), wxT("Save this plot as postscript!"), wxT("ps files (*.ps)|*.ps"), false },
+ { wxT("psc"), wxT("color postscript..."), wxT("Save this plot as color postscript!"), wxT("ps files (*.ps;*.psc)|*.ps;*.psc"), false },
+ { wxT("pscairo"), wxT("color postscript (cairo)..."), wxT("Save this plot as color postscript using cairo!"), wxT("ps files (*.ps;*.psc)|*.ps;*.psc"), false },
+ { wxT("svg"), wxT("svg..."), wxT("Save this plot as svg!"), wxT("svg files (*.svg)|*.svg"), false },
+ { wxT("svgcairo"), wxT("svg (cairo)..."), wxT("Save this plot as svg using cairo!"), wxT("svg files (*.svg)|*.svg"), false },
+ { wxT("xfig"), wxT("xfig..."), wxT("Save this plot as xfig!"), wxT("fig files (*.fig)|*.fig"), false }
};
@@ -98,7 +98,7 @@
EVT_CLOSE( wxPLplotFrame::OnClose )
END_EVENT_TABLE()
-/* event table the widget */
+/* event table for the plot widget */
BEGIN_EVENT_TABLE( wxPLplotWindow, wxWindow )
EVT_PAINT( wxPLplotWindow::OnPaint ) /* (re)draw the plot in window */
EVT_CHAR( wxPLplotWindow::OnChar )
@@ -109,6 +109,9 @@
EVT_MAXIMIZE( wxPLplotWindow::OnMaximize )
END_EVENT_TABLE()
+/* event table for the size dialog */
+BEGIN_EVENT_TABLE(wxGetSizeDialog,wxDialog)
+END_EVENT_TABLE()
/*----------------------------------------------------------------------*\
* bool wxPLplotApp::OnInit()
@@ -294,17 +297,35 @@
size_t index=event.GetId()-wxPL_Save;
if( (index>=0) && (index<sizeof(dev_entries)/sizeof(dev_entry)) ) {
- wxFileDialog dialog( this, wxT("Save plot as ")+dev_entries[index].dev_name, wxT(""), wxT(""),
- dev_entries[index].dev_file_app+wxT("|All Files (*.*)|*.*"),
+ int width=800;
+ int height=600;
+ bool proceed=false;
+
+ /* ask for geometry in pixels only for image devices */
+ if( dev_entries[index].pixelDevice ) {
+ wxGetSizeDialog sizeDialog( this, -1, wxT("Size of plot"), wxDefaultPosition, wxDefaultSize,
+ wxDEFAULT_DIALOG_STYLE|wxRESIZE_BORDER, width, height );
+ if( sizeDialog.ShowModal() == wxID_OK ) {
+ width=sizeDialog.getWidth();
+ height=sizeDialog.getHeight();
+ proceed=true;
+ }
+ } else
+ proceed=true;
+
+ if( proceed ) {
+ wxFileDialog dialog( this, wxT("Save plot as ")+dev_entries[index].dev_name, wxT(""), wxT(""),
+ dev_entries[index].dev_file_app+wxT("|All Files (*.*)|*.*"),
#if (wxMAJOR_VERSION<=2) & (wxMINOR_VERSION<=6)
- wxSAVE | wxOVERWRITE_PROMPT );
+ wxSAVE | wxOVERWRITE_PROMPT );
#else
- wxFD_SAVE | wxFD_OVERWRITE_PROMPT );
+ wxFD_SAVE | wxFD_OVERWRITE_PROMPT );
#endif
- if (dialog.ShowModal() == wxID_OK) {
- const wxCharBuffer buf1=dialog.GetPath().mb_str();
- const wxCharBuffer buf2=dev_entries[index].dev_name.mb_str();
- SavePlot( (const char*)buf1, (const char*)buf2, 800, 600 );
+ if (dialog.ShowModal() == wxID_OK) {
+ const wxCharBuffer buf1=dialog.GetPath().mb_str();
+ const wxCharBuffer buf2=dev_entries[index].dev_name.mb_str();
+ SavePlot( (const char*)buf1, (const char*)buf2, width, height );
+ }
}
}
}
@@ -804,4 +825,46 @@
Refresh();
}
+/*----------------------------------------------------------------------
+ * wxGetSizeDialog::wxGetSizeDialog( wxWindow *parent, ... )
+ *
+ * Constructor of GetSizeDialog.
+ *----------------------------------------------------------------------*/
+wxGetSizeDialog::wxGetSizeDialog( wxWindow *parent, wxWindowID id, const wxString &title,
+ const wxPoint &position, const wxSize& size, long style, int width, int height ) :
+ wxDialog( parent, id, title, position, size, style )
+{
+ wxBoxSizer *sizer = new wxBoxSizer( wxVERTICAL );
+
+ wxStaticBoxSizer *staticSizer = new wxStaticBoxSizer( new wxStaticBox(this, -1, wxT("Size of plot")), wxVERTICAL );
+
+ wxFlexGridSizer *flexSizer = new wxFlexGridSizer( 2, 0, 0 );
+ flexSizer->AddGrowableCol( 1 );
+
+ wxStaticText *textWidth = new wxStaticText( this, -1, wxT("Width [pixels]:"), wxDefaultPosition, wxDefaultSize, 0 );
+ flexSizer->Add( textWidth, 0, wxALIGN_RIGHT|wxALIGN_CENTER_VERTICAL|wxALL, 5 );
+ spinControlWidth = new wxSpinCtrl( this, -1, wxString::Format(wxT("%d"), width), wxDefaultPosition, wxSize(100,-1), wxSP_ARROW_KEYS, 10, 4096, width );
+ flexSizer->Add( spinControlWidth, 0, wxGROW|wxALIGN_CENTER_VERTICAL|wxALL, 5 );
+ wxStaticText *textHeight = new wxStaticText( this, -1, wxT("Height [pixels]:"), wxDefaultPosition, wxDefaultSize, wxALIGN_RIGHT );
+ flexSizer->Add( textHeight, 0, wxALIGN_RIGHT|wxALIGN_CENTER_VERTICAL|wxALL, 5 );
+ spinControlHeight = new wxSpinCtrl( this, -1, wxString::Format(wxT("%d"), height), wxDefaultPosition, wxSize(100,-1), wxSP_ARROW_KEYS, 10, 4096, height );
+ flexSizer->Add( spinControlHeight, 0, wxGROW|wxALIGN_CENTER_VERTICAL|wxALL, 5 );
+
+ staticSizer->Add( flexSizer, 0, wxGROW|wxALIGN_CENTER_VERTICAL|wxALL, 5 );
+
+ sizer->Add( staticSizer, 0, wxGROW|wxALIGN_CENTER_VERTICAL|wxALL, 5 );
+
+ wxBoxSizer *buttonSizer = new wxBoxSizer( wxHORIZONTAL );
+ wxButton *buttonOK = new wxButton( this, wxID_OK, wxT("OK"), wxDefaultPosition, wxDefaultSize, 0 );
+ buttonSizer->Add( buttonOK, 0, wxALIGN_CENTER|wxALL|wxEXPAND, 5 );
+ buttonSizer->Add( 20, 20, 1, wxALIGN_CENTER|wxALL, 5 );
+ wxButton *buttonCancel = new wxButton( this, wxID_CANCEL, wxT("Cancel"), wxDefaultPosition, wxDefaultSize, 0 );
+ buttonSizer->Add( buttonCancel, 0, wxALIGN_CENTER|wxALL|wxEXPAND, 5 );
+
+ sizer->Add( buttonSizer, 0, wxGROW|wxALIGN_CENTER_VERTICAL|wxLEFT|wxRIGHT, 15 );
+
+ this->SetSizer( sizer );
+ sizer->SetSizeHints( this );
+}
+
#endif /* PLD_wxwidgets */
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|