Documentation screenshot generator source code cleanup.

git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@72869 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
Bryan Petty
2012-11-03 18:08:54 +00:00
parent 78226dacc2
commit 6d6de9f10f
2 changed files with 134 additions and 113 deletions

View File

@@ -21,11 +21,11 @@ class wxWindow;
class wxNotebook; class wxNotebook;
/** /**
GlobalAdjustFlags works with AutoCaptureMechanism's constructor, to disbale/enable GlobalAdjustFlags works with AutoCaptureMechanism's constructor, to
some auto-adjustment for all controls. configure auto-adjustments of all controls.
They are used to make AutoCaptureMechanism more configurable and provide a fallback They are used to make AutoCaptureMechanism more configurable and provide a
to detect the bugs that the adjustments intended to avoid. fallback to detect the bugs that the adjustments intended to avoid.
@see AdjustFlags @see AdjustFlags
*/ */
@@ -45,8 +45,8 @@ enum GlobalAdjustFlags
/** /**
Enable region adjustment for all controls. Enable region adjustment for all controls.
If AJ_DisableRegionAdjust and AJ_AlwaysRegionAdjust are both specified, current If AJ_DisableRegionAdjust and AJ_AlwaysRegionAdjust are both specified,
implemetation will ignore AJ_DisableRegionAdjust. current implemetation will ignore AJ_DisableRegionAdjust.
*/ */
AJ_AlwaysRegionAdjust = 1 << 1, AJ_AlwaysRegionAdjust = 1 << 1,
@@ -56,15 +56,16 @@ enum GlobalAdjustFlags
AJ_DisableNameAdjust = 1 << 2, AJ_DisableNameAdjust = 1 << 2,
/** /**
For all the "Drop-down Controls", e.g. wxChoice, do not prompt the user about whether For all the "Drop-down Controls", e.g. wxChoice, do not prompt the user
to capture their drop-down state, and always capture only its non-drop-down state. about whether to capture their drop-down state, and always capture only
its non-drop-down state.
*/ */
AJ_DisableDropdown = 1 << 3 AJ_DisableDropdown = 1 << 3
}; };
/** /**
AdjustFlags works with AutoCaptureMechanism::RegisterControl() to specify how to AdjustFlags works with AutoCaptureMechanism::RegisterControl() to specify
adjust the screenshot of the current control. how to adjust the screenshot of the current control.
They are used to avoid bugs, look better or interact with user etc. They are used to avoid bugs, look better or interact with user etc.
@@ -80,40 +81,45 @@ enum AdjustFlags
/** /**
Perform region adjustment for this control. Perform region adjustment for this control.
On some platforms and for some controls, wxWindow::GetScreenRect() will return On some platforms and for some controls, wxWindow::GetScreenRect() will
a smaller or deflected region. In these cases, the screenshots we get are incomplete. return a smaller or deflected region. In these cases, the screenshots
It's recommended for everyone to fix the controls' code, yet this flag provides a we get are incomplete. It's recommended for everyone to fix the
workaround to get a guaranteed correct region without using wxWindow::GetScreenRect(). controls' code, yet this flag provides a workaround to get a guaranteed
correct region without using wxWindow::GetScreenRect().
This workaround("label trick") is inspired by (or say stolen from) Auria's work. This workaround ("label trick") is inspired by (or say stolen from)
Auria's work.
*/ */
AJ_RegionAdjust = 1 << 0, AJ_RegionAdjust = 1 << 0,
/** /**
This flag provides a way to capture the drop-down state of "Drop-down Controls", This flag provides a way to capture the drop-down state of "Drop-down
e.g. wxChoice. Controls", e.g. wxChoice.
For all the "Drop-down Controls", prompt the user about whether to capture their For all the "Drop-down Controls", prompt the user about whether to
drop-down state, if the user chooses YES, he should drop down the control in about capture their drop-down state, if the user chooses YES, he should drop
3 seconds and wait util it's captured in that state. down the control in about 3 seconds and wait util it's captured in that
state.
*/ */
AJ_Dropdown = 1 << 1, AJ_Dropdown = 1 << 1,
/** /**
This flag is used internally by RegisterPageTurn(). Don't use it directly unless you This flag is used internally by RegisterPageTurn(). Don't use it
know what you are doing. directly unless you know what you are doing.
*/ */
AJ_TurnPage = 1 << 2, AJ_TurnPage = 1 << 2,
/** /**
This flag provides a functionality to union screenshots of different modes/states of This flag provides a functionality to union screenshots of different
a control into one image. e.g. the single-line/multi-line modes of a wxTextCtrl. modes/states of a control into one image. e.g. the single-line /
multi-line modes of a wxTextCtrl.
For a series of controls to be unioned, you should specify AJ_Union for the first, For a series of controls to be unioned, you should specify AJ_Union for
and AJ_UnionEnd for the last. For the controls between them, you can either specify the first, and AJ_UnionEnd for the last. For the controls between them,
AJ_Union or not. you can either specify AJ_Union or not.
The filename of the generated screenshot is the name of the first control in the series. The filename of the generated screenshot is the name of the first
control in the series.
*/ */
AJ_Union = 1 << 3, AJ_Union = 1 << 3,
@@ -126,76 +132,85 @@ enum AdjustFlags
/** /**
@class AutoCaptureMechanism @class AutoCaptureMechanism
AutoCaptureMechanism provides an easy-to-use and adjustable facility to take the screenshots AutoCaptureMechanism provides an easy-to-use and adjustable facility to
for all controls fully automaticly and correctly. It also provides an advanced feature to take the screenshots for all controls fully automaticly and correctly. It
union screenshots of different states/modes of a control. also provides an advanced feature to union screenshots of different
states/modes of a control.
@section tag_filename_convention Screenshot File Name Convention @section tag_filename_convention Screenshot File Name Convention
All screenshots are generated as PNG files. For a control named wxName, its screenshot file All screenshots are generated as PNG files. For a control named wxName, its
name would be "name.png", e.g. "button.png" for wxButton. This is the protocol with the screenshot file name would be "name.png", e.g. "button.png" for wxButton.
doxygen document of wxWidgets. This is the protocol with the doxygen document of wxWidgets.
By default, screenshots are generated under the subdirectory "screenshots" of current working By default, screenshots are generated under the subdirectory "screenshots"
directory. During updating or adding new screenshots, first make sure screenshots are generated of current working directory. During updating or adding new screenshots,
correctly, and then copy them to the following subdirectory of docs/doxygen/images: first make sure screenshots are generated correctly, and then copy them to
the following subdirectory of docs/doxygen/images:
"wxmsw" for MS Windows, "wxgtk" for Linux and "wxmac" for Mac OS. "wxmsw" for MS Windows, "wxgtk" for Linux and "wxmac" for Mac OS.
@section tag_gui_assumption The Assumption of GUI @section tag_gui_assumption The Assumption of GUI
Unfortunately, this class have an assumption about the structure of GUI: Unfortunately, this class have an assumption about the structure of GUI: It
It must have the follwoing top-down structure: must have the follwoing top-down structure:
wxNotebook->wxPanel->wxSizer->wxControl wxNotebook->wxPanel->wxSizer->wxControl
That means, in the wxNotebook associated with this class, controls that needs to be That means, in the wxNotebook associated with this class, controls that
taken screenshots are placed on different panels(for grouping) and layed out by wxSizers. needs to be taken screenshots are placed on different panels(for grouping)
and layed out by wxSizers.
@section tag_tutorial Tutorial @section tag_tutorial Tutorial
In the contruction, you should associate a wxNotebook with this class, in that wxNotebook, In the contruction, you should associate a wxNotebook with this class, in
controls that needs to be captured are placed on different panels(for grouping). that wxNotebook, controls that needs to be captured are placed on different
panels(for grouping).
When you register controls, you should do it in order: Register the controls on the first When you register controls, you should do it in order: Register the
panel(using RegisterControl()), and then register a page turn(using RegisterPageTurn()), controls on the first panel(using RegisterControl()), and then register a
so this class can turn a page of the wxNotebook to present the second page. And then page turn(using RegisterPageTurn()), so this class can turn a page of the
you register the controls on the second panel, then a page turn, and so on. wxNotebook to present the second page. And then you register the controls
on the second panel, then a page turn, and so on.
When you are done, simply call CaptureAll(), then screenshots of all controls will be When you are done, simply call CaptureAll(), then screenshots of all
automaticly generated. controls will be automaticly generated.
@section tag_autoadjust Make Use of Auto Adjustments @section tag_autoadjust Make Use of Auto Adjustments
First take a look at the document of RegisterControl(), enum AdjustFlags and First take a look at the document of RegisterControl(), enum AdjustFlags
GlobalAdjustFlags. and GlobalAdjustFlags.
And then, ScreenshotFrame::OnCaptureAllControls() is a good example of making use of And then, ScreenshotFrame::OnCaptureAllControls() is a good example of
auto adjustment. Taking a look at it will get you started. making use of auto adjustment. Taking a look at it will get you started.
@section tag_developer_note Notes for Developers @section tag_developer_note Notes for Developers
@subsection tag_cnc CaptureAll() and Capture() @subsection tag_cnc CaptureAll() and Capture()
The implementation of Auto Adjustments is in CaptureAll() and Capture(), the code is The implementation of Auto Adjustments is in CaptureAll() and Capture(),
short, quite readable and well commented, please read the codes before any modification. the code is short, quite readable and well commented, please read the codes
before any modification.
If you need the class to do something sepcial for you, consider introducing a new flag If you need the class to do something sepcial for you, consider introducing
and implement it in them. For an operation performed on multiple controls, implemente a new flag and implement it in them. For an operation performed on multiple
its logic in CaptureAll(), otherwise in the private member Capture(). controls, implemente its logic in CaptureAll(), otherwise in the private
member Capture().
@subsection tag_yield_issue wxYield Issues @subsection tag_yield_issue wxYield Issues
Not quite a good habit, but this class made a lot of use of wxYield()/wxYieldIfNeeded(). Not quite a good habit, but this class made a lot of use of wxYield() /
They are used to ensure the update of GUI(e.g. the page turn of wxNotebook) is done wxYieldIfNeeded(). They are used to ensure the update of GUI (e.g. the
before any further screenshot-taking, or to do the timing(in Delay()). Without their use, page turn of wxNotebook) is done before any further screenshot-taking, or
there would be subtle bugs. to do the timing(in Delay()). Without their use, there would be subtle
bugs.
I've read documents about wxYield() and understand the down side of it before using it. I've read documents about wxYield() and understand the down side of it
But I didn't find a better approach to do those things, and I used them carefully. So before using it. But I didn't find a better approach to do those things,
please DO NOT remove any of these wxYield()s unless you're sure that it won't cause problems and I used them carefully. So please DO NOT remove any of these wxYield()s
on all of MS Windows XP/Vista, Linux(Ubuntu/Fedora), Mac OS Tiger/Leopard. And please unless you're sure that it won't cause problems on all of MS Windows
help me to find a better approach, thank you :) XP/Vista, Linux(Ubuntu/Fedora), Mac OS Tiger/Leopard. And please help me
to find a better approach, thank you :)
*/ */
class AutoCaptureMechanism class AutoCaptureMechanism
{ {
@@ -204,15 +219,13 @@ public:
Constructor. Constructor.
@param notebook @param notebook
The wxNotebook associated with this class.Please see @ref tag_gui_assumption The wxNotebook associated with this class. Please see
and @ref tag_tutorial. @ref tag_gui_assumption and @ref tag_tutorial.
@param flag @param flag
It's one of or a combination of GlobalAdjustFlags, to disbale/enable some auto-adjustment It's one of or a combination of GlobalAdjustFlags, to disable /
for all controls. enable some auto-adjustment for all controls.
@param margin @param margin
It's the margin around every control in the sreenshots. It's the margin around every control in the sreenshots.
*/ */
AutoCaptureMechanism(wxNotebook *notebook, AutoCaptureMechanism(wxNotebook *notebook,
int flag = AJ_NormalAll, int flag = AJ_NormalAll,
@@ -224,25 +237,27 @@ public:
Register a control and perform specifid auto adjustments. Register a control and perform specifid auto adjustments.
@param ctrl @param ctrl
The pointer to the control to be taken a screenshot. The pointer to the control to be taken a screenshot.
@param name @param name
If you find out that the screenshot for this control was generated under an incorrect If you find out that the screenshot for this control was generated
file name, specify @a name. e.g. for wxButton, "wxButton" or "button" are both OK. under an incorrect file name, specify @a name. e.g. for wxButton,
"wxButton" or "button" are both OK.
@param flag @param flag
If you end up with an a smaller or deflected screenshot, use
AJ_RegionAdjust.
If you end up with an a smaller or deflected screenshot, use AJ_RegionAdjust. If you want to caputure the "drop-down" state of a "drop-down"
control, use AJ_Dropdown.
If you want to caputure the "drop-down" state of a "drop-down" control, use AJ_Dropdown. If you want to present different states of a control in one
screenshot, use AJ_Union and AJ_UnionEnd.
If you want to present different states of a control in one screenshot, use AJ_Union Please read the document of enum AdjustFlags, and notice that this
and AJ_UnionEnd. flag could be enabled / disabled by global flag GlobalAdjustFlags.
Please read the document of enum AdjustFlags, and notice that this flag could be enabled/
disabled by global flag GlobalAdjustFlags.
*/ */
void RegisterControl(wxWindow * ctrl, wxString name = wxT(""), int flag = AJ_Normal) void RegisterControl(wxWindow* ctrl,
wxString name = wxT(""),
int flag = AJ_Normal)
{ {
m_controlList.push_back(Control(ctrl, name, flag)); m_controlList.push_back(Control(ctrl, name, flag));
} }
@@ -250,11 +265,11 @@ public:
/** /**
Register a control and perform specifid auto adjustments. Register a control and perform specifid auto adjustments.
This is the same as RegisterControl(wxWindow * ctrl, wxString name, int flag), This calls RegisterControl(wxWindow* ctrl, wxString name, int flag)
But with it, you won't have to specify the name if you only want to auto-adjust something with an empty name. This is useful when you only want to auto-adjust
other than name adjustment. something other than name adjustment.
*/ */
void RegisterControl(wxWindow * ctrl, int flag) void RegisterControl(wxWindow* ctrl, int flag)
{ {
RegisterControl(ctrl, wxT(""), flag); RegisterControl(ctrl, wxT(""), flag);
} }
@@ -262,8 +277,8 @@ public:
/** /**
Register a page turn. Register a page turn.
When you finished registering the controls on a panel, remember to call it to turn the When you finished registering the controls on a panel, remember to
wxNotebook to the next panel. call it to turn the wxNotebook to the next panel.
*/ */
void RegisterPageTurn() void RegisterPageTurn()
{ {
@@ -296,10 +311,13 @@ public:
@see Capture(wxBitmap*,wxRect,int) @see Capture(wxBitmap*,wxRect,int)
*/ */
static bool Capture(wxBitmap* bitmap, int x, int y, int width, int height, int delay = 0); static bool Capture(wxBitmap* bitmap,
int x, int y, int width, int height,
int delay = 0);
/** /**
Save the screenshot as the name of @a fileName in the default directory. Save the screenshot as the name of @a fileName in the default
directory.
@a fileName should be without ".png". @a fileName should be without ".png".
*/ */
@@ -316,7 +334,8 @@ public:
static wxString GetDefaultDirectory() { return default_dir; } static wxString GetDefaultDirectory() { return default_dir; }
/** /**
Get the absolute path of the default directory where the screenshots will be generated. Get the absolute path of the default directory where the screenshots
will be generated.
*/ */
static wxString GetDefaultDirectoryAbsPath(); static wxString GetDefaultDirectoryAbsPath();
@@ -344,8 +363,8 @@ private:
/* /*
Internal Functions Internal Functions
They are only used to clearify the logic of some public functions and it's nonsense They are only used to clearify the logic of some public functions and
to call them elsewhere. it's nonsense to call them elsewhere.
*/ */
/* /*
@@ -357,12 +376,12 @@ private:
Get the correct rectangular region that the control occupies. Used by Get the correct rectangular region that the control occupies. Used by
Capture(Control & ctrl). Capture(Control & ctrl).
If AJ_RegionAdjust is specified, it will use the "label trick" to perform If AJ_RegionAdjust is specified, it will use the "label trick" to
region auto adjustment. perform region auto adjustment.
The "label trick" is to reattach the control to a wxFlexGridSizer m_grid, The "label trick" is to reattach the control to a wxFlexGridSizer
surround the control with labels and get the control's region by label's positions. m_grid, surround the control with labels and get the control's region
Just like this: by label's positions. Just like this:
+---------+-----------+---------+ +---------+-----------+---------+
| 0 | label | 1 | | 0 | label | 1 |
@@ -372,10 +391,12 @@ private:
| 2 | label | 3 | | 2 | label | 3 |
+---------+-----------+---------+ +---------+-----------+---------+
So, there will be a side effect: the control is moved to a new position. So after taking the So, there will be a side effect: the control is moved to a new
screenshot, Capture(Control & ctrl) should call PutBack(wxWindow * ctrl) to put it back. position. So after taking the screenshot, Capture(Control & ctrl)
should call PutBack(wxWindow * ctrl) to put it back.
If AJ_RegionAdjust isn't specified, it will simply call wxWindow::GetScreenRect(). If AJ_RegionAdjust isn't specified, it will simply call
wxWindow::GetScreenRect().
*/ */
wxRect GetRect(wxWindow* ctrl, int flag); wxRect GetRect(wxWindow* ctrl, int flag);
@@ -386,8 +407,8 @@ private:
void PutBack(wxWindow * ctrl); void PutBack(wxWindow * ctrl);
/* /*
Union two screenshots in the vertical direction, and leave a gap between the Union two screenshots in the vertical direction, and leave a gap
screenshots. Used by CaptureAll(). between the screenshots. Used by CaptureAll().
The gap is 20 pixels by default. Currently it isn't configurable. The gap is 20 pixels by default. Currently it isn't configurable.
*/ */
@@ -415,5 +436,3 @@ private:
}; };
#endif // _AUTOCAPTURE_H_ #endif // _AUTOCAPTURE_H_

View File

@@ -99,9 +99,11 @@ void ScreenshotFrame::OnCaptureAllControls(wxCommandEvent& WXUNUSED(event))
// check if there are other screenshots taken before // check if there are other screenshots taken before
if (wxFileName::DirExists(dir)) if (wxFileName::DirExists(dir))
{ {
int choice = wxMessageBox(_("It seems that you have already generated some screenshots.\n\nClick YES to delete them all (recommended) or NO to preserve them.\nClick CANCEL to cancel this auto-capture operation."), int choice = wxMessageBox(
_("Delete existing screenshots?"), _("It seems that you have already generated some screenshots.\n\nClick YES to delete them all (recommended) or NO to preserve them.\nClick CANCEL to cancel this auto-capture operation."),
wxYES_NO|wxCANCEL|wxICON_QUESTION, this); _("Delete existing screenshots?"),
wxYES_NO | wxCANCEL | wxICON_QUESTION, this);
switch(choice) switch(choice)
{ {
case wxYES: case wxYES: