~centralelyon2010/inkscape/imagelinks2

« back to all changes in this revision

Viewing changes to src/libgdl/gdl-dock-item-button-image.c

  • Committer: JazzyNico
  • Date: 2011-08-29 20:25:30 UTC
  • Revision ID: nicoduf@yahoo.fr-20110829202530-6deuoz11q90usldv
Code refactoring and merging with trunk (revision 10599).

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*- 
 
2
 *
 
3
 * gdl-dock-item-button-image.c
 
4
 *
 
5
 * Author: Joel Holdsworth <joel@airwebreathe.org.uk>
 
6
 * 
 
7
 * This library is free software; you can redistribute it and/or
 
8
 * modify it under the terms of the GNU Library General Public
 
9
 * License as published by the Free Software Foundation; either
 
10
 * version 2 of the License, or (at your option) any later version.
 
11
 *
 
12
 * This library is distributed in the hope that it will be useful,
 
13
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 
14
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 
15
 * Library General Public License for more details.
 
16
 *
 
17
 * You should have received a copy of the GNU Library General Public
 
18
 * License along with this library; if not, write to the
 
19
 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
 
20
 * Boston, MA 02111-1307, USA.
 
21
 */
 
22
 
 
23
#include "gdl-dock-item-button-image.h"
 
24
 
 
25
#include <math.h>
 
26
#include "gdl-tools.h"
 
27
 
 
28
#define ICON_SIZE 12
 
29
 
 
30
GDL_CLASS_BOILERPLATE (GdlDockItemButtonImage,
 
31
                       gdl_dock_item_button_image,
 
32
                       GtkWidget, GTK_TYPE_WIDGET);
 
33
                       
 
34
static gint
 
35
gdl_dock_item_button_image_expose (GtkWidget      *widget,
 
36
                                   GdkEventExpose *event)
 
37
{
 
38
    GdlDockItemButtonImage *button_image;
 
39
    GtkStyle *style;
 
40
    GdkColor *color;
 
41
    
 
42
    g_return_val_if_fail (widget != NULL, 0);
 
43
    button_image = GDL_DOCK_ITEM_BUTTON_IMAGE (widget);
 
44
    
 
45
    cairo_t *cr = gdk_cairo_create (event->window);
 
46
    cairo_translate (cr, event->area.x, event->area.y);
 
47
 
 
48
    /* Set up the pen */
 
49
    cairo_set_line_width(cr, 1.0);
 
50
    
 
51
    style = gtk_widget_get_style (widget);
 
52
    g_return_val_if_fail (style != NULL, 0);
 
53
    color = &style->fg[GTK_STATE_NORMAL];
 
54
    cairo_set_source_rgba(cr, color->red / 65535.0,
 
55
        color->green / 65535.0, color->blue / 65535.0, 0.55);
 
56
 
 
57
    /* Draw the icon border */
 
58
    cairo_move_to (cr, 10.5, 2.5);
 
59
    cairo_arc (cr, 10.5, 4.5, 2, -0.5 * M_PI, 0);
 
60
    cairo_line_to (cr, 12.5, 10.5);
 
61
    cairo_arc (cr, 10.5, 10.5, 2, 0, 0.5 * M_PI);
 
62
    cairo_line_to (cr, 4.5, 12.5);
 
63
    cairo_arc (cr, 4.5, 10.5, 2, 0.5 * M_PI, M_PI);
 
64
    cairo_line_to (cr, 2.5, 4.5);
 
65
    cairo_arc (cr, 4.5, 4.5, 2, M_PI, 1.5 * M_PI);
 
66
    cairo_close_path (cr);
 
67
    
 
68
    cairo_stroke (cr);
 
69
    
 
70
    /* Draw the icon */
 
71
    cairo_new_path (cr);
 
72
 
 
73
    switch(button_image->image_type) {
 
74
    case GDL_DOCK_ITEM_BUTTON_IMAGE_CLOSE:
 
75
        cairo_move_to (cr, 4.0, 5.5);
 
76
        cairo_line_to (cr, 4.0, 5.5);
 
77
        cairo_line_to (cr, 6.0, 7.5);
 
78
        cairo_line_to (cr, 4.0, 9.5);
 
79
        cairo_line_to (cr, 5.5, 11.0);
 
80
        cairo_line_to (cr, 7.5, 9.0);
 
81
        cairo_line_to (cr, 9.5, 11.0);
 
82
        cairo_line_to (cr, 11.0, 9.5);
 
83
        cairo_line_to (cr, 9.0, 7.5);
 
84
        cairo_line_to (cr, 11.0, 5.5);
 
85
        cairo_line_to (cr, 9.5, 4.0);
 
86
        cairo_line_to (cr, 7.5, 6.0);
 
87
        cairo_line_to (cr, 5.5, 4.0);
 
88
        cairo_close_path (cr);
 
89
        break;
 
90
    
 
91
    case GDL_DOCK_ITEM_BUTTON_IMAGE_ICONIFY:
 
92
        if (gtk_widget_get_direction (widget) != GTK_TEXT_DIR_RTL) {
 
93
            cairo_move_to (cr, 4.5, 7.5);
 
94
            cairo_line_to (cr, 10.0, 4.75);
 
95
            cairo_line_to (cr, 10.0, 10.25);
 
96
            cairo_close_path (cr);
 
97
        } else {
 
98
            cairo_move_to (cr, 10.5, 7.5);
 
99
            cairo_line_to (cr, 5, 4.75);
 
100
            cairo_line_to (cr, 5, 10.25);
 
101
            cairo_close_path (cr);
 
102
        }
 
103
        break;
 
104
        
 
105
    default:
 
106
        break;
 
107
    }
 
108
    
 
109
    cairo_fill (cr);
 
110
    
 
111
    /* Finish up */
 
112
    cairo_destroy (cr);
 
113
    
 
114
    return 0;
 
115
}
 
