WIP: implement kemonomimi/facial masks dragging

This commit is contained in:
Andreas Frisch 2017-08-08 08:51:53 +02:00
parent 495c67b137
commit 1ecf3a7694
3 changed files with 85 additions and 3 deletions

View file

@ -48,7 +48,7 @@
</packing>
</child>
<child type="overlay">
<object class="GtkFixed">
<object class="GtkFixed" id="fixed">
<property name="visible">True</property>
<property name="can_focus">False</property>
<child>
@ -156,9 +156,31 @@
<property name="vexpand">True</property>
<property name="stock">gtk-missing-image</property>
</object>
</child>
<child>
<object class="GtkEventBox" id="mask_event">
<property name="width_request">100</property>
<property name="height_request">80</property>
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="events">GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK | GDK_BUTTON1_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK</property>
<signal name="button-press-event" handler="photo_booth_window_mask_press" swapped="no"/>
<signal name="button-release-event" handler="photo_booth_window_mask_release" swapped="no"/>
<signal name="motion-notify-event" handler="photo_booth_window_mask_motion" swapped="no"/>
<child>
<object class="GtkImage" id="mask">
<property name="width_request">100</property>
<property name="height_request">80</property>
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="pixbuf">overlays/mask_nasenbrille.png</property>
<property name="icon_size">5</property>
</object>
</child>
</object>
<packing>
<property name="x">0</property>
<property name="y">0</property>
<property name="x">435</property>
<property name="y">394</property>
</packing>
</child>
<style>

View file

@ -28,6 +28,11 @@ struct _PhotoBoothWindowPrivate
GtkLabel *countdown_label;
GtkScale *copies;
gint countdown;
GtkImage *mask;
GtkWidget *mask_event;
GtkFixed *fixed;
gboolean dragging;
gint startoffsetx, startoffsety;
};
G_DEFINE_TYPE_WITH_PRIVATE (PhotoBoothWindow, photo_booth_window, GTK_TYPE_APPLICATION_WINDOW);
@ -64,6 +69,9 @@ static void photo_booth_window_class_init (PhotoBoothWindowClass *klass)
gtk_widget_class_bind_template_child_private (GTK_WIDGET_CLASS (klass), PhotoBoothWindow, spinner);
gtk_widget_class_bind_template_child_private (GTK_WIDGET_CLASS (klass), PhotoBoothWindow, countdown_label);
gtk_widget_class_bind_template_child_private (GTK_WIDGET_CLASS (klass), PhotoBoothWindow, copies);
gtk_widget_class_bind_template_child_private (GTK_WIDGET_CLASS (klass), PhotoBoothWindow, mask);
gtk_widget_class_bind_template_child_private (GTK_WIDGET_CLASS (klass), PhotoBoothWindow, mask_event);
gtk_widget_class_bind_template_child_private (GTK_WIDGET_CLASS (klass), PhotoBoothWindow, fixed);
gtk_widget_class_bind_template_child (GTK_WIDGET_CLASS (klass), PhotoBoothWindow, image);
gtk_widget_class_bind_template_child (GTK_WIDGET_CLASS (klass), PhotoBoothWindow, button_cancel);
gtk_widget_class_bind_template_child (GTK_WIDGET_CLASS (klass), PhotoBoothWindow, button_print);
@ -99,6 +107,10 @@ static void photo_booth_window_init (PhotoBoothWindow *win)
gtk_button_set_label (win->button_print, _("Print photo"));
gtk_button_set_label (win->button_upload, _("Upload photo"));
g_timeout_add (1000, (GSourceFunc) _pbw_clock_tick, win->status_clock);
gtk_widget_set_has_window (GTK_WIDGET (priv->fixed), TRUE);
priv->dragging = FALSE;
priv->startoffsetx = 0, priv->startoffsety = 0;
}
void photo_booth_window_add_gtkgstwidget (PhotoBoothWindow *win, GtkWidget *gtkgstwidget)
@ -235,6 +247,51 @@ gchar* photo_booth_window_format_copies_value (GtkScale *scale, gdouble value, g
return g_strdup_printf (_("%d prints"), intval);
}
gboolean photo_booth_window_mask_press (GtkWidget *widget, GdkEventButton *event, gpointer user_data)
{
PhotoBoothWindowPrivate *priv;
GtkWidget* p;
gint widgetoffsetx, widgetoffsety, screenoffsetx, screenoffsety;
priv = photo_booth_window_get_instance_private (PHOTO_BOOTH_WINDOW (user_data));
priv->dragging = TRUE;
p = gtk_widget_get_parent (widget);
gdk_window_get_position (gtk_widget_get_parent_window (p), &widgetoffsetx, &widgetoffsety);
p = gtk_widget_get_parent (p);
gdk_window_get_position (gtk_widget_get_parent_window (p), &screenoffsetx, &screenoffsety);
priv->startoffsetx = (int)event->x+widgetoffsetx+screenoffsetx;
priv->startoffsety = (int)event->y+widgetoffsety+screenoffsety;
return TRUE;
}
gboolean photo_booth_window_mask_release (GtkWidget *widget, GdkEventButton *event, gpointer user_data)
{
PhotoBoothWindowPrivate *priv;
priv = photo_booth_window_get_instance_private (PHOTO_BOOTH_WINDOW (user_data));
priv->dragging = FALSE;
return TRUE;
}
gboolean photo_booth_window_mask_motion (GtkWidget *widget, GdkEventMotion *event, gpointer user_data)
{
PhotoBoothWindowPrivate *priv;
priv = photo_booth_window_get_instance_private (PHOTO_BOOTH_WINDOW (user_data));
GST_TRACE_OBJECT (user_data, "event (%.0f,%.0f) root (%d,%d) off (%d,%d)", event->x, event->y, (int)event->x_root, (int)event->y_root, priv->startoffsetx, priv->startoffsety);
if (priv->dragging)
{
int x = (int)event->x_root - priv->startoffsetx;
int y = (int)event->y_root - priv->startoffsety;
gtk_fixed_move (GTK_FIXED (gtk_widget_get_parent (widget)), GTK_WIDGET (widget), x, y);
}
return TRUE;
}
PhotoBoothWindow * photo_booth_window_new (PhotoBooth *pb)
{
return g_object_new (PHOTO_BOOTH_WINDOW_TYPE, "application", pb, NULL);

View file

@ -54,6 +54,9 @@ void photo_booth_window_hide_cursor (PhotoBoothWindow *w
void photo_booth_window_show_cursor (PhotoBoothWindow *win);
void photo_booth_window_set_copies_show (PhotoBoothWindow *win, gint min, gint max, gint def);
gint photo_booth_window_get_copies_hide (PhotoBoothWindow *win);
gboolean photo_booth_window_mask_press (GtkWidget *widget, GdkEventButton *event, gpointer user_data);
gboolean photo_booth_window_mask_release (GtkWidget *widget, GdkEventButton *event, gpointer user_data);
gboolean photo_booth_window_mask_motion (GtkWidget *widget, GdkEventMotion *event, gpointer user_data);
G_END_DECLS