creativity
v1.3.0
Agent-based model of creativity and piracy
|
Class that runs a GUI in a thread, collecting its events into a queue to be processed periodically (e.g. More...
#include <creativity/gui/GUI.hpp>
Classes | |
class | Event |
Simple class containing event information. More... | |
struct | Parameter |
The parameter struct for passing a configured value back from the GUI. More... | |
Public Types | |
enum | ParamType { ParamType::save_as, ParamType::load, ParamType::seed, ParamType::threads } |
Parameter types for a Parameter. More... | |
Public Member Functions | |
GUI (Creativity &creativity, std::function< void(Parameter param)> configure, std::function< void()> initialize, std::function< void(eris::eris_time_t end)> change_periods, std::function< void()> run, std::function< void()> stop, std::function< void()> step, std::function< void()> quit) | |
Creates a new GUI object. More... | |
void | start (const cmdargs::GUI &args) |
Starts the GUI, reading the glade file and starting the GUI thread. | |
void | checkEvents () |
Checks whether the GUI has generated any events and, if so, processes them. More... | |
void | waitEvents () |
If the GUI has queued events, processes them. More... | |
void | newStates (eris::eris_time_t switch_to=(eris::eris_time_t) -1) |
Signals the GUI thread that one or more states have been completed. More... | |
void | initialized () |
Sends a signal to the GUI thread that the simulation setup is complete. More... | |
void | running () |
Sends a signal to the GUI thread that the simulation has started or resumed running. More... | |
void | progress (eris::eris_time_t t, eris::eris_time_t end, double speed) |
Signals the GUI thread of a progress update. More... | |
void | stopped (bool more) |
Sends a signal to the GUI thread that the simulation has stopped running. More... | |
void | error (std::string message) |
Sends a signal to the GUI thread that an error has occurred. More... | |
void | waitForEvent (Event::Type t) |
Processes events sent by the GUI until at least one event of the given type has been received. | |
Static Public Member Functions | |
static std::string | pos_to_string (const eris::Position &pos) |
Utility method used by various GUI classes to convert a Position to a user-displayable string. | |
Friends | |
class | GraphArea |
Class that runs a GUI in a thread, collecting its events into a queue to be processed periodically (e.g.
between iterations) via GUIShim.
|
strong |
creativity::gui::GUI::GUI | ( | Creativity & | creativity, |
std::function< void(Parameter param)> | configure, | ||
std::function< void()> | initialize, | ||
std::function< void(eris::eris_time_t end)> | change_periods, | ||
std::function< void()> | run, | ||
std::function< void()> | stop, | ||
std::function< void()> | step, | ||
std::function< void()> | quit | ||
) |
Creates a new GUI object.
The GUI is not set up and started until the start() method is called.
creativity | The Creativity object containing the simulation storage. The object does not need to be initialized (by calling setup()): in particular, if the GUI is displaying a previously stored simulation run, it typically won't be. |
Note that the creativity object must persist as long as the created GUI object.
configure | A function to call with GUI simulation parameters when the user configures the simulation via the GUI. Note that this doesn't include simulation settings (like the number of readers)–those are set directly in the settings object. |
If the simulation cannot be started (for example, because some parameters are invalid) the function should throw an exception derived from std::exception; the .what() value of the exception will be displayed to the user as an error message.
initialize | A function to call to initialize the simulation without starting it. If something goes wrong, this should throw an exception derived from std::exception: the .what() value of the exception will be displayed to the user as an error message. |
change_periods | A function called to specify the number of simulation periods, and called again whenever the user changes the number of simulation periods. |
run | Called to run or continue running the simulation until the number of periods sent by the last change_periods call have been completed. initialize will be called before the first call to this, and change_periods will have been called one or more times. |
stop | Called when the user hits the stop button in the GUI. This should pause the current simulation run loop until run or step are called. |
step | Called when the user wishes to step forward one period then stop. |
quit | Called when the user quits the GUI. |
void creativity::gui::GUI::checkEvents | ( | ) |
Checks whether the GUI has generated any events and, if so, processes them.
If there are no pending events, this returns immediately.
void creativity::gui::GUI::error | ( | std::string | message | ) |
Sends a signal to the GUI thread that an error has occurred.
Takes a string to display in a dialog to the user.
void creativity::gui::GUI::initialized | ( | ) |
Sends a signal to the GUI thread that the simulation setup is complete.
The GUI will disable the various simulation setup options and start/initialize buttons and switch to the visualization tab. The states
variable given to the constructor must have been initialized with the initial simulation state: this method sends a new_states signal, to let the GUI thread know that there is a new state.
void creativity::gui::GUI::newStates | ( | eris::eris_time_t | switch_to = (eris::eris_time_t) -1 | ) |
Signals the GUI thread that one or more states have been completed.
The GUI will record the new number of states. If the user was viewing the most recent state, the GUI will be updated to display the new most recent state, otherwise the GUI remains on the current state.
The optional parameter allows the main thread to instruct the GUI to switch to the given state; if omitted, the GUI switches to the last state if the user was already there before the signal, and otherwise doesn't change the state.
void creativity::gui::GUI::progress | ( | eris::eris_time_t | t, |
eris::eris_time_t | end, | ||
double | speed | ||
) |
Signals the GUI thread of a progress update.
t | the current simulation state |
end | the simulation stage at which the current run will stop |
speed | the speed (in iterations per second) |
void creativity::gui::GUI::running | ( | ) |
Sends a signal to the GUI thread that the simulation has started or resumed running.
void creativity::gui::GUI::stopped | ( | bool | more | ) |
Sends a signal to the GUI thread that the simulation has stopped running.
more | is true if there are still more simulation periods to run (as specified in the Periods setting). |
void creativity::gui::GUI::waitEvents | ( | ) |
If the GUI has queued events, processes them.
If there are no queued events, this waits for an event to occur then processes it.