patch by Utensil Candel to improve wxMac autocapture code
git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@56264 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
@@ -21,23 +21,45 @@
|
||||
#include <wx/filename.h>
|
||||
#include "autocapture.h"
|
||||
|
||||
#ifdef __WXMAC__
|
||||
#include <cstring>
|
||||
#endif
|
||||
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
// AutoCaptureMechanism
|
||||
// ----------------------------------------------------------------------------
|
||||
|
||||
/* static */
|
||||
wxBitmap AutoCaptureMechanism::Capture(int x, int y, int width, int height)
|
||||
void AutoCaptureMechanism::Delay(int seconds)
|
||||
{
|
||||
using std::clock;
|
||||
using std::clock_t;
|
||||
|
||||
// Wait for 3 seconds
|
||||
clock_t start = clock();
|
||||
while (clock() - start < CLOCKS_PER_SEC * seconds)
|
||||
wxYieldIfNeeded();
|
||||
}
|
||||
|
||||
/* static */
|
||||
wxBitmap AutoCaptureMechanism::Capture(int x, int y, int width, int height, int delay)
|
||||
{
|
||||
// Somehow wxScreenDC.Blit() doesn't work under Mac for now. Here is a trick.
|
||||
#ifdef __WXMAC__
|
||||
|
||||
// wxExecute(_T("screencapture -x ") + tempfile, wxEXEC_SYNC);
|
||||
|
||||
system("screencapture -x /tmp/wx_screen_capture.png");
|
||||
char captureCommand[80] =""; // a reasonable max size is 80
|
||||
|
||||
sprintf(captureCommand, "sleep %d;%s", delay, "screencapture -x /tmp/wx_screen_capture.png");
|
||||
|
||||
system(captureCommand);
|
||||
|
||||
wxBitmap fullscreen;
|
||||
|
||||
if(delay) Delay(delay);
|
||||
|
||||
do
|
||||
{
|
||||
fullscreen = wxBitmap(_T("/tmp/wx_screen_capture.png"), wxBITMAP_TYPE_PNG);
|
||||
@@ -46,6 +68,9 @@ wxBitmap AutoCaptureMechanism::Capture(int x, int y, int width, int height)
|
||||
|
||||
wxBitmap screenshot = fullscreen.GetSubBitmap(wxRect(x,y,width,height));
|
||||
|
||||
// to prevent loading the old screenshot next time
|
||||
system("rm /tmp/wx_screen_capture.png");
|
||||
|
||||
#else // Under other paltforms, take a real screenshot
|
||||
|
||||
// Create a DC for the whole screen area
|
||||
@@ -83,10 +108,10 @@ wxBitmap AutoCaptureMechanism::Capture(int x, int y, int width, int height)
|
||||
}
|
||||
|
||||
/* static */
|
||||
wxBitmap AutoCaptureMechanism::Capture(wxRect rect)
|
||||
wxBitmap AutoCaptureMechanism::Capture(wxRect rect, int delay)
|
||||
{
|
||||
wxPoint origin = rect.GetPosition();
|
||||
return Capture(origin.x, origin.y, rect.GetWidth(), rect.GetHeight());
|
||||
return Capture(origin.x, origin.y, rect.GetWidth(), rect.GetHeight(), delay);
|
||||
}
|
||||
|
||||
void AutoCaptureMechanism::CaptureAll()
|
||||
@@ -137,16 +162,10 @@ wxBitmap AutoCaptureMechanism::Capture(Control& ctrl)
|
||||
ctrl.name, ctrl.name);
|
||||
|
||||
choice = wxMessageBox(msg, caption, wxYES_NO, m_notebook);
|
||||
if (choice == wxYES)
|
||||
{
|
||||
using std::clock;
|
||||
using std::clock_t;
|
||||
|
||||
// Wait for 3 seconds
|
||||
clock_t start = clock();
|
||||
while (clock() - start < CLOCKS_PER_SEC * 3)
|
||||
wxYieldIfNeeded();
|
||||
}
|
||||
#ifndef __WXMAC__ //not __WXMAC__
|
||||
if (choice == wxYES) Delay(3);
|
||||
#endif
|
||||
}
|
||||
|
||||
wxRect rect = GetRect(ctrl.ctrl, ctrl.flag);
|
||||
|
@@ -65,11 +65,14 @@ public:
|
||||
void CaptureAll();
|
||||
|
||||
// take a screenshot only of the given rect
|
||||
static wxBitmap Capture(wxRect rect);
|
||||
static wxBitmap Capture(int x, int y, int width, int height);
|
||||
// delay is only useful for Mac, for fixing a delay bug
|
||||
static wxBitmap Capture(wxRect rect, int delay = 0);
|
||||
static wxBitmap Capture(int x, int y, int width, int height, int delay = 0);
|
||||
|
||||
static void Delay(int seconds);
|
||||
|
||||
|
||||
protected: // internal utils
|
||||
private: // internal utils
|
||||
struct Control
|
||||
{
|
||||
Control() {}
|
||||
@@ -95,7 +98,6 @@ protected: // internal utils
|
||||
|
||||
void Save(wxBitmap screenshot, wxString fileName);
|
||||
|
||||
private:
|
||||
typedef std::vector<Control> ControlList;
|
||||
ControlList m_controlList;
|
||||
|
||||
|
Reference in New Issue
Block a user