#include "wdgt-rotate-label.h"
#include <glib/gi18n.h>
-#include <glade/glade-xml.h>
-#include <gtk/gtktogglebutton.h>
-#include <gtk/gtkcheckbutton.h>
+#include <gtk/gtkradiobutton.h>
#include <gtk/gtkdrawingarea.h>
#include <math.h>
#include "marshal.h"
#include "color.h"
+#include "hig.h"
#include <libglabels/db.h>
#include "cairo-label-path.h"
#define LINE_COLOR GL_COLOR(0,0,0)
#define FILL_COLOR GL_COLOR(255,255,255)
+#define SHADOW_COLOR GL_COLOR_A(192,192,192,128)
#define LINE_WIDTH_PIXELS 1.0
struct _glWdgtRotateLabelPrivate {
- GtkWidget *rotate_check;
- GtkWidget *rotate_drawingarea;
+ GtkWidget *no_rotate_radio;
+ GtkWidget *rotate_radio;
+ GtkWidget *no_rotate_image;
+ GtkWidget *rotate_image;
lglTemplate *template;
};
static void gl_wdgt_rotate_label_finalize (GObject *object);
-static void gl_wdgt_rotate_label_construct (glWdgtRotateLabel *rotate_label);
-
-static void entry_changed_cb (GtkToggleButton *toggle,
+static void toggled_cb (GtkToggleButton *toggle,
gpointer user_data);
-static void drawingarea_update (GtkDrawingArea *drawing_area,
- lglTemplate *template,
+static GdkPixbuf *create_pixbuf (lglTemplate *template,
gboolean rotate_flag);
-static gboolean expose_cb (GtkWidget *drawingarea,
- GdkEventExpose *event,
- gpointer user_data);
-
/****************************************************************************/
/* Boilerplate Object stuff. */
/****************************************************************************/
-G_DEFINE_TYPE (glWdgtRotateLabel, gl_wdgt_rotate_label, GTK_TYPE_VBOX);
+G_DEFINE_TYPE (glWdgtRotateLabel, gl_wdgt_rotate_label, GTK_TYPE_HBOX);
static void
gl_wdgt_rotate_label_init (glWdgtRotateLabel *rotate_label)
{
rotate_label->priv = g_new0 (glWdgtRotateLabelPrivate, 1);
+
+ gtk_container_set_border_width (GTK_CONTAINER (rotate_label), GL_HIG_PAD2);
+
+ rotate_label->priv->no_rotate_radio = gtk_radio_button_new_with_label (NULL, _("Normal"));
+ rotate_label->priv->rotate_radio = gtk_radio_button_new_with_label_from_widget (GTK_RADIO_BUTTON (rotate_label->priv->no_rotate_radio), _("Rotated"));
+
+ gtk_toggle_button_set_mode (GTK_TOGGLE_BUTTON (rotate_label->priv->no_rotate_radio),
+ FALSE);
+ gtk_toggle_button_set_mode (GTK_TOGGLE_BUTTON (rotate_label->priv->rotate_radio),
+ FALSE);
+
+ gtk_button_set_image_position (GTK_BUTTON (rotate_label->priv->no_rotate_radio),
+ GTK_POS_TOP);
+ gtk_button_set_image_position (GTK_BUTTON (rotate_label->priv->rotate_radio),
+ GTK_POS_TOP);
+
+ rotate_label->priv->no_rotate_image = gtk_image_new ();
+ rotate_label->priv->rotate_image = gtk_image_new ();
+
+ gtk_button_set_image (GTK_BUTTON (rotate_label->priv->no_rotate_radio),
+ rotate_label->priv->no_rotate_image);
+ gtk_button_set_image (GTK_BUTTON (rotate_label->priv->rotate_radio),
+ rotate_label->priv->rotate_image);
+
+ gtk_box_pack_start (GTK_BOX (rotate_label),
+ rotate_label->priv->no_rotate_radio,
+ FALSE, FALSE, GL_HIG_PAD1);
+ gtk_box_pack_start (GTK_BOX (rotate_label),
+ rotate_label->priv->rotate_radio,
+ FALSE, FALSE, GL_HIG_PAD1);
+
+ /* Connect signals to controls */
+ g_signal_connect (G_OBJECT (rotate_label->priv->no_rotate_radio),
+ "toggled",
+ G_CALLBACK (toggled_cb), rotate_label);
+ g_signal_connect (G_OBJECT (rotate_label->priv->rotate_radio),
+ "toggled",
+ G_CALLBACK (toggled_cb), rotate_label);
}
static void
rotate_label = g_object_new (gl_wdgt_rotate_label_get_type (), NULL);
- gl_wdgt_rotate_label_construct (rotate_label);
-
return GTK_WIDGET (rotate_label);
}
-/*--------------------------------------------------------------------------*/
-/* Construct composite widget. */
-/*--------------------------------------------------------------------------*/
-static void
-gl_wdgt_rotate_label_construct (glWdgtRotateLabel *rotate_label)
-{
- GladeXML *gui;
- GtkWidget *hbox;
-
- g_return_if_fail (GL_IS_WDGT_ROTATE_LABEL (rotate_label));
- g_return_if_fail (rotate_label->priv != NULL);
-
- gui = glade_xml_new (GLABELS_GLADE_DIR "wdgt-rotate-label.glade",
- "rotate_hbox", NULL);
-
- if (!gui) {
- g_critical ("Could not open wdgt-media-select.glade. gLabels may not be installed correctly!");
- return;
- }
-
- hbox = glade_xml_get_widget (gui, "rotate_hbox");
- gtk_container_add (GTK_CONTAINER (rotate_label), hbox);
-
- rotate_label->priv->rotate_check = glade_xml_get_widget (gui, "rotate_check");
- rotate_label->priv->rotate_drawingarea = glade_xml_get_widget (gui, "rotate_drawingarea");
-
- g_object_unref (gui);
-
-
- gtk_widget_set_size_request (rotate_label->priv->rotate_drawingarea,
- MINI_PREVIEW_CANVAS_PIXELS,
- MINI_PREVIEW_CANVAS_PIXELS);
-
- /* Connect signals to controls */
- g_signal_connect (G_OBJECT (rotate_label->priv->rotate_check),
- "toggled",
- G_CALLBACK (entry_changed_cb), rotate_label);
- g_signal_connect (G_OBJECT (rotate_label->priv->rotate_drawingarea),
- "expose_event",
- G_CALLBACK (expose_cb), rotate_label);
-}
-
/*--------------------------------------------------------------------------*/
/* PRIVATE. modify widget due to change of check button */
/*--------------------------------------------------------------------------*/
static void
-entry_changed_cb (GtkToggleButton *toggle,
- gpointer user_data)
+toggled_cb (GtkToggleButton *toggle,
+ gpointer user_data)
{
- glWdgtRotateLabel *rotate_label = GL_WDGT_ROTATE_LABEL (user_data);
-
- if (rotate_label->priv->template != NULL) {
- /* Update mini_preview canvas & details with template */
- drawingarea_update (GTK_DRAWING_AREA (rotate_label->priv->rotate_drawingarea),
- rotate_label->priv->template,
- gtk_toggle_button_get_active (toggle));
- }
/* Emit our "changed" signal */
g_signal_emit (G_OBJECT (user_data),
/*--------------------------------------------------------------------------*/
/* PRIVATE. Update mini-preview from template . */
/*--------------------------------------------------------------------------*/
-static void
-drawingarea_update (GtkDrawingArea *drawing_area,
- lglTemplate *template,
- gboolean rotate_flag)
+static GdkPixbuf *
+create_pixbuf (lglTemplate *template,
+ gboolean rotate_flag)
{
+ GdkPixbuf *pixbuf;
+ cairo_surface_t *surface;
const lglTemplateFrame *frame;
gdouble m, m_canvas, w, h, scale;
GtkStyle *style;
- guint line_color, fill_color, shadow_color;
cairo_t *cr;
- if (!GTK_WIDGET_DRAWABLE (GTK_WIDGET (drawing_area)))
- {
- return;
- }
+ /* Create pixbuf and cairo context. */
+ pixbuf = gdk_pixbuf_new (GDK_COLORSPACE_RGB, TRUE, 8, MINI_PREVIEW_CANVAS_PIXELS, MINI_PREVIEW_CANVAS_PIXELS);
+ surface = cairo_image_surface_create_for_data (gdk_pixbuf_get_pixels (pixbuf),
+ CAIRO_FORMAT_RGB24,
+ gdk_pixbuf_get_width (pixbuf),
+ gdk_pixbuf_get_height (pixbuf),
+ gdk_pixbuf_get_rowstride (pixbuf));
- /* Clear surface */
- gdk_window_clear (GTK_WIDGET (drawing_area)->window);
if (template == NULL)
{
- return;
+ return pixbuf;
}
frame = (lglTemplateFrame *)template->frames->data;
scale = MINI_PREVIEW_MAX_PIXELS / m;
m_canvas = MINI_PREVIEW_CANVAS_PIXELS / scale;
- style = gtk_widget_get_style (GTK_WIDGET (drawing_area));
-
- /* Adjust sensitivity (should the canvas be grayed?) */
- if (w != h) {
- line_color = LINE_COLOR;
- fill_color = FILL_COLOR;
- } else {
- line_color = gl_color_from_gdk_color (&style->text[GTK_STATE_INSENSITIVE]);
- fill_color = gl_color_from_gdk_color (&style->base[GTK_STATE_INSENSITIVE]);
- }
-
- shadow_color = gl_color_from_gdk_color (&style->bg[GTK_STATE_ACTIVE]);
+ cr = cairo_create (surface);
+ cairo_surface_destroy (surface);
+ /* Clear pixbuf */
+ cairo_save (cr);
+ cairo_set_operator (cr, CAIRO_OPERATOR_CLEAR);
+ cairo_paint (cr);
+ cairo_restore (cr);
- cr = gdk_cairo_create (GTK_WIDGET (drawing_area)->window);
+ cairo_set_antialias (cr, CAIRO_ANTIALIAS_GRAY);
cairo_identity_matrix (cr);
cairo_translate (cr, MINI_PREVIEW_CANVAS_PIXELS/2, MINI_PREVIEW_CANVAS_PIXELS/2);
cairo_translate (cr, SHADOW_X_OFFSET/scale, SHADOW_Y_OFFSET/scale);
gl_cairo_label_path (cr, template, rotate_flag, FALSE);
- cairo_set_source_rgb (cr, GL_COLOR_RGB_ARGS (shadow_color));
+ cairo_set_source_rgb (cr, GL_COLOR_RGB_ARGS (SHADOW_COLOR));
cairo_set_fill_rule (cr, CAIRO_FILL_RULE_EVEN_ODD);
cairo_fill (cr);
cairo_restore (cr);
*/
gl_cairo_label_path (cr, template, rotate_flag, FALSE);
- cairo_set_source_rgb (cr, GL_COLOR_RGB_ARGS (fill_color));
+ cairo_set_source_rgb (cr, GL_COLOR_RGB_ARGS (FILL_COLOR));
cairo_set_fill_rule (cr, CAIRO_FILL_RULE_EVEN_ODD);
cairo_fill_preserve (cr);
cairo_set_line_width (cr, LINE_WIDTH_PIXELS/scale);
- cairo_set_source_rgb (cr, GL_COLOR_RGB_ARGS (line_color));
+ cairo_set_source_rgb (cr, GL_COLOR_RGB_ARGS (LINE_COLOR));
cairo_stroke (cr);
cairo_destroy (cr);
-}
-
-/*--------------------------------------------------------------------------*/
-/* PRIVATE. Expose handler. */
-/*--------------------------------------------------------------------------*/
-static gboolean
-expose_cb (GtkWidget *drawingarea, GdkEventExpose *event, gpointer user_data)
-{
- glWdgtRotateLabel *rotate_label = GL_WDGT_ROTATE_LABEL (user_data);
-
- drawingarea_update (GTK_DRAWING_AREA (drawingarea),
- rotate_label->priv->template,
- gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (rotate_label->priv->rotate_check)));
-
- return FALSE;
+ return pixbuf;
}
/****************************************************************************/
{
return
gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON
- (rotate_label->priv->rotate_check));
+ (rotate_label->priv->rotate_radio));
}
/****************************************************************************/
gboolean state)
{
gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON
- (rotate_label->priv->rotate_check), state);
+ (rotate_label->priv->rotate_radio), state);
}
/****************************************************************************/
{
rotate_label->priv->template = NULL;
- gtk_widget_set_sensitive (rotate_label->priv->rotate_check,
- FALSE);
-
- drawingarea_update (GTK_DRAWING_AREA (rotate_label->priv->rotate_drawingarea),
- NULL,
- FALSE);
+ gtk_widget_set_sensitive (rotate_label->priv->no_rotate_radio, FALSE);
+ gtk_widget_set_sensitive (rotate_label->priv->rotate_radio, FALSE);
}
else
{
rotate_label->priv->template = template;
lgl_template_frame_get_size (frame, &raw_w, &raw_h);
- gtk_widget_set_sensitive (rotate_label->priv->rotate_check,
+ gtk_image_set_from_pixbuf (GTK_IMAGE (rotate_label->priv->no_rotate_image),
+ create_pixbuf (rotate_label->priv->template, FALSE));
+ gtk_image_set_from_pixbuf (GTK_IMAGE (rotate_label->priv->rotate_image),
+ create_pixbuf (rotate_label->priv->template, TRUE));
+
+ gtk_widget_set_sensitive (rotate_label->priv->no_rotate_radio,
+ (raw_w != raw_h));
+ gtk_widget_set_sensitive (rotate_label->priv->rotate_radio,
(raw_w != raw_h));
- drawingarea_update (GTK_DRAWING_AREA (rotate_label->priv->rotate_drawingarea),
- rotate_label->priv->template,
- FALSE);
+ gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON
+ (rotate_label->priv->no_rotate_radio), TRUE);
+ gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON
+ (rotate_label->priv->rotate_radio), FALSE);
+
}
- gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON
- (rotate_label->priv->rotate_check), FALSE);
+
}