%% options copyright owner = Dirk Krause copyright year = 2018-xxxx SPDX-License-Identifier: BSD-3-Clause %% wx-gui type = dialog contents = mainSizerHorizontal [wxBoxSizer mainSizerHorizontal] direction = horizontal contents = $space(10) contents = mainSizerVertical contents = $space(10) [wxBoxSizer mainSizerVertical] direction = vertical contents = $space(10) contents = choiceBookInput contents = $space(10) contents = resultSizerHexadecimal contents = resultSizerDecimal contents = $space(5) contents = colourViewResult contents = $space(10) contents = buttonsDialog centered-x contents = $space(10) [wxChoicebook choiceBookInput] id = ID_CHOICEBOOK contents = panelFig contents = panelHtmlNamed contents = panelHtml216 tip = lTexts[1] [wxPanel panelFig] text = lTexts[26] contents = figSizerHorizontal [wxBoxSizer figSizerHorizontal] direction = horizontal contents = $stretch(5) contents = figSizerVertical contents = $stretch(5) [wxBoxSizer figSizerVertical] direction = vertical contents = $stretch(5) contents = figButtonRow0 contents = $space(5) contents = figButtonRow1 contents = $space(5) contents = figButtonRow2 contents = $space(5) contents = figButtonRow3 contents = $space(10) contents = figShaderLabelSizer contents = $space(5) contents = figShaderSlider contents = $stretch(5) [wxBoxSizer figButtonRow0] direction = horizontal contents = b00 contents = $space(5) contents = b01 contents = $space(5) contents = b02 contents = $space(5) contents = b03 contents = $space(5) contents = b04 contents = $space(5) contents = b05 contents = $space(5) contents = b06 contents = $space(5) contents = b07 [wxBoxSizer figButtonRow1] direction = horizontal contents = b08 contents = $space(5) contents = b09 contents = $space(5) contents = b10 contents = $space(5) contents = b11 contents = $space(5) contents = b12 contents = $space(5) contents = b13 contents = $space(5) contents = b14 contents = $space(5) contents = b15 [wxBoxSizer figButtonRow2] direction = horizontal contents = b16 contents = $space(5) contents = b17 contents = $space(5) contents = b18 contents = $space(5) contents = b19 contents = $space(5) contents = b20 contents = $space(5) contents = b21 contents = $space(5) contents = b22 contents = $space(5) contents = b23 [wxBoxSizer figButtonRow3] direction = horizontal contents = b24 contents = $space(5) contents = b25 contents = $space(5) contents = b26 contents = $space(5) contents = b27 contents = $space(5) contents = b28 contents = $space(5) contents = b29 contents = $space(5) contents = b30 contents = $space(5) contents = b31 [Dk4WxColourPaletteItem b00] constructor = this, pAppHelper, 0, 0, 0 tip = lTexts[2] [Dk4WxColourPaletteItem b01] constructor = this, pAppHelper, 0, 0, 255 tip = lTexts[2] [Dk4WxColourPaletteItem b02] constructor = this, pAppHelper, 0, 255, 0 tip = lTexts[2] [Dk4WxColourPaletteItem b03] constructor = this, pAppHelper, 0, 255, 255 tip = lTexts[2] [Dk4WxColourPaletteItem b04] constructor = this, pAppHelper, 255, 0, 0 tip = lTexts[2] [Dk4WxColourPaletteItem b05] constructor = this, pAppHelper, 255, 0, 255 tip = lTexts[2] [Dk4WxColourPaletteItem b06] constructor = this, pAppHelper, 255, 255, 0 tip = lTexts[2] [Dk4WxColourPaletteItem b07] constructor = this, pAppHelper, 255, 255, 255 tip = lTexts[2] [Dk4WxColourPaletteItem b08] constructor = this, pAppHelper, 0, 0, 143 tip = lTexts[2] [Dk4WxColourPaletteItem b09] constructor = this, pAppHelper, 0, 0, 176 tip = lTexts[2] [Dk4WxColourPaletteItem b10] constructor = this, pAppHelper, 0, 0, 209 tip = lTexts[2] [Dk4WxColourPaletteItem b11] constructor = this, pAppHelper, 135, 207, 255 tip = lTexts[2] [Dk4WxColourPaletteItem b12] constructor = this, pAppHelper, 0, 143, 0 tip = lTexts[2] [Dk4WxColourPaletteItem b13] constructor = this, pAppHelper, 0, 176, 0 tip = lTexts[2] [Dk4WxColourPaletteItem b14] constructor = this, pAppHelper, 0, 209, 0 tip = lTexts[2] [Dk4WxColourPaletteItem b15] constructor = this, pAppHelper, 0, 143, 143 tip = lTexts[2] [Dk4WxColourPaletteItem b16] constructor = this, pAppHelper, 0, 176, 176 tip = lTexts[2] [Dk4WxColourPaletteItem b17] constructor = this, pAppHelper, 0, 209, 209 tip = lTexts[2] [Dk4WxColourPaletteItem b18] constructor = this, pAppHelper, 143, 0, 0 tip = lTexts[2] [Dk4WxColourPaletteItem b19] constructor = this, pAppHelper, 176, 0, 0 tip = lTexts[2] [Dk4WxColourPaletteItem b20] constructor = this, pAppHelper, 209, 0, 0 tip = lTexts[2] [Dk4WxColourPaletteItem b21] constructor = this, pAppHelper, 143, 0, 143 tip = lTexts[2] [Dk4WxColourPaletteItem b22] constructor = this, pAppHelper, 176, 0, 176 tip = lTexts[2] [Dk4WxColourPaletteItem b23] constructor = this, pAppHelper, 209, 0, 209 tip = lTexts[2] [Dk4WxColourPaletteItem b24] constructor = this, pAppHelper, 127, 48, 0 tip = lTexts[2] [Dk4WxColourPaletteItem b25] constructor = this, pAppHelper, 160, 63, 0 tip = lTexts[2] [Dk4WxColourPaletteItem b26] constructor = this, pAppHelper, 191, 97, 0 tip = lTexts[2] [Dk4WxColourPaletteItem b27] constructor = this, pAppHelper, 255, 127, 127 tip = lTexts[2] [Dk4WxColourPaletteItem b28] constructor = this, pAppHelper, 255, 160, 160 tip = lTexts[2] [Dk4WxColourPaletteItem b29] constructor = this, pAppHelper, 255, 191, 191 tip = lTexts[2] [Dk4WxColourPaletteItem b30] constructor = this, pAppHelper, 255, 224, 224 tip = lTexts[2] [Dk4WxColourPaletteItem b31] constructor = this, pAppHelper, 255, 214, 0 tip = lTexts[2] [wxBoxSizer figShaderLabelSizer] direction = horizontal contents = $stretch(10) contents = figShaderLabelText contents = $stretch(10) grow = yes [wxStaticText figShaderLabelText] text = lTexts[4] text style = centered tip = lTexts[6] [wxSlider figShaderSlider] id = ID_SLIDER_SHADE direction = horizontal range = -20 20 value = 0 grow = yes tip = lTexts[7] [wxPanel panelHtmlNamed] text = lTexts[27] contents = htmlNamedSizerHorizontal [wxBoxSizer htmlNamedSizerHorizontal] direction = horizontal contents = $space(5) contents = htmlNamedSizerVertical contents = $space(5) [wxBoxSizer htmlNamedSizerVertical] contents = $space(5) contents = listHtmlNames contents = $space(5) [wxListBox listHtmlNames] # constructor = wxDefaultPosition, wxDefaultSize, saHtmlNames, wxLB_SINGLE id = ID_HTML_NAMED_LIST choices = saHtmlNames size = 200 200 tip = lTexts[8] [wxPanel panelHtml216] text = lTexts[28] contents = html216SizerHorizontal [wxBoxSizer html216SizerHorizontal] direction = horizontal contents = $space(5) contents = html216SizerVertical contents = $space(5) [wxBoxSizer html216SizerVertical] direction = vertical contents = $space(250,5) contents = labelHtml216Red contents = sliderHtml216Red contents = $space(5) contents = labelHtml216Green contents = sliderHtml216Green contents = $space(5) contents = labelHtml216Blue contents = sliderHtml216Blue contents = $space(5) [wxStaticText labelHtml216Red] text = lTexts[9] [wxSlider sliderHtml216Red] id = ID_SLIDER_RED range = 0 5 value = 0 direction = horizontal grow = yes tip = lTexts[12] [wxStaticText labelHtml216Green] text = lTexts[10] [wxSlider sliderHtml216Green] id = ID_SLIDER_GREEN range = 0 5 value = 0 direction = horizontal grow = yes tip = lTexts[13] [wxStaticText labelHtml216Blue] text = lTexts[11] [wxSlider sliderHtml216Blue] id = ID_SLIDER_BLUE range = 0 5 value = 0 direction = horizontal grow = yes tip = lTexts[14] [wxBoxSizer resultSizerHexadecimal] direction = horizontal grow = yes contents = hexRed contents = $stretch(10) contents = hexGreen contents = $stretch(10) contents = hexBlue [wxBoxSizer resultSizerDecimal] direction = horizontal grow = yes contents = decRed contents = $stretch(10) contents = decGreen contents = $stretch(10) contents = decBlue [wxStaticText hexRed] text = not_localized_texts[0] tip = lTexts[17] [wxStaticText hexGreen] text = not_localized_texts[0] text style = centered tip = lTexts[18] [wxStaticText hexBlue] text = not_localized_texts[0] text style = right tip = lTexts[19] [wxStaticText decRed] text = not_localized_texts[1] tip = lTexts[20] [wxStaticText decGreen] text = not_localized_texts[1] text style = centered tip = lTexts[21] [wxStaticText decBlue] text = not_localized_texts[1] text style = right tip = lTexts[22] [Dk4WxColourView colourViewResult] constructor = pAppHelp, r, g, b tip = lTexts[23] grow = yes minimum size = 50 50 [wxStdDialogButtonSizer buttonsDialog] contents = buttonOK contents = buttonCancel [wxButton buttonOK] id = wxID_OK text = lTexts[24] tip = lTexts[25] [wxButton buttonCancel] id = wxID_CANCEL text = lTexts[15] tip = lTexts[16] %% header start #ifndef DK4CONF_H_INCLUDED #if DK4_BUILDING_DKTOOLS4 #include "dk4conf.h" #else #include #endif #endif #ifndef WX_WXPREC_H_INCLUDED #include #define WX_WXPREC_H_INCLUDED 1 #endif #ifdef __BORLANDC__ #pragma hdrstop #endif #ifndef WX_PRECOMP #ifndef WX_WX_H_INCLUDED #include #define WX_WX_H_INCLUDED 1 #endif #endif #ifndef WX_GBSIZER_H_INCLUDED #include #define WX_GBSIZER_H_INCLUDED 1 #endif #ifndef WX_BOOKCTRL_H_INCLUDED #include #define WX_BOOKCTRL_H_INCLUDED 1 #endif #ifndef WX_CHOICEBK_H_INCLUDED #include #define WX_CHOICEBK_H_INCLUDED 1 #endif #ifndef WX_STATBOX_H_INCLUDED #include #define WX_STATBOX_H_INCLUDED 1 #endif #ifndef DK4WXAPPLICTIONHELPER_H_INCLUDED #if DK4_BUILDING_DKTOOLS4 #include "Dk4WxApplicationHelper.h" #else #include #endif #endif #ifndef DK4WXCOLOURVIEW_H_INCLUDED #if DK4_BUILDING_DKTOOLS4 #include "Dk4WxColourView.h" #else #include #endif #endif %% class start /** Color palette allowing to choose between predefined colours. */ class Dk4WxColourPalette : public wxDialog { /** Item in a colour palette. */ class Dk4WxColourPaletteItem : public wxControl { /** Class is dynamic. */ #if wxCHECK_VERSION(3,0,0) wxDECLARE_DYNAMIC_CLASS(Dk4WxColourPaletteItem); #else DECLARE_DYNAMIC_CLASS(Dk4WxColourPaletteItem) #endif /** Event table for control. */ #if wxCHECK_VERSION(3,0,0) wxDECLARE_EVENT_TABLE(); #else DECLARE_EVENT_TABLE() #endif protected: /** Parent dialog we have to notify about color change. */ Dk4WxColourPalette *pParentWindow; /** Application helper. */ Dk4WxApplicationHelper *pAppHelp; /** Class name, used in constructor and Create(). */ static wxChar const Dk4WxColourPaletteItemName[]; /** Height. */ int w; /** Width. */ int h; /** Red component of color to show. */ int r; /** Green component of color to show. */ int g; /** Blue component of color to show. */ int b; public: /** Default constructor. */ Dk4WxColourPaletteItem(); /** Constructor. @param pParent Parent window. @param wxid Window ID. @param appHelper Application helper. @param red Red component of color to show. @param green Green component of color to show. @param blue Blue component of color to show. @param pos Object position. @param size Object minimum size. @param style Style for control. @param name Class name. */ Dk4WxColourPaletteItem( wxWindow *pParent, wxWindowID wxid, Dk4WxColourPalette *pal, Dk4WxApplicationHelper *appHelper, int red, int green, int blue, wxPoint const & pos = wxDefaultPosition, wxSize const & size = wxDefaultSize, long style = wxBORDER_NONE, wxChar const *name = Dk4WxColourPaletteItemName ); /** Create object after using default constructor. @param pParent Parent window. @param wxid Window ID. @param appHelper Application helper. @param red Red component of color to show. @param green Green component of color to show. @param blue Blue component of color to show. @param pos Object position. @param size Object minimum size. @param style Style for control. @param name Class name. @return true on success, false on error. */ bool Create( wxWindow *pParent, wxWindowID wxid, Dk4WxColourPalette *pal, Dk4WxApplicationHelper *appHelper, int red = 255, int green = 255, int blue = 255, wxPoint const & pos = wxDefaultPosition, wxSize const & size = wxDefaultSize, long style = wxBORDER_NONE, wxChar const *name = Dk4WxColourPaletteItemName ); /** Find minimum size. */ wxSize DoGetBestSize() const; /** Handler for erase event. @param event Event to process. */ void OnErase(wxEraseEvent & event); /** Handler for paint event. @param event Event to process. */ void OnPaint(wxPaintEvent & event); /** Handler for mouse click event. @param event Event to process. */ void OnLeftMouseButtonDown(wxMouseEvent & event); }; private: /** Events we have to respond to. */ #if wxCHECK_VERSION(3,0,0) wxDECLARE_EVENT_TABLE(); #else DECLARE_EVENT_TABLE() #endif protected: /** Red colour for text labels. */ wxColour colourRed; /** Green colour for text labels. */ wxColour colourGreen; /** Blue colour for text labels. */ wxColour colourBlue; /** Application helper. */ Dk4WxApplicationHelper *pAppHelp; /** Localized texts. */ wxChar const * const *localizedTexts; /** Shade slider value -20 to 20. */ int slvshade; /** Red slider value 0 to 5. */ int slvred; /** Green slider value 0 to 5. */ int slvgreen; /** Blue slider value 0 to 5. */ int slvblue; /** Index of selected list item. */ int listSelection; /** Base red component, not shaded. */ int rb; /** Base green component, not shaded. */ int gb; /** Base blue component, not shaded. */ int bb; /** Result red component. */ int r; /** Result green component. */ int g; /** Result blue component. */ int b; /** Flag: Already in correction process. */ bool bIsCorrecting; %% class end protected: /** Correct shade label. */ void CorrectShadeLabel(void); /** Shade a color. @param val Original value. @return Shaded color value. */ int ShadeColour(int val); /** Correct appearance after using controls. @param reason Which control was used. */ void CorrectGui(int reason); /** Set the R, G, B text labels for the r, g, b variables. */ void SetRgbTextLabels(void); /** Find RGB slider value next to a given color value. */ int FindSliderValue(int colval); /** Find slider values next to the r, g, b variables. */ void FindRgbSliderValues(void); /** Find list box entry next to the r, g, b variables. */ void FindListBoxEntry(void); public: /** Our IDs. */ enum { /** ID of choicebook change. */ ID_CHOICEBOOK = ((wxID_HIGHEST) + 1) , /** ID of XFig shade slider. */ ID_SLIDER_SHADE , /** ID of HTML named colors list control. */ ID_HTML_NAMED_LIST , /** ID of HTML 216 red slider. */ ID_SLIDER_RED , /** ID of HTML 216 green slider. */ ID_SLIDER_GREEN , /** ID of HTML 216 blue slider. */ ID_SLIDER_BLUE }; /** Reasons for GUI corrections. */ enum { /** New page selected in choice book. */ REASON_CHOICEBOOK = 0 , /** Base colors changed. */ REASON_BASE_COLOR , /** Shade slider changed. */ REASON_SHADE_SLIDER , /** List selection changed. */ REASON_LIST_SELECT , /** RGB slider changed. */ REASON_RGB_SLIDER }; /** Default constructor. */ Dk4WxColourPalette(); /** Real constructor. @param pParent Parent window. @param pAppHelper Application helper. @param red Initial red component. @param green Initial green component. @param blue Initial blue component. @param withborder Flag: Show border around dialog box. */ Dk4WxColourPalette( wxWindow *pParent, Dk4WxApplicationHelper *pAppHelper, int red, int green, int blue, bool withborder = true ); /** Handler for OK button. @param event Event to respond to, unused. */ void OnOK(wxCommandEvent & event); /** Handler for Cancel button. @param event Event to respond to, unused. */ void OnCancel(wxCommandEvent & event); /** Handler for shade slider events. @param event Event to respond to, unused. */ void OnShadeSlider(wxCommandEvent & event); /** Handler for RGB slider events. @param event Event to respond to, unused. */ void OnRgbSlider(wxCommandEvent & event); #if wxCHECK_VERSION(3,0,0) /** Handler for changed choicebook page. @param event Event to respond to, unused */ void OnChoicebookChanged(wxBookCtrlEvent & event); #else /** Handler for changed choicebook page. @param event Event to respond to, unused */ void OnChoicebookChanged(wxChoicebookEvent & event); #endif /** Handler for changed selection on list box. @param event Event to respond to, unused. */ void OnListBoxChanged(wxCommandEvent & event); /** Retrieve red component. @return Red value. */ int Red(void) const; /** Retrieve green component. @return Green value. */ int Green(void) const; /** Retrieve blue component. @return Blue value. */ int Blue(void) const; /** React on Dk4WxColourPaletteItem click. @param red New base red component. @param green New base green component. @param blue New base blue component. */ void SetBaseRGB(int red, int green, int blue); /** Construct a dialog style value. @param bBorder Flag: Draw border. @param bTitle Flag: Title bar on dialog. */ static int GetDialogStyle(bool bBorder = true, bool bTitle = true); }; %% header end %% module start #include "Dk4WxColourPalette.h" #ifndef WX_CONFIG_H_INCLUDED #include #define WX_CONFIG_H_INCLUDED 1 #endif #ifndef WX_ARRSTR_H_INCLUDED #include #define WX_ARRSTR_H_INCLUDED 1 #endif #ifndef WX_DCBUFFER_H_INCLUDED #include #define WX_DCBUFFER_H_INCLUDED 1 #endif $!trace-include /** HTML named color type. */ typedef struct { const wxChar *name; /**< Color name. */ unsigned long rgb; /**< 16*R+8*G+B. */ } html_color_t; /** The named HTML colors. */ static const html_color_t html_colors[] = { { wxT("AliceBlue"), 0xF0F8FFUL }, { wxT("AntiqueWhite"), 0xFAEBD7UL }, { wxT("Aqua"), 0x00FFFFUL }, { wxT("Aquamarine"), 0x7FFFD4UL }, { wxT("Azure"), 0xF0FFFFUL }, { wxT("Beige"), 0xF5F5DCUL }, { wxT("Bisque"), 0xFFE4C4UL }, { wxT("Black"), 0x000000UL }, { wxT("BlanchedAlmond"), 0xFFEBCDUL }, { wxT("Blue"), 0x0000FFUL }, { wxT("BlueViolet"), 0x8A2BE2UL }, { wxT("Brown"), 0xA52A2AUL }, { wxT("BurlyWood"), 0xDEB887UL }, { wxT("CadetBlue"), 0x5F9EA0UL }, { wxT("Chartreuse"), 0x7FFF00UL }, { wxT("Chocolate"), 0xD2691EUL }, { wxT("Coral"), 0xFF7F50UL }, { wxT("CornflowerBlue"), 0x6495EDUL }, { wxT("Cornsilk"), 0xFFF8DCUL }, { wxT("Crimson"), 0xDC143CUL }, { wxT("Cyan"), 0x00FFFFUL }, { wxT("DarkBlue"), 0x00008BUL }, { wxT("DarkCyan"), 0x008B8BUL }, { wxT("DarkGoldenRod"), 0xB8860BUL }, { wxT("DarkGray"), 0xA9A9A9UL }, { wxT("DarkGrey"), 0xA9A9A9UL }, { wxT("DarkGreen"), 0x006400UL }, { wxT("DarkKhaki"), 0xBDB76BUL }, { wxT("DarkMagenta"), 0x8B008BUL }, { wxT("DarkOliveGreen"), 0x556B2FUL }, { wxT("DarkOrange"), 0xFF8C00UL }, { wxT("DarkOrchid"), 0x9932CCUL }, { wxT("DarkRed"), 0x8B0000UL }, { wxT("DarkSalmon"), 0xE9967AUL }, { wxT("DarkSeaGreen"), 0x8FBC8FUL }, { wxT("DarkSlateBlue"), 0x483D8BUL }, { wxT("DarkSlateGray"), 0x2F4F4FUL }, { wxT("DarkSlateGrey"), 0x2F4F4FUL }, { wxT("DarkTurquoise"), 0x00CED1UL }, { wxT("DarkViolet"), 0x9400D3UL }, { wxT("DeepPink"), 0xFF1493UL }, { wxT("DeepSkyBlue"), 0x00BFFFUL }, { wxT("DimGray"), 0x696969UL }, { wxT("DimGrey"), 0x696969UL }, { wxT("DodgerBlue"), 0x1E90FFUL }, { wxT("FireBrick"), 0xB22222UL }, { wxT("FloralWhite"), 0xFFFAF0UL }, { wxT("ForestGreen"), 0x228B22UL }, { wxT("Fuchsia"), 0xFF00FFUL }, { wxT("Gainsboro"), 0xDCDCDCUL }, { wxT("GhostWhite"), 0xF8F8FFUL }, { wxT("Gold"), 0xFFD700UL }, { wxT("GoldenRod"), 0xDAA520UL }, { wxT("Gray"), 0x808080UL }, { wxT("Grey"), 0x808080UL }, { wxT("Green"), 0x008000UL }, { wxT("GreenYellow"), 0xADFF2FUL }, { wxT("HoneyDew"), 0xF0FFF0UL }, { wxT("HotPink"), 0xFF69B4UL }, { wxT("IndianRed"), 0xCD5C5CUL }, { wxT("Indigo"), 0x4B0082UL }, { wxT("Ivory"), 0xFFFFF0UL }, { wxT("Khaki"), 0xF0E68CUL }, { wxT("Lavender"), 0xE6E6FAUL }, { wxT("LavenderBlush"), 0xFFF0F5UL }, { wxT("LawnGreen"), 0x7CFC00UL }, { wxT("LemonChiffon"), 0xFFFACDUL }, { wxT("LightBlue"), 0xADD8E6UL }, { wxT("LightCoral"), 0xF08080UL }, { wxT("LightCyan"), 0xE0FFFFUL }, { wxT("LightGoldenRodYellow"), 0xFAFAD2UL }, { wxT("LightGray"), 0xD3D3D3UL }, { wxT("LightGrey"), 0xD3D3D3UL }, { wxT("LightGreen"), 0x90EE90UL }, { wxT("LightPink"), 0xFFB6C1UL }, { wxT("LightSalmon"), 0xFFA07AUL }, { wxT("LightSeaGreen"), 0x20B2AAUL }, { wxT("LightSkyBlue"), 0x87CEFAUL }, { wxT("LightSlateGray"), 0x778899UL }, { wxT("LightSlateGrey"), 0x778899UL }, { wxT("LightSteelBlue"), 0xB0C4DEUL }, { wxT("LightYellow"), 0xFFFFE0UL }, { wxT("Lime"), 0x00FF00UL }, { wxT("LimeGreen"), 0x32CD32UL }, { wxT("Linen"), 0xFAF0E6UL }, { wxT("Magenta"), 0xFF00FFUL }, { wxT("Maroon"), 0x800000UL }, { wxT("MediumAquaMarine"), 0x66CDAAUL }, { wxT("MediumBlue"), 0x0000CDUL }, { wxT("MediumOrchid"), 0xBA55D3UL }, { wxT("MediumPurple"), 0x9370DBUL }, { wxT("MediumSeaGreen"), 0x3CB371UL }, { wxT("MediumSlateBlue"), 0x7B68EEUL }, { wxT("MediumSpringGreen"), 0x00FA9AUL }, { wxT("MediumTurquoise"), 0x48D1CCUL }, { wxT("MediumVioletRed"), 0xC71585UL }, { wxT("MidnightBlue"), 0x191970UL }, { wxT("MintCream"), 0xF5FFFAUL }, { wxT("MistyRose"), 0xFFE4E1UL }, { wxT("Moccasin"), 0xFFE4B5UL }, { wxT("NavajoWhite"), 0xFFDEADUL }, { wxT("Navy"), 0x000080UL }, { wxT("OldLace"), 0xFDF5E6UL }, { wxT("Olive"), 0x808000UL }, { wxT("OliveDrab"), 0x6B8E23UL }, { wxT("Orange"), 0xFFA500UL }, { wxT("OrangeRed"), 0xFF4500UL }, { wxT("Orchid"), 0xDA70D6UL }, { wxT("PaleGoldenRod"), 0xEEE8AAUL }, { wxT("PaleGreen"), 0x98FB98UL }, { wxT("PaleTurquoise"), 0xAFEEEEUL }, { wxT("PaleVioletRed"), 0xDB7093UL }, { wxT("PapayaWhip"), 0xFFEFD5UL }, { wxT("PeachPuff"), 0xFFDAB9UL }, { wxT("Peru"), 0xCD853FUL }, { wxT("Pink"), 0xFFC0CBUL }, { wxT("Plum"), 0xDDA0DDUL }, { wxT("PowderBlue"), 0xB0E0E6UL }, { wxT("Purple"), 0x800080UL }, { wxT("RebeccaPurple"), 0x663399UL }, { wxT("Red"), 0xFF0000UL }, { wxT("RosyBrown"), 0xBC8F8FUL }, { wxT("RoyalBlue"), 0x4169E1UL }, { wxT("SaddleBrown"), 0x8B4513UL }, { wxT("Salmon"), 0xFA8072UL }, { wxT("SandyBrown"), 0xF4A460UL }, { wxT("SeaGreen"), 0x2E8B57UL }, { wxT("SeaShell"), 0xFFF5EEUL }, { wxT("Sienna"), 0xA0522DUL }, { wxT("Silver"), 0xC0C0C0UL }, { wxT("SkyBlue"), 0x87CEEBUL }, { wxT("SlateBlue"), 0x6A5ACDUL }, { wxT("SlateGray"), 0x708090UL }, { wxT("SlateGrey"), 0x708090UL }, { wxT("Snow"), 0xFFFAFAUL }, { wxT("SpringGreen"), 0x00FF7FUL }, { wxT("SteelBlue"), 0x4682B4UL }, { wxT("Tan"), 0xD2B48CUL }, { wxT("Teal"), 0x008080UL }, { wxT("Thistle"), 0xD8BFD8UL }, { wxT("Tomato"), 0xFF6347UL }, { wxT("Turquoise"), 0x40E0D0UL }, { wxT("Violet"), 0xEE82EEUL }, { wxT("Wheat"), 0xF5DEB3UL }, { wxT("White"), 0xFFFFFFUL }, { wxT("WhiteSmoke"), 0xF5F5F5UL }, { wxT("Yellow"), 0xFFFF00UL }, { wxT("YellowGreen"), 0x9ACD32UL } }; /** Number of elements in the html_colors array. */ static const size_t sz_html_colors = sizeof(html_colors)/sizeof(html_color_t); /** Window type name. */ wxChar const Dk4WxColourPalette::Dk4WxColourPaletteItem::Dk4WxColourPaletteItemName[] = { wxT("Dk4WxColourPaletteItem") } ; #if wxCHECK_VERSION(3,0,0) wxBEGIN_EVENT_TABLE(Dk4WxColourPalette::Dk4WxColourPaletteItem,wxControl) #else BEGIN_EVENT_TABLE(Dk4WxColourPalette::Dk4WxColourPaletteItem,wxControl) #endif EVT_ERASE_BACKGROUND(Dk4WxColourPalette::Dk4WxColourPaletteItem::OnErase) EVT_PAINT(Dk4WxColourPalette::Dk4WxColourPaletteItem::OnPaint) EVT_LEFT_DOWN(Dk4WxColourPalette::Dk4WxColourPaletteItem::OnLeftMouseButtonDown) #if wxCHECK_VERSION(3,0,0) wxEND_EVENT_TABLE() #else END_EVENT_TABLE() #endif #if wxCHECK_VERSION(3,0,0) wxIMPLEMENT_DYNAMIC_CLASS(Dk4WxColourPalette::Dk4WxColourPaletteItem,wxControl); #else IMPLEMENT_DYNAMIC_CLASS(Dk4WxColourPalette::Dk4WxColourPaletteItem,wxControl) #endif #if wxCHECK_VERSION(3,0,0) wxBEGIN_EVENT_TABLE(Dk4WxColourPalette,wxDialog) #else BEGIN_EVENT_TABLE(Dk4WxColourPalette,wxDialog) #endif EVT_BUTTON(\ wxID_OK,\ Dk4WxColourPalette::OnOK\ ) EVT_BUTTON(\ wxID_CANCEL,\ Dk4WxColourPalette::OnCancel\ ) EVT_SLIDER(\ Dk4WxColourPalette::ID_SLIDER_SHADE,\ Dk4WxColourPalette::OnShadeSlider\ ) EVT_SLIDER(\ Dk4WxColourPalette::ID_SLIDER_RED,\ Dk4WxColourPalette::OnRgbSlider\ ) EVT_SLIDER(\ Dk4WxColourPalette::ID_SLIDER_GREEN,\ Dk4WxColourPalette::OnRgbSlider\ ) EVT_SLIDER(\ Dk4WxColourPalette::ID_SLIDER_BLUE,\ Dk4WxColourPalette::OnRgbSlider\ ) EVT_CHOICEBOOK_PAGE_CHANGED(\ Dk4WxColourPalette::ID_CHOICEBOOK,\ Dk4WxColourPalette::OnChoicebookChanged\ ) EVT_LISTBOX(\ Dk4WxColourPalette::ID_HTML_NAMED_LIST,\ Dk4WxColourPalette::OnListBoxChanged\ ) #if wxCHECK_VERSION(3,0,0) wxEND_EVENT_TABLE() #else END_EVENT_TABLE() #endif /** Text fragments, replaced by localized versions if found. */ static const wxChar * const message_texts[] = { $!string-table macro=wxT # # 0 Window title # Colour palettes # # 1 Tip for choice book # Choose palette type # # 2 Tip for palette item # Click palette item to choose color # # 3-7 Special shading levels # black pure white Shading level Modify shading (mix towards black or white) # # 8 Tip for list # Select item to choose color # # 9-11 Labels for RGB sliders # Red Green Blue # # 12-14 Tips for RGB sliders # Modify red color component Modify green color component Modify blue color component # # 15-16 Initial label value # Cancel Leave dialog, skip settings # # 17-19 Tips for labels # Red color component value, hexadecimal 00...FF Green color component value, hexadecimal 00...FF Blue color component value, hexadecimal 00...FF # # 20-22 Tips for labels # Red color component value, decimal 0...255 Green color component value, decimal 0...255 Blue color component value, decimal 0...255 # # 23 Tip for result colour view # Result color # # 24-25 Button texts and tips # OK Apply settings # # 26-28 Palette types # XFig HTML WEB 216 # # # $!end }; static const wxChar * const not_localized_texts[] = { $!string-table macro=wxT # # 0-1 Initial label texts for numeric fields # FF 255 # # 2-4 Format strings # %+02d %% %03d %02X $!end }; /** String table file name. */ static const dkChar sttfilename[] = { dkT("dk4colpal.str") }; /** Color component values corresponding to the RGB slider settings. */ static const int rgbSliderValues[] = { 0, 0x0033, 0x0066, 0x0099, 0x00CC, 0x00FF }; Dk4WxColourPalette::Dk4WxColourPalette() { pAppHelp = NULL; slvshade = 0; rb = gb = bb = r = g = b = 255; slvred = slvgreen = slvblue = 5; listSelection = 0; bIsCorrecting = false; } %% constructor start Dk4WxColourPalette::Dk4WxColourPalette( wxWindow *pParent, Dk4WxApplicationHelper *pAppHelper, int red, int green, int blue, bool withborder ) : wxDialog( pParent, wxID_ANY, wxT("Colour palette"), wxDefaultPosition, wxDefaultSize, Dk4WxColourPalette::GetDialogStyle(false, withborder) ), colourRed(127, 0, 0), colourGreen(0, 127, 0), colourBlue(0, 0, 127) { wxArrayString saHtmlNames; wxChar const * const *lTexts; size_t i; $? "+ Dk4WxColourPalette::Dk4WxColourPalette" $? ". red = %d", red $? ". green = %d", green $? ". blue = %d", blue localizedTexts = lTexts = pAppHelper->GetStringTable(sttfilename, message_texts); if (NULL == localizedTexts) { localizedTexts = lTexts = message_texts; } pAppHelp = pAppHelper; slvshade = 0; rb = r = red; gb = g = green; bb = b = blue; slvred = slvgreen = slvblue = 5; listSelection = 0; bIsCorrecting = false; for (i = 0; i < sz_html_colors; i++) { saHtmlNames.Add(html_colors[i].name); } %% constructor end if (dkctGUILayoutOK) { colourViewResult->SetActive(false); colourViewResult->SetMarkActiveInactive(false); decRed->SetForegroundColour(colourRed); decGreen->SetForegroundColour(colourGreen); decBlue->SetForegroundColour(colourBlue); hexRed->SetForegroundColour(colourRed); hexGreen->SetForegroundColour(colourGreen); hexBlue->SetForegroundColour(colourBlue); SetRgbTextLabels(); FindRgbSliderValues(); FindListBoxEntry(); SetTitle(lTexts[0]); wxSize minsize = GetMinSize(); SetMaxSize(minsize); } $? "- Dk4WxColourPalette::Dk4WxColourPalette" } %% module end void Dk4WxColourPalette::OnOK(wxCommandEvent & WXUNUSED(event)) { if(IsModal()) { EndModal(wxID_OK); } else { SetReturnCode(wxID_OK); Show(false); } } void Dk4WxColourPalette::OnCancel(wxCommandEvent & WXUNUSED(event)) { if(IsModal()) { EndModal(wxID_CANCEL); } else { SetReturnCode(wxID_CANCEL); Show(false); } } #if wxCHECK_VERSION(3,0,0) void Dk4WxColourPalette::OnChoicebookChanged(wxBookCtrlEvent & event) #else void Dk4WxColourPalette::OnChoicebookChanged(wxChoicebookEvent & event) #endif { int pn; $? "+ Dk4WxColourPalette::OnChoicebookChanged" pn = event.GetSelection(); if (1 == pn) { if (wxNOT_FOUND != listSelection) { listHtmlNames->SetSelection(listSelection); } } $? "- Dk4WxColourPalette::OnChoicebookChanged" } int Dk4WxColourPalette::ShadeColour(int val) { int back; back = val; if (0 < slvshade) { back = (((20 - slvshade) * val) + (slvshade * 255)) / 20; } else { if (0 > slvshade) { back = (val * (20 + slvshade)) / 20; } } return back; } void Dk4WxColourPalette::CorrectShadeLabel(void) { wxString lstr; switch (slvshade) { case -20 : { figShaderLabelText->SetLabel(localizedTexts[3]); } break; case 0 : { figShaderLabelText->SetLabel(localizedTexts[4]); } break; case 20 : { figShaderLabelText->SetLabel(localizedTexts[5]); } break; default : { lstr.Printf(not_localized_texts[2], (5*slvshade)); figShaderLabelText->SetLabel(lstr); } break; } } void Dk4WxColourPalette::SetBaseRGB(int red, int green, int blue) { $? "+ Dk4WxColourPalette::SetBaseRGB" rb = red; gb = green; bb = blue; CorrectGui(REASON_BASE_COLOR); $? "- Dk4WxColourPalette::SetBaseRGB" } void Dk4WxColourPalette::OnShadeSlider(wxCommandEvent & WXUNUSED(event)) { $? "+ Dk4WxColourPalette::OnShadeSlider" if (!(bIsCorrecting)) { slvshade = figShaderSlider->GetValue(); CorrectGui(REASON_SHADE_SLIDER); } $? "- Dk4WxColourPalette::OnShadeSlider" } void Dk4WxColourPalette::OnListBoxChanged(wxCommandEvent & WXUNUSED(event)) { int in; unsigned long ul; $? "+ Dk4WxColourPalette::OnListBoxChanged" if (!(bIsCorrecting)) { listSelection = in = listHtmlNames->GetSelection(); if ((0 <= in) && (wxNOT_FOUND != in)) { ul = html_colors[in].rgb; r = rb = (int)((ul >> 16) & 0x000000FFUL); g = gb = (int)((ul >> 8) & 0x000000FFUL); b = bb = (int)( ul & 0x000000FFUL); CorrectGui(REASON_LIST_SELECT); } } $? "- Dk4WxColourPalette::OnListBoxChanged" } void Dk4WxColourPalette::OnRgbSlider(wxCommandEvent & WXUNUSED(event)) { $? "+ Dk4WxColourPalette::OnRgbSlider" if (!(bIsCorrecting)) { rb = r = rgbSliderValues[sliderHtml216Red->GetValue()]; gb = g = rgbSliderValues[sliderHtml216Green->GetValue()]; bb = b = rgbSliderValues[sliderHtml216Blue->GetValue()]; CorrectGui(REASON_RGB_SLIDER); } $? "- Dk4WxColourPalette::OnRgbSlider" } int Dk4WxColourPalette::FindSliderValue(int colval) { long mindiff = 0L; long curdiff; int back = 0; int i; for (i = 0; i < 6; i++) { curdiff = labs(colval - rgbSliderValues[i]); if ((0 == i) || (curdiff < mindiff)) { back = i; mindiff = curdiff; } } return back; } void Dk4WxColourPalette::FindRgbSliderValues(void) { int sl; sl = FindSliderValue(r); slvred = sl; sliderHtml216Red->SetValue(sl); sl = FindSliderValue(g); slvgreen = sl; sliderHtml216Green->SetValue(sl); sl = FindSliderValue(b); slvblue = sl; sliderHtml216Blue->SetValue(sl); } void Dk4WxColourPalette::FindListBoxEntry(void) { size_t i; size_t mini; unsigned long ul; unsigned long curdiff; unsigned long mindiff; unsigned long r0; unsigned long g0; unsigned long b0; mindiff = 0UL; mini = 0; for (i = 0; i < sz_html_colors; i++) { ul = html_colors[i].rgb; r0 = (ul >> 16) & 0x000000FFUL; g0 = (ul >> 8) & 0x000000FFUL; b0 = ul & 0x000000FFUL; r0 = labs((long)r0 - (long)r); g0 = labs((long)g0 - (long)g); b0 = labs((long)b0 - (long)b); r0 = r0 * r0; g0 = g0 * g0; b0 = b0 * b0; curdiff = r0 + g0 + b0; if ((0 == i) || (curdiff < mindiff)) { mindiff = curdiff; mini = i; } } listSelection = mini; listHtmlNames->SetSelection((int)mini); } void Dk4WxColourPalette::SetRgbTextLabels(void) { wxString valstr; valstr.Printf(not_localized_texts[3], r); decRed->SetLabel(valstr); valstr.Printf(not_localized_texts[3], g); decGreen->SetLabel(valstr); valstr.Printf(not_localized_texts[3], b); decBlue->SetLabel(valstr); valstr.Printf(not_localized_texts[4], r); hexRed->SetLabel(valstr); valstr.Printf(not_localized_texts[4], g); hexGreen->SetLabel(valstr); valstr.Printf(not_localized_texts[4], b); hexBlue->SetLabel(valstr); } void Dk4WxColourPalette::CorrectGui(int reason) { $? "+ Dk4WxColourPalette::CorrectGui" if(!(bIsCorrecting)) { $? ". not yet correcting" /* Mark correction in progress */ bIsCorrecting = true; /* Apply the changes */ switch (reason) { case REASON_CHOICEBOOK : { } break; case REASON_BASE_COLOR : { $? ". base color" r = ShadeColour(rb); g = ShadeColour(gb); b = ShadeColour(bb); FindListBoxEntry(); FindRgbSliderValues(); } break; case REASON_SHADE_SLIDER : { $? ". shade slider" r = ShadeColour(rb); g = ShadeColour(gb); b = ShadeColour(bb); FindListBoxEntry(); FindRgbSliderValues(); CorrectShadeLabel(); } break; case REASON_LIST_SELECT : { $? ". list selection" FindRgbSliderValues(); slvshade = 0; figShaderSlider->SetValue(0); CorrectShadeLabel(); } break; case REASON_RGB_SLIDER : { $? ". rgb slider" FindListBoxEntry(); slvshade = 0; figShaderSlider->SetValue(0); CorrectShadeLabel(); } break; } /* Mark correction as done */ bIsCorrecting = false; /* Update result color viewer and dialog window */ SetRgbTextLabels(); colourViewResult->SetRGB(r, g, b); Refresh(); Update(); } $? "- Dk4WxColourPalette::CorrectGui" } int Dk4WxColourPalette::Red(void) const { return r; } int Dk4WxColourPalette::Green(void) const { return g; } int Dk4WxColourPalette::Blue(void) const { return b; } Dk4WxColourPalette::Dk4WxColourPaletteItem::Dk4WxColourPaletteItem() { pParentWindow = NULL; pAppHelp = NULL; w = h = -1; r = g = b = 255; } Dk4WxColourPalette::Dk4WxColourPaletteItem::Dk4WxColourPaletteItem( wxWindow *pParent, wxWindowID wxid, Dk4WxColourPalette *pal, Dk4WxApplicationHelper *appHelper, int red, int green, int blue, wxPoint const & pos, wxSize const & size, long style, wxChar const *name ) : wxControl( pParent, wxid, pos, size, style, wxDefaultValidator, wxString(name) ) { pParentWindow = pal; pAppHelp = appHelper; w = h = -1; r = red; g = green; b = blue; } bool Dk4WxColourPalette::Dk4WxColourPaletteItem::Create( wxWindow *pParent, wxWindowID wxid, Dk4WxColourPalette *pal, Dk4WxApplicationHelper *appHelper, int red, int green, int blue, wxPoint const & pos, wxSize const & size, long style, wxChar const *name ) { bool back = wxControl::Create( pParent, wxid, pos, size, style, wxDefaultValidator, wxString(name) ); pParentWindow = pal; pAppHelp = appHelper; w = h = -1; r = red; g = green; b = blue; return back; } wxSize Dk4WxColourPalette::Dk4WxColourPaletteItem::DoGetBestSize() const { wxSize back(((-1 < w) ? w : 25), ((-1 < h) ? h : 25)); return back; } void Dk4WxColourPalette::Dk4WxColourPaletteItem::OnErase(wxEraseEvent & WXUNUSED(event)) { } void Dk4WxColourPalette::Dk4WxColourPaletteItem::OnPaint(wxPaintEvent & WXUNUSED(event)) { wxBufferedPaintDC useDC(this); wxSize sz = GetClientSize(); wxColour mycolor(r, g, b); #if wxCHECK_VERSION(3,0,0) wxBrush myBrush(mycolor, wxBRUSHSTYLE_SOLID); #else wxBrush myBrush(mycolor, wxSOLID); #endif const wxBrush oldBrus = useDC.GetBrush(); useDC.SetBrush(myBrush); useDC.DrawRectangle(0, 0, sz.GetWidth(), sz.GetHeight()); useDC.SetBrush(wxNullBrush); } void Dk4WxColourPalette::Dk4WxColourPaletteItem::OnLeftMouseButtonDown( wxMouseEvent & WXUNUSED(event) ) { if (NULL != pParentWindow) { pParentWindow->SetBaseRGB(r, g, b); } } int Dk4WxColourPalette::GetDialogStyle(bool bBorder, bool bTitle) { int back = wxDEFAULT_DIALOG_STYLE; back &= (~(wxCLOSE_BOX)); back &= (~(wxSYSTEM_MENU)); if (!(bBorder)) { back &= (~(wxRESIZE_BORDER)); } if (!(bTitle)) { back &= (~(wxCAPTION)); } return back; } /* vim: set ai sw=4 ts=4 : */