mirror of
https://github.com/ultimatepp/ultimatepp.git
synced 2026-08-31 07:12:39 -06:00
CtrlLib, Draw: Improved support for dark visual themes (corrected text color, icon inversion for toolbar / menubar)
git-svn-id: svn://ultimatepp.org/upp/trunk@3887 f0d560ea-af0d-0410-9eb7-867de7ffcac7
This commit is contained in:
parent
708d2022c2
commit
467611ad53
17 changed files with 2013 additions and 1889 deletions
|
|
@ -133,4 +133,9 @@ bool IsDark(Color c)
|
|||
return Grayscale(c) < 80;
|
||||
}
|
||||
|
||||
bool IsLight(Color c)
|
||||
{
|
||||
return Grayscale(c) > 255 - 80;
|
||||
}
|
||||
|
||||
END_UPP_NAMESPACE
|
||||
|
|
|
|||
|
|
@ -292,6 +292,7 @@ private:
|
|||
int arealook;
|
||||
Size maxiconsize;
|
||||
LookFrame frame;
|
||||
bool nodarkadjust;
|
||||
|
||||
friend class MenuItemBase;
|
||||
friend class SubMenuBase;
|
||||
|
|
@ -354,6 +355,7 @@ public:
|
|||
MenuBar& AreaLook(int q = 1) { arealook = q; Refresh(); return *this; }
|
||||
MenuBar& MaxIconSize(Size sz) { maxiconsize = sz; return *this; }
|
||||
Size GetMaxIconSize() const { return maxiconsize; }
|
||||
MenuBar& NoDarkAdjust(bool b = true) { nodarkadjust = b; return *this; }
|
||||
|
||||
typedef MenuBar CLASSNAME;
|
||||
|
||||
|
|
@ -407,6 +409,7 @@ protected:
|
|||
byte kind;
|
||||
Size minsize;
|
||||
Size maxiconsize;
|
||||
bool nodarkadjust;
|
||||
|
||||
const Style *style;
|
||||
|
||||
|
|
@ -434,6 +437,7 @@ public:
|
|||
ToolButton& Kind(int _kind) { kind = _kind; Refresh(); return *this; }
|
||||
ToolButton& Label(const char *text, int kind);
|
||||
ToolButton& Label(const char *text);
|
||||
ToolButton& NoDarkAdjust(bool b = true) { nodarkadjust = b; return *this; }
|
||||
|
||||
ToolButton();
|
||||
virtual ~ToolButton();
|
||||
|
|
@ -472,6 +476,7 @@ private:
|
|||
Size buttonminsize;
|
||||
Size maxiconsize;
|
||||
int kind;
|
||||
bool nodarkadjust;
|
||||
|
||||
protected:
|
||||
enum {
|
||||
|
|
@ -496,6 +501,7 @@ public:
|
|||
ToolBar& MaxIconSize(Size sz) { maxiconsize = sz; return *this; }
|
||||
ToolBar& ButtonKind(int _kind) { kind = _kind; return *this; }
|
||||
ToolBar& AreaLook(int q = 1) { arealook = q; Refresh(); return *this; }
|
||||
ToolBar& NoDarkAdjust(bool b = true) { nodarkadjust = b; return *this; }
|
||||
|
||||
typedef ToolBar CLASSNAME;
|
||||
|
||||
|
|
|
|||
|
|
@ -579,7 +579,7 @@ void Option::Paint(Draw& w) {
|
|||
if(showlabel) {
|
||||
bool ds = !IsShowEnabled();
|
||||
DrawSmartText(w, isz.cx + 4, ty, tsz.cx, label, font,
|
||||
ds || IsReadOnly() ? SColorDisabled : SColorLabel, ////////
|
||||
ds || IsReadOnly() ? SColorDisabled : GetLabelTextColor(this),
|
||||
VisibleAccessKeys() ? accesskey : 0);
|
||||
if(HasFocus())
|
||||
DrawFocus(w, RectC(isz.cx + 2, ty - 1, tsz.cx + 3, tsz.cy + 2) & sz);
|
||||
|
|
|
|||
|
|
@ -171,7 +171,24 @@ Image DisabledImage(const Image& img, bool dis)
|
|||
: img;
|
||||
}
|
||||
|
||||
Size DrawLabel::Paint(Draw& w, const Rect& r, bool visibleaccesskey) const
|
||||
Color GetLabelTextColor(const Ctrl *ctrl)
|
||||
{
|
||||
if(!IsLabelTextColorMismatch())
|
||||
return SColorLabel();
|
||||
while(ctrl) {
|
||||
if(!ctrl->IsTransparent()) {
|
||||
if(dynamic_cast<const TopWindow *>(ctrl) || dynamic_cast<const TabCtrl *>(ctrl) ||
|
||||
dynamic_cast<const ToolBar *>(ctrl) || dynamic_cast<const MenuBar *>(ctrl) ||
|
||||
dynamic_cast<const StaticRect *>(ctrl) || dynamic_cast<const StaticBarArea *>(ctrl))
|
||||
break;
|
||||
return SColorText();
|
||||
}
|
||||
ctrl = ctrl->GetParent();
|
||||
}
|
||||
return SColorLabel();
|
||||
}
|
||||
|
||||
Size DrawLabel::Paint(Ctrl *ctrl, Draw& w, const Rect& r, bool visibleaccesskey) const
|
||||
{
|
||||
int lspc = this->lspc;
|
||||
int rspc = this->rspc;
|
||||
|
|
@ -209,7 +226,7 @@ Size DrawLabel::Paint(Draw& w, const Rect& r, bool visibleaccesskey) const
|
|||
p.y = (r.bottom + r.top - txtsz.cy) / 2;
|
||||
Color color = disabled && !IsNull(disabledink) ? disabledink : ink;
|
||||
if(IsNull(color))
|
||||
color = disabled ? SColorDisabled : SColorLabel; /////////
|
||||
color = disabled ? SColorDisabled : GetLabelTextColor(ctrl);
|
||||
int ix;
|
||||
if(IsNull(lspc))
|
||||
ix = r.left + push;
|
||||
|
|
@ -247,6 +264,16 @@ Size DrawLabel::Paint(Draw& w, const Rect& r, bool visibleaccesskey) const
|
|||
return isz;
|
||||
}
|
||||
|
||||
Size DrawLabel::Paint(Ctrl *ctrl, Draw& w, int x, int y, int cx, int cy, bool visibleaccesskey) const
|
||||
{
|
||||
return Paint(ctrl, w, RectC(x, y, cx, cy), visibleaccesskey);
|
||||
}
|
||||
|
||||
Size DrawLabel::Paint(Draw& w, const Rect& r, bool visibleaccesskey) const
|
||||
{
|
||||
return Paint(NULL, w, r, visibleaccesskey);
|
||||
}
|
||||
|
||||
Size DrawLabel::Paint(Draw& w, int x, int y, int cx, int cy, bool vak) const
|
||||
{
|
||||
return Paint(w, RectC(x, y, cx, cy), vak);
|
||||
|
|
@ -316,13 +343,23 @@ LabelBase& LabelBase::SetVAlign(int valign) {
|
|||
return *this;
|
||||
}
|
||||
|
||||
Size LabelBase::PaintLabel(Draw& w, const Rect& r, bool disabled, bool push, bool focus, bool vak)
|
||||
Size LabelBase::PaintLabel(Ctrl *ctrl, Draw& w, const Rect& r, bool disabled, bool push, bool focus, bool vak)
|
||||
{
|
||||
DrawLabel lbl1 = lbl;
|
||||
lbl1.disabled = disabled;
|
||||
lbl1.push = push;
|
||||
lbl1.focus = focus;
|
||||
return lbl1.Paint(w, r, vak);
|
||||
return lbl1.Paint(ctrl, w, r, vak);
|
||||
}
|
||||
|
||||
Size LabelBase::PaintLabel(Ctrl *ctrl, Draw& w, int x, int y, int cx, int cy, bool disabled, bool push, bool focus, bool vak)
|
||||
{
|
||||
return PaintLabel(ctrl, w, RectC(x, y, cx, cy), disabled, push, focus, vak);
|
||||
}
|
||||
|
||||
Size LabelBase::PaintLabel(Draw& w, const Rect& r, bool disabled, bool push, bool focus, bool vak)
|
||||
{
|
||||
return PaintLabel(NULL, w, r, disabled, push, focus, vak);
|
||||
}
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -52,6 +52,8 @@ struct DrawLabel {
|
|||
|
||||
Size GetSize(int txtcx, Size sz1, int lspc, Size sz2, int rspc) const;
|
||||
Size GetSize(int txtcx = INT_MAX) const;
|
||||
Size Paint(Ctrl *ctrl, Draw& w, const Rect& r, bool visibleaccesskey = true) const;
|
||||
Size Paint(Ctrl *ctrl, Draw& w, int x, int y, int cx, int cy, bool visibleaccesskey = true) const;
|
||||
Size Paint(Draw& w, const Rect& r, bool visibleaccesskey = true) const;
|
||||
Size Paint(Draw& w, int x, int y, int cx, int cy, bool visibleaccesskey = true) const;
|
||||
|
||||
|
|
@ -59,6 +61,7 @@ struct DrawLabel {
|
|||
};
|
||||
|
||||
Image DisabledImage(const Image& img, bool disabled = true);
|
||||
Color GetLabelTextColor(const Ctrl *ctrl);
|
||||
|
||||
class LabelBase {
|
||||
protected:
|
||||
|
|
@ -86,6 +89,10 @@ public:
|
|||
Font GetFont() const { return lbl.font; }
|
||||
Color GetInk() const { return lbl.ink; }
|
||||
|
||||
Size PaintLabel(Ctrl *ctrl, Draw& w, const Rect& r,
|
||||
bool disabled = false, bool push = false, bool focus = false, bool vak = true);
|
||||
Size PaintLabel(Ctrl *ctrl, Draw& w, int x, int y, int cx, int cy,
|
||||
bool disabled = false, bool push = false, bool focus = false, bool vak = true);
|
||||
Size PaintLabel(Draw& w, const Rect& r,
|
||||
bool disabled = false, bool push = false, bool focus = false, bool vak = true);
|
||||
Size PaintLabel(Draw& w, int x, int y, int cx, int cy,
|
||||
|
|
|
|||
|
|
@ -62,6 +62,7 @@ MenuBar::MenuBar()
|
|||
SetStyle(StyleDefault());
|
||||
arealook = -1;
|
||||
maxiconsize = Null;
|
||||
nodarkadjust = false;
|
||||
}
|
||||
|
||||
MenuBar& MenuBar::SetStyle(const Style& s)
|
||||
|
|
|
|||
|
|
@ -42,6 +42,7 @@ protected:
|
|||
int accesskey;
|
||||
Size maxiconsize;
|
||||
const MenuBar::Style *style;
|
||||
bool nodarkadjust;
|
||||
|
||||
public:
|
||||
virtual void SyncState() = 0;
|
||||
|
|
@ -59,6 +60,7 @@ public:
|
|||
Font GetFont() const { return font; }
|
||||
MenuItemBase& MaxIconSize(Size sz) { maxiconsize = sz; return *this; }
|
||||
bool InOpaqueBar() const;
|
||||
MenuItemBase& NoDarkAdjust(bool b = true) { nodarkadjust = b; return *this; }
|
||||
|
||||
MenuItemBase();
|
||||
};
|
||||
|
|
|
|||
|
|
@ -173,8 +173,8 @@ void MenuItemBase::PaintTopItem(Draw& w, int state) {
|
|||
String text = GetText();
|
||||
Size isz = GetTextSize(text, StdFont());
|
||||
DrawMenuText(w, 6, (sz.cy - isz.cy) / 2, text, GetFont(), IsItemEnabled(), state,
|
||||
opaque ? style->topitemtext[0] : SColorLabel(),
|
||||
opaque2 ? style->topitemtext[state] : SColorLabel());
|
||||
opaque ? style->topitemtext[0] : GetLabelTextColor(this),
|
||||
opaque2 ? style->topitemtext[state] : GetLabelTextColor(this));
|
||||
}
|
||||
else {
|
||||
w.DrawRect(sz, SColorFace);
|
||||
|
|
@ -194,6 +194,8 @@ void MenuItemBase::PaintTopItem(Draw& w, int state) {
|
|||
Bar::Item& MenuItem::Image(const UPP::Image& img)
|
||||
{
|
||||
licon = img;
|
||||
if(IsDarkColorFace() && !nodarkadjust)
|
||||
licon = MakeImage(licon, AdjustForDarkBk);
|
||||
Refresh();
|
||||
return *this;
|
||||
}
|
||||
|
|
@ -201,6 +203,8 @@ Bar::Item& MenuItem::Image(const UPP::Image& img)
|
|||
MenuItem& MenuItem::RightImage(const UPP::Image& img)
|
||||
{
|
||||
ricon = img;
|
||||
if(IsDarkColorFace() && !nodarkadjust)
|
||||
ricon = MakeImage(ricon, AdjustForDarkBk);
|
||||
Refresh();
|
||||
return *this;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -7,7 +7,7 @@ void StaticText::Paint(Draw& w)
|
|||
Size sz = GetSize();
|
||||
if(!IsTransparent())
|
||||
w.DrawRect(0, 0, sz.cx, sz.cy, SColorFace);
|
||||
PaintLabel(w, 0, 0, sz.cx, sz.cy, !IsShowEnabled(), false, false, VisibleAccessKeys());
|
||||
PaintLabel(this, w, 0, 0, sz.cx, sz.cy, !IsShowEnabled(), false, false, VisibleAccessKeys());
|
||||
}
|
||||
|
||||
Size StaticText::GetMinSize() const
|
||||
|
|
@ -79,7 +79,7 @@ Label::Label() {
|
|||
|
||||
Label::~Label() {}
|
||||
|
||||
CH_COLOR(LabelBoxTextColor, LtBlue());
|
||||
CH_COLOR(LabelBoxTextColor, IsDark(SColorFace()) ? Blend(LtBlue(), White) : LtBlue());
|
||||
CH_COLOR(LabelBoxDisabledTextColor, SColorDisabled());
|
||||
CH_COLOR(LabelBoxColor, SColorShadow());
|
||||
|
||||
|
|
|
|||
|
|
@ -187,7 +187,7 @@ void Switch::Paint(Draw& w) {
|
|||
img = CtrlsImg::Get((v.value == value ? CtrlsImg::I_S1 : CtrlsImg::I_S0) + q);
|
||||
w.DrawImage(x, y + iy, img);
|
||||
DrawSmartText(w, x + isz.cx + 4, y + ty, sz.cx, v.label, font,
|
||||
dv || IsReadOnly() ? SColorDisabled : SColorLabel, ///////
|
||||
dv || IsReadOnly() ? SColorDisabled : GetLabelTextColor(this), ///////
|
||||
VisibleAccessKeys() ? v.accesskey : 0);
|
||||
if(HasFocus() && (pushindex == i || v.value == value && pushindex < 0))
|
||||
DrawFocus(w, RectC(x + isz.cx + 2, y + ty - 1, tsz.cx + 3, tsz.cy + 2) & sz);
|
||||
|
|
|
|||
|
|
@ -26,6 +26,7 @@ ToolBar::ToolBar()
|
|||
maxiconsize = Null;
|
||||
kind = ToolButton::NOLABEL;
|
||||
arealook = -1;
|
||||
nodarkadjust = false;
|
||||
}
|
||||
|
||||
ToolBar::~ToolBar() {}
|
||||
|
|
@ -60,6 +61,7 @@ Bar::Item& ToolBar::AddItem(Callback cb)
|
|||
m.MaxIconSize(IsNull(maxiconsize) ? style->maxiconsize : maxiconsize);
|
||||
m.Kind(kind);
|
||||
m.SetStyle(style->buttonstyle);
|
||||
m.NoDarkAdjust(nodarkadjust);
|
||||
pane.Add(&m, Null);
|
||||
return m;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,317 +1,321 @@
|
|||
#include "CtrlLib.h"
|
||||
|
||||
NAMESPACE_UPP
|
||||
|
||||
#define LTIMING(x) // TIMING(x)
|
||||
|
||||
CH_STYLE(ToolButton, Style, StyleDefault)
|
||||
{
|
||||
CtrlsImageLook(look, CtrlsImg::I_TB, 6);
|
||||
font = StdFont();
|
||||
for(int i = 0; i < 4; i++)
|
||||
textcolor[i] = Button::StyleNormal().textcolor[i];
|
||||
textcolor[CTRL_CHECKED] = textcolor[CTRL_NORMAL];
|
||||
textcolor[CTRL_HOTCHECKED] = textcolor[CTRL_HOT];
|
||||
for(int i = 0; i < 6; i++) {
|
||||
light[i] = false;
|
||||
contrast[i] = 0;
|
||||
}
|
||||
light[CTRL_PRESSED] = light[CTRL_HOT] = light[CTRL_HOTCHECKED] = true;
|
||||
}
|
||||
|
||||
CH_STYLE(ToolButton, Style, StyleSolid)
|
||||
{
|
||||
const Button::Style& bs = Button::StyleNormal();
|
||||
look[0] = bs.look[0];
|
||||
look[1] = bs.look[1];
|
||||
look[2] = bs.look[2];
|
||||
look[3] = bs.look[3];
|
||||
look[4] = bs.look[2];
|
||||
look[5] = bs.look[1];
|
||||
font = StdFont();
|
||||
for(int i = 0; i < 4; i++)
|
||||
textcolor[i] = Button::StyleNormal().textcolor[i];
|
||||
textcolor[CTRL_CHECKED] = textcolor[CTRL_NORMAL];
|
||||
textcolor[CTRL_HOTCHECKED] = textcolor[CTRL_HOT];
|
||||
for(int i = 0; i < 6; i++) {
|
||||
light[i] = false;
|
||||
contrast[i] = 0;
|
||||
}
|
||||
light[CTRL_PRESSED] = light[CTRL_HOT] = light[CTRL_HOTCHECKED] = true;
|
||||
}
|
||||
|
||||
ToolButton::ToolButton()
|
||||
{
|
||||
Reset();
|
||||
checked = false;
|
||||
paint_checked = false;
|
||||
Transparent();
|
||||
kind = NOLABEL;
|
||||
}
|
||||
|
||||
ToolButton::~ToolButton() {}
|
||||
|
||||
void ToolButton::Reset()
|
||||
{
|
||||
Tip("");
|
||||
Help("");
|
||||
Topic("");
|
||||
Description("");
|
||||
repeat = false;
|
||||
accel = 0;
|
||||
checked = false;
|
||||
NoWantFocus();
|
||||
minsize = Size(0, 0);
|
||||
maxiconsize = Size(INT_MAX, INT_MAX);
|
||||
style = &StyleDefault();
|
||||
}
|
||||
|
||||
void ToolButton::UpdateTip()
|
||||
{
|
||||
LTIMING("UpdateTip");
|
||||
String s = tiptext;
|
||||
if(IsNull(s) && kind == NOLABEL)
|
||||
s = text;
|
||||
if(accel) {
|
||||
if(s.GetCount())
|
||||
s << ' ';
|
||||
s << '(' << GetKeyDesc(accel) << ')';
|
||||
}
|
||||
Ctrl::Tip(s);
|
||||
}
|
||||
|
||||
Bar::Item& ToolButton::Text(const char *txt)
|
||||
{
|
||||
ExtractAccessKey(txt, text);
|
||||
UpdateTip();
|
||||
Refresh();
|
||||
return *this;
|
||||
}
|
||||
|
||||
Bar::Item& ToolButton::Check(bool check)
|
||||
{
|
||||
checked = check;
|
||||
Refresh();
|
||||
return *this;
|
||||
}
|
||||
|
||||
Bar::Item& ToolButton::Radio(bool check)
|
||||
{
|
||||
return Check(check);
|
||||
}
|
||||
|
||||
Bar::Item& ToolButton::Key(dword key)
|
||||
{
|
||||
if(key) {
|
||||
accel = key;
|
||||
UpdateTip();
|
||||
}
|
||||
return *this;
|
||||
}
|
||||
|
||||
Bar::Item& ToolButton::Repeat(bool r)
|
||||
{
|
||||
repeat = r;
|
||||
return *this;
|
||||
}
|
||||
|
||||
ToolButton& ToolButton::Label(const char *text, int _kind)
|
||||
{
|
||||
if(kind != _kind) {
|
||||
kind = _kind;
|
||||
Refresh();
|
||||
}
|
||||
Text(text);
|
||||
return *this;
|
||||
}
|
||||
|
||||
ToolButton& ToolButton::Label(const char *text)
|
||||
{
|
||||
Label(text, kind == NOLABEL ? RIGHTLABEL : kind);
|
||||
return *this;
|
||||
}
|
||||
|
||||
Image ToolButton::GetImage() const
|
||||
{
|
||||
return CachedRescale(img, min(img.GetSize(), maxiconsize));
|
||||
}
|
||||
|
||||
Bar::Item& ToolButton::Image(const UPP::Image& img_)
|
||||
{
|
||||
if(!img_.IsSame(img)) {
|
||||
img = img_;
|
||||
Refresh();
|
||||
}
|
||||
return *this;
|
||||
}
|
||||
|
||||
Bar::Item& ToolButton::Enable(bool enable)
|
||||
{
|
||||
Ctrl::Enable(enable);
|
||||
return *this;
|
||||
}
|
||||
|
||||
Bar::Item& ToolButton::Tip(const char *tip)
|
||||
{
|
||||
tiptext = tip;
|
||||
UpdateTip();
|
||||
return *this;
|
||||
}
|
||||
|
||||
Bar::Item& ToolButton::Help(const char *help)
|
||||
{
|
||||
HelpLine(help);
|
||||
return *this;
|
||||
}
|
||||
|
||||
Bar::Item& ToolButton::Topic(const char *help)
|
||||
{
|
||||
HelpTopic(help);
|
||||
return *this;
|
||||
}
|
||||
|
||||
Bar::Item& ToolButton::Description(const char *desc)
|
||||
{
|
||||
Ctrl::Description(desc);
|
||||
return *this;
|
||||
}
|
||||
|
||||
struct sCachedContrast : public ImageMaker
|
||||
{
|
||||
int d;
|
||||
Image img;
|
||||
|
||||
virtual String Key() const {
|
||||
String s;
|
||||
RawCat(s, d);
|
||||
RawCat(s, img.GetSerialId());
|
||||
return s;
|
||||
}
|
||||
|
||||
virtual Image Make() const {
|
||||
return Contrast(img, 256 + d);
|
||||
}
|
||||
};
|
||||
|
||||
Image CachedContrast(const Image& m, int d)
|
||||
{
|
||||
if(d == 0)
|
||||
return m;
|
||||
sCachedContrast cr;
|
||||
cr.d = d;
|
||||
cr.img = m;
|
||||
return MakeImage(cr);
|
||||
}
|
||||
|
||||
void ToolButton::Paint(Draw& w)
|
||||
{
|
||||
LTIMING("ToolButton::Paint");
|
||||
paint_checked = checked;
|
||||
Size sz = GetSize();
|
||||
UPP::Image image = GetImage();
|
||||
Size isz = image.GetSize();
|
||||
// Ctrl *q = GetParent()->GetParent();
|
||||
// if(!q || !q->IsTransparent())
|
||||
// w.DrawRect(sz, checked && !HasMouse() ? Blend(SColorFace, SColorLight) : SColorFace);
|
||||
int li = IsEnabled() ? HasMouse() ? GetMouseLeft() ? CTRL_PRESSED
|
||||
: checked ? CTRL_HOTCHECKED : CTRL_HOT
|
||||
: checked ? CTRL_CHECKED : CTRL_NORMAL
|
||||
: CTRL_DISABLED;
|
||||
ChPaint(w, sz, style->look[li]);
|
||||
Point off = style->offset[li];
|
||||
Point ip = (sz - isz) / 2 + off;
|
||||
Size tsz;
|
||||
if(kind != NOLABEL)
|
||||
tsz = GetTextSize(text, style->font);
|
||||
if(kind == BOTTOMLABEL) {
|
||||
ip.y -= tsz.cy / 2 + 1;
|
||||
w.DrawText((sz.cx - tsz.cx) / 2 + off.x, ip.y + isz.cy + 2 + off.y, text, style->font, style->textcolor[li]);
|
||||
}
|
||||
if(kind == RIGHTLABEL) {
|
||||
ip.x -= tsz.cx / 2 + 2;
|
||||
w.DrawText(ip.x + isz.cx + 3 + off.x, (sz.cy - tsz.cy) / 2 + off.y, text, style->font, style->textcolor[li]);
|
||||
}
|
||||
UPP::Image img = CachedContrast(image, style->contrast[li]);
|
||||
if(!IsEnabled())
|
||||
img = DisabledImage(img);
|
||||
if(IsEnabled() && style->light[li])
|
||||
DrawHighlightImage(w, ip.x, ip.y, img, true);
|
||||
else
|
||||
w.DrawImage(ip.x, ip.y, img);
|
||||
}
|
||||
|
||||
void ToolButton::MouseEnter(Point, dword)
|
||||
{
|
||||
BarCtrl::SendHelpLine(this);
|
||||
Refresh();
|
||||
}
|
||||
|
||||
void ToolButton::MouseLeave()
|
||||
{
|
||||
BarCtrl::ClearHelpLine(this);
|
||||
Refresh();
|
||||
}
|
||||
|
||||
Size ToolButton::GetMinSize() const
|
||||
{
|
||||
UPP::Image image = GetImage();
|
||||
Size sz = image.GetSize();
|
||||
if(sz.IsEmpty())
|
||||
sz = Size(16, 16);
|
||||
sz += 6;
|
||||
if(text.GetCount()) {
|
||||
Size tsz = GetTextSize(text, style->font);
|
||||
if(kind == BOTTOMLABEL) {
|
||||
sz.cy += tsz.cy + 3;
|
||||
sz.cx = max(sz.cx, tsz.cx + 9);
|
||||
}
|
||||
if(kind == RIGHTLABEL) {
|
||||
sz.cx += tsz.cx + 6;
|
||||
sz.cy = max(sz.cy, tsz.cy + 6);
|
||||
}
|
||||
}
|
||||
return max(sz, minsize);
|
||||
}
|
||||
|
||||
void ToolButton::LeftDown(Point, dword)
|
||||
{
|
||||
Refresh();
|
||||
if(repeat)
|
||||
WhenAction();
|
||||
}
|
||||
|
||||
void ToolButton::LeftRepeat(Point, dword)
|
||||
{
|
||||
Refresh();
|
||||
if(repeat)
|
||||
WhenAction();
|
||||
}
|
||||
|
||||
void ToolButton::LeftUp(Point, dword)
|
||||
{
|
||||
Refresh();
|
||||
if(!repeat)
|
||||
WhenAction();
|
||||
}
|
||||
|
||||
bool ToolButton::HotKey(dword key)
|
||||
{
|
||||
if(key == accel) {
|
||||
WhenAction();
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
void ToolButton::FinalSync()
|
||||
{
|
||||
if(checked != paint_checked)
|
||||
Refresh();
|
||||
}
|
||||
|
||||
String ToolButton::GetDesc() const
|
||||
{
|
||||
return tiptext;
|
||||
}
|
||||
|
||||
END_UPP_NAMESPACE
|
||||
#include "CtrlLib.h"
|
||||
|
||||
NAMESPACE_UPP
|
||||
|
||||
#define LTIMING(x) // TIMING(x)
|
||||
|
||||
CH_STYLE(ToolButton, Style, StyleDefault)
|
||||
{
|
||||
CtrlsImageLook(look, CtrlsImg::I_TB, 6);
|
||||
font = StdFont();
|
||||
for(int i = 0; i < 4; i++)
|
||||
textcolor[i] = Button::StyleNormal().textcolor[i];
|
||||
textcolor[CTRL_CHECKED] = textcolor[CTRL_NORMAL];
|
||||
textcolor[CTRL_HOTCHECKED] = textcolor[CTRL_HOT];
|
||||
for(int i = 0; i < 6; i++) {
|
||||
light[i] = false;
|
||||
contrast[i] = 0;
|
||||
}
|
||||
light[CTRL_PRESSED] = light[CTRL_HOT] = light[CTRL_HOTCHECKED] = true;
|
||||
}
|
||||
|
||||
CH_STYLE(ToolButton, Style, StyleSolid)
|
||||
{
|
||||
const Button::Style& bs = Button::StyleNormal();
|
||||
look[0] = bs.look[0];
|
||||
look[1] = bs.look[1];
|
||||
look[2] = bs.look[2];
|
||||
look[3] = bs.look[3];
|
||||
look[4] = bs.look[2];
|
||||
look[5] = bs.look[1];
|
||||
font = StdFont();
|
||||
for(int i = 0; i < 4; i++)
|
||||
textcolor[i] = Button::StyleNormal().textcolor[i];
|
||||
textcolor[CTRL_CHECKED] = textcolor[CTRL_NORMAL];
|
||||
textcolor[CTRL_HOTCHECKED] = textcolor[CTRL_HOT];
|
||||
for(int i = 0; i < 6; i++) {
|
||||
light[i] = false;
|
||||
contrast[i] = 0;
|
||||
}
|
||||
light[CTRL_PRESSED] = light[CTRL_HOT] = light[CTRL_HOTCHECKED] = true;
|
||||
}
|
||||
|
||||
ToolButton::ToolButton()
|
||||
{
|
||||
Reset();
|
||||
checked = false;
|
||||
paint_checked = false;
|
||||
nodarkadjust = false;
|
||||
Transparent();
|
||||
kind = NOLABEL;
|
||||
}
|
||||
|
||||
ToolButton::~ToolButton() {}
|
||||
|
||||
void ToolButton::Reset()
|
||||
{
|
||||
Tip("");
|
||||
Help("");
|
||||
Topic("");
|
||||
Description("");
|
||||
repeat = false;
|
||||
accel = 0;
|
||||
checked = false;
|
||||
NoWantFocus();
|
||||
minsize = Size(0, 0);
|
||||
maxiconsize = Size(INT_MAX, INT_MAX);
|
||||
style = &StyleDefault();
|
||||
}
|
||||
|
||||
void ToolButton::UpdateTip()
|
||||
{
|
||||
LTIMING("UpdateTip");
|
||||
String s = tiptext;
|
||||
if(IsNull(s) && kind == NOLABEL)
|
||||
s = text;
|
||||
if(accel) {
|
||||
if(s.GetCount())
|
||||
s << ' ';
|
||||
s << '(' << GetKeyDesc(accel) << ')';
|
||||
}
|
||||
Ctrl::Tip(s);
|
||||
}
|
||||
|
||||
Bar::Item& ToolButton::Text(const char *txt)
|
||||
{
|
||||
ExtractAccessKey(txt, text);
|
||||
UpdateTip();
|
||||
Refresh();
|
||||
return *this;
|
||||
}
|
||||
|
||||
Bar::Item& ToolButton::Check(bool check)
|
||||
{
|
||||
checked = check;
|
||||
Refresh();
|
||||
return *this;
|
||||
}
|
||||
|
||||
Bar::Item& ToolButton::Radio(bool check)
|
||||
{
|
||||
return Check(check);
|
||||
}
|
||||
|
||||
Bar::Item& ToolButton::Key(dword key)
|
||||
{
|
||||
if(key) {
|
||||
accel = key;
|
||||
UpdateTip();
|
||||
}
|
||||
return *this;
|
||||
}
|
||||
|
||||
Bar::Item& ToolButton::Repeat(bool r)
|
||||
{
|
||||
repeat = r;
|
||||
return *this;
|
||||
}
|
||||
|
||||
ToolButton& ToolButton::Label(const char *text, int _kind)
|
||||
{
|
||||
if(kind != _kind) {
|
||||
kind = _kind;
|
||||
Refresh();
|
||||
}
|
||||
Text(text);
|
||||
return *this;
|
||||
}
|
||||
|
||||
ToolButton& ToolButton::Label(const char *text)
|
||||
{
|
||||
Label(text, kind == NOLABEL ? RIGHTLABEL : kind);
|
||||
return *this;
|
||||
}
|
||||
|
||||
Image ToolButton::GetImage() const
|
||||
{
|
||||
UPP::Image m = img;
|
||||
if(IsDarkColorFace() && !nodarkadjust)
|
||||
m = MakeImage(m, AdjustForDarkBk);
|
||||
return CachedRescale(m, min(m.GetSize(), maxiconsize));
|
||||
}
|
||||
|
||||
Bar::Item& ToolButton::Image(const UPP::Image& img_)
|
||||
{
|
||||
if(!img_.IsSame(img)) {
|
||||
img = img_;
|
||||
Refresh();
|
||||
}
|
||||
return *this;
|
||||
}
|
||||
|
||||
Bar::Item& ToolButton::Enable(bool enable)
|
||||
{
|
||||
Ctrl::Enable(enable);
|
||||
return *this;
|
||||
}
|
||||
|
||||
Bar::Item& ToolButton::Tip(const char *tip)
|
||||
{
|
||||
tiptext = tip;
|
||||
UpdateTip();
|
||||
return *this;
|
||||
}
|
||||
|
||||
Bar::Item& ToolButton::Help(const char *help)
|
||||
{
|
||||
HelpLine(help);
|
||||
return *this;
|
||||
}
|
||||
|
||||
Bar::Item& ToolButton::Topic(const char *help)
|
||||
{
|
||||
HelpTopic(help);
|
||||
return *this;
|
||||
}
|
||||
|
||||
Bar::Item& ToolButton::Description(const char *desc)
|
||||
{
|
||||
Ctrl::Description(desc);
|
||||
return *this;
|
||||
}
|
||||
|
||||
struct sCachedContrast : public ImageMaker
|
||||
{
|
||||
int d;
|
||||
Image img;
|
||||
|
||||
virtual String Key() const {
|
||||
String s;
|
||||
RawCat(s, d);
|
||||
RawCat(s, img.GetSerialId());
|
||||
return s;
|
||||
}
|
||||
|
||||
virtual Image Make() const {
|
||||
return Contrast(img, 256 + d);
|
||||
}
|
||||
};
|
||||
|
||||
Image CachedContrast(const Image& m, int d)
|
||||
{
|
||||
if(d == 0)
|
||||
return m;
|
||||
sCachedContrast cr;
|
||||
cr.d = d;
|
||||
cr.img = m;
|
||||
return MakeImage(cr);
|
||||
}
|
||||
|
||||
void ToolButton::Paint(Draw& w)
|
||||
{
|
||||
LTIMING("ToolButton::Paint");
|
||||
paint_checked = checked;
|
||||
Size sz = GetSize();
|
||||
UPP::Image image = GetImage();
|
||||
Size isz = image.GetSize();
|
||||
// Ctrl *q = GetParent()->GetParent();
|
||||
// if(!q || !q->IsTransparent())
|
||||
// w.DrawRect(sz, checked && !HasMouse() ? Blend(SColorFace, SColorLight) : SColorFace);
|
||||
int li = IsEnabled() ? HasMouse() ? GetMouseLeft() ? CTRL_PRESSED
|
||||
: checked ? CTRL_HOTCHECKED : CTRL_HOT
|
||||
: checked ? CTRL_CHECKED : CTRL_NORMAL
|
||||
: CTRL_DISABLED;
|
||||
ChPaint(w, sz, style->look[li]);
|
||||
Point off = style->offset[li];
|
||||
Point ip = (sz - isz) / 2 + off;
|
||||
Size tsz;
|
||||
if(kind != NOLABEL)
|
||||
tsz = GetTextSize(text, style->font);
|
||||
if(kind == BOTTOMLABEL) {
|
||||
ip.y -= tsz.cy / 2 + 1;
|
||||
w.DrawText((sz.cx - tsz.cx) / 2 + off.x, ip.y + isz.cy + 2 + off.y, text, style->font, style->textcolor[li]);
|
||||
}
|
||||
if(kind == RIGHTLABEL) {
|
||||
ip.x -= tsz.cx / 2 + 2;
|
||||
w.DrawText(ip.x + isz.cx + 3 + off.x, (sz.cy - tsz.cy) / 2 + off.y, text, style->font, style->textcolor[li]);
|
||||
}
|
||||
UPP::Image img = CachedContrast(image, style->contrast[li]);
|
||||
if(!IsEnabled())
|
||||
img = DisabledImage(img);
|
||||
if(IsEnabled() && style->light[li])
|
||||
DrawHighlightImage(w, ip.x, ip.y, img, true);
|
||||
else
|
||||
w.DrawImage(ip.x, ip.y, img);
|
||||
}
|
||||
|
||||
void ToolButton::MouseEnter(Point, dword)
|
||||
{
|
||||
BarCtrl::SendHelpLine(this);
|
||||
Refresh();
|
||||
}
|
||||
|
||||
void ToolButton::MouseLeave()
|
||||
{
|
||||
BarCtrl::ClearHelpLine(this);
|
||||
Refresh();
|
||||
}
|
||||
|
||||
Size ToolButton::GetMinSize() const
|
||||
{
|
||||
UPP::Image image = GetImage();
|
||||
Size sz = image.GetSize();
|
||||
if(sz.IsEmpty())
|
||||
sz = Size(16, 16);
|
||||
sz += 6;
|
||||
if(text.GetCount()) {
|
||||
Size tsz = GetTextSize(text, style->font);
|
||||
if(kind == BOTTOMLABEL) {
|
||||
sz.cy += tsz.cy + 3;
|
||||
sz.cx = max(sz.cx, tsz.cx + 9);
|
||||
}
|
||||
if(kind == RIGHTLABEL) {
|
||||
sz.cx += tsz.cx + 6;
|
||||
sz.cy = max(sz.cy, tsz.cy + 6);
|
||||
}
|
||||
}
|
||||
return max(sz, minsize);
|
||||
}
|
||||
|
||||
void ToolButton::LeftDown(Point, dword)
|
||||
{
|
||||
Refresh();
|
||||
if(repeat)
|
||||
WhenAction();
|
||||
}
|
||||
|
||||
void ToolButton::LeftRepeat(Point, dword)
|
||||
{
|
||||
Refresh();
|
||||
if(repeat)
|
||||
WhenAction();
|
||||
}
|
||||
|
||||
void ToolButton::LeftUp(Point, dword)
|
||||
{
|
||||
Refresh();
|
||||
if(!repeat)
|
||||
WhenAction();
|
||||
}
|
||||
|
||||
bool ToolButton::HotKey(dword key)
|
||||
{
|
||||
if(key == accel) {
|
||||
WhenAction();
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
void ToolButton::FinalSync()
|
||||
{
|
||||
if(checked != paint_checked)
|
||||
Refresh();
|
||||
}
|
||||
|
||||
String ToolButton::GetDesc() const
|
||||
{
|
||||
return tiptext;
|
||||
}
|
||||
|
||||
END_UPP_NAMESPACE
|
||||
|
|
|
|||
|
|
@ -2,7 +2,7 @@
|
|||
#define _CtrlLib_icpp_init_stub
|
||||
#include "CtrlCore/init"
|
||||
#include "PdfDraw/init"
|
||||
#define BLITZ_INDEX__ F682CA52260E08DE87F9D30ACEC11FC17
|
||||
#define BLITZ_INDEX__ F81538F57228D18567476124EF6E8A601
|
||||
#include "CtrlLib.icpp"
|
||||
#undef BLITZ_INDEX__
|
||||
#endif
|
||||
|
|
|
|||
1204
uppsrc/Draw/Cham.cpp
1204
uppsrc/Draw/Cham.cpp
File diff suppressed because it is too large
Load diff
|
|
@ -1,120 +1,122 @@
|
|||
enum LookOp {
|
||||
LOOK_PAINT,
|
||||
LOOK_MARGINS,
|
||||
LOOK_PAINTEDGE,
|
||||
LOOK_ISOPAQUE,
|
||||
LOOK_ISBODYOPAQUE,
|
||||
};
|
||||
|
||||
void ChLookFn(Value (*fn)(Draw& w, const Rect& r, const Value& look, int lookop));
|
||||
|
||||
Image AdjustColors(const Image& img);
|
||||
|
||||
void Override(Iml& target, Iml& source, bool colored = false);
|
||||
void ColoredOverride(Iml& target, Iml& source);
|
||||
|
||||
void ChReset();
|
||||
void ChFinish();
|
||||
|
||||
void ChPaint(Draw& w, const Rect& r, const Value& look);
|
||||
void ChPaint(Draw& w, int x, int y, int cx, int cy, const Value& look);
|
||||
void ChPaintEdge(Draw& w, const Rect& r, const Value& look);
|
||||
void ChPaintEdge(Draw& w, int x, int y, int cx, int cy, const Value& look);
|
||||
void ChPaintBody(Draw& w, const Rect& r, const Value& look);
|
||||
void ChPaintBody(Draw& w, int x, int y, int cx, int cy, const Value& look);
|
||||
Rect ChMargins(const Value& look);
|
||||
bool ChIsOpaque(const Value& look);
|
||||
bool ChIsBodyOpaque(const Value& look);
|
||||
|
||||
void DeflateMargins(Rect& r, const Rect& margin);
|
||||
void ChDeflateMargins(Rect& r, const Value& look);
|
||||
void DeflateMargins(Size& sz, const Rect& m);
|
||||
void ChDeflateMargins(Size& sz, const Value& look);
|
||||
void InflateMargins(Rect& r, const Rect& m);
|
||||
void ChInflateMargins(Rect& r, const Value& look);
|
||||
void InflateMargins(Size& sz, const Rect& m);
|
||||
void ChInflateMargins(Size& sz, const Value& look);
|
||||
|
||||
void ChInvalidate();
|
||||
bool ChIsInvalidated();
|
||||
|
||||
template <class T>
|
||||
struct ChStyle {
|
||||
byte status;
|
||||
byte registered;
|
||||
T *standard;
|
||||
|
||||
const T& Standard() const { return *standard; }
|
||||
T& Write() const { T& x = *(T *)this; x.status = 2; ChInvalidate(); return x; }
|
||||
void Assign(const T& src) { *(T *)this = src; }
|
||||
|
||||
ChStyle() { status = 0; registered = 0; standard = NULL; }
|
||||
};
|
||||
|
||||
#define CH_STYLE(klass, type, style) \
|
||||
struct COMBINE5(klass, __, type, __, style) : klass::type { \
|
||||
void Init(); \
|
||||
static void InitIt(); \
|
||||
}; \
|
||||
\
|
||||
void COMBINE5(klass, __, type, __, style)::InitIt() { \
|
||||
klass::style(); \
|
||||
} \
|
||||
\
|
||||
const klass::type& klass::style() \
|
||||
{ \
|
||||
static COMBINE5(klass, __, type, __, style) b, standard; \
|
||||
if(b.status == 0) { \
|
||||
ChRegisterStyle__(b.status, b.registered, COMBINE5(klass, __, type, __, style)::InitIt); \
|
||||
b.Init(); \
|
||||
b.status = 1; \
|
||||
standard = b; \
|
||||
standard.standard = b.standard = &standard; \
|
||||
} \
|
||||
return b; \
|
||||
} \
|
||||
\
|
||||
void COMBINE5(klass, __, type, __, style)::Init()
|
||||
|
||||
#define CH_VAR(chtype, type, name, init) \
|
||||
chtype& COMBINE(ch_var__, name)(); \
|
||||
void COMBINE(ch_init__, name)() { \
|
||||
COMBINE(ch_var__, name)(); \
|
||||
} \
|
||||
\
|
||||
chtype& COMBINE(ch_var__, name)() { \
|
||||
static chtype b; \
|
||||
if(b.status == 0) { \
|
||||
ChRegisterStyle__(b.status, b.registered, COMBINE(ch_init__, name)); \
|
||||
b.value = init; \
|
||||
b.status = 1; \
|
||||
} \
|
||||
return b; \
|
||||
} \
|
||||
\
|
||||
type name() { return COMBINE(ch_var__, name)().value; } \
|
||||
void COMBINE(name, _Write)(type v) { COMBINE(ch_var__, name)().Write().value = v; }
|
||||
|
||||
struct ChColor : ChStyle<ChColor> { Color value; };
|
||||
#define CH_COLOR(name, init) CH_VAR(ChColor, Color, name, init)
|
||||
|
||||
struct ChInt : ChStyle<ChInt> { int value; };
|
||||
#define CH_INT(name, init) CH_VAR(ChInt, int, name, init)
|
||||
|
||||
struct ChValue : ChStyle<ChValue> { Value value; };
|
||||
#define CH_VALUE(name, init) CH_VAR(ChValue, Value, name, init)
|
||||
|
||||
struct ChImage : ChStyle<ChImage> { Image value; };
|
||||
#define CH_IMAGE(name, init) CH_VAR(ChImage, Image, name, init)
|
||||
|
||||
void ChPaint(Draw& w, const Rect& r, const Value& element);
|
||||
void ChPaint(Draw& w, int x, int y, int cx, int cy, const Value& element);
|
||||
|
||||
Value ChLookWith(const Value& look, const Image& img, Point offset = Point(0, 0));
|
||||
Value ChLookWith(const Value& look, const Image& img, Color color, Point offset = Point(0, 0));
|
||||
Value ChLookWith(const Value& look, const Image& img, Color (*color)(int i), int i, Point offset = Point(0, 0));
|
||||
|
||||
//private:
|
||||
void ChRegisterStyle__(byte& state, byte& registered, void (*init)());
|
||||
|
||||
Value ChBorder(const ColorF *colors, const Value& face = SColorFace());
|
||||
enum LookOp {
|
||||
LOOK_PAINT,
|
||||
LOOK_MARGINS,
|
||||
LOOK_PAINTEDGE,
|
||||
LOOK_ISOPAQUE,
|
||||
LOOK_ISBODYOPAQUE,
|
||||
};
|
||||
|
||||
void ChLookFn(Value (*fn)(Draw& w, const Rect& r, const Value& look, int lookop));
|
||||
|
||||
Image AdjustColors(const Image& img);
|
||||
|
||||
void Override(Iml& target, Iml& source, bool colored = false);
|
||||
void ColoredOverride(Iml& target, Iml& source);
|
||||
|
||||
void ChReset();
|
||||
void ChFinish();
|
||||
|
||||
void ChPaint(Draw& w, const Rect& r, const Value& look);
|
||||
void ChPaint(Draw& w, int x, int y, int cx, int cy, const Value& look);
|
||||
void ChPaintEdge(Draw& w, const Rect& r, const Value& look);
|
||||
void ChPaintEdge(Draw& w, int x, int y, int cx, int cy, const Value& look);
|
||||
void ChPaintBody(Draw& w, const Rect& r, const Value& look);
|
||||
void ChPaintBody(Draw& w, int x, int y, int cx, int cy, const Value& look);
|
||||
Rect ChMargins(const Value& look);
|
||||
bool ChIsOpaque(const Value& look);
|
||||
bool ChIsBodyOpaque(const Value& look);
|
||||
|
||||
void DeflateMargins(Rect& r, const Rect& margin);
|
||||
void ChDeflateMargins(Rect& r, const Value& look);
|
||||
void DeflateMargins(Size& sz, const Rect& m);
|
||||
void ChDeflateMargins(Size& sz, const Value& look);
|
||||
void InflateMargins(Rect& r, const Rect& m);
|
||||
void ChInflateMargins(Rect& r, const Value& look);
|
||||
void InflateMargins(Size& sz, const Rect& m);
|
||||
void ChInflateMargins(Size& sz, const Value& look);
|
||||
|
||||
void ChInvalidate();
|
||||
bool ChIsInvalidated();
|
||||
bool IsLabelTextColorMismatch();
|
||||
bool IsDarkColorFace();
|
||||
|
||||
template <class T>
|
||||
struct ChStyle {
|
||||
byte status;
|
||||
byte registered;
|
||||
T *standard;
|
||||
|
||||
const T& Standard() const { return *standard; }
|
||||
T& Write() const { T& x = *(T *)this; x.status = 2; ChInvalidate(); return x; }
|
||||
void Assign(const T& src) { *(T *)this = src; }
|
||||
|
||||
ChStyle() { status = 0; registered = 0; standard = NULL; }
|
||||
};
|
||||
|
||||
#define CH_STYLE(klass, type, style) \
|
||||
struct COMBINE5(klass, __, type, __, style) : klass::type { \
|
||||
void Init(); \
|
||||
static void InitIt(); \
|
||||
}; \
|
||||
\
|
||||
void COMBINE5(klass, __, type, __, style)::InitIt() { \
|
||||
klass::style(); \
|
||||
} \
|
||||
\
|
||||
const klass::type& klass::style() \
|
||||
{ \
|
||||
static COMBINE5(klass, __, type, __, style) b, standard; \
|
||||
if(b.status == 0) { \
|
||||
ChRegisterStyle__(b.status, b.registered, COMBINE5(klass, __, type, __, style)::InitIt); \
|
||||
b.Init(); \
|
||||
b.status = 1; \
|
||||
standard = b; \
|
||||
standard.standard = b.standard = &standard; \
|
||||
} \
|
||||
return b; \
|
||||
} \
|
||||
\
|
||||
void COMBINE5(klass, __, type, __, style)::Init()
|
||||
|
||||
#define CH_VAR(chtype, type, name, init) \
|
||||
chtype& COMBINE(ch_var__, name)(); \
|
||||
void COMBINE(ch_init__, name)() { \
|
||||
COMBINE(ch_var__, name)(); \
|
||||
} \
|
||||
\
|
||||
chtype& COMBINE(ch_var__, name)() { \
|
||||
static chtype b; \
|
||||
if(b.status == 0) { \
|
||||
ChRegisterStyle__(b.status, b.registered, COMBINE(ch_init__, name)); \
|
||||
b.value = init; \
|
||||
b.status = 1; \
|
||||
} \
|
||||
return b; \
|
||||
} \
|
||||
\
|
||||
type name() { return COMBINE(ch_var__, name)().value; } \
|
||||
void COMBINE(name, _Write)(type v) { COMBINE(ch_var__, name)().Write().value = v; }
|
||||
|
||||
struct ChColor : ChStyle<ChColor> { Color value; };
|
||||
#define CH_COLOR(name, init) CH_VAR(ChColor, Color, name, init)
|
||||
|
||||
struct ChInt : ChStyle<ChInt> { int value; };
|
||||
#define CH_INT(name, init) CH_VAR(ChInt, int, name, init)
|
||||
|
||||
struct ChValue : ChStyle<ChValue> { Value value; };
|
||||
#define CH_VALUE(name, init) CH_VAR(ChValue, Value, name, init)
|
||||
|
||||
struct ChImage : ChStyle<ChImage> { Image value; };
|
||||
#define CH_IMAGE(name, init) CH_VAR(ChImage, Image, name, init)
|
||||
|
||||
void ChPaint(Draw& w, const Rect& r, const Value& element);
|
||||
void ChPaint(Draw& w, int x, int y, int cx, int cy, const Value& element);
|
||||
|
||||
Value ChLookWith(const Value& look, const Image& img, Point offset = Point(0, 0));
|
||||
Value ChLookWith(const Value& look, const Image& img, Color color, Point offset = Point(0, 0));
|
||||
Value ChLookWith(const Value& look, const Image& img, Color (*color)(int i), int i, Point offset = Point(0, 0));
|
||||
|
||||
//private:
|
||||
void ChRegisterStyle__(byte& state, byte& registered, void (*init)());
|
||||
|
||||
Value ChBorder(const ColorF *colors, const Value& face = SColorFace());
|
||||
|
|
|
|||
File diff suppressed because it is too large
Load diff
|
|
@ -1,160 +1,159 @@
|
|||
Image CreateImage(Size sz, const RGBA& rgba);
|
||||
Image CreateImage(Size sz, Color color);
|
||||
Image SetColorKeepAlpha(const Image& img, Color c);
|
||||
|
||||
Image WithHotSpots(const Image& m, int x1, int y1, int x2, int y2);
|
||||
Image WithHotSpot(const Image& m, int x1, int y1);
|
||||
|
||||
void Over(ImageBuffer& dest, Point p, const Image& src, const Rect& srect);
|
||||
void Copy(ImageBuffer& dest, Point p, const Image& src, const Rect& srect);
|
||||
|
||||
void Copy(Image& dest, Point p, const Image& src, const Rect& srect);
|
||||
void Over(Image& dest, Point p, const Image& src, const Rect& srect);
|
||||
|
||||
void OverStraightOpaque(ImageBuffer& dest, Point p, const Image& src, const Rect& srect);
|
||||
void OverStraightOpaque(Image& dest, Point p, const Image& _src, const Rect& srect);
|
||||
|
||||
void Crop(RasterEncoder& tgt, Raster& img, const Rect& rc);
|
||||
Image Crop(const Image& img, const Rect& rc);
|
||||
Image Crop(const Image& img, int x, int y, int cx, int cy);
|
||||
|
||||
Image ColorMask(const Image& src, Color transparent);
|
||||
|
||||
void CanvasSize(RasterEncoder& tgt, Raster& img, int cx, int cy);
|
||||
Image CanvasSize(const Image& img, int cx, int cy);
|
||||
|
||||
Image AssignAlpha(const Image& img, const Image& new_alpha);
|
||||
|
||||
Image Grayscale(const Image& img);
|
||||
Image Grayscale(const Image& img, int amount);
|
||||
Image Contrast(const Image& img, int amount = 256);
|
||||
|
||||
Image HorzFadeOut(int cx, int cy, Color color);
|
||||
Image HorzFadeOut(Size sz, Color color);
|
||||
|
||||
class RescaleImage {
|
||||
Raster *src;
|
||||
Size tsz;
|
||||
Vector<dword> horz;
|
||||
Vector<dword> vert;
|
||||
void (*row_proc)(dword *dest, const RGBA *src, const dword *map);
|
||||
Size size;
|
||||
int cx4;
|
||||
int count;
|
||||
int segment;
|
||||
int entry;
|
||||
int step;
|
||||
int segspan;
|
||||
bool bigseg;
|
||||
Buffer<dword> row_buffers;
|
||||
int first;
|
||||
int full;
|
||||
const dword *offsets;
|
||||
int offset;
|
||||
int y;
|
||||
|
||||
struct Ln {
|
||||
RasterLine line;
|
||||
int ii;
|
||||
};
|
||||
|
||||
Ln cache[4];
|
||||
int cii;
|
||||
const RGBA *GetLine(int i);
|
||||
|
||||
public:
|
||||
void Create(Size sz, Raster& src, const Rect& src_rc);
|
||||
void Get(RGBA *line);
|
||||
};
|
||||
|
||||
void DrawRasterData(Draw& w, int x, int y, int cx, int cy, const String& data);
|
||||
|
||||
bool Rescale(RasterEncoder& tgt, Size sz, Raster& src, const Rect& src_rc,
|
||||
Gate2<int, int> progress = false);
|
||||
Image Rescale(const Image& src, Size sz, const Rect& src_rc, Gate2<int, int> progress = false);
|
||||
Image Rescale(const Image& src, Size sz, Gate2<int, int> progress = false);
|
||||
Image Rescale(const Image& src, int cx, int cy, Gate2<int, int> progress = false);
|
||||
|
||||
struct ImageFilter9 {
|
||||
virtual RGBA operator()(const RGBA **mx) = 0;
|
||||
virtual ~ImageFilter9() {}
|
||||
};
|
||||
|
||||
Image Filter(const Image& img, ImageFilter9& filter);
|
||||
void Filter(RasterEncoder& target, Raster& src, ImageFilter9& filter);
|
||||
|
||||
Image Etched(const Image& img);
|
||||
Image Sharpen(const Image& img, int amount = 100);
|
||||
|
||||
Image RotateClockwise(const Image& img);
|
||||
Image RotateAntiClockwise(const Image& img);
|
||||
Image Rotate180(const Image& orig);
|
||||
Image MirrorHorz(const Image& img);
|
||||
Image MirrorVert(const Image& img);
|
||||
Image Rotate(const Image& m, int angle);
|
||||
|
||||
// Experimental {
|
||||
Image Colorize(const Image& img, Color color, int alpha = 100);
|
||||
Image Equalight(const Image& img, int thold = 10);
|
||||
// }
|
||||
|
||||
//Chameleon support
|
||||
int Diff(RGBA a, RGBA b);
|
||||
Image Unglyph(const Image& m, Color& c, double& factor);
|
||||
Image Unglyph(const Image& m, Color& c);
|
||||
Image Unglyph(const Image& m);
|
||||
Image VertBlend(Image img1, Image img2, int y0, int y1);
|
||||
Image HorzBlend(Image img1, Image img2, int x0, int x1);
|
||||
Image HorzSymm(Image src);
|
||||
|
||||
enum {
|
||||
IMAGECONTENT_VERTDUP = 1,
|
||||
IMAGECONTENT_HORZDUP = 2,
|
||||
IMAGECONTENT_OPAQUEBODY = 4,
|
||||
};
|
||||
|
||||
int ClassifyContent(const Image& m, const Rect& rect);
|
||||
|
||||
Image RecreateAlpha(const Image& overwhite, const Image& overblack);
|
||||
int ImageMargin(const Image& m, int p, int dist);
|
||||
int ImageMarginV(const Image& _m, int p, int dist);
|
||||
|
||||
struct ChPartMaker {
|
||||
Image image;
|
||||
Color border;
|
||||
Color bg;
|
||||
|
||||
bool t, b, l, r;
|
||||
byte tl, tr, bl, br;
|
||||
|
||||
void ResetShape();
|
||||
Image Make() const;
|
||||
|
||||
ChPartMaker(const Image& m);
|
||||
};
|
||||
|
||||
// Image cache
|
||||
|
||||
struct ImageMaker {
|
||||
virtual String Key() const = 0;
|
||||
virtual Image Make() const = 0;
|
||||
virtual ~ImageMaker() {}
|
||||
};
|
||||
|
||||
Image MakeImage(const ImageMaker& m);
|
||||
Image MakeImage(const Image& image, Image (*make)(const Image& image));
|
||||
|
||||
void SweepMkImageCache();
|
||||
|
||||
void ClearMakeImageCache();
|
||||
void SetMakeImageCacheSize(int m);
|
||||
void SetMakeImageCacheMax(int m);
|
||||
|
||||
Image MakeImagePaintOnly(const ImageMaker& m);
|
||||
|
||||
Image CachedRescale(const Image& m, Size sz, const Rect& src);
|
||||
Image CachedRescale(const Image& m, Size sz);
|
||||
Image CachedRescalePaintOnly(const Image& m, Size sz, const Rect& src);
|
||||
Image CachedRescalePaintOnly(const Image& m, Size sz);
|
||||
|
||||
Image Magnify(const Image& img, int nx, int ny);
|
||||
Image CreateImage(Size sz, const RGBA& rgba);
|
||||
Image CreateImage(Size sz, Color color);
|
||||
Image SetColorKeepAlpha(const Image& img, Color c);
|
||||
|
||||
Image WithHotSpots(const Image& m, int x1, int y1, int x2, int y2);
|
||||
Image WithHotSpot(const Image& m, int x1, int y1);
|
||||
|
||||
void Over(ImageBuffer& dest, Point p, const Image& src, const Rect& srect);
|
||||
void Copy(ImageBuffer& dest, Point p, const Image& src, const Rect& srect);
|
||||
|
||||
void Copy(Image& dest, Point p, const Image& src, const Rect& srect);
|
||||
void Over(Image& dest, Point p, const Image& src, const Rect& srect);
|
||||
|
||||
void OverStraightOpaque(ImageBuffer& dest, Point p, const Image& src, const Rect& srect);
|
||||
void OverStraightOpaque(Image& dest, Point p, const Image& _src, const Rect& srect);
|
||||
|
||||
void Crop(RasterEncoder& tgt, Raster& img, const Rect& rc);
|
||||
Image Crop(const Image& img, const Rect& rc);
|
||||
Image Crop(const Image& img, int x, int y, int cx, int cy);
|
||||
|
||||
Image ColorMask(const Image& src, Color transparent);
|
||||
|
||||
void CanvasSize(RasterEncoder& tgt, Raster& img, int cx, int cy);
|
||||
Image CanvasSize(const Image& img, int cx, int cy);
|
||||
|
||||
Image AssignAlpha(const Image& img, const Image& new_alpha);
|
||||
|
||||
Image Grayscale(const Image& img);
|
||||
Image Grayscale(const Image& img, int amount);
|
||||
Image Contrast(const Image& img, int amount = 256);
|
||||
|
||||
Image HorzFadeOut(int cx, int cy, Color color);
|
||||
Image HorzFadeOut(Size sz, Color color);
|
||||
|
||||
class RescaleImage {
|
||||
Raster *src;
|
||||
Size tsz;
|
||||
Vector<dword> horz;
|
||||
Vector<dword> vert;
|
||||
void (*row_proc)(dword *dest, const RGBA *src, const dword *map);
|
||||
Size size;
|
||||
int cx4;
|
||||
int count;
|
||||
int segment;
|
||||
int entry;
|
||||
int step;
|
||||
int segspan;
|
||||
bool bigseg;
|
||||
Buffer<dword> row_buffers;
|
||||
int first;
|
||||
int full;
|
||||
const dword *offsets;
|
||||
int offset;
|
||||
int y;
|
||||
|
||||
struct Ln {
|
||||
RasterLine line;
|
||||
int ii;
|
||||
};
|
||||
|
||||
Ln cache[4];
|
||||
int cii;
|
||||
const RGBA *GetLine(int i);
|
||||
|
||||
public:
|
||||
void Create(Size sz, Raster& src, const Rect& src_rc);
|
||||
void Get(RGBA *line);
|
||||
};
|
||||
|
||||
void DrawRasterData(Draw& w, int x, int y, int cx, int cy, const String& data);
|
||||
|
||||
bool Rescale(RasterEncoder& tgt, Size sz, Raster& src, const Rect& src_rc,
|
||||
Gate2<int, int> progress = false);
|
||||
Image Rescale(const Image& src, Size sz, const Rect& src_rc, Gate2<int, int> progress = false);
|
||||
Image Rescale(const Image& src, Size sz, Gate2<int, int> progress = false);
|
||||
Image Rescale(const Image& src, int cx, int cy, Gate2<int, int> progress = false);
|
||||
|
||||
struct ImageFilter9 {
|
||||
virtual RGBA operator()(const RGBA **mx) = 0;
|
||||
virtual ~ImageFilter9() {}
|
||||
};
|
||||
|
||||
Image Filter(const Image& img, ImageFilter9& filter);
|
||||
void Filter(RasterEncoder& target, Raster& src, ImageFilter9& filter);
|
||||
|
||||
Image Etched(const Image& img);
|
||||
Image Sharpen(const Image& img, int amount = 100);
|
||||
|
||||
Image RotateClockwise(const Image& img);
|
||||
Image RotateAntiClockwise(const Image& img);
|
||||
Image Rotate180(const Image& orig);
|
||||
Image MirrorHorz(const Image& img);
|
||||
Image MirrorVert(const Image& img);
|
||||
Image Rotate(const Image& m, int angle);
|
||||
|
||||
Image Colorize(const Image& img, Color color, int alpha = 100);
|
||||
Image Equalight(const Image& img, int thold = 10);
|
||||
Image AdjustForDarkBk(const Image& img);
|
||||
|
||||
//Chameleon support
|
||||
int Diff(RGBA a, RGBA b);
|
||||
Image Unglyph(const Image& m, Color& c, double& factor);
|
||||
Image Unglyph(const Image& m, Color& c);
|
||||
Image Unglyph(const Image& m);
|
||||
Image VertBlend(Image img1, Image img2, int y0, int y1);
|
||||
Image HorzBlend(Image img1, Image img2, int x0, int x1);
|
||||
Image HorzSymm(Image src);
|
||||
|
||||
enum {
|
||||
IMAGECONTENT_VERTDUP = 1,
|
||||
IMAGECONTENT_HORZDUP = 2,
|
||||
IMAGECONTENT_OPAQUEBODY = 4,
|
||||
};
|
||||
|
||||
int ClassifyContent(const Image& m, const Rect& rect);
|
||||
|
||||
Image RecreateAlpha(const Image& overwhite, const Image& overblack);
|
||||
int ImageMargin(const Image& m, int p, int dist);
|
||||
int ImageMarginV(const Image& _m, int p, int dist);
|
||||
|
||||
struct ChPartMaker {
|
||||
Image image;
|
||||
Color border;
|
||||
Color bg;
|
||||
|
||||
bool t, b, l, r;
|
||||
byte tl, tr, bl, br;
|
||||
|
||||
void ResetShape();
|
||||
Image Make() const;
|
||||
|
||||
ChPartMaker(const Image& m);
|
||||
};
|
||||
|
||||
// Image cache
|
||||
|
||||
struct ImageMaker {
|
||||
virtual String Key() const = 0;
|
||||
virtual Image Make() const = 0;
|
||||
virtual ~ImageMaker() {}
|
||||
};
|
||||
|
||||
Image MakeImage(const ImageMaker& m);
|
||||
Image MakeImage(const Image& image, Image (*make)(const Image& image));
|
||||
|
||||
void SweepMkImageCache();
|
||||
|
||||
void ClearMakeImageCache();
|
||||
void SetMakeImageCacheSize(int m);
|
||||
void SetMakeImageCacheMax(int m);
|
||||
|
||||
Image MakeImagePaintOnly(const ImageMaker& m);
|
||||
|
||||
Image CachedRescale(const Image& m, Size sz, const Rect& src);
|
||||
Image CachedRescale(const Image& m, Size sz);
|
||||
Image CachedRescalePaintOnly(const Image& m, Size sz, const Rect& src);
|
||||
Image CachedRescalePaintOnly(const Image& m, Size sz);
|
||||
|
||||
Image Magnify(const Image& img, int nx, int ny);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue