20 #ifndef EZGL_APPLICATION_HPP
21 #define EZGL_APPLICATION_HPP
23 #include "ezgl/canvas.hpp"
24 #include "ezgl/control.hpp"
25 #include "ezgl/callback.hpp"
26 #include "ezgl/graphics.hpp"
27 #include "ezgl/color.hpp"
44 const bool build_ui_from_file =
false;
46 const bool build_ui_from_file =
true;
157 settings(std::string m_resource, std::string w_identifier, std::string c_identifier, std::string a_identifier =
"ezgl.app",
194 color background_color = WHITE);
284 const char *label_text
306 const char* id_string,
309 std::vector<std::string> options);
332 const char* id_string,
338 std::vector<std::string> options);
553 std::string m_main_ui;
556 std::string m_window_id;
559 std::string m_canvas_id;
562 std::string m_application_id;
565 GtkApplication *m_application;
568 GtkBuilder *m_builder;
574 std::map<std::string, std::unique_ptr<canvas>> m_canvases;
584 static void startup(GtkApplication *gtk_app, gpointer user_data);
587 static void activate(GtkApplication *gtk_app, gpointer user_data);
The core application.
Definition: application.hpp:95
application(application const &)=delete
Copies are disabled.
void create_combo_box_text(const char *id_string, int left, int top, int width, int height, combo_box_callback_fn combo_box_fn, std::vector< std::string > options)
Create a combo box text object.
application(application &&)=default
Ownership of an application is transferrable.
void create_dialog_window(dialog_callback_fn cbk_fn, const char *dialog_title, const char *window_text)
Creates a simple dialog window with "OK" and "CANCEL" buttons.
GtkWidget * find_widget(const char *widget_name)
Searches inner grid for widget with given name.
~application()
Destructor.
renderer * get_renderer()
Get a renderer that can be used to draw on top of the main canvas.
std::string get_main_canvas_id() const
Get the ID of the main canvas.
Definition: application.hpp:541
int run(setup_callback_fn initial_setup_user_callback, mouse_callback_fn mouse_press_user_callback, mouse_callback_fn mouse_move_user_callback, key_callback_fn key_press_user_callback)
Run the application.
void change_canvas_world_coordinates(std::string const &canvas_id, rectangle coordinate_system)
Change the coordinate system of a previously created canvas.
void create_popup_message_with_callback(dialog_callback_fn cbk_fn, const char *title, const char *message)
Creates a popup message with a "DONE" button.
void create_label(int left, int top, int width, int height, const char *label_text)
Create a label object in Inner Grid at specified position/dimensions.
std::string get_main_window_id() const
Get the ID of the main window.
Definition: application.hpp:533
void quit()
Quit the application.
canvas * add_canvas(std::string const &canvas_id, draw_canvas_fn draw_callback, rectangle coordinate_system, color background_color=WHITE)
Add a canvas to the application.
bool destroy_button(const char *button_text_to_destroy)
Deletes a button by its label (displayed text)
void change_combo_box_text_options(const char *name, std::vector< std::string > new_options)
changes list of options to new given vector.
void update_message(std::string const &message)
Update the message in the status bar.
void flush_drawing()
Flush the drawing done by the renderer to the on-screen buffer.
void refresh_drawing()
redraw the main canvas
application & operator=(application const &)=delete
Copies are disabled.
bool destroy_widget(const char *widget_name)
Destroys widget.
GObject * get_object(gchar const *name) const
Retrieve a GLib Object (i.e., a GObject).
void create_button(const char *button_text, int insert_row, button_callback_fn button_func)
Add a button convenience Adds a button at a given row index (assuming buttons in the right bar use 1 ...
application & operator=(application &&)=default
Ownership of an application is transferrable.
void change_button_text(const char *button_text, const char *new_button_text)
Change the label of the button (displayed text)
application(application::settings s)
Create an application.
void create_label(int insert_row, const char *label_text)
Creates a label object (a text label) in the Inner Grid.
void create_popup_message(const char *title, const char *message)
Creates a popup message with a "DONE" button.
void create_button(const char *button_text, int left, int top, int width, int height, button_callback_fn button_func)
Add a button that you can click on to call its callback function.
canvas * get_canvas(std::string const &canvas_id) const
Retrieve a pointer to a canvas that was previously added to the application.
void create_combo_box_text(const char *id_string, int insert_row, combo_box_callback_fn combo_box_fn, std::vector< std::string > options)
Creates a GTK combo box object in Inner Grid A combo box is a dropdown menu with different options.
Responsible for creating, destroying, and maintaining the rendering context of a GtkWidget.
Definition: canvas.hpp:54
Represents a rectangle as two diagonally opposite points.
Definition: rectangle.hpp:31
Provides functions to draw primitives (e.g., lines, shapes) to a rendering context (the MainCanvas).
Definition: graphics.hpp:173
A library for creating a graphical user interface.
Definition: application.hpp:40
void(*)(application *app) connect_g_objects_fn
The signature of a function that connects GObject to functions via signals.
Definition: application.hpp:56
void(*)(application *app, GdkEventButton *event, double x, double y) mouse_callback_fn
The signature of a user-defined callback function for mouse events.
Definition: application.hpp:71
void(*)(application *app, GdkEventKey *event, char *key_name) key_callback_fn
The signature of a user-defined callback function for keyboard events.
Definition: application.hpp:76
void set_disable_event_loop(bool new_setting)
Set the disable_event_loop flag to new_setting Call with new_setting == true to make the event_loop i...
void(*)(application *app, bool new_window) setup_callback_fn
The signature of a setup callback function.
Definition: application.hpp:61
void(*)(GtkComboBoxText *self, application *app) combo_box_callback_fn
The signature of a user-defined callback function for the combo-box "changed" signal.
Definition: application.hpp:81
void(*)(GtkDialog *self, gint response_id, application *app) dialog_callback_fn
The signature of a user-defined callback function for a dialog window.
Definition: application.hpp:86
void(*)(renderer *) draw_canvas_fn
The signature of a function that draws to an ezgl::canvas.
Definition: canvas.hpp:43
void(*)(GtkWidget *widget, application *app) button_callback_fn
The signature of a button callback function.
Definition: application.hpp:66
Configuration settings for the application.
Definition: application.hpp:103
std::string application_identifier
A user-defined name of the GTK application.
Definition: application.hpp:126
std::string window_identifier
The name of the main window in the XML file.
Definition: application.hpp:112
std::string canvas_identifier
The name of the main canvas in the XML file.
Definition: application.hpp:117
connect_g_objects_fn setup_callbacks
Specify the function that will connect GUI objects to user-defined callbacks.
Definition: application.hpp:139
settings(std::string m_resource, std::string w_identifier, std::string c_identifier, std::string a_identifier="ezgl.app", connect_g_objects_fn s_callbacks=nullptr)
Create the settings structure with user-defined values.
Definition: application.hpp:157
std::string main_ui_resource
The resource/file path that contains the XML file, which describes the GUI.
Definition: application.hpp:107
settings()
Create the settings structure with default values.
Definition: application.hpp:144
Represents a color as a mixture or red, green, and blue as well as the transparency level.
Definition: color.hpp:31