85G_MODULE_EXPORT gboolean view_curve_popup (GtkWidget * widget, gpointer data)
111 a = cstate ->
id ->
a;
112 b = cstate ->
id ->
b;
113 c = cstate ->
id ->
c;
117 event_y -= (double) curve_shift;
119 if (state && cstate -> mouseState.MouseIsDown)
122 cairo_region_t * reg;
124 GdkWindow * win = gtk_widget_get_window (this_proj -> curves[
b][
c] ->
plot);
125 reg = gdk_window_get_visible_region (win);
126 GdkDrawingContext * curve_context = gdk_window_begin_draw_frame (win, reg);
127 if (gdk_drawing_context_is_valid (curve_context))
129 rec = gdk_drawing_context_get_cairo_context (curve_context);
130 if (event_x >=
x_min && event_x <=
x_max && event_y <= y_min && event_y >=
y_max)
132 GtkNative * native = gtk_widget_get_native (this_proj -> curves[
b][
c] ->
plot);
133 GdkSurface * surf = gtk_native_get_surface (native);
134 cairo_surface_t * csurf = cairo_surface_create_for_rectangle (this_proj -> curves[
b][
c] -> surface, 0.0, (
double)curve_shift,
135 (
double)gtk_widget_get_width(this_proj -> curves[
b][
c] ->
plot),
136 (
double)gtk_widget_get_height(this_proj -> curves[
b][
c] ->
plot));
137 reg = gdk_cairo_region_create_from_surface (csurf);
138 GdkDrawContext * curve_context = (GdkDrawContext *) gdk_surface_create_cairo_context (surf);
139 gdk_draw_context_begin_frame (curve_context, reg);
140 if (gdk_draw_context_is_in_frame (curve_context))
142 rec = gdk_cairo_context_cairo_create ((GdkCairoContext *)curve_context);
143 if (event_x >=
x_min && event_x <=
x_max && event_y <=
y_min+(
double)curve_shift && event_y >=
y_max)
146 width = event_x - cstate -> mouseState.start_x;
147 height = event_y - cstate -> mouseState.start_y;
149 cairo_set_source_surface (rec, this_proj -> curves[
b][
c] -> surface, 0, -curve_shift);
151 height += (double) curve_shift;
152 cairo_set_source_surface (rec, this_proj -> curves[
b][
c] -> surface, 0, +curve_shift);
155 if (event_x < cstate -> mouseState.start_x)
158 x = cstate -> mouseState.start_x + 2;
159 if (event_y < cstate -> mouseState.start_y)
163 y = cstate -> mouseState.start_y + 8;
164 str = g_strdup_printf (
"zoom: out (x) / in (y)");
170 y = cstate -> mouseState.start_y - 4;
171 str = g_strdup_printf (
"zoom: out (x) / out (y)");
177 x = cstate -> mouseState.start_x - 100;
178 if (event_y < cstate -> mouseState.start_y)
182 y = cstate -> mouseState.start_y + 8;
183 str = g_strdup_printf (
"zoom: in (x) / in (y)");
189 y = cstate -> mouseState.start_y - 4;
190 str = g_strdup_printf (
"zoom: in (x) / out (y)");
193 cairo_set_source_rgba (rec, r, g,
d, 0.05);
194 cairo_rectangle (rec, cstate -> mouseState.start_x, cstate -> mouseState.start_y, width, height);
196 cairo_set_source_rgba (rec, r, g,
d, 1.0);
197 cairo_set_line_width (rec, 1.0);
198 cairo_move_to (rec, cstate -> mouseState.start_x, cstate -> mouseState.start_y);
200 event_y += (double) curve_shift;
202 cairo_line_to (rec, cstate -> mouseState.start_x, event_y);
203 cairo_line_to (rec, event_x, event_y);
204 cairo_line_to (rec, event_x, cstate -> mouseState.start_y);
205 cairo_line_to (rec, cstate -> mouseState.start_x, cstate -> mouseState.start_y);
207 if (abs(width) > 10 && abs(height) > 5)
209 cairo_move_to (rec,
x,
y);
210 cairo_show_text (rec, str);
213 width = event_x -
x_min;
214 tmp = this_proj -> curves[
b][
c] -> axmax[0] - this_proj -> curves[
b][
c] -> axmin[0];
215 xp = this_proj -> curves[
b][
c] -> axmin[0] + width * tmp /
XDRAW;
217 event_y -= (double) curve_shift;
219 height = event_y -
y_max;
220 tmp = this_proj -> curves[
b][
c] -> axmax[1] - this_proj -> curves[
b][
c] -> axmin[1];
221 yp = this_proj -> curves[
b][
c] -> axmax[1] + height * tmp /
YDRAW;
222 str = g_strdup_printf (
"(x= %f, y= %f)", xp, yp);
226 str = g_strdup_printf (
"(Not in plot)");
228 gtk_label_set_text (GTK_LABEL(this_proj -> curves[
b][
c] -> pos), str);
232 gdk_window_end_draw_frame (win, curve_context);
234 gdk_draw_context_end_frame (curve_context);
237 else if (! cstate -> mouseState.MouseIsDown)
241 gtk_window_get_size (GTK_WINDOW(this_proj -> curves[
b][
c] -> window),
242 & this_proj -> curves[
b][
c] -> wsize[0],
244 this_proj -> curves[
b][
c] -> wsize[1] =
y - curve_shift;
246 this_proj -> curves[
b][
c] -> wsize[0] = gtk_widget_get_width (this_proj -> curves[
b][
c] ->
plot);
247 this_proj -> curves[
b][
c] -> wsize[1] = gtk_widget_get_height (this_proj -> curves[
b][
c] ->
plot);
251 if (event_x >=
x_min && event_x <=
x_max && event_y <=
y_min+(
double)curve_shift && event_y >=
y_max)
253 if (event_x >=
x_min && event_x <=
x_max && event_y <= y_min && event_y >=
y_max)
256 width = event_x -
x_min;
257 tmp = this_proj -> curves[
b][
c] -> axmax[0] - this_proj -> curves[
b][
c] -> axmin[0];
258 xp = this_proj -> curves[
b][
c] -> axmin[0] + width * tmp /
XDRAW;
259 height = event_y -
y_max;
260 tmp = this_proj -> curves[
b][
c] -> axmax[1] - this_proj -> curves[
b][
c] -> axmin[1];
261 yp = this_proj -> curves[
b][
c] -> axmax[1] + height * tmp /
YDRAW;
262 str = g_strdup_printf (
"(x= %f, y= %f)", xp, yp);
266 str = g_strdup_printf (
"Not in plot");
268 gtk_label_set_text (GTK_LABEL(this_proj -> curves[
b][
c] -> pos), str);
283G_MODULE_EXPORT gboolean on_motion_notify_event (GtkWidget * widget, GdkEventMotion * event, gpointer data)
285 curve_zoom_in_out ((event -> state & GDK_BUTTON1_MASK) ? TRUE : FALSE,
event ->
x,
event ->
y, data);
299static void on_curve_pointer_motion (GtkEventControllerMotion *
motion, gdouble
x, gdouble
y, gpointer data)
318void curve_button_event (
double event_x,
double event_y, guint event_button, guint event_type, guint32 event_time, gpointer data)
333void curve_button_event (GdkEvent * event,
double event_x,
double event_y, guint event_button, guint event_type, guint32 event_time, gpointer data)
347 if (event_type == GDK_BUTTON_PRESS)
349 if (event_button == 1)
356 gtk_window_get_size (GTK_WINDOW(this_proj -> curves[
b][
c] -> window),
357 & this_proj -> curves[
b][
c] -> wsize[0],
361 this_proj -> curves[
b][
c] -> wsize[0] = gtk_widget_get_width (this_proj -> curves[
b][
c] ->
plot);
362 this_proj -> curves[
b][
c] -> wsize[1] = gtk_widget_get_height (this_proj -> curves[
b][
c] ->
plot);
366 if (event_x >=
x_min && event_x <=
x_max && event_y <=
y_min+(
double)curve_shift && event_y >=
y_max)
368 if (event_x >=
x_min && event_x <=
x_max && event_y <= y_min && event_y >=
y_max)
371 cstate -> mouseState.start_x = event_x;
372 cstate -> mouseState.start_y = event_y;
373 cstate -> mouseState.time = event_time;
374 cstate -> mouseState.MouseIsDown = TRUE;
377 else if (event_button == 3)
386 else if (event_type == GDK_BUTTON_RELEASE)
388 cstate -> mouseState.MouseIsDown = FALSE;
389 if (event_button == 1)
391 etime = event_time - cstate -> mouseState.time;
392 if (event_x >=
x_min && event_x <=
x_max && event_y <= y_min && event_y >=
y_max)
394 if (event_x != cstate -> mouseState.start_x && event_y != cstate -> mouseState.start_y)
398 x1 = cstate -> mouseState.start_x -
x_min;
399 y1 = cstate -> mouseState.start_y -
y_max;
400 x2 = event_x -
x_min;
401 y2 = event_y -
y_max;
406 tmp = this_proj -> curves[
b][
c] -> axmax[0] - this_proj -> curves[
b][
c] -> axmin[0];
410 this_proj -> curves[
b][
c] -> axmax[0] = this_proj -> curves[
b][
c] -> axmin[0] + x2 * tmp /
XDRAW;
411 this_proj -> curves[
b][
c] -> axmin[0] = this_proj -> curves[
b][
c] -> axmin[0] + x1 * tmp /
XDRAW;
416 this_proj -> curves[
b][
c] -> axmin[0] = this_proj -> curves[
b][
c] -> axmin[0] - (x1 - x2) * tmp /
XDRAW;
417 this_proj -> curves[
b][
c] -> axmax[0] = this_proj -> curves[
b][
c] -> axmax[0] + (x1 - x2) * tmp /
XDRAW;
419 tmp = this_proj -> curves[
b][
c] -> axmax[1] - this_proj -> curves[
b][
c] -> axmin[1];
423 this_proj -> curves[
b][
c] -> axmin[1] = this_proj -> curves[
b][
c] -> axmax[1] + y1 * tmp /
YDRAW;
424 this_proj -> curves[
b][
c] -> axmax[1] = this_proj -> curves[
b][
c] -> axmax[1] + y2 * tmp /
YDRAW;
429 this_proj -> curves[
b][
c] -> axmin[1] = this_proj -> curves[
b][
c] -> axmin[1] + (y2 - y1) * tmp /
YDRAW;
430 this_proj -> curves[
b][
c] -> axmax[1] = this_proj -> curves[
b][
c] -> axmax[1] - (y2 - y1) * tmp /
YDRAW;
456G_MODULE_EXPORT
void on_curve_button_pressed (GtkGesture * gesture,
int n_press,
double x,
double y, gpointer data)
458 curve_button_event (
x,
y, gtk_gesture_single_get_current_button ((GtkGestureSingle * )gesture), GDK_BUTTON_PRESS, gtk_event_controller_get_current_event_time((GtkEventController *)gesture), data);
472G_MODULE_EXPORT
void on_curve_button_released (GtkGesture * gesture,
int n_press,
double x,
double y, gpointer data)
474 curve_button_event (
x,
y, gtk_gesture_single_get_current_button ((GtkGestureSingle * )gesture), GDK_BUTTON_RELEASE, gtk_event_controller_get_current_event_time((GtkEventController *)gesture), data);
488 GdkEventButton * bevent = (GdkEventButton *)event;
489 curve_button_event (event, bevent ->
x, bevent ->
y, bevent -> button, bevent -> type, bevent -> time, data);
505 if (state & GDK_CONTROL_MASK)
538G_MODULE_EXPORT gboolean
on_curve_key_pressed (GtkWidget * widg, GdkEventKey * event, gpointer data)
540 if (event -> type == GDK_KEY_PRESS)
560G_MODULE_EXPORT gboolean
on_curve_key_pressed (GtkEventControllerKey * self, guint keyval, guint keycode, GdkModifierType state, gpointer data)
594 this_proj -> curves[
id ->
b][
id ->
c] -> wsize[0],
595 this_proj -> curves[
id ->
b][
id ->
c] -> wsize[1]+
get_curve_shift (this_proj,
id ->
b,
id ->
c));
611 gchar * str = g_strdup_printf (
"%s - %s",
prepare_for_title (this_proj -> name), this_proj -> curves[data ->
b][data ->
c] -> name);
618 add_box_child_start (GTK_ORIENTATION_VERTICAL,
vbox, this_proj -> curves[data ->
b][data ->
c] -> curve_vbox, FALSE, FALSE, 0);
622 this_proj -> curves[data ->
b][data ->
c] -> action_group = g_simple_action_group_new ();
623 GSimpleAction * curve_action[5];
624 curve_action[0] = g_simple_action_new (
"save.data", NULL);
625 curve_action[1] = g_simple_action_new (
"close.curve", NULL);
626 curve_action[2] = g_simple_action_new (
"edit.curve", NULL);
627 curve_action[3] = g_simple_action_new (
"save.image", NULL);
628 curve_action[4] = g_simple_action_new (
"shortcuts.curve", NULL);
632 g_action_map_add_action (G_ACTION_MAP(this_proj -> curves[data ->
b][data ->
c] -> action_group), G_ACTION(curve_action[i]));
635 str = g_strdup_printf (
"c-%d", this_proj -> curves[data ->
b][data ->
c] -> action_id);
636 gtk_widget_insert_action_group (
Curve, str, G_ACTION_GROUP(this_proj -> curves[data ->
b][data ->
c] -> action_group));
640 this_proj -> curves[data ->
b][data ->
c] -> datatree = NULL;
641 this_proj -> curves[data ->
b][data ->
c] -> state.
id = data;
642 this_proj -> curves[data ->
b][data ->
c] ->
plot = gtk_drawing_area_new ();
643 gtk_widget_set_size_request (this_proj -> curves[data ->
b][data ->
c] ->
plot, 100, 100);
644 gtk_widget_set_hexpand (this_proj -> curves[data ->
b][data ->
c] ->
plot, TRUE);
645 gtk_widget_set_vexpand (this_proj -> curves[data ->
b][data ->
c] ->
plot, TRUE);
647 gtk_widget_add_events (GTK_WIDGET (this_proj -> curves[data ->
b][data ->
c] ->
plot),
648 GDK_EXPOSURE_MASK | GDK_SMOOTH_SCROLL_MASK |
649 GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK |
650 GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK);
651 g_signal_connect (G_OBJECT(this_proj -> curves[data ->
b][data ->
c] ->
plot),
"motion_notify_event", G_CALLBACK(on_motion_notify_event), & this_proj -> curves[data ->
b][data ->
c] -> state);
652 g_signal_connect (G_OBJECT(this_proj -> curves[data ->
b][data ->
c] ->
plot),
"button_press_event", G_CALLBACK(
on_curve_button_event), & this_proj -> curves[data ->
b][data ->
c] -> state);
653 g_signal_connect (G_OBJECT(this_proj -> curves[data ->
b][data ->
c] ->
plot),
"button_release_event", G_CALLBACK(
on_curve_button_event),& this_proj -> curves[data ->
b][data ->
c] -> state);
654 g_signal_connect (G_OBJECT(this_proj -> curves[data ->
b][data ->
c] ->
plot),
"popup-menu", G_CALLBACK(view_curve_popup), & this_proj -> curves[data ->
b][data ->
c] -> state);
656 add_widget_gesture_and_key_action (
Curve,
"curve-button-pressed", G_CALLBACK(on_curve_button_pressed), & this_proj -> curves[data ->
b][data ->
c] -> state,
657 "curve-button-released", G_CALLBACK(on_curve_button_released), & this_proj -> curves[data ->
b][data ->
c] -> state,
659 "curve-pointer-motion", G_CALLBACK(on_curve_pointer_motion), & this_proj -> curves[data ->
b][data ->
c] -> state,
666 g_signal_connect (G_OBJECT(this_proj -> curves[data ->
b][data ->
c] ->
plot),
"draw", G_CALLBACK(
show_curve), data);
669 gtk_drawing_area_set_draw_func (GTK_DRAWING_AREA(this_proj -> curves[data ->
b][data ->
c] ->
plot), (GtkDrawingAreaDrawFunc)
show_curve, data, NULL);
Callback declarations for main window.
void edit_curve(gpointer data)
create the curve edition dialog
Variable declarations for the curve layout edition window.
void prep_plot(project *this_proj, int rid, int cid)
prepare curve plot (setting up variables for the plot)
void update_curve(gpointer data)
update curve rendering
Variable declarations for the curve widget Functions for interactions with the curve widget.
GtkWidget * curve_popup_menu(gpointer data)
create curve popup menu
G_MODULE_EXPORT gboolean to_hide_curve(GtkWindow *thecurve, gpointer data)
void hide_curve(gpointer data)
hide curve
void save_image(gpointer cdata)
export curve window plot to image - creating the dialog
void curve_window_add_menu_bar(tint *data)
add menu bar to the curve window
void show_curve(GtkDrawingArea *area, cairo_t *cr, int width, int height, gpointer curve)
show curve callback GTK3
void write_curve(gpointer idata)
save curve data - creating the dialog
Variable declarations for the curve data edition window.
Global variable declarations Global convenience function declarations Global data structure defin...
void resize_this_window(GtkWidget *window, int x, int y)
resize this GtkWindow
GtkWidget * create_win(gchar *str, GtkWidget *parent, gboolean modal, gboolean resiz)
create a new GtkWindow
int get_widget_height(GtkWidget *widg)
retrive GtkWidget height
void pop_menu_at_pointer(GtkWidget *widg, GdkEvent *event)
popup a menu at pointer location
struct Curve Curve
curve data structure
void add_gtk_close_event(GtkWidget *widg, GCallback handler, gpointer data)
add a close event signal and callback to a GtkWidget
void add_box_child_start(int orientation, GtkWidget *widg, GtkWidget *child, gboolean expand, gboolean fill, int padding)
Add a GtkWidget in a GtkBox at the initial position.
gchar * prepare_for_title(gchar *init)
prepare a string for a window title, getting rid of all markup
void add_container_child(int type, GtkWidget *widg, GtkWidget *child)
Add a GtkWidget into another GtkWidget.
GtkWidget * create_vbox(int spacing)
create a GtkBox with vertical orientation
project * get_project_by_id(int p)
get project pointer using id number
void motion(glwin *view, gint x, gint y, GdkModifierType state)
mouse motion in the OpenGL window
void curve_key_pressed(guint keyval, GdkModifierType state, gpointer data)
the keyboard shortcut actions for the curve window
void autoscale(gpointer data)
autoscale callback
int get_curve_shift(project *this_proj, int b, int c)
get cruve window size shift
void curve_button_event(GdkEvent *event, double event_x, double event_y, guint event_button, guint event_type, guint32 event_time, gpointer data)
handle mouse button event on the curve window GTK3
G_MODULE_EXPORT gboolean on_curve_key_pressed(GtkEventControllerKey *self, guint keyval, guint keycode, GdkModifierType state, gpointer data)
keyboard key press event for the curve window GTK4
void curve_zoom_in_out(gboolean state, gdouble event_x, gdouble event_y, gpointer data)
curve zoom in or out
G_MODULE_EXPORT gboolean on_curve_button_event(GtkWidget *widget, GdkEvent *event, gpointer data)
mouse button event on the curve window
G_MODULE_EXPORT void on_curve_realize(GtkWidget *widg, gpointer data)
curve window realize callback
void curve_menu_bar_action(GSimpleAction *action, GVariant *parameter, gpointer data)
curve menu action callback
GtkWidget * create_curve(tint *data)
create the curve data plot window