~hamo/ubuntu/precise/grub2/grub2.hi_res

« back to all changes in this revision

Viewing changes to grub-core/gfxmenu/gui_circular_progress.c

  • Committer: Bazaar Package Importer
  • Author(s): Colin Watson, Colin Watson, Robert Millan, Updated translations
  • Date: 2010-11-22 12:24:56 UTC
  • mfrom: (1.26.4 upstream) (17.3.36 sid)
  • mto: (17.3.43 sid)
  • mto: This revision was merged to the branch mainline in revision 89.
  • Revision ID: james.westby@ubuntu.com-20101122122456-y82z3sfb7k4zfdcc
Tags: 1.99~20101122-1
[ Colin Watson ]
* New Bazaar snapshot.  Too many changes to list in full, but some of the
  more user-visible ones are as follows:
  - GRUB script:
    + Function parameters, "break", "continue", "shift", "setparams",
      "return", and "!".
    + "export" command supports multiple variable names.
    + Multi-line quoted strings support.
    + Wildcard expansion.
  - sendkey support.
  - USB hotunplugging and USB serial support.
  - Rename CD-ROM to cd on BIOS.
  - Add new --boot-directory option to grub-install, grub-reboot, and
    grub-set-default; the old --root-directory option is still accepted
    but was often confusing.
  - Basic btrfs detection/UUID support (but no file reading yet).
  - bash-completion for utilities.
  - If a device is listed in device.map, always assume that it is
    BIOS-visible rather than using extra layers such as LVM or RAID.
  - Add grub-mknetdir script (closes: #550658).
  - Remove deprecated "root" command.
  - Handle RAID devices containing virtio components.
  - GRUB Legacy configuration file support (via grub-menulst2cfg).
  - Keyboard layout support (via grub-mklayout and grub-kbdcomp).
  - Check generated grub.cfg for syntax errors before saving.
  - Pause execution for at most ten seconds if any errors are displayed,
    so that the user has a chance to see them.
  - Support submenus.
  - Write embedding zone using Reed-Solomon, so that it's robust against
    being partially overwritten (closes: #550702, #591416, #593347).
  - GRUB_DISABLE_LINUX_RECOVERY and GRUB_DISABLE_NETBSD_RECOVERY merged
    into a single GRUB_DISABLE_RECOVERY variable.
  - Fix loader memory allocation failure (closes: #551627).
  - Don't call savedefault on recovery entries (closes: #589325).
  - Support triple-indirect blocks on ext2 (closes: #543924).
  - Recognise DDF1 fake RAID (closes: #603354).

[ Robert Millan ]
* Use dpkg architecture wildcards.

[ Updated translations ]
* Slovenian (Vanja Cvelbar).  Closes: #604003
* Dzongkha (dawa pemo via Tenzin Dendup).  Closes: #604102

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/* gui_circular_process.c - GUI circular progress indicator component.  */
 
2
/*
 
3
 *  GRUB  --  GRand Unified Bootloader
 
4
 *  Copyright (C) 2008,2009  Free Software Foundation, Inc.
 
5
 *
 
6
 *  GRUB is free software: you can redistribute it and/or modify
 
7
 *  it under the terms of the GNU General Public License as published by
 
8
 *  the Free Software Foundation, either version 3 of the License, or
 
9
 *  (at your option) any later version.
 
10
 *
 
11
 *  GRUB is distributed in the hope that it will be useful,
 
12
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 
13
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
14
 *  GNU General Public License for more details.
 
15
 *
 
16
 *  You should have received a copy of the GNU General Public License
 
17
 *  along with GRUB.  If not, see <http://www.gnu.org/licenses/>.
 
18
 */
 
19
 
 
20
#include <grub/mm.h>
 
21
#include <grub/misc.h>
 
22
#include <grub/gui.h>
 
23
#include <grub/font.h>
 
24
#include <grub/gui_string_util.h>
 
25
#include <grub/gfxmenu_view.h>
 
26
#include <grub/gfxwidgets.h>
 
27
#include <grub/trig.h>
 
28
 
 
29
struct grub_gui_circular_progress
 
30
{
 
31
  struct grub_gui_progress progress;
 
32
 
 
33
  grub_gui_container_t parent;
 
34
  grub_video_rect_t bounds;
 
35
  char *id;
 
36
  int visible;
 
37
  int start;
 
38
  int end;
 
39
  int value;
 
40
  int num_ticks;
 
41
  int start_angle;
 
42
  int ticks_disappear;
 
43
  char *theme_dir;
 
44
  int need_to_load_pixmaps;
 
45
  char *center_file;
 
46
  char *tick_file;
 
47
  struct grub_video_bitmap *center_bitmap;
 
48
  struct grub_video_bitmap *tick_bitmap;
 
49
};
 
50
 
 
51
typedef struct grub_gui_circular_progress *circular_progress_t;
 
52
 
 
53
static void
 
54
circprog_destroy (void *vself)
 
55
{
 
56
  circular_progress_t self = vself;
 
57
  grub_gfxmenu_timeout_unregister ((grub_gui_component_t) self);
 
58
  grub_free (self);
 
59
}
 
60
 
 
61
static const char *
 
62
circprog_get_id (void *vself)
 
63
{
 
64
  circular_progress_t self = vself;
 
65
  return self->id;
 
66
}
 
67
 
 
68
static int
 
69
circprog_is_instance (void *vself __attribute__((unused)), const char *type)
 
70
{
 
71
  return grub_strcmp (type, "component") == 0;
 
72
}
 
73
 
 
74
static struct grub_video_bitmap *
 
75
load_bitmap (const char *dir, const char *file)
 
76
{
 
77
  struct grub_video_bitmap *bitmap;
 
78
  char *abspath;
 
79
 
 
80
  /* Check arguments.  */
 
81
  if (! dir || ! file)
 
82
    return 0;
 
83
 
 
84
  /* Resolve to an absolute path.  */
 
85
  abspath = grub_resolve_relative_path (dir, file);
 
86
  if (! abspath)
 
87
    return 0;
 
88
 
 
89
  /* Load the image.  */
 
90
  grub_errno = GRUB_ERR_NONE;
 
91
  grub_video_bitmap_load (&bitmap, abspath);
 
92
  grub_errno = GRUB_ERR_NONE;
 
93
 
 
94
  grub_free (abspath);
 
95
  return bitmap;
 
96
}
 
97
 
 
98
static int
 
99
check_pixmaps (circular_progress_t self)
 
100
{
 
101
  if (self->need_to_load_pixmaps)
 
102
    {
 
103
      if (self->center_bitmap)
 
104
        grub_video_bitmap_destroy (self->center_bitmap);
 
105
      self->center_bitmap = load_bitmap (self->theme_dir, self->center_file);
 
106
      self->tick_bitmap = load_bitmap (self->theme_dir, self->tick_file);
 
107
      self->need_to_load_pixmaps = 0;
 
108
    }
 
109
 
 
110
  return (self->center_bitmap != 0 && self->tick_bitmap != 0);
 
111
}
 
112
 
 
113
static void
 
114
circprog_paint (void *vself, const grub_video_rect_t *region)
 
115
{
 
116
  circular_progress_t self = vself;
 
117
 
 
118
  if (! self->visible)
 
119
    return;
 
120
 
 
121
  if (!grub_video_have_common_points (region, &self->bounds))
 
122
    return;
 
123
 
 
124
  if (! check_pixmaps (self))
 
125
    return;
 
126
 
 
127
  grub_video_rect_t vpsave;
 
128
  grub_gui_set_viewport (&self->bounds, &vpsave);
 
129
 
 
130
  int width = self->bounds.width;
 
131
  int height = self->bounds.height;
 
132
  int center_width = grub_video_bitmap_get_width (self->center_bitmap);
 
133
  int center_height = grub_video_bitmap_get_height (self->center_bitmap);
 
134
  int tick_width = grub_video_bitmap_get_width (self->tick_bitmap);
 
135
  int tick_height = grub_video_bitmap_get_height (self->tick_bitmap);
 
136
  grub_video_blit_bitmap (self->center_bitmap, GRUB_VIDEO_BLIT_BLEND,
 
137
                          (width - center_width) / 2,
 
138
                          (height - center_height) / 2, 0, 0,
 
139
                          center_width, center_height);
 
140
 
 
141
  int radius = width / 2 - tick_width / 2 - 1;
 
142
  int nticks;
 
143
  int tick_begin;
 
144
  int tick_end;
 
145
  if (self->end == self->start)
 
146
    nticks = 0;
 
147
  else
 
148
    nticks = (self->num_ticks
 
149
              * (self->value - self->start)
 
150
              / (self->end - self->start));
 
151
  /* Do ticks appear or disappear as the value approached the end?  */
 
152
  if (self->ticks_disappear)
 
153
    {
 
154
      tick_begin = nticks;
 
155
      tick_end = self->num_ticks - 1;
 
156
    }
 
157
  else
 
158
    {
 
159
      tick_begin = 0;
 
160
      tick_end = nticks - 1;
 
161
    }
 
162
 
 
163
  int i;
 
164
  for (i = tick_begin; i < tick_end; i++)
 
165
    {
 
166
       int x;
 
167
       int y;
 
168
       int angle;
 
169
 
 
170
       /* Calculate the location of the tick.  */
 
171
       angle = self->start_angle + i * GRUB_TRIG_ANGLE_MAX / self->num_ticks;
 
172
       x = width / 2 + (grub_cos (angle) * radius / GRUB_TRIG_FRACTION_SCALE);
 
173
       y = height / 2 + (grub_sin (angle) * radius / GRUB_TRIG_FRACTION_SCALE);
 
174
 
 
175
       /* Adjust (x,y) so the tick is centered.  */
 
176
       x -= tick_width / 2;
 
177
       y -= tick_height / 2;
 
178
 
 
179
       /* Draw the tick.  */
 
180
       grub_video_blit_bitmap (self->tick_bitmap, GRUB_VIDEO_BLIT_BLEND,
 
181
                               x, y, 0, 0, tick_width, tick_height);
 
182
    }
 
183
 
 
184
  grub_gui_restore_viewport (&vpsave);
 
185
}
 
186
 
 
187
static void
 
188
circprog_set_parent (void *vself, grub_gui_container_t parent)
 
189
{
 
190
  circular_progress_t self = vself;
 
191
  self->parent = parent;
 
192
}
 
193
 
 
194
static grub_gui_container_t
 
195
circprog_get_parent (void *vself)
 
196
{
 
197
  circular_progress_t self = vself;
 
198
  return self->parent;
 
199
}
 
200
 
 
201
static void
 
202
circprog_set_bounds (void *vself, const grub_video_rect_t *bounds)
 
203
{
 
204
  circular_progress_t self = vself;
 
205
  self->bounds = *bounds;
 
206
}
 
207
 
 
208
static void
 
209
circprog_get_bounds (void *vself, grub_video_rect_t *bounds)
 
210
{
 
211
  circular_progress_t self = vself;
 
212
  *bounds = self->bounds;
 
213
}
 
214
 
 
215
static void
 
216
circprog_set_state (void *vself, int visible, int start,
 
217
                    int current, int end)
 
218
{
 
219
  circular_progress_t self = vself;  
 
220
  self->visible = visible;
 
221
  self->start = start;
 
222
  self->value = current;
 
223
  self->end = end;
 
224
}
 
225
 
 
226
static grub_err_t
 
227
circprog_set_property (void *vself, const char *name, const char *value)
 
228
{
 
229
  circular_progress_t self = vself;
 
230
  if (grub_strcmp (name, "num_ticks") == 0)
 
231
    {
 
232
      self->num_ticks = grub_strtol (value, 0, 10);
 
233
    }
 
234
  else if (grub_strcmp (name, "start_angle") == 0)
 
235
    {
 
236
      self->start_angle = grub_strtol (value, 0, 10);
 
237
    }
 
238
  else if (grub_strcmp (name, "ticks_disappear") == 0)
 
239
    {
 
240
      self->ticks_disappear = grub_strcmp (value, "false") != 0;
 
241
    }
 
242
  else if (grub_strcmp (name, "center_bitmap") == 0)
 
243
    {
 
244
      self->need_to_load_pixmaps = 1;
 
245
      grub_free (self->center_file);
 
246
      self->center_file = value ? grub_strdup (value) : 0;
 
247
    }
 
248
  else if (grub_strcmp (name, "tick_bitmap") == 0)
 
249
    {
 
250
      self->need_to_load_pixmaps = 1;
 
251
      grub_free (self->tick_file);
 
252
      self->tick_file = value ? grub_strdup (value) : 0;
 
253
    }
 
254
  else if (grub_strcmp (name, "theme_dir") == 0)
 
255
    {
 
256
      self->need_to_load_pixmaps = 1;
 
257
      grub_free (self->theme_dir);
 
258
      self->theme_dir = value ? grub_strdup (value) : 0;
 
259
    }
 
260
  else if (grub_strcmp (name, "id") == 0)
 
261
    {
 
262
      grub_gfxmenu_timeout_unregister ((grub_gui_component_t) self);
 
263
      grub_free (self->id);
 
264
      if (value)
 
265
        self->id = grub_strdup (value);
 
266
      else
 
267
        self->id = 0;
 
268
      if (self->id && grub_strcmp (self->id, GRUB_GFXMENU_TIMEOUT_COMPONENT_ID)
 
269
          == 0)
 
270
        grub_gfxmenu_timeout_register ((grub_gui_component_t) self,
 
271
                                       circprog_set_state);
 
272
    }
 
273
  return grub_errno;
 
274
}
 
275
 
 
276
static struct grub_gui_component_ops circprog_ops =
 
277
{
 
278
  .destroy = circprog_destroy,
 
279
  .get_id = circprog_get_id,
 
280
  .is_instance = circprog_is_instance,
 
281
  .paint = circprog_paint,
 
282
  .set_parent = circprog_set_parent,
 
283
  .get_parent = circprog_get_parent,
 
284
  .set_bounds = circprog_set_bounds,
 
285
  .get_bounds = circprog_get_bounds,
 
286
  .set_property = circprog_set_property
 
287
};
 
288
 
 
289
static struct grub_gui_progress_ops circprog_prog_ops =
 
290
  {
 
291
    .set_state = circprog_set_state
 
292
  };
 
293
 
 
294
grub_gui_component_t
 
295
grub_gui_circular_progress_new (void)
 
296
{
 
297
  circular_progress_t self;
 
298
  self = grub_zalloc (sizeof (*self));
 
299
  if (! self)
 
300
    return 0;
 
301
  self->progress.ops = &circprog_prog_ops;
 
302
  self->progress.component.ops = &circprog_ops;
 
303
  self->visible = 1;
 
304
  self->num_ticks = 64;
 
305
  self->start_angle = -64;
 
306
 
 
307
  return (grub_gui_component_t) self;
 
308
}