NetSurf
con_image.c
Go to the documentation of this file.
1/*
2 * Copyright 2006 Richard Wilson <info@tinct.net>
3 *
4 * This file is part of NetSurf, http://www.netsurf-browser.org/
5 *
6 * NetSurf 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; version 2 of the License.
9 *
10 * NetSurf is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program. If not, see <http://www.gnu.org/licenses/>.
17 */
18
19#include <stdbool.h>
20#include <swis.h>
21#include <oslib/osspriteop.h>
22#include <oslib/wimp.h>
23
24#include "utils/nsoption.h"
25#include "utils/log.h"
26#include "utils/utils.h"
27
28#include "riscos/gui.h"
30#include "riscos/dialog.h"
31#include "riscos/menus.h"
32#include "riscos/tinct.h"
33#include "riscos/wimp.h"
34#include "riscos/wimp_event.h"
35
36
37#define IMAGE_FOREGROUND_FIELD 3
38#define IMAGE_FOREGROUND_MENU 4
39#define IMAGE_BACKGROUND_FIELD 6
40#define IMAGE_BACKGROUND_MENU 7
41#define IMAGE_CURRENT_DISPLAY 8
42#define IMAGE_DISABLE_ANIMATION 11
43#define IMAGE_DEFAULT_BUTTON 12
44#define IMAGE_CANCEL_BUTTON 13
45#define IMAGE_OK_BUTTON 14
46
47static bool ro_gui_options_image_click(wimp_pointer *pointer);
48static bool ro_gui_options_image_ok(wimp_w w);
49static void ro_gui_options_image_redraw(wimp_draw *redraw);
50static bool ro_gui_options_image_update(wimp_w w, wimp_i i, wimp_menu *m,
51 wimp_selection *s, menu_action a);
52static void ro_gui_options_image_read(wimp_w w, unsigned int *bg,
53 unsigned int *fg);
54static void ro_gui_options_update_shading(wimp_w w);
55
56static osspriteop_area *example_images;
60
62{
63 int i;
64
65 /* load the sprite file */
66 if (example_users == 0) {
67 char pathname[256];
68 snprintf(pathname, 256, "%s.Resources.Image", NETSURF_DIR);
69 pathname[255] = '\0';
71 if (!example_images)
72 return false;
73 }
75
76 /* set the current values */
77 for (i = 0; (i < 4); i++) {
78 if ((unsigned int)nsoption_int(plot_fg_quality) == tinct_options[i])
80 image_quality_menu->entries[i].
81 data.indirected_text.text, true);
82 if ((unsigned int)nsoption_int(plot_bg_quality) == tinct_options[i])
84 image_quality_menu->entries[i].
85 data.indirected_text.text, true);
86 }
88 !nsoption_bool(animate_images));
90
91 /* register icons */
106 ro_gui_wimp_event_set_help_prefix(w, "HelpImageConfig");
108
109 return true;
110}
111
113{
115 if (example_users == 0) {
116 free(example_images);
117 example_images = NULL;
118 }
120}
121
122bool ro_gui_options_image_update(wimp_w w, wimp_i i, wimp_menu *m,
123 wimp_selection *s, menu_action a)
124{
126
127 return true;
128}
129
130void ro_gui_options_image_redraw(wimp_draw *redraw)
131{
132 osbool more;
133 os_error *error;
134 wimp_icon_state icon_state;
135 osspriteop_header *bg = NULL, *fg = NULL;
136 unsigned int bg_tinct = 0, fg_tinct = 0;
137
138 /* get the icon location */
139 icon_state.w = redraw->w;
140 icon_state.i = IMAGE_CURRENT_DISPLAY;
141 error = xwimp_get_icon_state(&icon_state);
142 if (error) {
143 NSLOG(netsurf, INFO,
144 "xwimp_get_icon_state: 0x%x: %s",
145 error->errnum, error->errmess);
146 ro_warn_user("MenuError", error->errmess);
147 return;
148 }
149
150 /* find the sprites */
151 if (example_images) {
152 ro_gui_options_image_read(redraw->w, &bg_tinct, &fg_tinct);
153 fg_tinct |= 0xeeeeee00;
154 xosspriteop_select_sprite(osspriteop_USER_AREA,
155 example_images, (osspriteop_id)"img_bg", &bg);
156 xosspriteop_select_sprite(osspriteop_USER_AREA,
157 example_images, (osspriteop_id)"img_fg", &fg);
158 }
159
160 /* perform the redraw */
161 more = wimp_redraw_window(redraw);
162 while (more) {
163 int origin_x, origin_y;
164 origin_x = redraw->box.x0 - redraw->xscroll +
165 icon_state.icon.extent.x0 + 2;
166 origin_y = redraw->box.y1 - redraw->yscroll +
167 icon_state.icon.extent.y0 + 2;
168 if (bg)
169 _swix(Tinct_Plot, _INR(2,4) | _IN(7),
170 bg, origin_x, origin_y, bg_tinct);
171 if (fg)
172 _swix(Tinct_PlotAlpha, _INR(2,4) | _IN(7),
173 fg, origin_x, origin_y, fg_tinct);
174 more = wimp_get_rectangle(redraw);
175 }
176}
177
178void ro_gui_options_image_read(wimp_w w, unsigned int *bg, unsigned int *fg)
179{
180 const char *text;
181 int i;
182
184 for (i = 0; i < 4; i++)
185 if (!strcmp(text, image_quality_menu->entries[i].
186 data.indirected_text.text))
187 *fg = tinct_options[i];
188
190 for (i = 0; i < 4; i++)
191 if (!strcmp(text, image_quality_menu->entries[i].
192 data.indirected_text.text))
193 *bg = tinct_options[i];
194}
195
196bool ro_gui_options_image_click(wimp_pointer *pointer)
197{
198 unsigned int old_fg, old_bg, bg, fg;
199
200 ro_gui_options_image_read(pointer->w, &old_bg, &old_fg);
201 switch (pointer->i) {
203 ro_gui_set_icon_string(pointer->w,
205 image_quality_menu->entries[3].
206 data.indirected_text.text, true);
207 ro_gui_set_icon_string(pointer->w,
209 image_quality_menu->entries[2].
210 data.indirected_text.text, true);
216 break;
218 ro_gui_wimp_event_restore(pointer->w);
219 break;
220 default:
221 return false;
222 }
223
224 ro_gui_options_image_read(pointer->w, &bg, &fg);
225 if ((bg != old_bg) || (fg != old_fg))
226 ro_gui_options_image_update(pointer->w, pointer->i,
227 NULL, NULL, NO_ACTION);
228
229 return false;
230}
231
233{
234 bool shaded;
235
237}
238
240{
242 (unsigned int *)&nsoption_int(plot_bg_quality),
243 (unsigned int *)&nsoption_int(plot_fg_quality));
244
245 nsoption_set_bool(animate_images,
249
250 return true;
251}
menu_action
Definition: scaffolding.h:77
void ro_gui_options_image_finalise(wimp_w w)
Definition: con_image.c:112
static void ro_gui_options_image_read(wimp_w w, unsigned int *bg, unsigned int *fg)
Definition: con_image.c:178
unsigned int tinct_options[]
Definition: con_image.c:58
int example_users
Definition: con_image.c:57
static bool ro_gui_options_image_ok(wimp_w w)
Definition: con_image.c:239
#define IMAGE_CANCEL_BUTTON
Definition: con_image.c:44
static bool ro_gui_options_image_update(wimp_w w, wimp_i i, wimp_menu *m, wimp_selection *s, menu_action a)
Definition: con_image.c:122
#define IMAGE_CURRENT_DISPLAY
Definition: con_image.c:41
static void ro_gui_options_update_shading(wimp_w w)
Definition: con_image.c:232
#define IMAGE_DISABLE_ANIMATION
Definition: con_image.c:42
#define IMAGE_DEFAULT_BUTTON
Definition: con_image.c:43
#define IMAGE_OK_BUTTON
Definition: con_image.c:45
bool ro_gui_options_image_initialise(wimp_w w)
Definition: con_image.c:61
#define IMAGE_FOREGROUND_FIELD
Definition: con_image.c:37
static osspriteop_area * example_images
Definition: con_image.c:56
static bool ro_gui_options_image_click(wimp_pointer *pointer)
Definition: con_image.c:196
#define IMAGE_BACKGROUND_FIELD
Definition: con_image.c:39
#define IMAGE_FOREGROUND_MENU
Definition: con_image.c:38
#define IMAGE_BACKGROUND_MENU
Definition: con_image.c:40
static void ro_gui_options_image_redraw(wimp_draw *redraw)
Definition: con_image.c:130
Automated RISC OS WIMP event handling (interface).
void ro_gui_save_options(void)
Save the current options.
Definition: dialog.c:670
#define NO_ACTION
Definition: idna.c:695
#define NSLOG(catname, level, logmsg, args...)
Definition: log.h:116
wimp_menu * image_quality_menu
The available menus.
Definition: menus.c:104
const char * NETSURF_DIR
Definition: gui.c:110
nserror ro_warn_user(const char *warning, const char *detail)
Display a warning for a serious problem (eg memory exhaustion).
Definition: gui.c:2077
Tinct SWI numbers and flags for version 0.11.
#define tinct_ERROR_DIFFUSE
Definition: tinct.h:136
#define tinct_DITHER
Definition: tinct.h:135
#define tinct_USE_OS_SPRITE_OP
Definition: tinct.h:141
#define Tinct_PlotAlpha
Plots an alpha-blended sprite at the specified coordinates.
Definition: tinct.h:39
#define Tinct_Plot
Plots a sprite at the specified coordinates with a constant 0xff value for the alpha channel,...
Definition: tinct.h:64
Option reading and saving interface.
#define nsoption_int(OPTION)
Get the value of an integer option.
Definition: nsoption.h:313
#define nsoption_set_bool(OPTION, VALUE)
set a boolean option in the default table
Definition: nsoption.h:344
#define nsoption_bool(OPTION)
Get the value of a boolean option.
Definition: nsoption.h:304
Interface to a number of general purpose functionality.
#define fallthrough
switch fall through
Definition: utils.h:119
void ro_gui_set_icon_string(wimp_w w, wimp_i i, const char *text, bool is_utf8)
Set the contents of a text or sprite icon to a string.
Definition: wimp.c:269
osspriteop_area * ro_gui_load_sprite_file(const char *pathname)
Load a sprite file into memory.
Definition: wimp.c:806
const char * ro_gui_get_icon_string(wimp_w w, wimp_i i)
Read the contents of a text or sprite icon.
Definition: wimp.c:235
void ro_gui_set_icon_selected_state(wimp_w w, wimp_i i, bool state)
Set the selected state of an icon.
Definition: wimp.c:444
#define ro_gui_redraw_icon(w, i)
Redraws an icon.
Definition: wimp.c:184
bool ro_gui_get_icon_selected_state(wimp_w w, wimp_i i)
Gets the selected state of an icon.
Definition: wimp.c:463
General RISC OS WIMP/OS library functions (interface).
bool ro_gui_wimp_event_set_help_prefix(wimp_w w, const char *help_prefix)
Set the associated help prefix for a given window.
Definition: wimp_event.c:390
bool ro_gui_wimp_event_register_redraw_window(wimp_w w, void(*callback)(wimp_draw *redraw))
Register a function to be called for all window redraw operations.
Definition: wimp_event.c:1507
bool ro_gui_wimp_event_register_menu_gright(wimp_w w, wimp_i i, wimp_i gright, wimp_menu *menu)
Register an icon menu to be automatically handled.
Definition: wimp_event.c:1331
void ro_gui_wimp_event_finalise(wimp_w w)
Free any resources associated with a window.
Definition: wimp_event.c:296
bool ro_gui_wimp_event_register_cancel(wimp_w w, wimp_i i)
Register a function to be called for the Cancel action on a window.
Definition: wimp_event.c:1403
bool ro_gui_wimp_event_memorise(wimp_w w)
Memorises the current state of any registered components in a window.
Definition: wimp_event.c:139
bool ro_gui_wimp_event_register_menu_selection(wimp_w w, bool(*callback)(wimp_w w, wimp_i i, wimp_menu *m, wimp_selection *s, menu_action a))
Register a function to be called following a menu selection.
Definition: wimp_event.c:1581
bool ro_gui_wimp_event_register_mouse_click(wimp_w w, bool(*callback)(wimp_pointer *pointer))
Register a function to be called for all mouse-clicks to icons in a window that don't have registered...
Definition: wimp_event.c:1439
bool ro_gui_wimp_event_register_checkbox(wimp_w w, wimp_i i)
Register a checkbox to be automatically handled.
Definition: wimp_event.c:1349
bool ro_gui_wimp_event_restore(wimp_w w)
Restore the state of any registered components in a window to their memorised state.
Definition: wimp_event.c:186
bool ro_gui_wimp_event_register_ok(wimp_w w, wimp_i i, bool(*callback)(wimp_w w))
Register a function to be called for the OK action on a window.
Definition: wimp_event.c:1417
Automated RISC OS WIMP event handling (interface).
static nserror text(const struct redraw_context *ctx, const struct plot_font_style *fstyle, int x, int y, const char *text, size_t length)
Text plotting.
Definition: plot.c:978