The book widget is a widget that can be used to display a series of images as the pages of a flippable book. This example demonstrates how to use the BookWidget that is part of Cornerstone SDK.
In principle the usage of the widget is very simple: just instruct the widget to load a directory that contains a set of images. Here we show step-by-step how to do this.
We begin by parsing the command line arguments:
The code defines an Attribute dirname and adds it to a dummy Node object opts. The attribute is used to store the value of a command line argument named "dir" (ie. –dir path/to/some/dir) to the variable. By calling parse the command line parser scans the list of command line arguments and automatically fills the attributes of the given node with corresponding values.
Alternatively we could have created dirname later and given app as a host object for the AttributeString. Application init-function runs CmdParser automatically for all attributes added to the application. The downside of this approach is that the arguments are parsed only when init returns.
Next we check that the application was started with the correct (and non-empty) command line parameter, printing an error and exiting if not:
At this point we initialize the application in the exact same way as in other examples:
Next we actually create the book widget, set its size and location and then tell the widget to load the directory that was passed in as a command line argument:
This is all that is needed to get a working book widget. To showcase some of the API of the book widget we still create two buttons that can be used to open the first and last pages of the widget:
Lastly, we still need to run the application of course:
The full source code for the complete example is listed below: