aboutsummaryrefslogtreecommitdiffstats
path: root/src/lib/ecore_x/ecore_x_gc.c
blob: 6b8168bb3b0b5232fd40aa5ff1d3dfd9af309758 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
#ifdef HAVE_CONFIG_H
# include <config.h>
#endif /* ifdef HAVE_CONFIG_H */

#include <string.h>

#include "Ecore.h"
#include "ecore_x_private.h"
#include "Ecore_X.h"

/**
 * Creates a new default graphics context associated with the given
 * drawable.
 * @param  draw Drawable to create graphics context with.  If @c 0 is
 *              given instead, the default root window is used.
 * @param value_mask Bitmask values.
 * @param value_list List of values. The order of values must be the
 *                   same than the corresponding bitmaks.
 * @return The new default graphics context.
 */
EAPI Ecore_X_GC
ecore_x_gc_new(Ecore_X_Drawable draw,
               Ecore_X_GC_Value_Mask value_mask,
               const unsigned int *value_list)
{
   Ecore_X_GC gc;
   XGCValues gcv;
   int mask;
   int idx;
   int i;

   LOGFN(__FILE__, __LINE__, __FUNCTION__);
   if (!draw)
     draw = DefaultRootWindow(_ecore_x_disp);

   memset(&gcv, 0, sizeof (gcv));

   for (i = 0, idx = 0, mask = 1; i <= 22; i++, mask <<= 1)
     {
        switch (mask & value_mask)
          {
           case ECORE_X_GC_VALUE_MASK_FUNCTION:
             gcv.function = value_list[idx];
             idx++;
             break;

           case ECORE_X_GC_VALUE_MASK_PLANE_MASK:
             gcv.plane_mask = value_list[idx];
             idx++;
             break;

           case ECORE_X_GC_VALUE_MASK_FOREGROUND:
             gcv.foreground = value_list[idx];
             idx++;
             break;

           case ECORE_X_GC_VALUE_MASK_BACKGROUND:
             gcv.background = value_list[idx];
             idx++;
             break;

           case ECORE_X_GC_VALUE_MASK_LINE_WIDTH:
             gcv.line_width = value_list[idx];
             idx++;
             break;

           case ECORE_X_GC_VALUE_MASK_LINE_STYLE:
             gcv.line_style = value_list[idx];
             idx++;
             break;

           case ECORE_X_GC_VALUE_MASK_CAP_STYLE:
             gcv.cap_style = value_list[idx];
             idx++;
             break;

           case ECORE_X_GC_VALUE_MASK_JOIN_STYLE:
             gcv.join_style = value_list[idx];
             idx++;
             break;

           case ECORE_X_GC_VALUE_MASK_FILL_STYLE:
             gcv.fill_style = value_list[idx];
             idx++;
             break;

           case ECORE_X_GC_VALUE_MASK_FILL_RULE:
             gcv.fill_rule = value_list[idx];
             idx++;
             break;

           case ECORE_X_GC_VALUE_MASK_TILE:
             gcv.tile = value_list[idx];
             idx++;
             break;

           case ECORE_X_GC_VALUE_MASK_STIPPLE:
             gcv.stipple = value_list[idx];
             idx++;
             break;

           case ECORE_X_GC_VALUE_MASK_TILE_STIPPLE_ORIGIN_X:
             gcv.ts_x_origin = value_list[idx];
             idx++;
             break;

           case ECORE_X_GC_VALUE_MASK_TILE_STIPPLE_ORIGIN_Y:
             gcv.ts_y_origin = value_list[idx];
             idx++;
             break;

           case ECORE_X_GC_VALUE_MASK_FONT:
             gcv.font = value_list[idx];
             idx++;
             break;

           case ECORE_X_GC_VALUE_MASK_SUBWINDOW_MODE:
             gcv.subwindow_mode = value_list[idx];
             idx++;
             break;

           case ECORE_X_GC_VALUE_MASK_GRAPHICS_EXPOSURES:
             gcv.graphics_exposures = value_list[idx];
             idx++;
             break;

           case ECORE_X_GC_VALUE_MASK_CLIP_ORIGIN_X:
             gcv.clip_x_origin = value_list[idx];
             idx++;
             break;

           case ECORE_X_GC_VALUE_MASK_CLIP_ORIGIN_Y:
             gcv.clip_y_origin = value_list[idx];
             idx++;
             break;

           case ECORE_X_GC_VALUE_MASK_CLIP_MASK:
             gcv.clip_mask = value_list[idx];
             idx++;
             break;

           case ECORE_X_GC_VALUE_MASK_DASH_OFFSET:
             gcv.dash_offset = value_list[idx];
             idx++;
             break;

           case ECORE_X_GC_VALUE_MASK_DASH_LIST:
             gcv.dashes = value_list[idx];
             idx++;
             break;

           case ECORE_X_GC_VALUE_MASK_ARC_MODE:
             gcv.arc_mode = value_list[idx];
             idx++;
             break;
          }
     }

   gc = XCreateGC(_ecore_x_disp, draw, value_mask, &gcv);
   if (_ecore_xlib_sync) ecore_x_sync();
   return gc;
}

/**
 * Deletes and frees the given graphics context.
 * @param gc The given graphics context.
 */
EAPI void
ecore_x_gc_free(Ecore_X_GC gc)
{
   LOGFN(__FILE__, __LINE__, __FUNCTION__);
   XFreeGC(_ecore_x_disp, gc);
   if (_ecore_xlib_sync) ecore_x_sync();
}