summaryrefslogtreecommitdiffstats
path: root/gtk
diff options
context:
space:
mode:
authorjstebbins <[email protected]>2009-04-09 17:55:11 +0000
committerjstebbins <[email protected]>2009-04-09 17:55:11 +0000
commitad143cd2573a8958c427f92cbba5afa32675d379 (patch)
tree4ad014fa7935d9673adb2679c09c70065b250dc7 /gtk
parentb49fb8b3e06020318570adac2f8a19a3332e15a7 (diff)
LinGui: give the hud nicer looking rounded corners
git-svn-id: svn://svn.handbrake.fr/HandBrake/trunk@2314 b64f7644-9d1e-0410-96f1-a4d463321fa5
Diffstat (limited to 'gtk')
-rw-r--r--gtk/src/ghb.ui1
-rw-r--r--gtk/src/preview.c152
2 files changed, 98 insertions, 55 deletions
diff --git a/gtk/src/ghb.ui b/gtk/src/ghb.ui
index 937c8773f..d9e6c202e 100644
--- a/gtk/src/ghb.ui
+++ b/gtk/src/ghb.ui
@@ -4872,6 +4872,7 @@ location as the movie.</property>
<property name="app-paintable">True</property>
<property name="events">GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK | GDK_ENTER_NOTIFY_MASK</property>
<signal name="enter-notify-event" handler="hud_enter_cb"/>
+ <signal handler="preview_hud_size_alloc_cb" name="size-allocate"/>
<child>
<object class="GtkAlignment" id="alignment53">
<property name="visible">True</property>
diff --git a/gtk/src/preview.c b/gtk/src/preview.c
index 5b10d9b11..e999b3e07 100644
--- a/gtk/src/preview.c
+++ b/gtk/src/preview.c
@@ -1065,6 +1065,101 @@ preview_motion_cb(
return FALSE;
}
+GdkDrawable*
+ghb_curved_rect_mask(gint width, gint height, gint radius)
+{
+ GdkDrawable *shape;
+ cairo_t *cr;
+ double x1, y1;
+ double x0, y0;
+
+ shape = (GdkDrawable *)gdk_pixmap_new (NULL, width, height, 1);
+
+ cr = gdk_cairo_create (shape);
+
+ x0 = y0 = 0;
+ x1 = width;
+ y1 = height;
+
+ // fill shape with black
+ cairo_save(cr);
+ cairo_rectangle (cr, 0, 0, width, height);
+ cairo_set_operator (cr, CAIRO_OPERATOR_CLEAR);
+ cairo_fill (cr);
+ cairo_restore (cr);
+
+ if (!width || !height)
+ return NULL;
+
+ if (width/2 < radius) {
+ if (height/2 < radius) {
+ cairo_move_to (cr, x0, (y0 + y1)/2);
+ cairo_curve_to (cr, x0 ,y0, x0, y0, (x0 + x1)/2, y0);
+ cairo_curve_to (cr, x1, y0, x1, y0, x1, (y0 + y1)/2);
+ cairo_curve_to (cr, x1, y1, x1, y1, (x1 + x0)/2, y1);
+ cairo_curve_to (cr, x0, y1, x0, y1, x0, (y0 + y1)/2);
+ } else {
+ cairo_move_to (cr, x0, y0 + radius);
+ cairo_curve_to (cr, x0 ,y0, x0, y0, (x0 + x1)/2, y0);
+ cairo_curve_to (cr, x1, y0, x1, y0, x1, y0 + radius);
+ cairo_line_to (cr, x1 , y1 - radius);
+ cairo_curve_to (cr, x1, y1, x1, y1, (x1 + x0)/2, y1);
+ cairo_curve_to (cr, x0, y1, x0, y1, x0, y1- radius);
+ }
+ } else {
+ if (height/2 < radius) {
+ cairo_move_to (cr, x0, (y0 + y1)/2);
+ cairo_curve_to (cr, x0 , y0, x0 , y0, x0 + radius, y0);
+ cairo_line_to (cr, x1 - radius, y0);
+ cairo_curve_to (cr, x1, y0, x1, y0, x1, (y0 + y1)/2);
+ cairo_curve_to (cr, x1, y1, x1, y1, x1 - radius, y1);
+ cairo_line_to (cr, x0 + radius, y1);
+ cairo_curve_to (cr, x0, y1, x0, y1, x0, (y0 + y1)/2);
+ } else {
+ cairo_move_to (cr, x0, y0 + radius);
+ cairo_curve_to (cr, x0 , y0, x0 , y0, x0 + radius, y0);
+ cairo_line_to (cr, x1 - radius, y0);
+ cairo_curve_to (cr, x1, y0, x1, y0, x1, y0 + radius);
+ cairo_line_to (cr, x1 , y1 - radius);
+ cairo_curve_to (cr, x1, y1, x1, y1, x1 - radius, y1);
+ cairo_line_to (cr, x0 + radius, y1);
+ cairo_curve_to (cr, x0, y1, x0, y1, x0, y1- radius);
+ }
+ }
+ cairo_close_path(cr);
+
+ cairo_set_source_rgb(cr, 1, 1, 1);
+ cairo_fill_preserve(cr);
+
+ cairo_set_line_width(cr, 10.0);
+ cairo_stroke(cr);
+
+ cairo_destroy(cr);
+
+ return shape;
+}
+
+G_MODULE_EXPORT void
+preview_hud_size_alloc_cb(
+ GtkWidget *widget,
+ GtkAllocation *allocation,
+ signal_user_data_t *ud)
+{
+ GdkDrawable *shape;
+
+ //g_message("preview_hud_size_alloc_cb()");
+ if (GTK_WIDGET_VISIBLE(widget) && allocation->height > 50)
+ {
+ shape = ghb_curved_rect_mask(allocation->width,
+ allocation->height, allocation->height/2);
+ if (shape != NULL)
+ {
+ gtk_widget_shape_combine_mask(widget, shape, 0, 0);
+ gdk_pixmap_unref(shape);
+ }
+ }
+}
+
G_MODULE_EXPORT gboolean
preview_configure_cb(
GtkWidget *widget,
@@ -1073,7 +1168,7 @@ preview_configure_cb(
{
gint x, y;
- g_debug("preview_configure_cb()");
+ //g_message("preview_configure_cb()");
if (GTK_WIDGET_VISIBLE(widget))
{
gtk_window_get_position(GTK_WINDOW(widget), &x, &y);
@@ -1094,7 +1189,7 @@ settings_configure_cb(
{
gint x, y;
- g_debug("settings_configure_cb()");
+ //g_message("settings_configure_cb()");
if (GTK_WIDGET_VISIBLE(widget))
{
gtk_window_get_position(GTK_WINDOW(widget), &x, &y);
@@ -1107,56 +1202,3 @@ settings_configure_cb(
return FALSE;
}
-#if 0
-G_MODULE_EXPORT gboolean
-preview_window_expose_cb(
- GtkWidget *widget,
- GdkEventExpose *event,
- signal_user_data_t *ud)
-{
- GdkRegion *region;
- GtkWidget *child;
- cairo_t *cr;
-
- //g_debug("preview_window_expose_cb()");
- /* get our child (in this case, the draw area) */
- child = GHB_WIDGET(ud->builder, "preview_image");
- /* create a cairo context to draw to the window */
- cr = gdk_cairo_create (widget->window);
- /* the source data is the (composited) event box */
- gdk_cairo_set_source_pixmap (cr, child->window,
- child->allocation.x,
- child->allocation.y);
- /* draw no more than our expose event intersects our child */
- region = gdk_region_rectangle (&child->allocation);
- gdk_region_intersect (region, event->region);
- gdk_cairo_region (cr, region);
- cairo_clip (cr);
- /* composite, with a 100% opacity */
- cairo_set_operator (cr, CAIRO_OPERATOR_OVER);
- cairo_paint_with_alpha (cr, 1);
-
- cairo_reset_clip(cr);
- /* get our child (in this case, the event box) */
- child = GHB_WIDGET(ud->builder, "preview_event_box");
- /* create a cairo context to draw to the window */
- cr = gdk_cairo_create (widget->window);
- /* the source data is the (composited) event box */
- gdk_cairo_set_source_pixmap (cr, child->window,
- child->allocation.x,
- child->allocation.y);
- /* draw no more than our expose event intersects our child */
- region = gdk_region_rectangle (&child->allocation);
- gdk_region_intersect (region, event->region);
- gdk_cairo_region (cr, region);
- cairo_clip (cr);
- /* composite, with a 85% opacity */
- cairo_set_operator (cr, CAIRO_OPERATOR_OVER);
- cairo_paint_with_alpha (cr, .85);
-
- /* we're done */
- cairo_destroy (cr);
- return FALSE;
-}
-
-#endif