many fixes; now the application correctly starts up
git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@56112 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
@@ -84,6 +84,117 @@ wxBitmap Capture(wxRect rect)
|
||||
return Capture(origin.x, origin.y, rect.GetWidth(), rect.GetHeight());
|
||||
}
|
||||
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
// AutoCaptureMechanism
|
||||
// ----------------------------------------------------------------------------
|
||||
|
||||
wxBitmap AutoCaptureMechanism::Capture(Control & ctrl)
|
||||
{
|
||||
if(ctrl.name == wxT("")) //no mannual specification for the control name
|
||||
{
|
||||
//Get name from wxRTTI
|
||||
ctrl.name = ctrl.ctrl->GetClassInfo()->GetClassName();
|
||||
}
|
||||
|
||||
int choice = wxNO;
|
||||
|
||||
if(ctrl.flag & AJ_Dropdown)
|
||||
{
|
||||
wxString caption = _("Do you wish to capture the dropdown list of ") + ctrl.name + _("?");
|
||||
wxString notice = _("Click YES to capture it.\nAnd you MUST drop down the ") + ctrl.name + _(" in 3 seconds after close me.\n");
|
||||
notice += _("Click NO otherwise.");
|
||||
|
||||
choice = wxMessageBox(notice, caption, wxYES_NO, m_notebook);
|
||||
|
||||
if(choice == wxYES)
|
||||
{
|
||||
//Wait for 3 seconds
|
||||
using std::clock;
|
||||
using std::clock_t;
|
||||
|
||||
clock_t start = clock();
|
||||
while(clock() - start < CLOCKS_PER_SEC * 3)
|
||||
{
|
||||
wxYieldIfNeeded();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
wxRect rect = GetRect(ctrl.ctrl, ctrl.flag);
|
||||
|
||||
//Do some rect adjust so it can include the dropdown list
|
||||
//Currently it only works well under MSW, not adjusted for Linux and Mac OS
|
||||
if(ctrl.flag & AJ_Dropdown && choice == wxYES)
|
||||
{
|
||||
// #ifdef __WXMSW__
|
||||
int h = rect.GetHeight();
|
||||
rect.SetHeight(h * 4);
|
||||
// #endif
|
||||
}
|
||||
|
||||
//cut off "wx" and change them into lowercase.
|
||||
// e.g. wxButton will have a name of "button" at the end
|
||||
ctrl.name.StartsWith(_T("wx"), &(ctrl.name));
|
||||
ctrl.name.MakeLower();
|
||||
|
||||
wxBitmap screenshot = ::Capture(rect);
|
||||
|
||||
if(ctrl.flag & AJ_RegionAdjust)
|
||||
{
|
||||
PutBack(ctrl.ctrl);
|
||||
}
|
||||
|
||||
return screenshot;
|
||||
}
|
||||
|
||||
//if AJ_RegionAdjust is specified, the following line will use the label trick to adjust
|
||||
//the region position and size
|
||||
wxRect GetRect(wxWindow* ctrl, int flag);
|
||||
//put the control back after the label trick(Using reparent/resizer approach)
|
||||
void PutBack(wxWindow * ctrl);
|
||||
|
||||
wxBitmap AutoCaptureMechanism::Union(wxBitmap pic1, wxBitmap pic2)
|
||||
{
|
||||
int w1, w2, h1, h2, w, h;
|
||||
w1 = pic1.GetWidth();
|
||||
w2 = pic2.GetWidth();
|
||||
h1 = pic1.GetHeight();
|
||||
h2 = pic2.GetHeight();
|
||||
|
||||
const int gap_between = 20;
|
||||
|
||||
w = (w1 >= w2) ? w1 : w2;
|
||||
h = h1 + h2 + gap_between;
|
||||
|
||||
wxBitmap result(w, h, -1);
|
||||
|
||||
wxMemoryDC dstDC;
|
||||
dstDC.SelectObject(result);
|
||||
|
||||
dstDC.DrawBitmap(pic1, 0, 0, false);
|
||||
dstDC.DrawBitmap(pic2, 0, h1 + gap_between, false);
|
||||
|
||||
dstDC.SelectObject(wxNullBitmap);
|
||||
|
||||
wxMemoryDC maskDC;
|
||||
wxBitmap mask(w, h, 1);
|
||||
maskDC.SelectObject(mask);
|
||||
|
||||
maskDC.SetPen(*wxTRANSPARENT_PEN);
|
||||
maskDC.SetBrush(*wxBLACK_BRUSH);
|
||||
maskDC.DrawRectangle(0, 0, w + 1, h + 1);
|
||||
|
||||
maskDC.SetBrush(*wxWHITE_BRUSH);
|
||||
maskDC.DrawRectangle(0, 0, w1, h1);
|
||||
maskDC.DrawRectangle(0, h1 + gap_between, w2, h2);
|
||||
maskDC.SelectObject(wxNullBitmap);
|
||||
|
||||
result.SetMask(new wxMask(mask));
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
void AutoCaptureMechanism::Save(wxBitmap screenshot, wxString fileName)
|
||||
{
|
||||
//Check if m_defaultDir already existed
|
||||
|
Reference in New Issue
Block a user