added the automatic screenshot generator utility by Utensil Candel (with some revisions and reorganizations)
git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@56106 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
361
utils/screenshotgen/src/screenshot_main.cpp
Normal file
361
utils/screenshotgen/src/screenshot_main.cpp
Normal file
@@ -0,0 +1,361 @@
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
// Name: screenshot_main.cpp
|
||||
// Purpose: Implement the Application Frame
|
||||
// Author: Utensil Candel (UtensilCandel@@gmail.com)
|
||||
// RCS-ID: $Id$
|
||||
// Licence: wxWindows license
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
// For compilers that support precompilation, includes "wx/wx.h".
|
||||
#include "wx/wxprec.h"
|
||||
|
||||
#ifdef __BORLANDC__
|
||||
#pragma hdrstop
|
||||
#endif
|
||||
|
||||
// for all others, include the necessary headers
|
||||
#ifndef WX_PRECOMP
|
||||
#include <wx/filename.h>
|
||||
#include <wx/dcbuffer.h>
|
||||
#include <wx/colordlg.h>
|
||||
#include <wx/fontdlg.h>
|
||||
#include <wx/filedlg.h>
|
||||
#include <wx/dirdlg.h>
|
||||
#endif
|
||||
|
||||
#include <wx/dir.h>
|
||||
#include "screenshot_main.h"
|
||||
#include "ctrlmaskout.h"
|
||||
#include "autocapture.h"
|
||||
|
||||
|
||||
// Global helper functions
|
||||
enum wxBuildInfoFormat
|
||||
{
|
||||
short_f,
|
||||
long_f
|
||||
};
|
||||
|
||||
wxString wxbuildinfo(wxBuildInfoFormat format)
|
||||
{
|
||||
wxString wxbuild(wxVERSION_STRING);
|
||||
|
||||
if (format == long_f )
|
||||
{
|
||||
#if defined(__WXMSW__)
|
||||
wxbuild << _T("-Windows");
|
||||
#elif defined(__WXMAC__)
|
||||
wxbuild << _T("-Mac");
|
||||
#elif defined(__UNIX__)
|
||||
wxbuild << _T("-Linux");
|
||||
#endif
|
||||
|
||||
#if wxUSE_UNICODE
|
||||
wxbuild << _T("-Unicode build");
|
||||
#else
|
||||
wxbuild << _T("-ANSI build");
|
||||
#endif // wxUSE_UNICODE
|
||||
}
|
||||
|
||||
return wxbuild;
|
||||
}
|
||||
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
// wxScreenshotFrame
|
||||
// ----------------------------------------------------------------------------
|
||||
|
||||
wxScreenshotFrame::wxScreenshotFrame(wxFrame *frame)
|
||||
#if SCREENSHOTGEN_USE_AUI
|
||||
: AuiGUIFrame(frame)
|
||||
#else
|
||||
: GUIFrame(frame)
|
||||
#endif
|
||||
{
|
||||
#if wxUSE_STATUSBAR
|
||||
statusBar->SetStatusText(_("Hello wxWidgets user!"), 0);
|
||||
// statusBar->SetStatusText(wxbuildinfo(short_f), 1);
|
||||
#endif
|
||||
|
||||
// We will hold one during the whole life time of the main frame
|
||||
m_maskout = new wxCtrlMaskOut();
|
||||
|
||||
// At the begining, we are not specifying the rect region
|
||||
capturingRect = false;
|
||||
|
||||
// Do some further customization on some controls generated by wxFormBuilder
|
||||
InitFBControls();
|
||||
#if SCREENSHOTGEN_USE_AUI
|
||||
// Somehow it will be very small after I move to Aui
|
||||
SetSize(600, 600);
|
||||
// Maximize(true);
|
||||
#endif
|
||||
}
|
||||
|
||||
wxScreenshotFrame::~wxScreenshotFrame()
|
||||
{
|
||||
delete m_maskout;
|
||||
}
|
||||
|
||||
/*
|
||||
Do some further customization on some controls generated by wxFormBuilder.
|
||||
|
||||
Some controls can only be generated by wxFormBuilder without further
|
||||
customization, e.g. unable to load a richtext file in a wxRichtextCtrl
|
||||
during initialization.
|
||||
|
||||
Those customizations will be done here.
|
||||
*/
|
||||
void wxScreenshotFrame::InitFBControls()
|
||||
{
|
||||
// Do the default selection for wxComboBox
|
||||
m_comboBox1->Select(0);
|
||||
|
||||
// To look better under gtk
|
||||
#ifdef __WXGTK__
|
||||
m_comboBox1->Delete(4);
|
||||
#endif
|
||||
|
||||
// Add a root and some nodes for wxTreeCtrl
|
||||
wxTreeItemId root = m_treeCtrl1->AddRoot(_("wxTreeCtrl"));
|
||||
|
||||
m_treeCtrl1->AppendItem(root, _("Node1"));
|
||||
|
||||
wxTreeItemId node2 = m_treeCtrl1->AppendItem(root, _("Node2"));
|
||||
m_treeCtrl1->AppendItem(node2, _("Node3"));
|
||||
|
||||
m_treeCtrl1->ExpandAll();
|
||||
|
||||
// Add items into wxListCtrl
|
||||
for(long index = 0; index < 5; index++)
|
||||
m_listCtrl1->InsertItem( index, wxString::Format(_("Item\n(0,%d)"),index));
|
||||
|
||||
// Check the first item in wxCheckListBox
|
||||
m_checkList1->Check(0);
|
||||
|
||||
// Load richtext.xml into wxRichtextCtrl
|
||||
m_richText1->LoadFile(_T("richtext.xml"));
|
||||
m_richText1->ShowPosition(335);
|
||||
}
|
||||
|
||||
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
// wxScreenshotFrame - event handlers
|
||||
// ----------------------------------------------------------------------------
|
||||
|
||||
void wxScreenshotFrame::OnClose(wxCloseEvent& WXUNUSED(event))
|
||||
{
|
||||
Destroy();
|
||||
}
|
||||
|
||||
void wxScreenshotFrame::OnQuit(wxCommandEvent& WXUNUSED(event))
|
||||
{
|
||||
Destroy();
|
||||
}
|
||||
|
||||
void wxScreenshotFrame::OnSeeScreenshots(wxCommandEvent& WXUNUSED(event))
|
||||
{
|
||||
wxString defaultDir = m_maskout->GetDefaultDirectory();
|
||||
|
||||
// Check if defaultDir already existed
|
||||
if(!wxDirExists(defaultDir))
|
||||
wxMkdir(defaultDir);
|
||||
|
||||
// Use the native file browser to open defaultDir
|
||||
#if defined(__WXMSW__)
|
||||
wxExecute(_T("explorer ") + defaultDir);
|
||||
#elif defined(__UNIX__) // nautilus is the GNOME file browser but works also for KDE
|
||||
wxExecute(_T("nautilus ") + defaultDir);
|
||||
#elif defined(_WXMAC_)
|
||||
wxExecute(_T("open ") + defaultDir);
|
||||
#else
|
||||
wxMessageBox(_("Sorry, not Implemeted for this platform yet! Please open subdirectory \"")
|
||||
+ defaultDir
|
||||
+ _("\" manually.") );
|
||||
#endif
|
||||
}
|
||||
|
||||
void wxScreenshotFrame::OnAbout(wxCommandEvent& WXUNUSED(event))
|
||||
{
|
||||
wxString msg = wxbuildinfo(long_f);
|
||||
wxMessageBox(msg, _("Welcome to..."));
|
||||
}
|
||||
|
||||
void wxScreenshotFrame::OnCaptureFullScreen(wxCommandEvent& WXUNUSED(event))
|
||||
{
|
||||
// Create a DC for the whole screen area
|
||||
wxScreenDC dcScreen;
|
||||
|
||||
// Get the size of the screenDC
|
||||
wxCoord screenWidth, screenHeight;
|
||||
dcScreen.GetSize(&screenWidth, &screenHeight);
|
||||
|
||||
m_maskout->Capture(0, 0, screenWidth, screenHeight, _T("fullscreen"));
|
||||
}
|
||||
|
||||
void wxScreenshotFrame::OnCaptureRect(wxCommandEvent& WXUNUSED(event))
|
||||
{
|
||||
capturingRect = true;
|
||||
wxMenuBar * menubar = this->GetMenuBar();
|
||||
menubar->FindItem(idMenuCapRect)->Enable(false);
|
||||
menubar->FindItem(idMenuEndCapRect)->Enable(true);
|
||||
|
||||
wxWindow * thePage = m_notebook1->GetPage(m_notebook1->GetSelection());
|
||||
|
||||
thePage->Connect( wxEVT_LEFT_DOWN, wxMouseEventHandler( wxCtrlMaskOut::OnLeftButtonDown ), NULL, m_maskout);
|
||||
thePage->Connect( wxEVT_LEFT_UP, wxMouseEventHandler( wxCtrlMaskOut::OnLeftButtonUp ), NULL, m_maskout);
|
||||
thePage->Connect( wxEVT_MOTION, wxMouseEventHandler( wxCtrlMaskOut::OnMouseMoving ), NULL, m_maskout);
|
||||
}
|
||||
|
||||
void wxScreenshotFrame::OnEndCaptureRect(wxCommandEvent& WXUNUSED(event))
|
||||
{
|
||||
capturingRect = false;
|
||||
wxMenuBar * menubar = this->GetMenuBar();
|
||||
menubar->FindItem(idMenuCapRect)->Enable(true);
|
||||
menubar->FindItem(idMenuEndCapRect)->Enable(false);
|
||||
|
||||
wxWindow * thePage = m_notebook1->GetPage(m_notebook1->GetSelection());
|
||||
|
||||
thePage->Disconnect( wxEVT_LEFT_DOWN, wxMouseEventHandler( wxCtrlMaskOut::OnLeftButtonDown ), NULL, m_maskout);
|
||||
thePage->Disconnect( wxEVT_LEFT_UP, wxMouseEventHandler( wxCtrlMaskOut::OnLeftButtonUp ), NULL, m_maskout);
|
||||
thePage->Disconnect( wxEVT_MOTION, wxMouseEventHandler( wxCtrlMaskOut::OnMouseMoving ), NULL, m_maskout);
|
||||
}
|
||||
|
||||
void wxScreenshotFrame::OnNotebookPageChanging(
|
||||
#if SCREENSHOTGEN_USE_AUI
|
||||
wxAuiNotebookEvent& event
|
||||
#else
|
||||
wxNotebookEvent& event
|
||||
#endif
|
||||
)
|
||||
{
|
||||
if (!capturingRect)
|
||||
{
|
||||
event.Skip();
|
||||
return;
|
||||
}
|
||||
|
||||
wxWindow * thePage = m_notebook1->GetPage(event.GetOldSelection());
|
||||
|
||||
thePage->Disconnect( wxEVT_LEFT_DOWN, wxMouseEventHandler( wxCtrlMaskOut::OnLeftButtonDown ), NULL, m_maskout);
|
||||
thePage->Disconnect( wxEVT_LEFT_UP, wxMouseEventHandler( wxCtrlMaskOut::OnLeftButtonUp ), NULL, m_maskout);
|
||||
thePage->Disconnect( wxEVT_MOTION, wxMouseEventHandler( wxCtrlMaskOut::OnMouseMoving ), NULL, m_maskout);
|
||||
|
||||
event.Skip();
|
||||
}
|
||||
|
||||
void wxScreenshotFrame::OnNotebookPageChanged(
|
||||
#if SCREENSHOTGEN_USE_AUI
|
||||
wxAuiNotebookEvent& event
|
||||
#else
|
||||
wxNotebookEvent& event
|
||||
#endif
|
||||
)
|
||||
{
|
||||
if(!capturingRect)
|
||||
{
|
||||
event.Skip();
|
||||
return;
|
||||
}
|
||||
|
||||
wxWindow *thePage = m_notebook1->GetPage(event.GetSelection());
|
||||
|
||||
thePage->Connect( wxEVT_LEFT_DOWN, wxMouseEventHandler( wxCtrlMaskOut::OnLeftButtonDown ), NULL, m_maskout);
|
||||
thePage->Connect( wxEVT_LEFT_UP, wxMouseEventHandler( wxCtrlMaskOut::OnLeftButtonUp ), NULL, m_maskout);
|
||||
thePage->Connect( wxEVT_MOTION, wxMouseEventHandler( wxCtrlMaskOut::OnMouseMoving ), NULL, m_maskout);
|
||||
|
||||
event.Skip();
|
||||
}
|
||||
|
||||
void wxScreenshotFrame::OnCaptureAllControls(wxCommandEvent& WXUNUSED(event))
|
||||
{
|
||||
wxString dir = wxT("screenshots");
|
||||
|
||||
if (wxFileName::DirExists(dir))
|
||||
{
|
||||
int choice = wxMessageBox(_("It seems that you have already generated some screenshots.\nClick YES to delete them all(recommended), NO to preserve them\nCANCEL to cancel this auto-capture(so you can save them elsewhere)."),
|
||||
_("Do you want to delete the existing screenshots?"),
|
||||
wxYES_NO|wxCANCEL|wxICON_QUESTION, this);
|
||||
switch(choice)
|
||||
{
|
||||
case wxYES :
|
||||
{
|
||||
wxArrayString files;
|
||||
wxDir::GetAllFiles(dir, &files, wxT("*.png"), wxDIR_FILES);
|
||||
|
||||
int n = files.GetCount();
|
||||
for (int i = 0; i < n; ++i)
|
||||
wxRemoveFile(files[i]);
|
||||
}
|
||||
break;
|
||||
|
||||
case wxNO : break;
|
||||
case wxCANCEL : return;
|
||||
}
|
||||
}
|
||||
|
||||
this->Maximize();
|
||||
|
||||
AutoCaptureMechanism auto_cap(m_notebook1);
|
||||
|
||||
auto_cap.RegisterControl(m_button1);
|
||||
auto_cap.RegisterControl(m_staticText1);
|
||||
auto_cap.RegisterControl(m_checkBox1, AJ_Union);
|
||||
auto_cap.RegisterControl(m_checkBox2, AJ_UnionEnd);
|
||||
auto_cap.RegisterControl(m_radioBtn1, AJ_Union);
|
||||
auto_cap.RegisterControl(m_radioBtn2, AJ_UnionEnd);
|
||||
auto_cap.RegisterControl(m_bpButton1);
|
||||
auto_cap.RegisterControl(m_bitmap1);
|
||||
auto_cap.RegisterControl(m_gauge1, wxT("wxGauge"));
|
||||
auto_cap.RegisterControl(m_slider1);
|
||||
auto_cap.RegisterControl(m_toggleBtn1, AJ_Union);
|
||||
auto_cap.RegisterControl(m_toggleBtn2, AJ_UnionEnd);
|
||||
auto_cap.RegisterControl(m_hyperlink1);
|
||||
auto_cap.RegisterControl(m_spinCtrl1, AJ_RegionAdjust);
|
||||
auto_cap.RegisterControl(m_spinBtn1);
|
||||
auto_cap.RegisterControl(m_scrollBar1);
|
||||
|
||||
auto_cap.RegisterPageTurn();
|
||||
|
||||
auto_cap.RegisterControl(m_checkList1);
|
||||
auto_cap.RegisterControl(m_listBox1);
|
||||
auto_cap.RegisterControl(m_radioBox1);
|
||||
auto_cap.RegisterControl(m_staticBox1);
|
||||
auto_cap.RegisterControl(m_treeCtrl1);
|
||||
auto_cap.RegisterControl(m_listCtrl1, wxT("wxListCtrl"));
|
||||
|
||||
auto_cap.RegisterControl(m_animationCtrl1);
|
||||
auto_cap.RegisterControl(m_collPane1, wxT("wxCollapsiblePane"), AJ_Union);
|
||||
auto_cap.RegisterControl(m_collPane2, AJ_UnionEnd);
|
||||
|
||||
auto_cap.RegisterPageTurn();
|
||||
|
||||
auto_cap.RegisterControl(m_textCtrl1, AJ_Union);
|
||||
auto_cap.RegisterControl(m_textCtrl2, AJ_UnionEnd);
|
||||
auto_cap.RegisterControl(m_richText1);
|
||||
|
||||
auto_cap.RegisterPageTurn();
|
||||
|
||||
auto_cap.RegisterControl(m_colourPicker1, wxT("wxColourPickerCtrl"));
|
||||
auto_cap.RegisterControl(m_fontPicker1, wxT("wxFontPickerCtrl"));
|
||||
auto_cap.RegisterControl(m_filePicker1, wxT("wxFilePickerCtrl"), AJ_RegionAdjust);
|
||||
auto_cap.RegisterControl(m_calendar1, wxT("wxCalendarCtrl"), AJ_RegionAdjust);
|
||||
auto_cap.RegisterControl(m_datePicker1, wxT("wxDatePickerCtrl"));
|
||||
auto_cap.RegisterControl(m_genericDirCtrl1, wxT("wxGenericDirCtrl"));
|
||||
auto_cap.RegisterControl(m_dirPicker1, wxT("wxDirPickerCtrl"), AJ_RegionAdjust);
|
||||
|
||||
auto_cap.RegisterPageTurn();
|
||||
|
||||
auto_cap.RegisterControl(m_choice1, AJ_Dropdown);
|
||||
auto_cap.RegisterControl(m_comboBox1, AJ_Dropdown);
|
||||
auto_cap.RegisterControl(m_bmpComboBox1, AJ_Dropdown);
|
||||
auto_cap.RegisterControl(m_ownerDrawnComboBox1, AJ_Dropdown);
|
||||
auto_cap.RegisterControl(m_comboCtrl1, AJ_Dropdown|AJ_Union);
|
||||
auto_cap.RegisterControl(m_comboCtrl2, AJ_Dropdown|AJ_UnionEnd);
|
||||
|
||||
auto_cap.CaptureAll();
|
||||
|
||||
wxMessageBox(_("All screenshots are generated successfully.\nSelect \"File->See screenshots\" to see them."),
|
||||
_("Success"), wxOK, this);
|
||||
}
|
Reference in New Issue
Block a user