*CtrlLib, Draw: Fixed issues with menu and dark themes in Ubuntu (RM Bug #5)

git-svn-id: svn://ultimatepp.org/upp/trunk@3125 f0d560ea-af0d-0410-9eb7-867de7ffcac7
This commit is contained in:
cxl 2011-01-30 12:42:32 +00:00
parent 4fdf4bb530
commit 093cad7882
12 changed files with 1971 additions and 1978 deletions

View file

@ -128,4 +128,9 @@ int Grayscale(const Color& c)
return (77 * c.GetR() + 151 * c.GetG() + 28 * c.GetB()) >> 8;
}
bool IsDark(Color c)
{
return Grayscale(c) < 80;
}
END_UPP_NAMESPACE

View file

@ -114,6 +114,7 @@ Color Blend(Color c1, Color c2, int alpha = 128);
String ColorToHtml(Color color);
int Grayscale(const Color& c);
bool IsDark(Color c);
inline bool operator==(const Value& v, Color x) { return v == x.operator Value(); }

View file

@ -162,6 +162,7 @@ MTrand::MTrand()
#ifdef PLATFORM_POSIX
int fd = open("/dev/urandom", O_RDONLY);
read(fd, seed, sizeof(seed));
close(fd);
#else
for(int i = 0; i < 1024; i++) {
Uuid uuid;

View file

@ -1884,6 +1884,11 @@ ckPaint]()&]
[s7;i1120;a17; [*/ Return value]-|BackPaint(NOBACKPAINT).&]
[s3;%- &]
[s4;%- &]
[s5;:Ctrl`:`:BackPaintHint`(`):%- [_^Ctrl^ Ctrl][@(0.0.255) `&]_[* BackPaintHint]()&]
[s2; Activates FULLBACKPAINT mode if computer is a `"decent machine`"
(simple heurestics to identify fast enough PC with enough memory).&]
[s3;%- &]
[s4;%- &]
[s5;:Ctrl`:`:GetBackPaint`(`)const:%- [@(0.0.255) int]_[* GetBackPaint]()_[@(0.0.255) const
]&]
[s7;i1120;a17; [*/ Return value]-|Current back`-paint mode of Ctrl.&]

View file

@ -1191,7 +1191,7 @@ void ChHostSkin()
Image mimg = GetGTK(popup, 0, 2, "menu", GTK_BGBOX, 32, 32);
Color c = mimg[16][16];
Value rlook;
if(!IsNull(c) && Diff(c, SColorPaper()) < 200)
if(!IsNull(c)/* && Diff(c, SColorPaper()) < 200*/)
SColorMenu_Write(c);
{
MenuBar::Style& s = MenuBar::StyleDefault().Write();

View file

@ -58,13 +58,11 @@ public:
MenuItemBase& Style(const MenuBar::Style *s) { style = s; return *this; }
Font GetFont() const { return font; }
MenuItemBase& MaxIconSize(Size sz) { maxiconsize = sz; return *this; }
bool InOpaqueBar() const;
MenuItemBase();
};
void DrawMenuText(Draw& w, int x, int y, const String& s, Font f, bool enabled,
bool highlight, int mn, Color color, Color hltext);
class MenuItem : public MenuItemBase {
public:
virtual void Paint(Draw& w);

View file

@ -25,6 +25,18 @@ MenuItemBase::MenuItemBase()
maxiconsize = Size(INT_MAX, INT_MAX);
}
bool MenuItemBase::InOpaqueBar() const
{
const Ctrl *q = GetParent();
while(q) {
const MenuBar *bar = dynamic_cast<const MenuBar *>(q);
if(bar)
return !bar->IsTransparent();
q = q->GetParent();
}
return true;
}
Bar::Item& MenuItemBase::Text(const char *s)
{
accesskey = ExtractAccessKey(s, text);
@ -108,7 +120,7 @@ void MenuItemBase::AssignAccessKeys(dword used)
}
void DrawMnemonicText(Draw& w, int x, int y, const String& s, Font font, Color color,
int mnemonic)
int mnemonic, bool menumark)
{
int apos = HIWORD(mnemonic);
int q;
@ -123,20 +135,20 @@ void DrawMnemonicText(Draw& w, int x, int y, const String& s, Font font, Color c
if(q < 0) return;
FontInfo f = font.Info();
w.DrawRect(x + GetTextSize(~s, font, q).cx, y + f.GetAscent() + 1, f[s[q]], 1,
SColorMark());
menumark ? SColorMenuMark() : SColorMark());
}
void DrawMenuText(Draw& w, int x, int y, const String& s, Font f, bool enabled,
bool hl, int mnemonic, Color color, Color hlcolor)
bool hl, int mnemonic, Color color, Color hlcolor, bool menumark)
{
if(enabled)
DrawMnemonicText(w, x, y, s, f, hl ? hlcolor : color, mnemonic);
DrawMnemonicText(w, x, y, s, f, hl ? hlcolor : color, mnemonic, menumark);
else {
if(GUI_GlobalStyle() >= GUISTYLE_XP)
DrawMnemonicText(w, x, y, s, f, SColorDisabled, 0);
DrawMnemonicText(w, x, y, s, f, SColorDisabled, 0, menumark);
else {
DrawMnemonicText(w, x + 1, y + 1, s, f, SColorPaper, 0);
DrawMnemonicText(w, x, y, s, f, SColorDisabled, 0);
DrawMnemonicText(w, x + 1, y + 1, s, f, SColorPaper, 0, menumark);
DrawMnemonicText(w, x, y, s, f, SColorDisabled, 0, menumark);
}
}
}
@ -145,17 +157,23 @@ void MenuItemBase::DrawMenuText(Draw& w, int x, int y, const String& s, Font f,
bool hl, Color color, Color hlcolor)
{
UPP::DrawMenuText(w, x, y, s, f, enabled, hl, VisibleAccessKeys() ? accesskey : 0,
color, hlcolor);
color, hlcolor, InOpaqueBar());
}
void MenuItemBase::PaintTopItem(Draw& w, int state) {
Size sz = GetSize();
if(GUI_GlobalStyle() >= GUISTYLE_XP) {
ChPaint(w, 0, 0, sz.cx, sz.cy, style->topitem[state]);
bool opaque = InOpaqueBar();
bool opaque2 = opaque || state == 2;
if(opaque2)
ChPaint(w, 0, 0, sz.cx, sz.cy, style->topitem[state]);
else
w.DrawRect(0, 0, sz.cx, sz.cy, SColorFace());
String text = GetText();
Size isz = GetTextSize(text, StdFont());
DrawMenuText(w, 6, (sz.cy - isz.cy) / 2, text, GetFont(), IsItemEnabled(), state,
style->topitemtext[0], style->topitemtext[state]);
opaque ? style->topitemtext[0] : SColorText(),
opaque2 ? style->topitemtext[state] : SColorText());
}
else {
w.DrawRect(sz, SColorFace);
@ -296,14 +314,14 @@ void MenuItem::Paint(Draw& w)
style->itemtext);
isz = ricon.GetSize();
if(isenabled)
DrawHighlightImage(w, sz.cx - isz.cx, (sz.cy - isz.cy) / 2, ricon, hl, true);
w.DrawImage(sz.cx - isz.cx, (sz.cy - isz.cy) / 2, ricon, SColorMenuText());
else
w.DrawImage(sz.cx - isz.cx, (sz.cy - isz.cy) / 2, DisabledImage(ricon));
x = sz.cx - max(isz.cx, 16) - 1;
if(!IsEmpty(keydesc)) {
isz = GetTextSize(keydesc, StdFont());
UPP::DrawMenuText(w, x - isz.cx - 2, (sz.cy - isz.cy) / 2, keydesc, font, isenabled, hl,
0, SColorMark(), style->itemtext);
0, SColorMenuMark(), style->itemtext, false);
}
}

View file

@ -1,42 +0,0 @@
#include "Draw.h"
NAMESPACE_UPP
CH_COLOR(SBlack, Black());
CH_COLOR(SGray, Gray());
CH_COLOR(SLtGray, LtGray());
CH_COLOR(SWhiteGray, WhiteGray());
CH_COLOR(SWhite, White());
CH_COLOR(SRed, Red());
CH_COLOR(SGreen, Green());
CH_COLOR(SBrown, Brown());
CH_COLOR(SBlue, Blue());
CH_COLOR(SMagenta, Magenta());
CH_COLOR(SCyan, Cyan());
CH_COLOR(SYellow, Yellow());
CH_COLOR(SLtRed, LtRed());
CH_COLOR(SLtGreen, LtGreen());
CH_COLOR(SLtYellow, LtYellow());
CH_COLOR(SLtBlue, LtBlue());
CH_COLOR(SLtMagenta, LtMagenta());
CH_COLOR(SLtCyan, LtCyan());
CH_COLOR(SColorPaper, White());
CH_COLOR(SColorFace, LtGray());
CH_COLOR(SColorText, Black());
CH_COLOR(SColorHighlight, Blue());
CH_COLOR(SColorHighlightText, White());
CH_COLOR(SColorMenu, LtGray());
CH_COLOR(SColorMenuText, Black());
CH_COLOR(SColorInfo, LtYellow());
CH_COLOR(SColorInfoText, Black());
CH_COLOR(SColorDisabled, Gray());
CH_COLOR(SColorLight, White());
CH_COLOR(SColorShadow, Gray());
CH_COLOR(SColorMark, LtBlue());
CH_COLOR(SColorLabel, Black()); //////////////
CH_COLOR(SColorLtFace, Blend(SColorFace, SColorLight));
CH_COLOR(SColorDkShadow, Blend(SColorShadow, SColorText));
END_UPP_NAMESPACE

View file

@ -325,6 +325,7 @@ Color SColorMenuText();
Color SColorInfo();
Color SColorInfoText();//
Color SColorMark();
Color SColorMenuMark();
Color SColorDisabled();
Color SColorLight();
Color SColorFace();
@ -363,6 +364,7 @@ void SColorMenuText_Write(Color c);
void SColorInfo_Write(Color c);
void SColorInfoText_Write(Color c);//
void SColorMark_Write(Color c);
void SColorMenuMark_Write(Color c);
void SColorDisabled_Write(Color c);
void SColorLight_Write(Color c);
void SColorFace_Write(Color c);

View file

@ -33,7 +33,8 @@ CH_COLOR(SColorInfoText, Black());
CH_COLOR(SColorDisabled, Gray());
CH_COLOR(SColorLight, White());
CH_COLOR(SColorShadow, Gray());
CH_COLOR(SColorMark, LtBlue());
CH_COLOR(SColorMark, IsDark(SColorPaper()) ? LtYellow() : LtBlue());
CH_COLOR(SColorMenuMark, IsDark(SColorMenu()) ? LtYellow() : LtBlue());
CH_COLOR(SColorLtFace, Blend(SColorFace, SColorLight));
CH_COLOR(SColorDkShadow, Blend(SColorShadow, SColorText));

View file

@ -3,6 +3,10 @@
#include "ndisasm.h"
extern "C" {
#undef INT64_MIN
#undef INT64_MAX
#undef UINT64_MAX
#include "lib/compiler.h"
#include "lib/inttypes.h"
#include "lib/disasm.h"