2 #include "creativity/cmdargs/GUI.hpp" 3 #include "creativity/gui/GraphArea.hpp" 4 #include <eris/noncopyable.hpp> 5 #include <eris/Position.hpp> 6 #include <eris/types.hpp> 7 #include <glibmm/refptr.h> 8 #include <sigc++/connection.h> 9 #include <gtkmm/widget.h> 10 #include <gtkmm/builder.h> 11 #include <boost/geometry/core/cs.hpp> 12 #include <boost/geometry/geometries/point.hpp> 13 #include <boost/geometry/index/rtree.hpp> 14 #include <unordered_map> 19 #include <type_traits> 24 #include <condition_variable> 27 namespace Gdk {
class Cursor; }
28 namespace Glib {
class Dispatcher; }
29 namespace Gtk {
class Application; }
30 namespace Gtk {
class FileFilter; }
31 namespace Gtk {
class ScrolledWindow; }
32 namespace Gtk {
class TreeView; }
33 namespace Gtk {
class Window; }
35 namespace creativity {
namespace state {
class State; } }
49 class GUI : eris::noncopyable {
73 std::function<
void(
Parameter param)> configure,
80 std::function<
void()> initialize,
84 std::function<
void(eris::eris_time_t end)> change_periods,
91 std::function<
void()> run,
95 std::function<
void()> stop,
98 std::function<
void()> step,
101 std::function<
void()> quit
130 void newStates(eris::eris_time_t switch_to = (eris::eris_time_t) -1);
147 void progress(eris::eris_time_t t, eris::eris_time_t end,
double speed);
154 void stopped(
bool more);
158 void error(std::string message);
183 std::chrono::milliseconds dur_ms;
241 static std::string pos_to_string(
const eris::Position &pos);
248 std::thread gui_thread_{};
253 Glib::RefPtr<Gtk::Application> app_;
258 Glib::RefPtr<Gtk::Builder> builder_;
261 std::shared_ptr<Gtk::Window> main_window_;
264 std::string main_window_title_;
267 bool thread_running_{
false};
270 bool piracy_tick_added_ =
false;
273 bool public_tick_added_ =
false;
276 std::unordered_map<std::string, double> default_override_;
281 std::unique_ptr<Glib::Dispatcher> dispatcher_;
291 std::condition_variable cv_;
296 void processEvents_(std::unique_lock<decltype(mutex_)> &lock);
321 Type type = Type::none;
328 std::vector<uint64_t> uls;
330 std::vector<double> doubles;
335 Signal(
Type type) : type(type) {}
337 Signal(
Type type,
const std::string &message) : type{type}, message{message} {}
339 Signal(
Type type,
bool b) : type{type},
boolean{b} {}
341 Signal(
Type type,
double d) : type{type}, doubles(1, d) {}
343 template<typename UIntT, typename = typename std::enable_if<std::is_integral<UIntT>::value and std::is_unsigned<UIntT>::value>::type>
344 Signal(
Type type, UIntT ul) : type{type}, uls(1, ul) {}
349 std::list<Signal> signal_queue_;
352 void queueSignal(Signal &&s);
355 std::list<Event> event_queue_;
360 template <
typename... Args>
361 void queueEvent(Args&&... args);
392 void thr_connect_vis_setting(
393 const std::string &field,
396 bool affects_rtree =
false,
397 const std::vector<std::string> &needs_all = {},
398 const std::vector<std::string> &needs_any = {});
415 void thr_connect_vis_enabled(
416 const std::string &field,
418 bool affects_rtree =
false,
419 const std::vector<std::string> &needs_all = {},
420 const std::vector<std::string> &needs_any = {});
433 void thr_connect_vis_colour(
434 const std::string &field,
436 const std::vector<std::string> &needs_all = {},
437 const std::vector<std::string> &needs_any = {});
443 void thr_connect_vis_deps(
445 const std::vector<std::string> &needs_all,
446 const std::vector<std::string> &needs_any);
451 void thr_update_parameters();
455 void thr_set_state(eris::eris_time_t t);
458 eris::eris_time_t state_curr_ = (eris::eris_time_t) -1;
464 eris::eris_time_t state_num_ = 0;
472 void thr_info_dialog(eris::eris_id_t member_id);
484 void initializeSim();
492 std::unique_ptr<GraphArea> graph_;
495 Gtk::ScrolledWindow *rdr_win_;
498 Gtk::ScrolledWindow *bk_win_;
503 typename std::enable_if<std::is_base_of<Gtk::Widget, T>::value, T*>::type
504 widget(
const std::string &widget_name) {
506 builder_->get_widget(widget_name, widget);
511 double sb(
const std::string &widget_name);
514 int sb_int(
const std::string &widget_name);
519 std::string save_, load_;
522 mutable Glib::RefPtr<Gtk::FileFilter> ff_;
525 decltype(ff_) fileFilter() const;
529 std::function<
void()> on_initialize_;
530 std::function<
void(
unsigned int count)> on_change_periods_;
531 std::function<
void()> on_run_;
532 std::function<
void()> on_stop_;
533 std::function<
void()> on_step_;
534 std::function<
void()> on_quit_;
537 void handleEvent(const
GUI::
Event &event);
542 using rt_point =
boost::geometry::model::point<
double, 2,
boost::geometry::cs::cartesian>;
543 using rt_val =
std::pair<rt_point,
eris::eris_id_t>;
544 using RTree =
boost::geometry::index::rtree<rt_val,
boost::geometry::index::rstar<16>>;
553 std::vector<rt_val> thr_nearest(const rt_point &point,
int n = 1);
558 void thr_reset_rtrees();
563 void thr_init_rtree(RTree &rt, const
std::shared_ptr<const state::State> &state) const;
565 std::function<
bool(GdkEventMotion* event)> motion_handler_;
566 sigc::connection motion_handler_conn_;
567 Glib::RefPtr<
Gdk::Cursor> hand_;
571 struct temporal_data {
572 Glib::RefPtr<ReaderStore> rdr_model;
573 std::unique_ptr<Gtk::TreeView> rdr_tree;
574 Glib::RefPtr<BookStore> bk_model;
575 std::unique_ptr<Gtk::TreeView> bk_tree;
576 std::unique_ptr<RTree> rtree;
580 std::list<std::pair<eris::eris_time_t, temporal_data>> temporal_cache_;
583 unsigned int temporal_cache_size_ = 10;
587 template <
typename... Args>
588 void GUI::queueEvent(Args&&... args) {
589 std::unique_lock<std::mutex> lock(mutex_);
590 event_queue_.push_back(
Event(std::forward<Args>(args)...));
Definition: BookStore.hpp:14
Primary namespace for all Creativity library code.
Definition: config.hpp:4
CmdArgs/Simulator subclass for graphical simulator command-line arguments.
Definition: GUI.hpp:11
Definition: BookInfoWindow.hpp:6
Parameter parameter
Will be set to a list of configured GUI::Parameters if this is a setup event.
Definition: GUI.hpp:215
Simple class containing event information.
Definition: GUI.hpp:190
Definition: Variable.hpp:389
Gtk drawing area upon which the simulation state visualization is drawn.
Definition: GraphArea.hpp:20
Gtk dialog for showing reader or book info.
Definition: InfoWindow.hpp:23
The parameter struct for passing a configured value back from the GUI.
Definition: GUI.hpp:172
Definition: Policy.hpp:125
ParamType
Parameter types for a Parameter.
Definition: GUI.hpp:161
Class that runs a GUI in a thread, collecting its events into a queue to be processed periodically (e...
Definition: GUI.hpp:49
ParamType param
The parameter type.
Definition: GUI.hpp:174
Cairo::RefPtr< Cairo::SolidPattern > Colour
Typedef of Colour to the appropriate ref-pointed Cairo class.
Definition: GraphArea.hpp:69
Central class for a creativity simulation; this class handles setting up the simulation according to ...
Definition: Creativity.hpp:22
Type
The types of events that the GUI thread can send to the main thread.
Definition: GUI.hpp:193
unsigned long ul
unsigned long integer value associated with the event.
Definition: GUI.hpp:220