Skip to content

Commit 069d5b8

Browse files
authored
Merge pull request #1845 from verilog-to-routing/update_libezgl_external_subtree
Update libezgl external subtree
2 parents 8861b11 + d1503cb commit 069d5b8

File tree

10 files changed

+224
-80
lines changed

10 files changed

+224
-80
lines changed

libs/EXTERNAL/libezgl/examples/basic-application/basic_application.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -392,7 +392,7 @@ void draw_line_example(ezgl::renderer *g)
392392
{
393393
double offsetY = 50*i;
394394

395-
g->set_horiz_text_just(ezgl::text_just::left);
395+
g->set_horiz_justification(ezgl::justification::left);
396396

397397
if (i == 0) {
398398
g->set_color(ezgl::BLACK);
@@ -415,7 +415,7 @@ void draw_line_example(ezgl::renderer *g)
415415
g->draw_text({950, 920+offsetY}, "Butt ends, 67% transparent", 400, DBL_MAX);
416416
}
417417

418-
g->set_horiz_text_just(ezgl::text_just::center);
418+
g->set_horiz_justification(ezgl::justification::center);
419419

420420
g->draw_text({200, 900+offsetY}, "Thin line (width 1)", 200, DBL_MAX);
421421
g->set_line_width(1);

libs/EXTERNAL/libezgl/examples/basic-application/main.ui

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@
3131
<child>
3232
<object class="GtkButton" id="UpButton">
3333
<property name="visible">True</property>
34-
<property name="can_focus">True</property>
34+
<property name="can_focus">False</property>
3535
<property name="receives_default">True</property>
3636
<child>
3737
<object class="GtkArrow" id="UpArrow">
@@ -49,7 +49,7 @@
4949
<child>
5050
<object class="GtkButton" id="DownButton">
5151
<property name="visible">True</property>
52-
<property name="can_focus">True</property>
52+
<property name="can_focus">False</property>
5353
<property name="receives_default">True</property>
5454
<child>
5555
<object class="GtkArrow" id="DownArrow">
@@ -67,7 +67,7 @@
6767
<child>
6868
<object class="GtkButton" id="LeftButton">
6969
<property name="visible">True</property>
70-
<property name="can_focus">True</property>
70+
<property name="can_focus">False</property>
7171
<property name="receives_default">True</property>
7272
<child>
7373
<object class="GtkArrow" id="LeftArrow">
@@ -85,7 +85,7 @@
8585
<child>
8686
<object class="GtkButton" id="RightButton">
8787
<property name="visible">True</property>
88-
<property name="can_focus">True</property>
88+
<property name="can_focus">False</property>
8989
<property name="receives_default">True</property>
9090
<child>
9191
<object class="GtkArrow" id="RightArrow">
@@ -103,7 +103,7 @@
103103
<object class="GtkButton" id="ZoomInButton">
104104
<property name="label" translatable="yes">Zoom In</property>
105105
<property name="visible">True</property>
106-
<property name="can_focus">True</property>
106+
<property name="can_focus">False</property>
107107
<property name="receives_default">True</property>
108108
</object>
109109
<packing>
@@ -116,7 +116,7 @@
116116
<object class="GtkButton" id="ZoomOutButton">
117117
<property name="label" translatable="yes">Zoom Out</property>
118118
<property name="visible">True</property>
119-
<property name="can_focus">True</property>
119+
<property name="can_focus">False</property>
120120
<property name="receives_default">True</property>
121121
</object>
122122
<packing>
@@ -129,7 +129,7 @@
129129
<object class="GtkButton" id="ZoomFitButton">
130130
<property name="label" translatable="yes">Zoom Fit</property>
131131
<property name="visible">True</property>
132-
<property name="can_focus">True</property>
132+
<property name="can_focus">False</property>
133133
<property name="receives_default">True</property>
134134
</object>
135135
<packing>
@@ -142,7 +142,7 @@
142142
<object class="GtkButton" id="ProceedButton">
143143
<property name="label" translatable="yes">Proceed</property>
144144
<property name="visible">True</property>
145-
<property name="can_focus">True</property>
145+
<property name="can_focus">False</property>
146146
<property name="receives_default">True</property>
147147
</object>
148148
<packing>

libs/EXTERNAL/libezgl/include/ezgl/application.hpp

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
#include <map>
2929
#include <memory>
3030
#include <string>
31+
#include <ctime>
3132

3233
#include <gtk/gtk.h>
3334

@@ -36,6 +37,13 @@
3637
*/
3738
namespace ezgl {
3839

40+
// A flag to specify whether the GUI is built from an XML file or an XML resource
41+
#ifndef ECE297
42+
const bool build_ui_from_file = false;
43+
#else
44+
const bool build_ui_from_file = true;
45+
#endif
46+
3947
class application;
4048

4149
/**
@@ -81,7 +89,7 @@ class application {
8189
*/
8290
struct settings {
8391
/**
84-
* The resource path that contains the XML file, which describes the GUI.
92+
* The resource/file path that contains the XML file, which describes the GUI.
8593
*/
8694
std::string main_ui_resource;
8795

@@ -121,9 +129,13 @@ class application {
121129
* Create the settings structure with default values
122130
*/
123131
settings()
124-
: main_ui_resource("/ezgl/main.ui"), window_identifier("MainWindow"), canvas_identifier("MainCanvas"), application_identifier("ezgl.app"),
132+
: main_ui_resource(build_ui_from_file ? "main_ui" : "/ezgl/main.ui"), window_identifier("MainWindow"), canvas_identifier("MainCanvas"), application_identifier("ezgl.app"),
125133
setup_callbacks(nullptr)
126134
{
135+
// Uniquify the application_identifier by appending a time stamp,
136+
// so that each instance of the same program has a different application ID.
137+
// This allows multiple instance of the program to run independelty.
138+
application_identifier += ".t" + std::to_string(std::time(nullptr));
127139
}
128140

129141
/**
@@ -134,6 +146,10 @@ class application {
134146
: main_ui_resource(m_resource), window_identifier(w_identifier), canvas_identifier(c_identifier), application_identifier(a_identifier),
135147
setup_callbacks(s_callbacks)
136148
{
149+
// Uniquify the application_identifier by appending a time stamp,
150+
// so that each instance of the same program has a different application ID.
151+
// This allows multiple instance of the program to run independelty.
152+
application_identifier += ".t" + std::to_string(std::time(nullptr));
137153
}
138154
};
139155

@@ -403,7 +419,6 @@ class application {
403419
/**
404420
* Set the disable_event_loop flag to new_setting
405421
* Call with new_setting == true to make the event_loop immediately return.
406-
* Needed only for auto-marking
407422
*
408423
* @param new_setting The new state of disable_event_loop flag
409424
*/

libs/EXTERNAL/libezgl/include/ezgl/callback.hpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,9 @@
2727

2828
#include <iostream>
2929

30+
// Mouse button used for panning (left button (1) - middle button (2) - right button (3))
31+
#define PANNING_MOUSE_BUTTON 1
32+
3033
namespace ezgl {
3134

3235
/**** Callback functions for keyboard and mouse input, and for all the ezgl predefined buttons. *****/

libs/EXTERNAL/libezgl/include/ezgl/graphics.hpp

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -65,9 +65,9 @@ enum t_coordinate_system {
6565
};
6666

6767
/**
68-
* Text justification options
68+
* Justification options (used for text and surfaces)
6969
*/
70-
enum class text_just {
70+
enum class justification {
7171
/**
7272
* Center Justification: used for both vertical and horizontal justification
7373
*/
@@ -279,18 +279,18 @@ class renderer {
279279
void set_text_rotation(double degrees);
280280

281281
/**
282-
* set horizontal text justification.
282+
* set horizontal justification (used for text and surfaces).
283283
*
284284
* @param horiz_just Options: center, left and right justification.
285285
*/
286-
void set_horiz_text_just(text_just horiz_just);
286+
void set_horiz_justification(justification horiz_just);
287287

288288
/**
289-
* set vertical text justification.
289+
* set vertical justification (used for text and surfaces).
290290
*
291291
* @param vert_just Options: center, top and bottom justification.
292292
*/
293-
void set_vert_text_just(text_just vert_just);
293+
void set_vert_justification(justification vert_just);
294294

295295
/**** Functions to draw various graphics primitives ****/
296296

@@ -425,9 +425,10 @@ class renderer {
425425
* Draw a surface
426426
*
427427
* @param surface The surface to draw
428-
* @param top_left The corner point of the drawn surface.
428+
* @param anchor_point The anchor_point point of the drawn surface.
429+
* @param scale_factor The scaling factor of the drawn surface (optional)
429430
*/
430-
void draw_surface(surface *surface, point2d top_left);
431+
void draw_surface(surface *p_surface, point2d anchor_point, double scale_factor = 1);
431432

432433
/**
433434
* load a png image
@@ -516,11 +517,11 @@ class renderer {
516517
// the rotation angle variable used in rotating text
517518
double rotation_angle;
518519

519-
// Current horizontal text justification
520-
text_just horiz_text_just = text_just::center;
520+
// Current horizontal justification (used for text and surfaces)
521+
justification horiz_justification = justification::center;
521522

522-
// Current vertical text justification
523-
text_just vert_text_just = text_just::center;
523+
// Current vertical justification (used for text and surfaces)
524+
justification vert_justification = justification::center;
524525

525526
// Current line width
526527
int current_line_width = 1;

libs/EXTERNAL/libezgl/include/ezgl/point.hpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,13 @@ namespace ezgl {
2626
*/
2727
class point2d {
2828
public:
29+
/**
30+
* Default constructor: Create a point at (0, 0).
31+
*/
32+
point2d() : x(0.0), y(0.0)
33+
{
34+
}
35+
2936
/**
3037
* Create a point at the given x and y position.
3138
*/

libs/EXTERNAL/libezgl/src/application.cpp

Lines changed: 23 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,9 @@
1919
#include "ezgl/application.hpp"
2020

2121
namespace ezgl {
22+
2223
// A flag to disable event loop (default is false)
24+
// This allows basic scripted testing even if the GUI is on (return immediately when the event loop is called)
2325
bool disable_event_loop = false;
2426

2527
void application::startup(GtkApplication *, gpointer user_data)
@@ -29,10 +31,21 @@ void application::startup(GtkApplication *, gpointer user_data)
2931

3032
char const *main_ui_resource = ezgl_app->m_main_ui.c_str();
3133

32-
// Build the main user interface from the XML resource.
33-
GError *error = nullptr;
34-
if(gtk_builder_add_from_resource(ezgl_app->m_builder, main_ui_resource, &error) == 0) {
35-
g_error("%s.", error->message);
34+
if (!build_ui_from_file) {
35+
// Build the main user interface from the XML resource.
36+
// The XML resource is built from an XML file using the glib-compile-resources tool.
37+
// This adds an extra compilation step, but it embeds the UI description in the executable.
38+
GError *error = nullptr;
39+
if(gtk_builder_add_from_resource(ezgl_app->m_builder, main_ui_resource, &error) == 0) {
40+
g_error("%s.", error->message);
41+
}
42+
}
43+
else {
44+
// Build the main user interface from the XML file.
45+
GError *error = nullptr;
46+
if(gtk_builder_add_from_file(ezgl_app->m_builder, main_ui_resource, &error) == 0) {
47+
g_error("%s.", error->message);
48+
}
3649
}
3750

3851
for(auto &c_pair : ezgl_app->m_canvases) {
@@ -307,6 +320,11 @@ void application::create_button(const char *button_text,
307320
// create the new button with the given label
308321
GtkWidget *new_button = gtk_button_new_with_label(button_text);
309322

323+
// set can_focus property to false
324+
#if GTK_CHECK_VERSION (3, 20, 0)
325+
gtk_widget_set_focus_on_click(new_button, false);
326+
#endif
327+
310328
// connect the buttons clicked event to the callback
311329
if(button_func != NULL) {
312330
g_signal_connect(G_OBJECT(new_button), "clicked", G_CALLBACK(button_func), this);
@@ -460,4 +478,4 @@ void set_disable_event_loop(bool new_setting)
460478
{
461479
disable_event_loop = new_setting;
462480
}
463-
}
481+
}

0 commit comments

Comments
 (0)