From 91966b562ed11a933df764db54b56a893fce09b9 Mon Sep 17 00:00:00 2001 From: Vincent Sanders Date: Mon, 27 May 2013 15:01:47 +0100 Subject: move amiga to new options code --- amiga/Makefile.target | 10 +- amiga/gui.c | 113 +++++++++++++--- amiga/system_colour.c | 367 -------------------------------------------------- 3 files changed, 98 insertions(+), 392 deletions(-) delete mode 100644 amiga/system_colour.c (limited to 'amiga') diff --git a/amiga/Makefile.target b/amiga/Makefile.target index b51a1fafa..fa850e270 100644 --- a/amiga/Makefile.target +++ b/amiga/Makefile.target @@ -72,14 +72,14 @@ EXETARGET := NetSurf # ---------------------------------------------------------------------------- # S_AMIGA are sources purely for the Amiga build -S_AMIGA := gui.c tree.c history.c hotlist.c schedule.c file.c \ +S_AMIGA := gui.c tree.c history.c hotlist.c schedule.c file.c \ thumbnail.c misc.c bitmap.c font.c filetype.c utf8.c login.c \ plotters.c object.c menu.c save_pdf.c arexx.c version.c \ - cookies.c context_menu.c clipboard.c help.c font_scan.c \ - launch.c search.c history_local.c download.c iff_dr2d.c \ - sslcert.c gui_options.c print.c theme.c drag.c icon.c system_colour.c \ + cookies.c context_menu.c clipboard.c help.c font_scan.c \ + launch.c search.c history_local.c download.c iff_dr2d. c \ + sslcert.c gui_options.c print.c theme.c drag.c icon.c \ datatypes.c dt_picture.c dt_anim.c dt_sound.c plugin_hack.c \ - stringview/stringview.c stringview/urlhistory.c \ + stringview/stringview.c stringview/urlhistory.c \ agclass/amigaguide_class.c S_AMIGA := $(addprefix amiga/,$(S_AMIGA)) diff --git a/amiga/gui.c b/amiga/gui.c index dcbf90b51..9737ed087 100644 --- a/amiga/gui.c +++ b/amiga/gui.c @@ -391,7 +391,54 @@ void ami_open_resources(void) //ami_help_init(NULL); } -void ami_set_options(void) +/** + * set option from pen + */ +static nserror +ami_colour_option_from_pen(struct nsoption_s *opts, + UWORD pen, + enum nsoption_e option, + colour def_colour) +{ + ULONG colour[3]; + struct DrawInfo *drinfo; + + if((option < NSOPTION_SYS_COLOUR_START) || + (option > NSOPTION_SYS_COLOUR_END) || + (opts[option].type != OPTION_COLOUR)) { + return NSERROR_BAD_PARAMETER; + } + + if(scrn != NULL) { + drinfo = GetScreenDrawInfo(scrn); + if(drinfo != NULL) { + + if(pen == AMINS_SCROLLERPEN) pen = ami_system_colour_scrollbar_fgpen(drinfo); + + /* Get the colour of the pen being used for "pen" */ + GetRGB32(screen->ViewPort.ColorMap, drinfo->dri_Pens[pen], 1, (ULONG *)&colour); + + /* convert it to a color */ + def_colour = ((colour[0] & 0xff000000) >> 24) | + ((colour[1] & 0xff000000) >> 16) | + ((colour[2] & 0xff000000) >> 8); + + FreeScreenDrawInfo(screen, drinfo); + } + } + + opts[option].value.c = def_colour; + + return NSERROR_OK; +} + +/** + * Set option defaults for amiga frontend + * + * @param defaults The option table to update. + * @return error status. + */ +static nserror ami_set_options(struct nsoption_s *defaults) { STRPTR tempacceptlangs; BPTR lock = 0; @@ -440,9 +487,6 @@ void ami_set_options(void) (char *)strdup("PROGDIR:Resources/ca-bundle")); - nsoption_setnull_charp(search_engines_file, - (char *)strdup("PROGDIR:Resources/SearchEngines")); - search_engines_file_location = nsoption_charp(search_engines_file); sprintf(temp, "%s/FontGlyphCache", current_user_dir); @@ -474,15 +518,8 @@ void ami_set_options(void) } } - nsoption_setnull_charp(theme, - (char *)strdup("PROGDIR:Resources/Themes/Default")); - tree_set_icon_dir(strdup("ENV:Sys")); - nsoption_setnull_charp(arexx_dir, (char *)strdup("Rexx")); - nsoption_setnull_charp(arexx_startup, (char *)strdup("Startup.nsrx")); - nsoption_setnull_charp(arexx_shutdown, (char *)strdup("Shutdown.nsrx")); - if(!nsoption_int(window_width)) nsoption_set_int(window_width, 800); if(!nsoption_int(window_height)) nsoption_set_int(window_height, 600); @@ -492,6 +529,38 @@ void ami_set_options(void) nsoption_set_bool(font_antialiasing, false); nsoption_set_bool(truecolour_mouse_pointers, false); #endif + + /* set system colours for amiga ui */ + ami_colour_option_from_pen(defaults, FILLPEN, NSOPTION_sys_colour_ActiveBorder, 0x00000000); + ami_colour_option_from_pen(defaults, FILLPEN, NSOPTION_sys_colour_ActiveCaption, 0x00dddddd); + ami_colour_option_from_pen(defaults, BACKGROUNDPEN, NSOPTION_sys_colour_AppWorkspace, 0x00eeeeee); + ami_colour_option_from_pen(defaults, BACKGROUNDPEN, NSOPTION_sys_colour_Background, 0x00aa0000); + ami_colour_option_from_pen(defaults, FOREGROUNDPEN, NSOPTION_sys_colour_ButtonFace, 0x00aaaaaa); + ami_colour_option_from_pen(defaults, FORESHINEPEN, NSOPTION_sys_colour_ButtonHighlight, 0x00cccccc); + ami_colour_option_from_pen(defaults, FORESHADOWPEN, NSOPTION_sys_colour_ButtonShadow, 0x00bbbbbb); + ami_colour_option_from_pen(defaults, TEXTPEN, NSOPTION_sys_colour_ButtonText, 0x00000000); + ami_colour_option_from_pen(defaults, FILLTEXTPEN, NSOPTION_sys_colour_CaptionText, 0x00000000); + ami_colour_option_from_pen(defaults, DISABLEDTEXTPEN, NSOPTION_sys_colour_GrayText, 0x00777777); + ami_colour_option_from_pen(defaults, SELECTPEN, NSOPTION_sys_colour_Highlight, 0x00ee0000); + ami_colour_option_from_pen(defaults, SELECTTEXTPEN, NSOPTION_sys_colour_HighlightText, 0x00000000); + ami_colour_option_from_pen(defaults, INACTIVEFILLPEN, NSOPTION_sys_colour_InactiveBorder, 0x00000000); + ami_colour_option_from_pen(defaults, INACTIVEFILLPEN, NSOPTION_sys_colour_InactiveCaption, 0x00ffffff); + ami_colour_option_from_pen(defaults, INACTIVEFILLTEXTPEN, NSOPTION_sys_colour_InactiveCaptionText, 0x00cccccc); + ami_colour_option_from_pen(defaults, BACKGROUNDPEN, NSOPTION_sys_colour_InfoBackground, 0x00aaaaaa);/* This is wrong, HelpHint backgrounds are pale yellow but doesn't seem to be a DrawInfo pen defined for it. */ + ami_colour_option_from_pen(defaults, TEXTPEN, NSOPTION_sys_colour_InfoText, 0x00000000); + ami_colour_option_from_pen(defaults, MENUBACKGROUNDPEN, NSOPTION_sys_colour_Menu, 0x00aaaaaa); + ami_colour_option_from_pen(defaults, MENUTEXTPEN, NSOPTION_sys_colour_MenuText, 0x00000000); + ami_colour_option_from_pen(defaults, AMINS_SCROLLERPEN, NSOPTION_sys_colour_Scrollbar, 0x00aaaaaa); + ami_colour_option_from_pen(defaults, FORESHADOWPEN, NSOPTION_sys_colour_ThreeDDarkShadow, 0x00555555); + ami_colour_option_from_pen(defaults, FOREGROUNDPEN, NSOPTION_sys_colour_ThreeDFace, 0x00dddddd); + ami_colour_option_from_pen(defaults, FORESHINEPEN, NSOPTION_sys_colour_ThreeDHighlight, 0x00aaaaaa); + ami_colour_option_from_pen(defaults, HALFSHINEPEN, NSOPTION_sys_colour_ThreeDLightShadow, 0x00999999); + ami_colour_option_from_pen(defaults, HALFSHADOWPEN, NSOPTION_sys_colour_ThreeDShadow, 0x00777777); + ami_colour_option_from_pen(defaults, BACKGROUNDPEN, NSOPTION_sys_colour_Window, 0x00aaaaaa); + ami_colour_option_from_pen(defaults, INACTIVEFILLPEN, NSOPTION_sys_colour_WindowFrame, 0x00000000); + ami_colour_option_from_pen(defaults, TEXTPEN, NSOPTION_sys_colour_WindowText, 0x00000000); + + return NSERROR_OK; } void ami_amiupdate(void) @@ -553,13 +622,6 @@ nsurl *gui_get_resource_url(const char *path) return url; } -/* Documented in utils/nsoption.h */ -void gui_options_init_defaults(void) -{ - /* Set defaults for absent option strings */ - ami_set_options(); /* check options and set defaults where required */ -} - void gui_init(int argc, char** argv) { BPTR lock = 0; @@ -905,7 +967,7 @@ int main(int argc, char** argv) char temp[1024]; BPTR lock = 0; int32 user = 0; - + nserror ret; Object *splash_window = ami_gui_splash_open(); user = GetVar("user", temp, 1024, GVF_GLOBAL_ONLY); @@ -934,7 +996,18 @@ int main(int argc, char** argv) */ nslog_init(NULL, &argc, argv); - netsurf_init(&argc, &argv, current_user_options, messages); + /* user options setup */ + ret = nsoption_init(ami_set_options, &nsoptions, &nsoptions_default); + if (ret != NSERROR_OK) { + die("Options failed to initialise"); + } + nsoption_read(current_user_options, NULL); + nsoption_commandline(&argc, argv, NULL); + + ret = netsurf_init(messages); + if (ret != NSERROR_OK) { + die("NetSurf failed to initialise"); + } amiga_icon_init(); diff --git a/amiga/system_colour.c b/amiga/system_colour.c deleted file mode 100644 index d78f54bbc..000000000 --- a/amiga/system_colour.c +++ /dev/null @@ -1,367 +0,0 @@ -/* - * Copyright 2011 Vincent Sanders - * - * 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 . - */ - -/** \file - * System colour handling - * - */ - -#include "amiga/gui.h" -#include "utils/utils.h" -#include "utils/log.h" -#include "desktop/gui.h" -#include "utils/nsoption.h" -#include "desktop/tree.h" - -#include -#include -#include -#include -#include - -#define AMINS_SCROLLERPEN NUMDRIPENS - -struct gui_system_colour_ctx { - const char *name; - int length; - css_color colour; - colour *option_colour; - UWORD amiga_pen; - lwc_string *lwcstr; -}; - -static struct gui_system_colour_ctx colour_list[] = { - { - "ActiveBorder", - SLEN("ActiveBorder"), - 0xff000000, - &nsoption_colour(sys_colour_ActiveBorder), - FILLPEN, - NULL - }, { - "ActiveCaption", - SLEN("ActiveCaption"), - 0xffdddddd, - &nsoption_colour(sys_colour_ActiveCaption), - FILLPEN, - NULL - }, { - "AppWorkspace", - SLEN("AppWorkspace"), - 0xffeeeeee, - &nsoption_colour(sys_colour_AppWorkspace), - BACKGROUNDPEN, - NULL - }, { - "Background", - SLEN("Background"), - 0xff0000aa, - &nsoption_colour(sys_colour_Background), - BACKGROUNDPEN, - NULL - }, { - "ButtonFace", - SLEN("ButtonFace"), - 0xffaaaaaa, - &nsoption_colour(sys_colour_ButtonFace), - FOREGROUNDPEN, - NULL - }, { - "ButtonHighlight", - SLEN("ButtonHighlight"), - 0xffdddddd, - &nsoption_colour(sys_colour_ButtonHighlight), - FORESHINEPEN, - NULL - }, { - "ButtonShadow", - SLEN("ButtonShadow"), - 0xffbbbbbb, - &nsoption_colour(sys_colour_ButtonShadow), - FORESHADOWPEN, - NULL - }, { - "ButtonText", - SLEN("ButtonText"), - 0xff000000, - &nsoption_colour(sys_colour_ButtonText), - TEXTPEN, - NULL - }, { - "CaptionText", - SLEN("CaptionText"), - 0xff000000, - &nsoption_colour(sys_colour_CaptionText), - FILLTEXTPEN, - NULL - }, { - "GrayText", - SLEN("GrayText"), - 0xffcccccc, - &nsoption_colour(sys_colour_GrayText), - DISABLEDTEXTPEN, - NULL - }, { - "Highlight", - SLEN("Highlight"), - 0xff0000ee, - &nsoption_colour(sys_colour_Highlight), - SELECTPEN, - NULL - }, { - "HighlightText", - SLEN("HighlightText"), - 0xff000000, - &nsoption_colour(sys_colour_HighlightText), - SELECTTEXTPEN, - NULL - }, { - "InactiveBorder", - SLEN("InactiveBorder"), - 0xffffffff, - &nsoption_colour(sys_colour_InactiveBorder), - INACTIVEFILLPEN, - NULL - }, { - "InactiveCaption", - SLEN("InactiveCaption"), - 0xffffffff, - &nsoption_colour(sys_colour_InactiveCaption), - INACTIVEFILLPEN, - NULL - }, { - "InactiveCaptionText", - SLEN("InactiveCaptionText"), - 0xffcccccc, - &nsoption_colour(sys_colour_InactiveCaptionText), - INACTIVEFILLTEXTPEN, - NULL - }, { - "InfoBackground", - SLEN("InfoBackground"), - 0xffaaaaaa, - &nsoption_colour(sys_colour_InfoBackground), - BACKGROUNDPEN, /* This is wrong, HelpHint backgrounds are pale yellow but doesn't seem to be a DrawInfo pen defined for it. */ - NULL - }, { - "InfoText", - SLEN("InfoText"), - 0xff000000, - &nsoption_colour(sys_colour_InfoText), - TEXTPEN, - NULL - }, { - "Menu", - SLEN("Menu"), - 0xffaaaaaa, - &nsoption_colour(sys_colour_Menu), - MENUBACKGROUNDPEN, - NULL - }, { - "MenuText", - SLEN("MenuText"), - 0xff000000, - &nsoption_colour(sys_colour_MenuText), - MENUTEXTPEN, - NULL - }, { - "Scrollbar", - SLEN("Scrollbar"), - 0xffaaaaaa, - &nsoption_colour(sys_colour_Scrollbar), - AMINS_SCROLLERPEN, - NULL - }, { - "ThreeDDarkShadow", - SLEN("ThreeDDarkShadow"), - 0xff555555, - &nsoption_colour(sys_colour_ThreeDDarkShadow), - FORESHADOWPEN, - NULL - }, { - "ThreeDFace", - SLEN("ThreeDFace"), - 0xffdddddd, - &nsoption_colour(sys_colour_ThreeDFace), - FOREGROUNDPEN, - NULL - }, { - "ThreeDHighlight", - SLEN("ThreeDHighlight"), - 0xffaaaaaa, - &nsoption_colour(sys_colour_ThreeDHighlight), - FORESHINEPEN, - NULL - }, { - "ThreeDLightShadow", - SLEN("ThreeDLightShadow"), - 0xff999999, - &nsoption_colour(sys_colour_ThreeDLightShadow), - HALFSHINEPEN, - NULL - }, { - "ThreeDShadow", - SLEN("ThreeDShadow"), - 0xff777777, - &nsoption_colour(sys_colour_ThreeDShadow), - HALFSHADOWPEN, - NULL - }, { - "Window", - SLEN("Window"), - 0xffaaaaaa, - &nsoption_colour(sys_colour_Window), - BACKGROUNDPEN, - NULL - }, { - "WindowFrame", - SLEN("WindowFrame"), - 0xff000000, - &nsoption_colour(sys_colour_WindowFrame), - INACTIVEFILLPEN, - NULL - }, { - - "WindowText", - SLEN("WindowText"), - 0xff000000, - &nsoption_colour(sys_colour_WindowText), - TEXTPEN, - NULL - }, - -}; - -#define colour_list_len (sizeof(colour_list) / sizeof(struct gui_system_colour_ctx)) - -static struct gui_system_colour_ctx *gui_system_colour_pw = NULL; - -css_color ami_css_colour_from_pen(struct Screen *screen, UWORD pen); - -UWORD ami_system_colour_scrollbar_fgpen(struct DrawInfo *drinfo) -{ - LONG scrollerfillpen = FALSE; - - GetGUIAttrs(NULL, drinfo, GUIA_PropKnobColor, &scrollerfillpen, TAG_DONE); - - if(scrollerfillpen) return FILLPEN; - else return FOREGROUNDPEN; -} - -bool gui_system_colour_init(void) -{ - unsigned int ccount; - - if (gui_system_colour_pw != NULL) - return false; - - /* Intern colour strings */ - for (ccount = 0; ccount < colour_list_len; ccount++) { - if (lwc_intern_string(colour_list[ccount].name, - colour_list[ccount].length, - &(colour_list[ccount].lwcstr)) != lwc_error_ok) { - return false; - } - } - - /* pull in options if set (ie not transparent) */ - for (ccount = 0; ccount < colour_list_len; ccount++) { - if (*(colour_list[ccount].option_colour) != 0) { - colour_list[ccount].colour = *(colour_list[ccount].option_colour); - } - else if(scrn) { - colour_list[ccount].colour = - ami_css_colour_from_pen(scrn, colour_list[ccount].amiga_pen); - } - } - - gui_system_colour_pw = colour_list; - tree_setup_colours(); - - return true; -} - -void gui_system_colour_finalize(void) -{ - unsigned int ccount; - - for (ccount = 0; ccount < colour_list_len; ccount++) { - lwc_string_unref(colour_list[ccount].lwcstr); - } - - gui_system_colour_pw = NULL; -} - -colour ami_css_color_to_colour(css_color c) -{ - return (c & 0xFF00FF00) | ((c >> 16) & 0xFF) | ((c & 0xFF) << 16); -} - -colour gui_system_colour_char(const char *name) -{ - colour ret = 0xff00000; - unsigned int ccount; - - for (ccount = 0; ccount < colour_list_len; ccount++) { - if (strcmp(name, colour_list[ccount].name) == 0) { - ret = ami_css_color_to_colour(colour_list[ccount].colour); - break; - } - } - return ret; -} - -css_error gui_system_colour(void *pw, lwc_string *name, css_color *colour) -{ - unsigned int ccount; - bool match; - - for (ccount = 0; ccount < colour_list_len; ccount++) { - if (lwc_string_caseless_isequal(name, - colour_list[ccount].lwcstr, - &match) == lwc_error_ok && match) { - *colour = colour_list[ccount].colour; - return CSS_OK; - } - } - - return CSS_INVALID; -} - -css_color ami_css_colour_from_pen(struct Screen *screen, UWORD pen) -{ - css_color css_colour = 0x00000000; - ULONG colour[3]; - struct DrawInfo *drinfo = GetScreenDrawInfo(screen); - - if(drinfo == NULL) return 0x00000000; - - if(pen == AMINS_SCROLLERPEN) pen = ami_system_colour_scrollbar_fgpen(drinfo); - - /* Get the colour of the pen being used for "pen" */ - GetRGB32(screen->ViewPort.ColorMap, drinfo->dri_Pens[pen], 1, (ULONG *)&colour); - - /* convert it to a css_color */ - css_colour = (0xff << 24) | - ((colour[0] & 0xff000000) >> 8) | - ((colour[1] & 0xff000000) >> 16) | - ((colour[2] & 0xff000000) >> 24); - - FreeScreenDrawInfo(screen, drinfo); - return css_colour; -} -- cgit v1.2.3