116
 
 
117
static void
 
118
gdl_dock_item_button_image_instance_init (
 
119
    GdlDockItemButtonImage *button_image)
 
120
{
 
121
    GTK_WIDGET_SET_FLAGS (button_image, GTK_NO_WINDOW);
 
122
}
 
123
 
 
124
static void
 
125
gdl_dock_item_button_image_size_request (GtkWidget      *widget,
 
126
                                         GtkRequisition *requisition)
 
127
{
 
128
    g_return_if_fail (GDL_IS_DOCK_ITEM_BUTTON_IMAGE (widget));
 
129
    g_return_if_fail (requisition != NULL);
 
130
    
 
131
    requisition->width = ICON_SIZE;
 
132
    requisition->height = ICON_SIZE;
 
133
}
 
134
 
 
135
static void
 
136
gdl_dock_item_button_image_class_init (
 
137
    GdlDockItemButtonImageClass *klass)
 
138
{
 
139
    GObjectClass *gobject_class = G_OBJECT_CLASS (klass);
 
140
    GtkObjectClass *gtk_object_class = GTK_OBJECT_CLASS (klass);
 
141
    GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (klass);
 
142
    
 
143
    parent_class = g_type_class_peek_parent (klass);
 
144
    
 
145
    widget_class->expose_event =
 
146
        gdl_dock_item_button_image_expose;
 
147
    widget_class->size_request =
 
148
        gdl_dock_item_button_image_size_request;
 
149
}
 
150
 
 
151
/* ----- Public interface ----- */
 
152
 
 
153
/**
 
154
 * gdl_dock_item_button_image_new:
 
155
 * @param image_type: Specifies what type of image the widget should
 
156
 * display
 
157
 * 
 
158
 * Creates a new GDL dock button image object.
 
159
 * Returns: The newly created dock item button image widget.
 
160
 **/
 
161
GtkWidget*
 
162
gdl_dock_item_button_image_new (GdlDockItemButtonImageType image_type)
 
163
{
 
164
    GdlDockItemButtonImage *button_image = g_object_new (
 
165
        GDL_TYPE_DOCK_ITEM_BUTTON_IMAGE, NULL);
 
166
    button_image->image_type = image_type;
 
167
 
 
168
    return GTK_WIDGET (button_image);
 
169
}