diff --git a/bazaar/CtrlFinder/CtrlFinder.h b/bazaar/CtrlFinder/CtrlFinder.h index dc17856e3..c578345e2 100644 --- a/bazaar/CtrlFinder/CtrlFinder.h +++ b/bazaar/CtrlFinder/CtrlFinder.h @@ -25,7 +25,7 @@ public: DEEP = 0x80, DEF = VISIBLE | INVISIBLE | ENABLED | DISABLED | VIEW | FRAME | DEEP, - }; + } FLAGS; CtrlFinder() : flags(DEF), filter(STDBACK(StdCtrlFilter)), multi(true) { WantFocus(); } diff --git a/bazaar/Gen/Misc.h b/bazaar/Gen/Misc.h index 3c5326c9d..0870f2778 100644 --- a/bazaar/Gen/Misc.h +++ b/bazaar/Gen/Misc.h @@ -1,6 +1,8 @@ #ifndef _Gen_Misc_h_ #define _Gen_Misc_h_ +#include + NAMESPACE_UPP //some usefull interfaces @@ -38,8 +40,8 @@ public: virtual ~GetSetData() {} //might be used as base interface virtual T GetData() const = 0; virtual void SetData(const T& _v) = 0; - virtual T& GetRef() = 0; - virtual const T& GetRef() const = 0; +// virtual T& GetRef() { NEVER(); Value v; return v; } +// virtual const T& GetRef() const { NEVER(); Value v; return v; } T operator~() const { return GetData(); } const T& operator<<=(const T& v) { SetData(v); return v; } }; diff --git a/bazaar/Styler/Styler.cpp b/bazaar/Styler/Styler.cpp index 645c9eb16..95c42a77b 100644 --- a/bazaar/Styler/Styler.cpp +++ b/bazaar/Styler/Styler.cpp @@ -4,6 +4,11 @@ #define IMAGEFILE #include +Color Invert(const Color& c) +{ + return Color(255-c.GetR(), 255-c.GetG(),255-c.GetB()); +} + void ColorizeIml(Iml& target, Iml& source, const Color& c, int alpha) { for(int i = 0; i < target.GetCount(); i++) { @@ -33,18 +38,18 @@ void ChStylerSkin(const Color& c, int blnd, const Color& fg, const Color& bg) ColorizeIml(CtrlsImg::Iml(), StylerCtrlsImg::Iml(), c, 255); - SColorFace_Write(Blend(c, fg, blnd)); //controls face color - SColorShadow_Write(Blend(c, bg, blnd)); - SColorLtFace_Write(Blend(c, fg, blnd+20)); - SColorDkShadow_Write(Blend(c, bg, blnd+20)); + SColorFace_Write(Blend(c, fg, min(255, blnd))); //controls face color + SColorShadow_Write(Blend(c, bg, min(255, blnd))); + SColorLtFace_Write(Blend(c, fg, min(255, blnd+20))); + SColorDkShadow_Write(Blend(c, bg, min(255, blnd+20))); - SColorHighlight_Write(Blend(fg, c, blnd+20)); - SColorDisabled_Write(Blend(bg, c, blnd+20)); + SColorHighlight_Write(Blend(fg, c, min(255, blnd+20))); + SColorDisabled_Write(Blend(bg, c, min(255, blnd+20))); - SColorPaper_Write(Blend(c, fg, blnd+40)); //for lists, edits etc.. - SColorText_Write(Blend(c, bg, blnd+40)); + SColorPaper_Write(Blend(c, fg, min(255, blnd+40))); //for lists, edits etc.. + SColorText_Write(Blend(c, bg, min(255, blnd+40))); - SColorHighlightText_Write(Blend(c, fg, blnd+60)); + SColorHighlightText_Write(Blend(c, fg, min(255, blnd+60))); SColorLight_Write(SColorHighlight()); @@ -59,229 +64,7 @@ void ChStylerSkin(const Color& c, int blnd, const Color& fg, const Color& bg) LabelBoxColor_Write(SColorHighlight()); } -void StylerCtrl::ColorizedSkin() -{ - Color c = ~mcl; - int blnd = ~bl; - Color fg = ~fgcl; - Color bg = ~bgcl; - - if(Grayscale(fg)FindTag(tag); - if(i>=0) { ::Xmlize(xml.At(i), c); } + if(i>=0) { XmlIO _ = xml.At(i); ::Xmlize(_, c); } } } -#define XMLIZECOL(TAG, SCOL) \ - if(xml.IsStoring()) \ - XmlizeCol(xml, TAG, c = SCOL()); \ - if(xml.IsLoading()) \ - { \ - c = Null; \ - XmlizeCol(xml, TAG, c); if(!c.IsNullInstance()) COMBINE(SCOL, _Write)(c); \ - } \ - \ - - NAMESPACE_UPP template<> Stream& operator%(Stream& s, PerChStyle& o) { @@ -363,7 +135,17 @@ template<> Stream& operator%(Stream& s, PerChStyle& o) return s; } -template<> void Xmlize(XmlIO xml, PerChStyle& o) +#define XMLIZECOL(TAG, SCOL) \ + if(xml.IsStoring()) \ + XmlizeCol(xml, TAG, c = SCOL()); \ + if(xml.IsLoading()) \ + { \ + c = Null; \ + XmlizeCol(xml, TAG, c); if(!c.IsNullInstance()) COMBINE(SCOL, _Write)(c); \ + } \ + + +template<> void Xmlize(XmlIO& xml, PerChStyle& o) { Color c; @@ -389,3 +171,228 @@ template<> void Xmlize(XmlIO xml, PerChStyle& o) XMLIZECOL("labelbox", LabelBoxColor) } END_UPP_NAMESPACE + +bool SaveGlobalStyle(const String& filename) +{ + PerChStyle d; + return StoreAsXMLFile(d, "style", filename); + //return StoreToFile(d, fs.Get()); +} + +bool LoadGlobalStyle(const String& filename) +{ + ChReset(); + + PerChStyle d; + bool b = LoadFromXMLFile(d, filename); + //b = LoadFromFile(d, filename); + + if(!b) return b; + + RefreshGlobalStyles(); + RefreshLayoutDeepAll(); + + return b; +} + +//ChamStyleCtrl + +void ChamStyleCtrl::Updated() +{ + clface <<= SColorFace(); + clshadow <<= SColorShadow(); + clltface <<= SColorLtFace(); + cldkshadow <<= SColorDkShadow(); + clhighlight <<= SColorHighlight(); + cldisabled <<= SColorDisabled(); + clpaper <<= SColorPaper(); + cltext <<= SColorText(); + clhighlighttext <<= SColorHighlightText(); + cllight <<= SColorLight(); + + clmenu <<= SColorMenu(); + clmenutext <<= SColorMenuText(); + clmenumark <<= SColorMenuMark(); + clinfo <<= SColorInfo(); + clinfotext <<= SColorInfoText(); + clmark <<= SColorMark(); + cllabel <<= SColorLabel(); + cllbtext <<= LabelBoxTextColor(); + cllb <<= LabelBoxColor(); +} + +void ChamStyleCtrl::OnColorAction() +{ + ChReset(); + + SColorFace_Write(~clface); + SColorShadow_Write(~clshadow); + SColorLtFace_Write(~clltface); + SColorDkShadow_Write(~cldkshadow); + SColorHighlight_Write(~clhighlight); + SColorDisabled_Write(~cldisabled); + SColorPaper_Write(~clpaper); + SColorText_Write(~cltext); + SColorHighlightText_Write(~clhighlighttext); + SColorLight_Write(~cllight); + + SColorMenu_Write(~clmenu); + SColorMenuText_Write(~clmenutext); + SColorMenuMark_Write(~clmenumark); + SColorInfo_Write(~clinfo); + SColorInfoText_Write(~clinfotext); + SColorMark_Write(~clmark); + SColorLabel_Write(~cllabel); + LabelBoxTextColor_Write(~cllbtext); + LabelBoxColor_Write(~cllb); + + RefreshGlobalStyles(); + WhenSColorsChange(); //let outside apply own changes after recalculation, before we apply them + RefreshLayoutDeepAll(); + + Action(); +} + +ChamStyleCtrl::ChamStyleCtrl() +{ + CtrlLayout(*this); + + clface <<= THISBACK(OnColorAction); + clshadow <<= THISBACK(OnColorAction); + clltface <<= THISBACK(OnColorAction); + cldkshadow <<= THISBACK(OnColorAction); + clhighlight <<= THISBACK(OnColorAction); + cldisabled <<= THISBACK(OnColorAction); + clpaper <<= THISBACK(OnColorAction); + cltext <<= THISBACK(OnColorAction); + clhighlighttext <<= THISBACK(OnColorAction); + cllight <<= THISBACK(OnColorAction); + + clmenu <<= THISBACK(OnColorAction); + clmenutext <<= THISBACK(OnColorAction); + clmenumark <<= THISBACK(OnColorAction); + clinfo <<= THISBACK(OnColorAction); + clinfotext <<= THISBACK(OnColorAction); + clmark <<= THISBACK(OnColorAction); + cllabel <<= THISBACK(OnColorAction); + cllbtext <<= THISBACK(OnColorAction); + cllb <<= THISBACK(OnColorAction); + + load <<= THISBACK(DoLoad); + save <<= THISBACK(DoSave); +} + +void ChamStyleCtrl::DoSave() +{ + FileSel fs; + if(!fs.ExecuteSaveAs("Save global colors")) return; + SaveGlobalStyle(fs.Get()); +} + +void ChamStyleCtrl::DoLoad() +{ + FileSel fs; + if(!fs.ExecuteOpen("Save global colors")) return; + LoadGlobalStyle(fs.Get()); + Update(); +} + +//StylerCtrl + +void StylerCtrl::SetColorizedSkin() +{ + Color c = ~mcl; + int blnd = ~bl; + Color fg = ~fgcl; + Color bg = ~bgcl; + + ChStylerSkin(c, blnd, fg, bg); +} + +void StylerCtrl::OnSkinAction() +{ + if((int)stsw.GetData() != 2) + { + mcl.Disable(); + fgcl.Disable(); + bgcl.Disable(); + bl.Disable(); + inv.Disable(); + } + else + { + mcl.Enable(); + fgcl.Enable(); + bgcl.Enable(); + bl.Enable(); + inv.Enable(); + } + + //reset + switch((int)stsw.GetData()) + { + case 1: ChStdSkin(); break; + case 2: SetColorizedSkin(); break; + default: + case 0: ChClassicSkin(); break; + } + + RefreshGlobalStyles(); + WhenSkinChange(); //let outside apply own changes after recalculation, before we apply them + RefreshLayoutDeepAll(); + + UpdateAction(); +} + +void StylerCtrl::OnInvertAction() +{ + Color c = ~mcl; + Color fg = ~fgcl; + Color bg = ~bgcl; + + fg = Invert(fg); + bg = Invert(bg); + c = Invert(c); + + fgcl <<= fg; + bgcl <<= bg; + mcl <<= c; + + OnSkinAction(); +} + +void StylerCtrl::Updated() +{ + Color fg = ~fgcl; + Color bg = ~bgcl; + + dk <<= bool(Grayscale(fg) - using namespace Upp; -struct PerChStyle : ChStyle -{ - //dummy for saving the current status -}; - -NAMESPACE_UPP -template<> Stream& operator%(Stream& s, PerChStyle& o); -template<> void Xmlize(XmlIO xml, PerChStyle& o); -END_UPP_NAMESPACE - #define IMAGECLASS StylerCtrlsImg #define IMAGEFILE #include +#define LAYOUTFILE +#include + +Color Invert(const Color& c); + void ColorizeIml(Iml& target, Iml& source, const Color& c, int alpha = 100); void RefreshGlobalStyles(); void RefreshLayoutDeepAll(); -#define LAYOUTFILE -#include +void ChStylerSkin(const Color& c, int blnd, const Color& fg, const Color& bg); +void XmlizeCol(XmlIO& xml, const String& tag, Color& c); + +//dummy for saving the global status +struct PerChStyle : ChStyle {}; + +NAMESPACE_UPP +template<> Stream& operator%(Stream& s, PerChStyle& o); +template<> void Xmlize(XmlIO& xml, PerChStyle& o); +END_UPP_NAMESPACE + +bool SaveGlobalStyle(const String& filename); +bool LoadGlobalStyle(const String& filename); + +//for manipulating the SColors +class ChamStyleCtrl : public WithChamStyleLay { +public: + typedef ChamStyleCtrl CLASSNAME; + ChamStyleCtrl(); + + virtual void Updated(); + + void DoLoad(); + void DoSave(); + + void OnColorAction(); + + Callback WhenSColorsChange; +}; + +class StylerCtrl : public WithStylerLay { +public: + typedef StylerCtrl CLASSNAME; + StylerCtrl(); + + virtual void Updated(); + + void OnSkinAction(); + void OnInvertAction(); + + Callback WhenSkinChange; + +protected: + void SetColorizedSkin(); +}; + + +//overriding CH_STYLE definitions for a class:: StyleFunction by own definitions, which are not bound to the namespace #define CH_LOCSTYLE(klass, type, style) \ struct COMBINE5(klass, __, type, __, style) : klass::type { \ void Init(); \ static void InitIt(); \ }; \ \ -const klass::Style& style(); \ +const klass::type& style(); \ void COMBINE5(klass, __, type, __, style)::InitIt() { \ style(); \ } \ \ -const klass::Style& style() \ +const klass::type& style() \ { \ static COMBINE5(klass, __, type, __, style) b, standard; \ if(b.status == 0) { \ @@ -52,39 +92,5 @@ const klass::Style& style() \ \ void COMBINE5(klass, __, type, __, style)::Init() -void XmlizeCol(XmlIO xml, const String& tag, Color& c); - -void RefreshGlobalStyles(); -void RefreshLayoutDeepAll(); - -void ChStylerSkin(const Color& c, int blnd, const Color& fg, const Color& bg); - -class StylerCtrl : public WithStylerLay { -public: - typedef StylerCtrl CLASSNAME; - StylerCtrl(); - - virtual void Updated(); - - void SkinAction(); - void InvertAction(); - -protected: - void ColorizedSkin(); -}; - -class ChamStyleCtrl : public WithChamStyleLay { -public: - typedef ChamStyleCtrl CLASSNAME; - ChamStyleCtrl(); - - virtual void Updated(); - - void LoadCB(); - void SaveCB(); - - void ColorAction(); -}; - #endif diff --git a/bazaar/Styler/Styler.lay b/bazaar/Styler/Styler.lay index 6aeb296b5..8974bc198 100644 --- a/bazaar/Styler/Styler.lay +++ b/bazaar/Styler/Styler.lay @@ -3,7 +3,7 @@ LAYOUT(StylerLay, 160, 116) ITEM(ColorPusher, fgcl, LeftPosZ(48, 28).TopPosZ(24, 20)) ITEM(ColorPusher, bgcl, LeftPosZ(48, 28).TopPosZ(44, 20)) ITEM(Switch, stsw, SetLabel(t_("ClassicSkin\nStdSkin\nStylerSkin")).RightPosZ(4, 76).TopPosZ(4, 60)) - ITEM(Option, inv, SetLabel(t_("inverted")).RightPosZ(4, 76).VSizePosZ(68, 32)) + ITEM(Button, inv, SetLabel(t_("Invert")).RightPosZ(4, 76).VSizePosZ(68, 32)) ITEM(SliderCtrl, bl, HSizePosZ(4, 4).BottomPosZ(4, 24)) ITEM(StaticText, dv___6, SetText(t_("main:")).LeftPosZ(4, 40).TopPosZ(4, 19)) ITEM(StaticText, dv___7, SetText(t_("fg:")).LeftPosZ(4, 40).TopPosZ(24, 19)) diff --git a/bazaar/StylerTest/StylerTest.lay b/bazaar/StylerTest/StylerTest.lay index d30222729..5411dd6ac 100644 --- a/bazaar/StylerTest/StylerTest.lay +++ b/bazaar/StylerTest/StylerTest.lay @@ -45,5 +45,6 @@ LAYOUT(StylerTestLayout, 768, 640) ITEM(StatusBar, stbar, LeftPosZ(0, 768).TopPosZ(616, 23)) ITEM(MenuBar, mbar, LeftPosZ(0, 768).TopPosZ(592, 23)) ITEM(ToolBar, tool, LeftPosZ(0, 768).TopPosZ(568, 23)) + ITEM(Option, overdef, SetLabel(t_("Override StyleDefaults with own")).LeftPosZ(544, 216).TopPosZ(168, 16)) END_LAYOUT diff --git a/bazaar/StylerTest/main.cpp b/bazaar/StylerTest/main.cpp index 9fe3bc97c..34e6ff509 100644 --- a/bazaar/StylerTest/main.cpp +++ b/bazaar/StylerTest/main.cpp @@ -19,7 +19,7 @@ static Color SColorSpinButtonMonoColord = LtYellow; CH_LOCSTYLE(EditField, Style, EditFieldStyleDFM) { - paper = SColorEditPaper; + paper = Blend(SColorPaper(), SColorEditPaper); disabled = SColorFace(); focus = paper; invalid = Blend(paper, Color(255, 0, 0), 32); @@ -35,7 +35,7 @@ CH_LOCSTYLE(EditField, Style, EditFieldStyleDFM) CH_LOCSTYLE(Button, Style, ButtonStyleDFM) { - look[0] = SColorButtonFace; + look[0] = Blend(SColorFace(), SColorButtonFace); look[1] = SColorFace(); look[2] = LtBlue(); look[3] = LtYellow(); @@ -84,23 +84,22 @@ void StylerTest::Menu(Bar& bar) void StylerTest::ApplyOwnStyle() { - return; - //recalculate own colors - ChFinish(); - - EditField::Style& stef = EditField::StyleDefault().Write(); - stef = EditFieldStyleDFM(); + if(!overdef.Get()) return; + //override default style settings, without changing ref in each ctrl { - Button::Style& stbt = Button::StyleNormal().Write(); - stbt = ButtonStyleDFM(); + EditField::Style& s = EditField::StyleDefault().Write(); + s = EditFieldStyleDFM(); + } + { + Button::Style& s = Button::StyleNormal().Write(); + s = ButtonStyleDFM(); } - SpinButtons::Style& stspbt = SpinButtons::StyleDefault().Write(); - stspbt = SpinButtonStyleDFM(); - - RefreshGlobalStyles(); - RefreshLayoutDeepAll(); + { + SpinButtons::Style& s = SpinButtons::StyleDefault().Write(); + s = SpinButtonStyleDFM(); + } } StylerTest::StylerTest() @@ -108,16 +107,20 @@ StylerTest::StylerTest() CtrlLayout(*this, "Window title"); Sizeable().Zoomable(); - sc <<= THISBACK(ReloadChamCB); + sc.WhenSkinChange = THISBACK(ReloadChamCB); Add(sc.LeftPos(0,200).BottomPos(0,200)); - chc <<= THISBACK(ApplyOwnStyle); + chc.WhenSColorsChange = THISBACK(ApplyOwnStyle); Add(chc.RightPos(0,400).BottomPos(0,200)); - InitDummys(); - b.SetStyle(ButtonStyleDFM()); + overdef <<= callback(&sc, &StylerCtrl::OnSkinAction); //emulate a skin change - ApplyOwnStyle(); + InitDummys(); + b.SetStyle(ButtonStyleDFM()); //to see statically without change + + overdef.Set(0); //dont override default by default + + sc.OnSkinAction(); } void StylerTest::InitDummys()