82G_MODULE_EXPORT gboolean view_curve_popup (GtkWidget * widget, gpointer data)
110 event_y -= (double) curve_shift;
112 if (state && cstate -> mouseState.MouseIsDown)
115 cairo_region_t * reg;
117 GdkWindow * win = gtk_widget_get_window (this_curve ->
plot);
118 reg = gdk_window_get_visible_region (win);
119 GdkDrawingContext * curve_context = gdk_window_begin_draw_frame (win, reg);
120 if (gdk_drawing_context_is_valid (curve_context))
122 rec = gdk_drawing_context_get_cairo_context (curve_context);
123 if (event_x >=
x_min && event_x <=
x_max && event_y <= y_min && event_y >=
y_max)
125 GtkNative * native = gtk_widget_get_native (this_curve ->
plot);
126 GdkSurface * surf = gtk_native_get_surface (native);
127 cairo_surface_t * csurf = cairo_surface_create_for_rectangle (this_curve -> surface, 0.0, (
double)curve_shift,
128 (
double)gtk_widget_get_width(this_curve ->
plot),
129 (
double)gtk_widget_get_height(this_curve ->
plot));
130 reg = gdk_cairo_region_create_from_surface (csurf);
131 GdkDrawContext * curve_context = (GdkDrawContext *) gdk_surface_create_cairo_context (surf);
132 gdk_draw_context_begin_frame (curve_context, reg);
133 if (gdk_draw_context_is_in_frame (curve_context))
135 rec = gdk_cairo_context_cairo_create ((GdkCairoContext *)curve_context);
136 if (event_x >=
x_min && event_x <=
x_max && event_y <=
y_min+(
double)curve_shift && event_y >=
y_max)
139 width = event_x - cstate -> mouseState.start_x;
140 height = event_y - cstate -> mouseState.start_y;
142 cairo_set_source_surface (rec, this_curve -> surface, 0, -curve_shift);
144 height += (double) curve_shift;
145 cairo_set_source_surface (rec, this_curve -> surface, 0, +curve_shift);
148 if (event_x < cstate -> mouseState.start_x)
151 x = cstate -> mouseState.start_x + 2;
152 if (event_y < cstate -> mouseState.start_y)
156 y = cstate -> mouseState.start_y + 8;
157 str = g_strdup_printf (_(
"zoom: out (x) / in (y)"));
163 y = cstate -> mouseState.start_y - 4;
164 str = g_strdup_printf (_(
"zoom: out (x) / out (y)"));
170 x = cstate -> mouseState.start_x - 100;
171 if (event_y < cstate -> mouseState.start_y)
175 y = cstate -> mouseState.start_y + 8;
176 str = g_strdup_printf (_(
"zoom: in (x) / in (y)"));
182 y = cstate -> mouseState.start_y - 4;
183 str = g_strdup_printf (_(
"zoom: in (x) / out (y)"));
186 cairo_set_source_rgba (rec, r, g, d, 0.05);
187 cairo_rectangle (rec, cstate -> mouseState.start_x, cstate -> mouseState.start_y, width, height);
189 cairo_set_source_rgba (rec, r, g, d, 1.0);
190 cairo_set_line_width (rec, 1.0);
191 cairo_move_to (rec, cstate -> mouseState.start_x, cstate -> mouseState.start_y);
193 event_y += (double) curve_shift;
195 cairo_line_to (rec, cstate -> mouseState.start_x, event_y);
196 cairo_line_to (rec, event_x, event_y);
197 cairo_line_to (rec, event_x, cstate -> mouseState.start_y);
198 cairo_line_to (rec, cstate -> mouseState.start_x, cstate -> mouseState.start_y);
200 if (abs(width) > 10 && abs(height) > 5)
202 cairo_move_to (rec,
x,
y);
203 cairo_show_text (rec, str);
206 width = event_x -
x_min;
207 tmp = this_curve -> axmax[0] - this_curve -> axmin[0];
208 xp = this_curve -> axmin[0] + width * tmp /
XDRAW;
210 event_y -= (double) curve_shift;
212 height = event_y -
y_max;
213 tmp = this_curve -> axmax[1] - this_curve -> axmin[1];
214 yp = this_curve -> axmax[1] + height * tmp /
YDRAW;
215 str = g_strdup_printf (
"(x= %f, y= %f)", xp, yp);
219 str = g_strdup_printf (_(
"(Not in plot)"));
221 gtk_label_set_text (GTK_LABEL(this_curve -> pos), str);
225 gdk_window_end_draw_frame (win, curve_context);
227 gdk_draw_context_end_frame (curve_context);
230 else if (! cstate -> mouseState.MouseIsDown)
234 gtk_window_get_size (GTK_WINDOW(this_curve -> window), & this_curve -> wsize[0], &
y);
235 this_curve -> wsize[1] =
y - curve_shift;
237 this_curve -> wsize[0] = gtk_widget_get_width (this_curve ->
plot);
238 this_curve -> wsize[1] = gtk_widget_get_height (this_curve ->
plot);
242 if (event_x >=
x_min && event_x <=
x_max && event_y <=
y_min+(
double)curve_shift && event_y >=
y_max)
244 if (event_x >=
x_min && event_x <=
x_max && event_y <= y_min && event_y >=
y_max)
247 width = event_x -
x_min;
248 tmp = this_curve -> axmax[0] - this_curve -> axmin[0];
249 xp = this_curve -> axmin[0] + width * tmp /
XDRAW;
250 height = event_y -
y_max;
251 tmp = this_curve -> axmax[1] - this_curve -> axmin[1];
252 yp = this_curve -> axmax[1] + height * tmp /
YDRAW;
253 str = g_strdup_printf (
"(x= %f, y= %f)", xp, yp);
257 str = g_strdup_printf (_(
"Not in plot"));
259 gtk_label_set_text (GTK_LABEL(this_curve -> pos), str);
274G_MODULE_EXPORT gboolean on_motion_notify_event (GtkWidget * widget, GdkEventMotion * event, gpointer data)
276 curve_zoom_in_out ((event -> state & GDK_BUTTON1_MASK) ? TRUE : FALSE, event ->
x, event ->
y, data);
290static void on_curve_pointer_motion (GtkEventControllerMotion *
motion, gdouble
x, gdouble
y, gpointer data)
309void curve_button_event (
double event_x,
double event_y, guint event_button, guint event_type, guint32 event_time, gpointer data)
324void curve_button_event (GdkEvent * event,
double event_x,
double event_y, guint event_button, guint event_type, guint32 event_time, gpointer data)
334 if (event_type == GDK_BUTTON_PRESS)
336 if (event_button == 1)
343 gtk_window_get_size (GTK_WINDOW(this_curve -> window), & this_curve -> wsize[0], & y1);
346 this_curve -> wsize[0] = gtk_widget_get_width (this_curve ->
plot);
347 this_curve -> wsize[1] = gtk_widget_get_height (this_curve ->
plot);
351 if (event_x >=
x_min && event_x <=
x_max && event_y <=
y_min+(
double)curve_shift && event_y >=
y_max)
353 if (event_x >=
x_min && event_x <=
x_max && event_y <= y_min && event_y >=
y_max)
356 cstate -> mouseState.start_x = event_x;
357 cstate -> mouseState.start_y = event_y;
358 cstate -> mouseState.time = event_time;
359 cstate -> mouseState.MouseIsDown = TRUE;
362 else if (event_button == 3)
371 else if (event_type == GDK_BUTTON_RELEASE)
373 cstate -> mouseState.MouseIsDown = FALSE;
374 if (event_button == 1)
376 etime = event_time - cstate -> mouseState.time;
377 if (event_x >=
x_min && event_x <=
x_max && event_y <= y_min && event_y >=
y_max)
379 if (event_x != cstate -> mouseState.start_x && event_y != cstate -> mouseState.start_y)
383 x1 = cstate -> mouseState.start_x -
x_min;
384 y1 = cstate -> mouseState.start_y -
y_max;
385 x2 = event_x -
x_min;
386 y2 = event_y -
y_max;
391 tmp = this_curve -> axmax[0] - this_curve -> axmin[0];
395 this_curve -> axmax[0] = this_curve -> axmin[0] + x2 * tmp /
XDRAW;
396 this_curve -> axmin[0] = this_curve -> axmin[0] + x1 * tmp /
XDRAW;
401 this_curve -> axmin[0] = this_curve -> axmin[0] - (x1 - x2) * tmp /
XDRAW;
402 this_curve -> axmax[0] = this_curve -> axmax[0] + (x1 - x2) * tmp /
XDRAW;
404 tmp = this_curve -> axmax[1] - this_curve -> axmin[1];
408 this_curve -> axmin[1] = this_curve -> axmax[1] + y1 * tmp /
YDRAW;
409 this_curve -> axmax[1] = this_curve -> axmax[1] + y2 * tmp /
YDRAW;
414 this_curve -> axmin[1] = this_curve -> axmin[1] + (y2 - y1) * tmp /
YDRAW;
415 this_curve -> axmax[1] = this_curve -> axmax[1] - (y2 - y1) * tmp /
YDRAW;
437G_MODULE_EXPORT
void on_curve_button_pressed (GtkGesture * gesture,
int n_press,
double x,
double y, gpointer data)
439 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);
453G_MODULE_EXPORT
void on_curve_button_released (GtkGesture * gesture,
int n_press,
double x,
double y, gpointer data)
455 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);
469 GdkEventButton * bevent = (GdkEventButton *)event;
470 curve_button_event (event, bevent ->
x, bevent ->
y, bevent -> button, bevent -> type, bevent -> time, data);
486 if (state & GDK_CONTROL_MASK)
519G_MODULE_EXPORT gboolean
on_curve_key_pressed (GtkWidget * widg, GdkEventKey * event, gpointer data)
521 if (event -> type == GDK_KEY_PRESS)
541G_MODULE_EXPORT gboolean
on_curve_key_pressed (GtkEventControllerKey * self, guint keyval, guint keycode, GdkModifierType state, gpointer data)
583 GtkWidget * curve_win, *
vbox;
600 this_curve -> action_group = g_simple_action_group_new ();
601 GSimpleAction * curve_action[5];
602 curve_action[0] = g_simple_action_new (
"save.data", NULL);
603 curve_action[1] = g_simple_action_new (
"close.curve", NULL);
604 curve_action[2] = g_simple_action_new (
"edit.curve", NULL);
605 curve_action[3] = g_simple_action_new (
"save.image", NULL);
606 curve_action[4] = g_simple_action_new (
"shortcuts.curve", NULL);
610 g_action_map_add_action (G_ACTION_MAP(this_curve -> action_group), G_ACTION(curve_action[i]));
613 str = g_strdup_printf (
"c-%d", this_curve -> action_id);
614 gtk_widget_insert_action_group (curve_win, str, G_ACTION_GROUP(this_curve -> action_group));
618 this_curve -> datatree = NULL;
619 this_curve -> state.id = data;
620 this_curve ->
plot = gtk_drawing_area_new ();
621 gtk_widget_set_size_request (this_curve ->
plot, 100, 100);
622 gtk_widget_set_hexpand (this_curve ->
plot, TRUE);
623 gtk_widget_set_vexpand (this_curve ->
plot, TRUE);
625 gtk_widget_add_events (GTK_WIDGET (this_curve ->
plot),
626 GDK_EXPOSURE_MASK | GDK_SMOOTH_SCROLL_MASK |
627 GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK |
628 GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK);
629 g_signal_connect (G_OBJECT(this_curve ->
plot),
"motion_notify_event", G_CALLBACK(on_motion_notify_event), & this_curve -> state);
630 g_signal_connect (G_OBJECT(this_curve ->
plot),
"button_press_event", G_CALLBACK(
on_curve_button_event), & this_curve -> state);
631 g_signal_connect (G_OBJECT(this_curve ->
plot),
"button_release_event", G_CALLBACK(
on_curve_button_event),& this_curve -> state);
632 g_signal_connect (G_OBJECT(this_curve ->
plot),
"popup-menu", G_CALLBACK(view_curve_popup), & this_curve -> state);
634 add_widget_gesture_and_key_action (curve_win,
"curve-button-pressed", G_CALLBACK(on_curve_button_pressed), & this_curve -> state,
635 "curve-button-released", G_CALLBACK(on_curve_button_released), & this_curve -> state,
637 "curve-pointer-motion", G_CALLBACK(on_curve_pointer_motion), & this_curve -> state,
644 g_signal_connect (G_OBJECT(this_curve ->
plot),
"draw", G_CALLBACK(
show_curve), data);
645 g_signal_connect (G_OBJECT(curve_win),
"key-press-event", G_CALLBACK(
on_curve_key_pressed), data);
647 gtk_drawing_area_set_draw_func (GTK_DRAWING_AREA(this_curve ->
plot), (GtkDrawingAreaDrawFunc)
show_curve, data, NULL);
649 g_signal_connect (G_OBJECT(curve_win),
"realize", G_CALLBACK(
on_curve_realize), data);
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(Curve *this_curve)
prepare curve plot (setting up variables for the plot)
Curve * get_curve_from_pointer(gpointer data)
get Curve pointer from pointer
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
int get_curve_shift(Curve *this_curve)
get cruve window size shift
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
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
G_MODULE_EXPORT void curve_menu_bar_action(GSimpleAction *action, GVariant *parameter, gpointer data)
curve menu action callback
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(Curve *this_curve)
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