2006-01-02 08:21:23 +03:00
|
|
|
/*
|
|
|
|
* Copyright 2006 Richard Wilson <info@tinct.net>
|
2007-08-08 20:16:03 +04:00
|
|
|
*
|
|
|
|
* This file is part of NetSurf, http://www.netsurf-browser.org/
|
|
|
|
*
|
|
|
|
* NetSurf is free software; you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation; version 2 of the License.
|
|
|
|
*
|
|
|
|
* NetSurf is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
2006-01-02 08:21:23 +03:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include <stdbool.h>
|
2014-06-06 02:01:37 +04:00
|
|
|
#include <swis.h>
|
|
|
|
#include <oslib/osspriteop.h>
|
|
|
|
#include <oslib/wimp.h>
|
|
|
|
|
2013-05-26 01:46:27 +04:00
|
|
|
#include "utils/nsoption.h"
|
2014-06-06 02:01:37 +04:00
|
|
|
#include "utils/log.h"
|
|
|
|
|
|
|
|
#include "riscos/gui.h"
|
2007-05-31 02:39:54 +04:00
|
|
|
#include "riscos/configure/configure.h"
|
|
|
|
#include "riscos/dialog.h"
|
|
|
|
#include "riscos/menus.h"
|
|
|
|
#include "riscos/tinct.h"
|
|
|
|
#include "riscos/wimp.h"
|
|
|
|
#include "riscos/wimp_event.h"
|
2006-01-02 08:21:23 +03:00
|
|
|
|
|
|
|
|
|
|
|
#define IMAGE_FOREGROUND_FIELD 3
|
|
|
|
#define IMAGE_FOREGROUND_MENU 4
|
|
|
|
#define IMAGE_BACKGROUND_FIELD 6
|
|
|
|
#define IMAGE_BACKGROUND_MENU 7
|
|
|
|
#define IMAGE_CURRENT_DISPLAY 8
|
2006-01-03 04:40:32 +03:00
|
|
|
#define IMAGE_SPEED_TEXT 11
|
|
|
|
#define IMAGE_SPEED_FIELD 12
|
|
|
|
#define IMAGE_SPEED_DEC 13
|
|
|
|
#define IMAGE_SPEED_INC 14
|
|
|
|
#define IMAGE_SPEED_CS 15
|
|
|
|
#define IMAGE_DISABLE_ANIMATION 16
|
|
|
|
#define IMAGE_DEFAULT_BUTTON 17
|
|
|
|
#define IMAGE_CANCEL_BUTTON 18
|
|
|
|
#define IMAGE_OK_BUTTON 19
|
2006-01-02 08:21:23 +03:00
|
|
|
|
2006-01-02 08:33:53 +03:00
|
|
|
static bool ro_gui_options_image_click(wimp_pointer *pointer);
|
2006-01-02 08:21:23 +03:00
|
|
|
static bool ro_gui_options_image_ok(wimp_w w);
|
|
|
|
static void ro_gui_options_image_redraw(wimp_draw *redraw);
|
2011-02-21 02:16:33 +03:00
|
|
|
static bool ro_gui_options_image_update(wimp_w w, wimp_i i, wimp_menu *m,
|
|
|
|
wimp_selection *s, menu_action a);
|
|
|
|
static void ro_gui_options_image_read(wimp_w w, unsigned int *bg,
|
2009-03-27 05:32:26 +03:00
|
|
|
unsigned int *fg);
|
2006-01-03 04:40:32 +03:00
|
|
|
static void ro_gui_options_update_shading(wimp_w w);
|
2006-01-02 08:21:23 +03:00
|
|
|
|
|
|
|
static osspriteop_area *example_images;
|
|
|
|
int example_users = 0;
|
|
|
|
unsigned int tinct_options[] = {tinct_USE_OS_SPRITE_OP, 0, tinct_DITHER,
|
|
|
|
tinct_ERROR_DIFFUSE};
|
|
|
|
|
2008-07-27 02:29:15 +04:00
|
|
|
bool ro_gui_options_image_initialise(wimp_w w)
|
|
|
|
{
|
2006-01-02 08:21:23 +03:00
|
|
|
int i;
|
|
|
|
|
|
|
|
/* load the sprite file */
|
|
|
|
if (example_users == 0) {
|
2014-05-26 13:02:30 +04:00
|
|
|
char pathname[256];
|
2006-01-02 08:21:23 +03:00
|
|
|
snprintf(pathname, 256, "%s.Resources.Image", NETSURF_DIR);
|
|
|
|
pathname[255] = '\0';
|
|
|
|
example_images = ro_gui_load_sprite_file(pathname);
|
|
|
|
if (!example_images)
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
example_users++;
|
|
|
|
|
|
|
|
/* set the current values */
|
|
|
|
for (i = 0; (i < 4); i++) {
|
2013-05-28 19:44:46 +04:00
|
|
|
if ((unsigned int)nsoption_int(plot_fg_quality) == tinct_options[i])
|
2006-01-02 08:21:23 +03:00
|
|
|
ro_gui_set_icon_string(w, IMAGE_FOREGROUND_FIELD,
|
|
|
|
image_quality_menu->entries[i].
|
2008-08-05 05:32:15 +04:00
|
|
|
data.indirected_text.text, true);
|
2013-05-28 19:44:46 +04:00
|
|
|
if ((unsigned int)nsoption_int(plot_bg_quality) == tinct_options[i])
|
2006-01-02 08:21:23 +03:00
|
|
|
ro_gui_set_icon_string(w, IMAGE_BACKGROUND_FIELD,
|
|
|
|
image_quality_menu->entries[i].
|
2008-08-05 05:32:15 +04:00
|
|
|
data.indirected_text.text, true);
|
2006-01-02 08:21:23 +03:00
|
|
|
}
|
2011-02-21 02:16:33 +03:00
|
|
|
ro_gui_set_icon_decimal(w, IMAGE_SPEED_FIELD,
|
2012-03-22 13:34:34 +04:00
|
|
|
nsoption_int(minimum_gif_delay), 2);
|
2006-01-03 04:40:32 +03:00
|
|
|
ro_gui_set_icon_selected_state(w, IMAGE_DISABLE_ANIMATION,
|
2012-03-22 13:34:34 +04:00
|
|
|
!nsoption_bool(animate_images));
|
2006-01-03 04:40:32 +03:00
|
|
|
ro_gui_options_update_shading(w);
|
2006-01-02 08:21:23 +03:00
|
|
|
|
|
|
|
/* register icons */
|
|
|
|
ro_gui_wimp_event_register_menu_gright(w, IMAGE_FOREGROUND_FIELD,
|
|
|
|
IMAGE_FOREGROUND_MENU, image_quality_menu);
|
|
|
|
ro_gui_wimp_event_register_menu_gright(w, IMAGE_BACKGROUND_FIELD,
|
|
|
|
IMAGE_BACKGROUND_MENU, image_quality_menu);
|
2006-01-03 04:40:32 +03:00
|
|
|
ro_gui_wimp_event_register_text_field(w, IMAGE_SPEED_TEXT);
|
|
|
|
ro_gui_wimp_event_register_numeric_field(w, IMAGE_SPEED_FIELD,
|
|
|
|
IMAGE_SPEED_INC, IMAGE_SPEED_DEC, 0, 6000, 10, 2);
|
|
|
|
ro_gui_wimp_event_register_checkbox(w, IMAGE_DISABLE_ANIMATION);
|
|
|
|
ro_gui_wimp_event_register_text_field(w, IMAGE_SPEED_CS);
|
2006-01-02 08:21:23 +03:00
|
|
|
ro_gui_wimp_event_register_redraw_window(w,
|
|
|
|
ro_gui_options_image_redraw);
|
2006-01-02 08:33:53 +03:00
|
|
|
ro_gui_wimp_event_register_mouse_click(w,
|
|
|
|
ro_gui_options_image_click);
|
2006-01-02 08:21:23 +03:00
|
|
|
ro_gui_wimp_event_register_menu_selection(w,
|
|
|
|
ro_gui_options_image_update);
|
|
|
|
ro_gui_wimp_event_register_cancel(w, IMAGE_CANCEL_BUTTON);
|
|
|
|
ro_gui_wimp_event_register_ok(w, IMAGE_OK_BUTTON,
|
|
|
|
ro_gui_options_image_ok);
|
|
|
|
ro_gui_wimp_event_set_help_prefix(w, "HelpImageConfig");
|
|
|
|
ro_gui_wimp_event_memorise(w);
|
|
|
|
|
2009-03-27 05:32:26 +03:00
|
|
|
return true;
|
2006-01-02 08:21:23 +03:00
|
|
|
}
|
|
|
|
|
2008-07-27 02:29:15 +04:00
|
|
|
void ro_gui_options_image_finalise(wimp_w w)
|
|
|
|
{
|
2006-01-02 08:21:23 +03:00
|
|
|
example_users--;
|
|
|
|
if (example_users == 0) {
|
|
|
|
free(example_images);
|
|
|
|
example_images = NULL;
|
|
|
|
}
|
|
|
|
ro_gui_wimp_event_finalise(w);
|
|
|
|
}
|
|
|
|
|
2011-02-21 02:16:33 +03:00
|
|
|
bool ro_gui_options_image_update(wimp_w w, wimp_i i, wimp_menu *m,
|
|
|
|
wimp_selection *s, menu_action a)
|
2008-07-27 02:29:15 +04:00
|
|
|
{
|
2006-01-02 18:58:34 +03:00
|
|
|
ro_gui_redraw_icon(w, IMAGE_CURRENT_DISPLAY);
|
2011-02-21 02:16:33 +03:00
|
|
|
|
|
|
|
return true;
|
2006-01-02 08:21:23 +03:00
|
|
|
}
|
|
|
|
|
2008-07-27 02:29:15 +04:00
|
|
|
void ro_gui_options_image_redraw(wimp_draw *redraw)
|
|
|
|
{
|
2006-01-02 08:21:23 +03:00
|
|
|
osbool more;
|
|
|
|
os_error *error;
|
|
|
|
wimp_icon_state icon_state;
|
|
|
|
osspriteop_header *bg = NULL, *fg = NULL;
|
|
|
|
unsigned int bg_tinct = 0, fg_tinct = 0;
|
|
|
|
|
|
|
|
/* get the icon location */
|
|
|
|
icon_state.w = redraw->w;
|
|
|
|
icon_state.i = IMAGE_CURRENT_DISPLAY;
|
|
|
|
error = xwimp_get_icon_state(&icon_state);
|
|
|
|
if (error) {
|
2015-05-28 19:06:18 +03:00
|
|
|
LOG("xwimp_get_icon_state: 0x%x: %s",
|
|
|
|
error->errnum, error->errmess);
|
2016-04-26 17:16:33 +03:00
|
|
|
ro_warn_user("MenuError", error->errmess);
|
2006-01-02 08:21:23 +03:00
|
|
|
return;
|
|
|
|
}
|
2006-11-27 18:35:18 +03:00
|
|
|
|
2006-01-02 08:21:23 +03:00
|
|
|
/* find the sprites */
|
|
|
|
if (example_images) {
|
|
|
|
ro_gui_options_image_read(redraw->w, &bg_tinct, &fg_tinct);
|
2006-01-03 04:40:32 +03:00
|
|
|
fg_tinct |= 0xeeeeee00;
|
2006-01-02 08:21:23 +03:00
|
|
|
xosspriteop_select_sprite(osspriteop_USER_AREA,
|
|
|
|
example_images, (osspriteop_id)"img_bg", &bg);
|
|
|
|
xosspriteop_select_sprite(osspriteop_USER_AREA,
|
|
|
|
example_images, (osspriteop_id)"img_fg", &fg);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* perform the redraw */
|
|
|
|
more = wimp_redraw_window(redraw);
|
|
|
|
while (more) {
|
2014-05-26 13:02:30 +04:00
|
|
|
int origin_x, origin_y;
|
2006-01-02 08:21:23 +03:00
|
|
|
origin_x = redraw->box.x0 - redraw->xscroll +
|
|
|
|
icon_state.icon.extent.x0 + 2;
|
|
|
|
origin_y = redraw->box.y1 - redraw->yscroll +
|
|
|
|
icon_state.icon.extent.y0 + 2;
|
|
|
|
if (bg)
|
2009-03-27 05:32:26 +03:00
|
|
|
_swix(Tinct_Plot, _INR(2,4) | _IN(7),
|
2006-01-02 08:21:23 +03:00
|
|
|
bg, origin_x, origin_y, bg_tinct);
|
|
|
|
if (fg)
|
2009-03-27 05:32:26 +03:00
|
|
|
_swix(Tinct_PlotAlpha, _INR(2,4) | _IN(7),
|
2006-01-02 08:21:23 +03:00
|
|
|
fg, origin_x, origin_y, fg_tinct);
|
|
|
|
more = wimp_get_rectangle(redraw);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-07-27 02:29:15 +04:00
|
|
|
void ro_gui_options_image_read(wimp_w w, unsigned int *bg, unsigned int *fg)
|
|
|
|
{
|
2008-08-05 05:32:15 +04:00
|
|
|
const char *text;
|
2006-01-02 08:21:23 +03:00
|
|
|
int i;
|
2006-11-27 18:35:18 +03:00
|
|
|
|
2006-01-02 08:21:23 +03:00
|
|
|
text = ro_gui_get_icon_string(w, IMAGE_FOREGROUND_FIELD);
|
2008-08-05 05:32:15 +04:00
|
|
|
for (i = 0; i < 4; i++)
|
2006-01-02 08:21:23 +03:00
|
|
|
if (!strcmp(text, image_quality_menu->entries[i].
|
|
|
|
data.indirected_text.text))
|
|
|
|
*fg = tinct_options[i];
|
2009-03-27 05:32:26 +03:00
|
|
|
|
2006-01-02 08:21:23 +03:00
|
|
|
text = ro_gui_get_icon_string(w, IMAGE_BACKGROUND_FIELD);
|
2008-08-05 05:32:15 +04:00
|
|
|
for (i = 0; i < 4; i++)
|
2006-01-02 08:21:23 +03:00
|
|
|
if (!strcmp(text, image_quality_menu->entries[i].
|
|
|
|
data.indirected_text.text))
|
|
|
|
*bg = tinct_options[i];
|
|
|
|
}
|
|
|
|
|
2008-07-27 02:29:15 +04:00
|
|
|
bool ro_gui_options_image_click(wimp_pointer *pointer)
|
|
|
|
{
|
2006-01-02 18:58:34 +03:00
|
|
|
unsigned int old_fg, old_bg, bg, fg;
|
2006-11-27 18:35:18 +03:00
|
|
|
|
2006-01-02 18:58:34 +03:00
|
|
|
ro_gui_options_image_read(pointer->w, &old_bg, &old_fg);
|
2006-01-02 08:33:53 +03:00
|
|
|
switch (pointer->i) {
|
|
|
|
case IMAGE_DEFAULT_BUTTON:
|
2011-02-21 02:16:33 +03:00
|
|
|
ro_gui_set_icon_string(pointer->w,
|
2009-03-27 05:32:26 +03:00
|
|
|
IMAGE_FOREGROUND_FIELD,
|
2006-01-02 08:33:53 +03:00
|
|
|
image_quality_menu->entries[3].
|
2008-08-05 05:32:15 +04:00
|
|
|
data.indirected_text.text, true);
|
2011-02-21 02:16:33 +03:00
|
|
|
ro_gui_set_icon_string(pointer->w,
|
2009-03-27 05:32:26 +03:00
|
|
|
IMAGE_BACKGROUND_FIELD,
|
2006-01-02 08:33:53 +03:00
|
|
|
image_quality_menu->entries[2].
|
2008-08-05 05:32:15 +04:00
|
|
|
data.indirected_text.text, true);
|
2006-01-03 04:40:32 +03:00
|
|
|
ro_gui_set_icon_decimal(pointer->w, IMAGE_SPEED_FIELD,
|
|
|
|
10, 2);
|
|
|
|
ro_gui_set_icon_selected_state(pointer->w,
|
|
|
|
IMAGE_DISABLE_ANIMATION, false);
|
|
|
|
case IMAGE_DISABLE_ANIMATION:
|
|
|
|
ro_gui_options_update_shading(pointer->w);
|
2006-01-02 18:58:34 +03:00
|
|
|
break;
|
2006-01-02 08:33:53 +03:00
|
|
|
case IMAGE_CANCEL_BUTTON:
|
2006-01-02 18:58:34 +03:00
|
|
|
ro_gui_wimp_event_restore(pointer->w);
|
2006-01-02 08:33:53 +03:00
|
|
|
break;
|
2006-01-02 18:58:34 +03:00
|
|
|
default:
|
|
|
|
return false;
|
2006-01-02 08:33:53 +03:00
|
|
|
}
|
2009-03-27 05:32:26 +03:00
|
|
|
|
2006-01-02 18:58:34 +03:00
|
|
|
ro_gui_options_image_read(pointer->w, &bg, &fg);
|
|
|
|
if ((bg != old_bg) || (fg != old_fg))
|
2011-02-21 02:16:33 +03:00
|
|
|
ro_gui_options_image_update(pointer->w, pointer->i,
|
|
|
|
NULL, NULL, NO_ACTION);
|
2009-03-27 05:32:26 +03:00
|
|
|
|
2006-01-02 08:33:53 +03:00
|
|
|
return false;
|
2006-01-02 08:21:23 +03:00
|
|
|
}
|
|
|
|
|
2008-07-27 02:29:15 +04:00
|
|
|
void ro_gui_options_update_shading(wimp_w w)
|
|
|
|
{
|
2006-01-03 04:40:32 +03:00
|
|
|
bool shaded;
|
|
|
|
|
|
|
|
shaded = ro_gui_get_icon_selected_state(w, IMAGE_DISABLE_ANIMATION);
|
|
|
|
ro_gui_set_icon_shaded_state(w, IMAGE_SPEED_TEXT, shaded);
|
|
|
|
ro_gui_set_icon_shaded_state(w, IMAGE_SPEED_FIELD, shaded);
|
|
|
|
ro_gui_set_icon_shaded_state(w, IMAGE_SPEED_DEC, shaded);
|
|
|
|
ro_gui_set_icon_shaded_state(w, IMAGE_SPEED_INC, shaded);
|
|
|
|
ro_gui_set_icon_shaded_state(w, IMAGE_SPEED_CS, shaded);
|
|
|
|
}
|
|
|
|
|
2008-07-27 02:29:15 +04:00
|
|
|
bool ro_gui_options_image_ok(wimp_w w)
|
|
|
|
{
|
2012-03-22 13:34:34 +04:00
|
|
|
ro_gui_options_image_read(w,
|
2013-05-28 19:44:46 +04:00
|
|
|
(unsigned int *)&nsoption_int(plot_bg_quality),
|
|
|
|
(unsigned int *)&nsoption_int(plot_fg_quality));
|
2012-03-22 13:34:34 +04:00
|
|
|
|
|
|
|
nsoption_set_int(minimum_gif_delay,
|
|
|
|
ro_gui_get_icon_decimal(w, IMAGE_SPEED_FIELD, 2));
|
|
|
|
|
|
|
|
nsoption_set_bool(animate_images,
|
|
|
|
!ro_gui_get_icon_selected_state(w,
|
|
|
|
IMAGE_DISABLE_ANIMATION));
|
2006-01-02 08:21:23 +03:00
|
|
|
ro_gui_save_options();
|
2009-03-27 05:32:26 +03:00
|
|
|
|
2006-01-02 08:21:23 +03:00
|
|
|
return true;
|
|
|
|
}
|