From 093cad78825a0405d2746ade4c787bd5c29cc8c1 Mon Sep 17 00:00:00 2001 From: cxl Date: Sun, 30 Jan 2011 12:42:32 +0000 Subject: [PATCH] *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 --- uppsrc/Core/Color.cpp | 5 + uppsrc/Core/Color.h | 1 + uppsrc/Core/Random.cpp | 1 + uppsrc/CtrlCore/src.tpp/Ctrl$en-us.tpp | 5 + uppsrc/CtrlLib/ChGtk.cpp | 2 +- uppsrc/CtrlLib/MenuImp.h | 364 +++-- uppsrc/CtrlLib/MenuItem.cpp | 1256 +++++++++-------- uppsrc/CtrlLib/SSettings.cpp | 42 - uppsrc/Draw/Draw.h | 1782 ++++++++++++------------ uppsrc/Draw/SSettings.cpp | 85 +- uppsrc/plugin/ndisasm/lib/inttypes.h | 402 +++--- uppsrc/plugin/ndisasm/ndisupp.cpp | 4 + 12 files changed, 1971 insertions(+), 1978 deletions(-) delete mode 100644 uppsrc/CtrlLib/SSettings.cpp diff --git a/uppsrc/Core/Color.cpp b/uppsrc/Core/Color.cpp index 2b5a16c0b..b25d5a404 100644 --- a/uppsrc/Core/Color.cpp +++ b/uppsrc/Core/Color.cpp @@ -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 diff --git a/uppsrc/Core/Color.h b/uppsrc/Core/Color.h index 48681cbe9..7e6dddbbe 100644 --- a/uppsrc/Core/Color.h +++ b/uppsrc/Core/Color.h @@ -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(); } diff --git a/uppsrc/Core/Random.cpp b/uppsrc/Core/Random.cpp index 9a0b9fdd3..64d034ff0 100644 --- a/uppsrc/Core/Random.cpp +++ b/uppsrc/Core/Random.cpp @@ -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; diff --git a/uppsrc/CtrlCore/src.tpp/Ctrl$en-us.tpp b/uppsrc/CtrlCore/src.tpp/Ctrl$en-us.tpp index b76d1685b..ce3910390 100644 --- a/uppsrc/CtrlCore/src.tpp/Ctrl$en-us.tpp +++ b/uppsrc/CtrlCore/src.tpp/Ctrl$en-us.tpp @@ -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.&] diff --git a/uppsrc/CtrlLib/ChGtk.cpp b/uppsrc/CtrlLib/ChGtk.cpp index f0141c456..13d238855 100644 --- a/uppsrc/CtrlLib/ChGtk.cpp +++ b/uppsrc/CtrlLib/ChGtk.cpp @@ -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(); diff --git a/uppsrc/CtrlLib/MenuImp.h b/uppsrc/CtrlLib/MenuImp.h index 231a38c79..0cb794c9e 100644 --- a/uppsrc/CtrlLib/MenuImp.h +++ b/uppsrc/CtrlLib/MenuImp.h @@ -1,183 +1,181 @@ -#include "CtrlLib.h" - -#ifndef CtrlCore_MenuImp_h -#define CtrlCore_MenuImp_h - -NAMESPACE_UPP - -class MenuItemBase : public Ctrl, public Bar::Item -{ -public: - virtual Bar::Item& Text(const char *text); - virtual Bar::Item& Key(dword key); - virtual Bar::Item& Image(const UPP::Image& img); - virtual Bar::Item& Enable(bool _enable); - virtual Bar::Item& Tip(const char *tip); - virtual Bar::Item& Help(const char *help); - virtual Bar::Item& Topic(const char *help); - virtual Bar::Item& Description(const char *desc); - virtual Bar::Item& Check(bool check); - virtual Bar::Item& Radio(bool check); - - virtual String GetDesc() const; - virtual dword GetAccessKeys() const; - virtual void AssignAccessKeys(dword used); - -protected: - enum { - NOTHING, CHECK0, CHECK1, RADIO0, RADIO1 - }; - - enum { - NORMAL, HIGHLIGHT, PUSH - }; - - String text; - dword accel; - int state; - int leftgap, textgap; - Font font; - bool isenabled; - byte type; - int accesskey; - Size maxiconsize; - const MenuBar::Style *style; - -public: - virtual void SyncState() = 0; - - void DrawMenuText(Draw& w, int x, int y, const String& s, Font f, bool enabled, bool hl, - Color color, Color hlcolor); - void PaintTopItem(Draw& w, int state); - - bool IsItemEnabled() const { return isenabled; } - String GetText() const { return text; } - MenuItemBase& LeftGap(int cx) { leftgap = cx; return *this; } - MenuItemBase& TextGap(int cx) { textgap = cx; return *this; } - MenuItemBase& SetFont(Font f) { font = f; return *this; } - MenuItemBase& Style(const MenuBar::Style *s) { style = s; return *this; } - Font GetFont() const { return font; } - MenuItemBase& MaxIconSize(Size sz) { maxiconsize = sz; return *this; } - - 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); - virtual void MouseEnter(Point, dword); - virtual void MouseLeave(); - virtual Size GetMinSize() const; - virtual void LeftUp(Point, dword); - virtual void RightUp(Point, dword); - virtual void GotFocus(); - virtual void LostFocus(); - virtual bool Key(dword key, int count); - virtual bool HotKey(dword key); - virtual void SyncState(); - - virtual Bar::Item& Image(const UPP::Image& img); - -private: - UPP::Image licon, ricon; - - void SendHelpLine(); - void ClearHelpLine(); - -protected: - virtual int GetVisualState(); - -public: - MenuItem& RightImage(const UPP::Image& img); -}; - -class SubMenuBase { -protected: - MenuBar menu; - Callback1 proc; - MenuBar *parentmenu; - - void Pull(Ctrl *item, Point p, Size sz); - -public: - virtual void Pull() = 0; - - void SetParent(MenuBar *m) { parentmenu = m; menu.MaxIconSize(m->GetMaxIconSize()); } - void Set(Callback1 _submenu) { proc = _submenu; } - Callback1 Get() { return proc; } - - SubMenuBase() { parentmenu = NULL; } - virtual ~SubMenuBase() {} -}; - -class SubMenuItem : public MenuItem, public SubMenuBase { -public: - virtual void MouseEnter(Point, dword); - virtual void MouseLeave(); - virtual void GotFocus(); - virtual bool HotKey(dword key); - virtual bool Key(dword key, int count); - virtual int GetVisualState(); - virtual void Pull(); - -protected: - enum { - TIMEID_PULL = BarCtrl::TIMEID_COUNT, - TIMEID_COUNT - }; - -public: - typedef SubMenuItem CLASSNAME; - - SubMenuItem(); -}; - -class TopSubMenuItem : public MenuItemBase, public SubMenuBase { -public: - virtual void Paint(Draw& w); - virtual void MouseEnter(Point, dword); - virtual void MouseLeave(); - virtual void GotFocus(); - virtual void LostFocus(); - virtual void LeftDown(Point, dword); - virtual void SyncState(); - virtual Size GetMinSize() const; - virtual bool Key(dword key, int); - virtual bool HotKey(dword key); - virtual void Pull(); - -private: - int GetState(); - -public: - TopSubMenuItem() { NoInitFocus(); } -}; - -class TopMenuItem : public MenuItemBase { -public: - virtual void Paint(Draw& w); - virtual void MouseEnter(Point, dword); - virtual void MouseLeave(); - virtual void LeftUp(Point, dword); - virtual void LeftDown(Point, dword); - virtual void GotFocus(); - virtual void LostFocus(); - virtual bool Key(dword key, int count); - virtual Size GetMinSize() const; - virtual void SyncState(); - - static int GetStdHeight(Font font = StdFont()); - -private: - int GetState(); - -public: - TopMenuItem() { NoInitFocus(); } -}; - -END_UPP_NAMESPACE - -#endif +#include "CtrlLib.h" + +#ifndef CtrlCore_MenuImp_h +#define CtrlCore_MenuImp_h + +NAMESPACE_UPP + +class MenuItemBase : public Ctrl, public Bar::Item +{ +public: + virtual Bar::Item& Text(const char *text); + virtual Bar::Item& Key(dword key); + virtual Bar::Item& Image(const UPP::Image& img); + virtual Bar::Item& Enable(bool _enable); + virtual Bar::Item& Tip(const char *tip); + virtual Bar::Item& Help(const char *help); + virtual Bar::Item& Topic(const char *help); + virtual Bar::Item& Description(const char *desc); + virtual Bar::Item& Check(bool check); + virtual Bar::Item& Radio(bool check); + + virtual String GetDesc() const; + virtual dword GetAccessKeys() const; + virtual void AssignAccessKeys(dword used); + +protected: + enum { + NOTHING, CHECK0, CHECK1, RADIO0, RADIO1 + }; + + enum { + NORMAL, HIGHLIGHT, PUSH + }; + + String text; + dword accel; + int state; + int leftgap, textgap; + Font font; + bool isenabled; + byte type; + int accesskey; + Size maxiconsize; + const MenuBar::Style *style; + +public: + virtual void SyncState() = 0; + + void DrawMenuText(Draw& w, int x, int y, const String& s, Font f, bool enabled, bool hl, + Color color, Color hlcolor); + void PaintTopItem(Draw& w, int state); + + bool IsItemEnabled() const { return isenabled; } + String GetText() const { return text; } + MenuItemBase& LeftGap(int cx) { leftgap = cx; return *this; } + MenuItemBase& TextGap(int cx) { textgap = cx; return *this; } + MenuItemBase& SetFont(Font f) { font = f; return *this; } + 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(); +}; + +class MenuItem : public MenuItemBase { +public: + virtual void Paint(Draw& w); + virtual void MouseEnter(Point, dword); + virtual void MouseLeave(); + virtual Size GetMinSize() const; + virtual void LeftUp(Point, dword); + virtual void RightUp(Point, dword); + virtual void GotFocus(); + virtual void LostFocus(); + virtual bool Key(dword key, int count); + virtual bool HotKey(dword key); + virtual void SyncState(); + + virtual Bar::Item& Image(const UPP::Image& img); + +private: + UPP::Image licon, ricon; + + void SendHelpLine(); + void ClearHelpLine(); + +protected: + virtual int GetVisualState(); + +public: + MenuItem& RightImage(const UPP::Image& img); +}; + +class SubMenuBase { +protected: + MenuBar menu; + Callback1 proc; + MenuBar *parentmenu; + + void Pull(Ctrl *item, Point p, Size sz); + +public: + virtual void Pull() = 0; + + void SetParent(MenuBar *m) { parentmenu = m; menu.MaxIconSize(m->GetMaxIconSize()); } + void Set(Callback1 _submenu) { proc = _submenu; } + Callback1 Get() { return proc; } + + SubMenuBase() { parentmenu = NULL; } + virtual ~SubMenuBase() {} +}; + +class SubMenuItem : public MenuItem, public SubMenuBase { +public: + virtual void MouseEnter(Point, dword); + virtual void MouseLeave(); + virtual void GotFocus(); + virtual bool HotKey(dword key); + virtual bool Key(dword key, int count); + virtual int GetVisualState(); + virtual void Pull(); + +protected: + enum { + TIMEID_PULL = BarCtrl::TIMEID_COUNT, + TIMEID_COUNT + }; + +public: + typedef SubMenuItem CLASSNAME; + + SubMenuItem(); +}; + +class TopSubMenuItem : public MenuItemBase, public SubMenuBase { +public: + virtual void Paint(Draw& w); + virtual void MouseEnter(Point, dword); + virtual void MouseLeave(); + virtual void GotFocus(); + virtual void LostFocus(); + virtual void LeftDown(Point, dword); + virtual void SyncState(); + virtual Size GetMinSize() const; + virtual bool Key(dword key, int); + virtual bool HotKey(dword key); + virtual void Pull(); + +private: + int GetState(); + +public: + TopSubMenuItem() { NoInitFocus(); } +}; + +class TopMenuItem : public MenuItemBase { +public: + virtual void Paint(Draw& w); + virtual void MouseEnter(Point, dword); + virtual void MouseLeave(); + virtual void LeftUp(Point, dword); + virtual void LeftDown(Point, dword); + virtual void GotFocus(); + virtual void LostFocus(); + virtual bool Key(dword key, int count); + virtual Size GetMinSize() const; + virtual void SyncState(); + + static int GetStdHeight(Font font = StdFont()); + +private: + int GetState(); + +public: + TopMenuItem() { NoInitFocus(); } +}; + +END_UPP_NAMESPACE + +#endif diff --git a/uppsrc/CtrlLib/MenuItem.cpp b/uppsrc/CtrlLib/MenuItem.cpp index 5239568cf..987c30d7a 100644 --- a/uppsrc/CtrlLib/MenuItem.cpp +++ b/uppsrc/CtrlLib/MenuItem.cpp @@ -1,619 +1,637 @@ -#include "MenuImp.h" - -#ifdef PLATFORM_WIN32 -#include -#endif - -NAMESPACE_UPP - -#define LLOG(x) // LOG(x) -#define LTIMING(x) // RTIMING(x) - -MenuItemBase::MenuItemBase() -{ - accel = 0; - state = 0; - isenabled = true; - type = 0; - font = StdFont(); - leftgap = 16; - textgap = 6; - accesskey = 0; - NoWantFocus(); - style = &MenuBar::StyleDefault(); - Transparent(); - maxiconsize = Size(INT_MAX, INT_MAX); -} - -Bar::Item& MenuItemBase::Text(const char *s) -{ - accesskey = ExtractAccessKey(s, text); - Refresh(); - return *this; -} - -Bar::Item& MenuItemBase::Key(dword key) -{ - if(key) { - accel = key; - Refresh(); - } - return *this; -} - -Bar::Item& MenuItemBase::Image(const UPP::Image& img) -{ - return *this; -} - -Bar::Item& MenuItemBase::Check(bool check) -{ - type = CHECK0 + check; - return *this; -} - -Bar::Item& MenuItemBase::Radio(bool check) -{ - type = RADIO0 + check; - return *this; -} - -Bar::Item& MenuItemBase::Tip(const char *s) -{ - return *this; -} - -Bar::Item& MenuItemBase::Help(const char *s) -{ - HelpLine(s); - return *this; -} - -Bar::Item& MenuItemBase::Description(const char *s) -{ - Ctrl::Description(s); - return *this; -} - -Bar::Item& MenuItemBase::Topic(const char *s) -{ - HelpTopic(s); - return *this; -} - -Bar::Item& MenuItemBase::Enable(bool en) -{ - isenabled = en; - Refresh(); - return *this; -} - -String MenuItemBase::GetDesc() const -{ - return text; -} - -dword MenuItemBase::GetAccessKeys() const -{ - return AccessKeyBit(accesskey); -} - -void MenuItemBase::AssignAccessKeys(dword used) -{ - if(!accesskey) { - accesskey = ChooseAccessKey(text, used); - used |= AccessKeyBit(accesskey); - } - Ctrl::AssignAccessKeys(used); -} - -void DrawMnemonicText(Draw& w, int x, int y, const String& s, Font font, Color color, - int mnemonic) -{ - int apos = HIWORD(mnemonic); - int q; - if(apos && apos < s.GetLength()) - q = apos - 1; - else { - q = s.Find(ToUpper(mnemonic)); - if(q < 0) - q = s.Find(ToLower(mnemonic)); - } - w.DrawText(x, y, s, font, color); - 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()); -} - -void DrawMenuText(Draw& w, int x, int y, const String& s, Font f, bool enabled, - bool hl, int mnemonic, Color color, Color hlcolor) -{ - if(enabled) - DrawMnemonicText(w, x, y, s, f, hl ? hlcolor : color, mnemonic); - else { - if(GUI_GlobalStyle() >= GUISTYLE_XP) - DrawMnemonicText(w, x, y, s, f, SColorDisabled, 0); - else { - DrawMnemonicText(w, x + 1, y + 1, s, f, SColorPaper, 0); - DrawMnemonicText(w, x, y, s, f, SColorDisabled, 0); - } - } -} - -void MenuItemBase::DrawMenuText(Draw& w, int x, int y, const String& s, Font f, bool enabled, - bool hl, Color color, Color hlcolor) -{ - UPP::DrawMenuText(w, x, y, s, f, enabled, hl, VisibleAccessKeys() ? accesskey : 0, - color, hlcolor); -} - -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]); - 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]); - } - else { - w.DrawRect(sz, SColorFace); - static const ColorF b0[] = { (ColorF)1, SColorLight, SColorLight, SColorShadow, SColorShadow, }; - static const ColorF b1[] = { (ColorF)1, SColorShadow, SColorShadow, SColorLight, SColorLight, }; - String text = GetText(); - Size isz = GetTextSize(text, StdFont()); - DrawMenuText(w, 6, (sz.cy - isz.cy) / 2, text, GetFont(), IsItemEnabled(), false, - SColorMenuText, SColorHighlightText); - if(state) - DrawBorder(w, 0, 0, sz.cx, sz.cy, state == 2 ? b1 : b0); - } -} - -// ------------------------------------- - -Bar::Item& MenuItem::Image(const UPP::Image& img) -{ - licon = img; - Refresh(); - return *this; -} - -MenuItem& MenuItem::RightImage(const UPP::Image& img) -{ - ricon = img; - Refresh(); - return *this; -} - -void MenuItem::SendHelpLine() -{ - BarCtrl::SendHelpLine(this); -} - -void MenuItem::ClearHelpLine() -{ - BarCtrl::ClearHelpLine(this); -} - -void MenuItem::MouseEnter(Point, dword) -{ - SetFocus(); - Refresh(); - SendHelpLine(); -} - -void MenuItem::MouseLeave() -{ - ClearHelpLine(); -} - -void MenuItem::GotFocus() -{ - Refresh(); - SendHelpLine(); -} - -void MenuItem::LostFocus() -{ - Refresh(); - ClearHelpLine(); -} - -int MenuItem::GetVisualState() -{ - return HasFocus() ? - (HasMouse() && GetMouseLeft() || GetMouseRight()) ? PUSH : HIGHLIGHT : NORMAL; -} - -void MenuItem::SyncState() -{ - int s = GetVisualState(); - if(s != state) { - state = s; - Refresh(); - } -} - -void MenuItem::Paint(Draw& w) -{ - int q = text.Find('\t'); - String txt, keydesc; - if(accel) - keydesc = GetKeyDesc(accel); - if(q >= 0) { - keydesc = text.Mid(q + 1); - txt = text.Mid(0, q); - } - else - txt = text; - state = GetVisualState(); - bool hl = state != NORMAL; - Size sz = GetSize(); - - if(hl) - if(GUI_GlobalStyle() >= GUISTYLE_XP) - ChPaint(w, 0, 0, sz.cx, sz.cy, style->item); - else - w.DrawRect(sz, SColorHighlight); - UPP::Image li = licon; - if(li.IsEmpty()) { - switch(type) { - case CHECK0: li = CtrlImg::MenuCheck0(); break; - case CHECK1: li = CtrlImg::MenuCheck1(); break; - case RADIO0: li = CtrlImg::MenuRadio0(); break; - case RADIO1: li = CtrlImg::MenuRadio1(); break; - } - } - Size imsz = li.GetSize(); - Size isz = min(maxiconsize, imsz); - if(isz != imsz) - li = CachedRescale(li, isz); - int iy = (sz.cy - isz.cy) / 2; - bool chk = false; - int x = (max(isz.cx, leftgap - 2) - isz.cx) / 2; - if(!licon.IsEmpty() && type) { - chk = type == CHECK1 || type == RADIO1; - x = 2; - if(GUI_GlobalStyle() >= GUISTYLE_XP) { - if(chk && !hl) { - DrawXPButton(w, RectC(0, iy - 2, isz.cx + 4, isz.cy + 4), BUTTON_EDGE|BUTTON_CHECKED); - } - } - else { - w.DrawRect(1, iy - 1, isz.cx + 2, isz.cy + 2, chk ? Blend(SColorFace, SColorLight) - : SColorFace); - DrawBorder(w, 0, iy - 2, isz.cx + 4, isz.cy + 4, chk ? ThinInsetBorder : ThinOutsetBorder); - } - } - if(isenabled) - DrawHighlightImage(w, x, iy, li, hl || chk, true); - else - w.DrawImage(x, iy, DisabledImage(li)); - x = max(isz.cx, leftgap) + textgap; - isz = GetTextSize(text, StdFont()); - DrawMenuText(w, x, (sz.cy - isz.cy) / 2, txt, font, isenabled, hl, SColorMenuText, - style->itemtext); - isz = ricon.GetSize(); - if(isenabled) - DrawHighlightImage(w, sz.cx - isz.cx, (sz.cy - isz.cy) / 2, ricon, hl, true); - 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); - } -} - -Size MenuItem::GetMinSize() const -{ - Size sz1 = GetTextSize(text, font); - Size sz2(0, 0); - if(accel) { - sz2 = GetTextSize(GetKeyDesc(accel), font); - sz2.cx += 12; - } - Size lsz = min(maxiconsize, licon.GetSize()); - Size rsz = ricon.GetSize(); - return AddFrameSize(Size(max(lsz.cx, leftgap) + sz1.cx + max(sz2.cx, (rsz.cx ? 16 : 0)) - + max(rsz.cx, 16) + textgap + 10, - max(max(lsz.cy, rsz.cy) + 4, sz1.cy + 6))); -} - -void MenuItem::LeftUp(Point, dword) -{ - if(!isenabled) return; -#ifdef PLATFORM_WIN32 -#ifdef PLATFORM_WINCE - PlaySound(L"MenuCommand", NULL, SND_ASYNC|SND_NODEFAULT); //TODO? -#else - PlaySound("MenuCommand", NULL, SND_ASYNC|SND_NODEFAULT); -#endif -#endif - LLOG("Menu Item pre Action"); - WhenAction(); - LLOG("Menu Item post Action"); -} - -void MenuItem::RightUp(Point p, dword w) -{ - LeftUp(p, w); -} - -bool MenuItem::HotKey(dword key) -{ - if(isenabled && (key == accel || CompareAccessKey(accesskey, key) - || key < 256 && IsAlNum((char)key) && CompareAccessKey(accesskey, ToUpper((char)key) + K_DELTA + K_ALT))) { - LLOG("MenuItem::HotKey(" << key << ") -> SetFocus"); - SetFocus(); - Sync(); - Sleep(50); - WhenAction(); - return true; - } - return false; -} - -bool MenuItem::Key(dword key, int count) -{ - if(key == K_ENTER && isenabled) { - WhenAction(); - return true; - } - return false; -} - -// ---------------------------------------------------- - -void SubMenuBase::Pull(Ctrl *item, Point p, Size sz) -{ - if(!item->IsOpen() || menu.IsOpen()) return; - menu.Clear(); - if(parentmenu) - menu.SetStyle(*parentmenu->style); - proc(menu); - if(parentmenu) { - parentmenu->SetActiveSubmenu(&menu, item); - menu.SetParentMenu(parentmenu); - } - menu.PopUp(parentmenu, p, sz); - if(parentmenu) { - parentmenu->doeffect = false; - parentmenu->WhenSubMenuOpen(); - } -} - -// ---------------------------------------------------- - -SubMenuItem::SubMenuItem() -{ - RightImage(CtrlImg::right_arrow()); -} - -void SubMenuItem::GotFocus() -{ - Refresh(); -} - -void SubMenuItem::Pull() -{ - Rect r = GetScreenRect(); - Point p = r.TopRight(); - p.x -= 3; - p.y -= 2; - SubMenuBase::Pull(this, p, Size(-r.Width(), 0)); - if(parentmenu) - parentmenu->SyncState(); -} - -void SubMenuItem::MouseEnter(Point, dword) -{ - SetFocus(); - Refresh(); - if(!menu.IsOpen() && isenabled) - SetTimeCallback(400, THISBACK(Pull), TIMEID_PULL); -} - -void SubMenuItem::MouseLeave() -{ - if(HasFocus() && GetParent()) - GetParent()->SetFocus(); - KillTimeCallback(TIMEID_PULL); -} - -int SubMenuItem::GetVisualState() -{ - if(menu.IsOpen() && !GetParent()->HasFocusDeep()) - return PUSH; - return MenuItem::GetVisualState(); -} - -bool SubMenuItem::Key(dword key, int count) -{ - if(key == K_RIGHT || key == K_ENTER) { - Pull(); - return true; - } - return MenuItem::Key(key, count); -} - -bool SubMenuItem::HotKey(dword key) -{ - if(isenabled && (key == accel || CompareAccessKey(accesskey, key))) { - Pull(); - return true; - } - return false; -} - - -// ---------------------------------------------------- - -Size TopSubMenuItem::GetMinSize() const -{ - return AddFrameSize(GetTextSize(text, font) + Size(12, 7)); -} - -int TopSubMenuItem::GetState() -{ - if(parentmenu && parentmenu->GetActiveSubmenu() == &menu) return PUSH; - if(HasMouse() && GetParent() && !GetParent()->HasFocusDeep() && - (!parentmenu || !parentmenu->GetActiveSubmenu() || parentmenu->GetActiveSubmenu() == &menu) - || HasFocus()) - return HIGHLIGHT; - return NORMAL; -} - -void TopSubMenuItem::Paint(Draw& w) -{ - PaintTopItem(w, state = GetState()); -} - -void TopSubMenuItem::Pull() -{ - Rect r = GetScreenRect(); - if(parentmenu && parentmenu->IsChild() && !parentmenu->submenu) - parentmenu->SetupRestoreFocus(); - Point p = r.BottomLeft(); - if(GUI_GlobalStyle() >= GUISTYLE_XP) - p += style->pullshift; - SubMenuBase::Pull(this, p, Size(r.Width(), -r.Height())); - if(parentmenu) - parentmenu->SyncState(); -} - -void TopSubMenuItem::MouseEnter(Point p, dword) -{ - Refresh(); - if(isenabled && parentmenu->GetActiveSubmenu()) - Pull(); -} - -bool TopSubMenuItem::Key(dword key, int) { - if(isenabled && (key == K_ENTER || key == K_DOWN)) { - Pull(); - return true; - } - return false; -} - -void TopSubMenuItem::GotFocus() -{ - Refresh(); -} - -void TopSubMenuItem::LostFocus() -{ - Refresh(); -} - -bool TopSubMenuItem::HotKey(dword key) -{ - if(BarCtrl::Scan(proc, key)) - return true; - if(isenabled && (key == accel || CompareAccessKey(accesskey, key))) { - Pull(); - return true; - } - return false; -} - -void TopSubMenuItem::MouseLeave() -{ - Refresh(); -} - -void TopSubMenuItem::LeftDown(Point, dword) -{ - if(isenabled && !menu.IsOpen()) { - Pull(); - Refresh(); - } -} - -void TopSubMenuItem::SyncState() -{ - int q = GetState(); - if(q != state) { - state = q; - Refresh(); - } -} - -// ---------------------------------------------------- - -int TopMenuItem::GetState() -{ - if(!IsEnabled()) return NORMAL; - if(HasMouse() && GetMouseLeft() || GetMouseRight()) return PUSH; - if(HasFocus() || HasMouse()) return HIGHLIGHT; - return NORMAL; -} - -void TopMenuItem::Paint(Draw& w) -{ - PaintTopItem(w, state = GetState()); -} - -void TopMenuItem::MouseEnter(Point, dword) -{ - Refresh(); -} - -void TopMenuItem::MouseLeave() -{ - Refresh(); -} - -void TopMenuItem::LeftUp(Point, dword) -{ - if(!isenabled) return; - WhenAction(); - Refresh(); -} - -void TopMenuItem::LeftDown(Point, dword) -{ - Refresh(); -} - -void TopMenuItem::GotFocus() -{ - Refresh(); -} - -void TopMenuItem::LostFocus() -{ - Refresh(); -} - -bool TopMenuItem::Key(dword key, int count) -{ - if(isenabled && key == K_ENTER) { - WhenAction(); - return true; - } - return false; -} - -Size TopMenuItem::GetMinSize() const -{ - return AddFrameSize(GetTextSize(text, StdFont()) + Size(12, 7)); -} - -int TopMenuItem::GetStdHeight(Font font) -{ - return font.Info().GetHeight() + 7; -} - -void TopMenuItem::SyncState() -{ - if(state != GetState()) { - state = GetState(); - Refresh(); - } -} - -END_UPP_NAMESPACE +#include "MenuImp.h" + +#ifdef PLATFORM_WIN32 +#include +#endif + +NAMESPACE_UPP + +#define LLOG(x) // LOG(x) +#define LTIMING(x) // RTIMING(x) + +MenuItemBase::MenuItemBase() +{ + accel = 0; + state = 0; + isenabled = true; + type = 0; + font = StdFont(); + leftgap = 16; + textgap = 6; + accesskey = 0; + NoWantFocus(); + style = &MenuBar::StyleDefault(); + Transparent(); + maxiconsize = Size(INT_MAX, INT_MAX); +} + +bool MenuItemBase::InOpaqueBar() const +{ + const Ctrl *q = GetParent(); + while(q) { + const MenuBar *bar = dynamic_cast(q); + if(bar) + return !bar->IsTransparent(); + q = q->GetParent(); + } + return true; +} + +Bar::Item& MenuItemBase::Text(const char *s) +{ + accesskey = ExtractAccessKey(s, text); + Refresh(); + return *this; +} + +Bar::Item& MenuItemBase::Key(dword key) +{ + if(key) { + accel = key; + Refresh(); + } + return *this; +} + +Bar::Item& MenuItemBase::Image(const UPP::Image& img) +{ + return *this; +} + +Bar::Item& MenuItemBase::Check(bool check) +{ + type = CHECK0 + check; + return *this; +} + +Bar::Item& MenuItemBase::Radio(bool check) +{ + type = RADIO0 + check; + return *this; +} + +Bar::Item& MenuItemBase::Tip(const char *s) +{ + return *this; +} + +Bar::Item& MenuItemBase::Help(const char *s) +{ + HelpLine(s); + return *this; +} + +Bar::Item& MenuItemBase::Description(const char *s) +{ + Ctrl::Description(s); + return *this; +} + +Bar::Item& MenuItemBase::Topic(const char *s) +{ + HelpTopic(s); + return *this; +} + +Bar::Item& MenuItemBase::Enable(bool en) +{ + isenabled = en; + Refresh(); + return *this; +} + +String MenuItemBase::GetDesc() const +{ + return text; +} + +dword MenuItemBase::GetAccessKeys() const +{ + return AccessKeyBit(accesskey); +} + +void MenuItemBase::AssignAccessKeys(dword used) +{ + if(!accesskey) { + accesskey = ChooseAccessKey(text, used); + used |= AccessKeyBit(accesskey); + } + Ctrl::AssignAccessKeys(used); +} + +void DrawMnemonicText(Draw& w, int x, int y, const String& s, Font font, Color color, + int mnemonic, bool menumark) +{ + int apos = HIWORD(mnemonic); + int q; + if(apos && apos < s.GetLength()) + q = apos - 1; + else { + q = s.Find(ToUpper(mnemonic)); + if(q < 0) + q = s.Find(ToLower(mnemonic)); + } + w.DrawText(x, y, s, font, color); + if(q < 0) return; + FontInfo f = font.Info(); + w.DrawRect(x + GetTextSize(~s, font, q).cx, y + f.GetAscent() + 1, f[s[q]], 1, + 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 menumark) +{ + if(enabled) + 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, menumark); + else { + DrawMnemonicText(w, x + 1, y + 1, s, f, SColorPaper, 0, menumark); + DrawMnemonicText(w, x, y, s, f, SColorDisabled, 0, menumark); + } + } +} + +void MenuItemBase::DrawMenuText(Draw& w, int x, int y, const String& s, Font f, bool enabled, + bool hl, Color color, Color hlcolor) +{ + UPP::DrawMenuText(w, x, y, s, f, enabled, hl, VisibleAccessKeys() ? accesskey : 0, + color, hlcolor, InOpaqueBar()); +} + +void MenuItemBase::PaintTopItem(Draw& w, int state) { + Size sz = GetSize(); + if(GUI_GlobalStyle() >= GUISTYLE_XP) { + 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, + opaque ? style->topitemtext[0] : SColorText(), + opaque2 ? style->topitemtext[state] : SColorText()); + } + else { + w.DrawRect(sz, SColorFace); + static const ColorF b0[] = { (ColorF)1, SColorLight, SColorLight, SColorShadow, SColorShadow, }; + static const ColorF b1[] = { (ColorF)1, SColorShadow, SColorShadow, SColorLight, SColorLight, }; + String text = GetText(); + Size isz = GetTextSize(text, StdFont()); + DrawMenuText(w, 6, (sz.cy - isz.cy) / 2, text, GetFont(), IsItemEnabled(), false, + SColorMenuText, SColorHighlightText); + if(state) + DrawBorder(w, 0, 0, sz.cx, sz.cy, state == 2 ? b1 : b0); + } +} + +// ------------------------------------- + +Bar::Item& MenuItem::Image(const UPP::Image& img) +{ + licon = img; + Refresh(); + return *this; +} + +MenuItem& MenuItem::RightImage(const UPP::Image& img) +{ + ricon = img; + Refresh(); + return *this; +} + +void MenuItem::SendHelpLine() +{ + BarCtrl::SendHelpLine(this); +} + +void MenuItem::ClearHelpLine() +{ + BarCtrl::ClearHelpLine(this); +} + +void MenuItem::MouseEnter(Point, dword) +{ + SetFocus(); + Refresh(); + SendHelpLine(); +} + +void MenuItem::MouseLeave() +{ + ClearHelpLine(); +} + +void MenuItem::GotFocus() +{ + Refresh(); + SendHelpLine(); +} + +void MenuItem::LostFocus() +{ + Refresh(); + ClearHelpLine(); +} + +int MenuItem::GetVisualState() +{ + return HasFocus() ? + (HasMouse() && GetMouseLeft() || GetMouseRight()) ? PUSH : HIGHLIGHT : NORMAL; +} + +void MenuItem::SyncState() +{ + int s = GetVisualState(); + if(s != state) { + state = s; + Refresh(); + } +} + +void MenuItem::Paint(Draw& w) +{ + int q = text.Find('\t'); + String txt, keydesc; + if(accel) + keydesc = GetKeyDesc(accel); + if(q >= 0) { + keydesc = text.Mid(q + 1); + txt = text.Mid(0, q); + } + else + txt = text; + state = GetVisualState(); + bool hl = state != NORMAL; + Size sz = GetSize(); + + if(hl) + if(GUI_GlobalStyle() >= GUISTYLE_XP) + ChPaint(w, 0, 0, sz.cx, sz.cy, style->item); + else + w.DrawRect(sz, SColorHighlight); + UPP::Image li = licon; + if(li.IsEmpty()) { + switch(type) { + case CHECK0: li = CtrlImg::MenuCheck0(); break; + case CHECK1: li = CtrlImg::MenuCheck1(); break; + case RADIO0: li = CtrlImg::MenuRadio0(); break; + case RADIO1: li = CtrlImg::MenuRadio1(); break; + } + } + Size imsz = li.GetSize(); + Size isz = min(maxiconsize, imsz); + if(isz != imsz) + li = CachedRescale(li, isz); + int iy = (sz.cy - isz.cy) / 2; + bool chk = false; + int x = (max(isz.cx, leftgap - 2) - isz.cx) / 2; + if(!licon.IsEmpty() && type) { + chk = type == CHECK1 || type == RADIO1; + x = 2; + if(GUI_GlobalStyle() >= GUISTYLE_XP) { + if(chk && !hl) { + DrawXPButton(w, RectC(0, iy - 2, isz.cx + 4, isz.cy + 4), BUTTON_EDGE|BUTTON_CHECKED); + } + } + else { + w.DrawRect(1, iy - 1, isz.cx + 2, isz.cy + 2, chk ? Blend(SColorFace, SColorLight) + : SColorFace); + DrawBorder(w, 0, iy - 2, isz.cx + 4, isz.cy + 4, chk ? ThinInsetBorder : ThinOutsetBorder); + } + } + if(isenabled) + DrawHighlightImage(w, x, iy, li, hl || chk, true); + else + w.DrawImage(x, iy, DisabledImage(li)); + x = max(isz.cx, leftgap) + textgap; + isz = GetTextSize(text, StdFont()); + DrawMenuText(w, x, (sz.cy - isz.cy) / 2, txt, font, isenabled, hl, SColorMenuText, + style->itemtext); + isz = ricon.GetSize(); + if(isenabled) + 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, SColorMenuMark(), style->itemtext, false); + } +} + +Size MenuItem::GetMinSize() const +{ + Size sz1 = GetTextSize(text, font); + Size sz2(0, 0); + if(accel) { + sz2 = GetTextSize(GetKeyDesc(accel), font); + sz2.cx += 12; + } + Size lsz = min(maxiconsize, licon.GetSize()); + Size rsz = ricon.GetSize(); + return AddFrameSize(Size(max(lsz.cx, leftgap) + sz1.cx + max(sz2.cx, (rsz.cx ? 16 : 0)) + + max(rsz.cx, 16) + textgap + 10, + max(max(lsz.cy, rsz.cy) + 4, sz1.cy + 6))); +} + +void MenuItem::LeftUp(Point, dword) +{ + if(!isenabled) return; +#ifdef PLATFORM_WIN32 +#ifdef PLATFORM_WINCE + PlaySound(L"MenuCommand", NULL, SND_ASYNC|SND_NODEFAULT); //TODO? +#else + PlaySound("MenuCommand", NULL, SND_ASYNC|SND_NODEFAULT); +#endif +#endif + LLOG("Menu Item pre Action"); + WhenAction(); + LLOG("Menu Item post Action"); +} + +void MenuItem::RightUp(Point p, dword w) +{ + LeftUp(p, w); +} + +bool MenuItem::HotKey(dword key) +{ + if(isenabled && (key == accel || CompareAccessKey(accesskey, key) + || key < 256 && IsAlNum((char)key) && CompareAccessKey(accesskey, ToUpper((char)key) + K_DELTA + K_ALT))) { + LLOG("MenuItem::HotKey(" << key << ") -> SetFocus"); + SetFocus(); + Sync(); + Sleep(50); + WhenAction(); + return true; + } + return false; +} + +bool MenuItem::Key(dword key, int count) +{ + if(key == K_ENTER && isenabled) { + WhenAction(); + return true; + } + return false; +} + +// ---------------------------------------------------- + +void SubMenuBase::Pull(Ctrl *item, Point p, Size sz) +{ + if(!item->IsOpen() || menu.IsOpen()) return; + menu.Clear(); + if(parentmenu) + menu.SetStyle(*parentmenu->style); + proc(menu); + if(parentmenu) { + parentmenu->SetActiveSubmenu(&menu, item); + menu.SetParentMenu(parentmenu); + } + menu.PopUp(parentmenu, p, sz); + if(parentmenu) { + parentmenu->doeffect = false; + parentmenu->WhenSubMenuOpen(); + } +} + +// ---------------------------------------------------- + +SubMenuItem::SubMenuItem() +{ + RightImage(CtrlImg::right_arrow()); +} + +void SubMenuItem::GotFocus() +{ + Refresh(); +} + +void SubMenuItem::Pull() +{ + Rect r = GetScreenRect(); + Point p = r.TopRight(); + p.x -= 3; + p.y -= 2; + SubMenuBase::Pull(this, p, Size(-r.Width(), 0)); + if(parentmenu) + parentmenu->SyncState(); +} + +void SubMenuItem::MouseEnter(Point, dword) +{ + SetFocus(); + Refresh(); + if(!menu.IsOpen() && isenabled) + SetTimeCallback(400, THISBACK(Pull), TIMEID_PULL); +} + +void SubMenuItem::MouseLeave() +{ + if(HasFocus() && GetParent()) + GetParent()->SetFocus(); + KillTimeCallback(TIMEID_PULL); +} + +int SubMenuItem::GetVisualState() +{ + if(menu.IsOpen() && !GetParent()->HasFocusDeep()) + return PUSH; + return MenuItem::GetVisualState(); +} + +bool SubMenuItem::Key(dword key, int count) +{ + if(key == K_RIGHT || key == K_ENTER) { + Pull(); + return true; + } + return MenuItem::Key(key, count); +} + +bool SubMenuItem::HotKey(dword key) +{ + if(isenabled && (key == accel || CompareAccessKey(accesskey, key))) { + Pull(); + return true; + } + return false; +} + + +// ---------------------------------------------------- + +Size TopSubMenuItem::GetMinSize() const +{ + return AddFrameSize(GetTextSize(text, font) + Size(12, 7)); +} + +int TopSubMenuItem::GetState() +{ + if(parentmenu && parentmenu->GetActiveSubmenu() == &menu) return PUSH; + if(HasMouse() && GetParent() && !GetParent()->HasFocusDeep() && + (!parentmenu || !parentmenu->GetActiveSubmenu() || parentmenu->GetActiveSubmenu() == &menu) + || HasFocus()) + return HIGHLIGHT; + return NORMAL; +} + +void TopSubMenuItem::Paint(Draw& w) +{ + PaintTopItem(w, state = GetState()); +} + +void TopSubMenuItem::Pull() +{ + Rect r = GetScreenRect(); + if(parentmenu && parentmenu->IsChild() && !parentmenu->submenu) + parentmenu->SetupRestoreFocus(); + Point p = r.BottomLeft(); + if(GUI_GlobalStyle() >= GUISTYLE_XP) + p += style->pullshift; + SubMenuBase::Pull(this, p, Size(r.Width(), -r.Height())); + if(parentmenu) + parentmenu->SyncState(); +} + +void TopSubMenuItem::MouseEnter(Point p, dword) +{ + Refresh(); + if(isenabled && parentmenu->GetActiveSubmenu()) + Pull(); +} + +bool TopSubMenuItem::Key(dword key, int) { + if(isenabled && (key == K_ENTER || key == K_DOWN)) { + Pull(); + return true; + } + return false; +} + +void TopSubMenuItem::GotFocus() +{ + Refresh(); +} + +void TopSubMenuItem::LostFocus() +{ + Refresh(); +} + +bool TopSubMenuItem::HotKey(dword key) +{ + if(BarCtrl::Scan(proc, key)) + return true; + if(isenabled && (key == accel || CompareAccessKey(accesskey, key))) { + Pull(); + return true; + } + return false; +} + +void TopSubMenuItem::MouseLeave() +{ + Refresh(); +} + +void TopSubMenuItem::LeftDown(Point, dword) +{ + if(isenabled && !menu.IsOpen()) { + Pull(); + Refresh(); + } +} + +void TopSubMenuItem::SyncState() +{ + int q = GetState(); + if(q != state) { + state = q; + Refresh(); + } +} + +// ---------------------------------------------------- + +int TopMenuItem::GetState() +{ + if(!IsEnabled()) return NORMAL; + if(HasMouse() && GetMouseLeft() || GetMouseRight()) return PUSH; + if(HasFocus() || HasMouse()) return HIGHLIGHT; + return NORMAL; +} + +void TopMenuItem::Paint(Draw& w) +{ + PaintTopItem(w, state = GetState()); +} + +void TopMenuItem::MouseEnter(Point, dword) +{ + Refresh(); +} + +void TopMenuItem::MouseLeave() +{ + Refresh(); +} + +void TopMenuItem::LeftUp(Point, dword) +{ + if(!isenabled) return; + WhenAction(); + Refresh(); +} + +void TopMenuItem::LeftDown(Point, dword) +{ + Refresh(); +} + +void TopMenuItem::GotFocus() +{ + Refresh(); +} + +void TopMenuItem::LostFocus() +{ + Refresh(); +} + +bool TopMenuItem::Key(dword key, int count) +{ + if(isenabled && key == K_ENTER) { + WhenAction(); + return true; + } + return false; +} + +Size TopMenuItem::GetMinSize() const +{ + return AddFrameSize(GetTextSize(text, StdFont()) + Size(12, 7)); +} + +int TopMenuItem::GetStdHeight(Font font) +{ + return font.Info().GetHeight() + 7; +} + +void TopMenuItem::SyncState() +{ + if(state != GetState()) { + state = GetState(); + Refresh(); + } +} + +END_UPP_NAMESPACE diff --git a/uppsrc/CtrlLib/SSettings.cpp b/uppsrc/CtrlLib/SSettings.cpp deleted file mode 100644 index 4bc8889ee..000000000 --- a/uppsrc/CtrlLib/SSettings.cpp +++ /dev/null @@ -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 diff --git a/uppsrc/Draw/Draw.h b/uppsrc/Draw/Draw.h index 8fa111cb5..13a88bbd4 100644 --- a/uppsrc/Draw/Draw.h +++ b/uppsrc/Draw/Draw.h @@ -1,890 +1,892 @@ -#ifndef DRAW_H -#define DRAW_H - -#define SYSTEMDRAW 1 - -#include - -NAMESPACE_UPP - -class Drawing; -class Draw; -class Painting; -class SystemDraw; -class ImageDraw; - -#ifdef _MULTITHREADED -void EnterGMutex(); -void EnterGMutex(int n); -void LeaveGMutex(); -int LeaveGMutexAll(); - -struct DrawLock { - DrawLock() { EnterGMutex(); } - ~DrawLock() { LeaveGMutex(); } -}; -#else -inline void EnterGMutex() {} -inline void EnterGMutex(int n) {} -inline void LeaveGMutex() {} -inline int LeaveGMutexAll() { return 0; } - -struct DrawLock { - DrawLock() {} - ~DrawLock() {} -}; -#endif - -#include "Image.h" - -const int FONT_V = 40; - -#include "FontInt.h" - -class FontInfo; - -class Font : AssignValueTypeNo >{ - union { - int64 data; - struct { - word face; - word flags; - int16 height; - int16 width; - } v; - }; - - static Font AStdFont; - static Size StdFontSize; - - static const Vector& List(); - static void SyncStdFont(); - static void InitStdFont(); - - const CommonFontInfo& Fi() const; - - friend void sInitFonts(); - -public: - enum { - FIXEDPITCH = 0x0001, - SCALEABLE = 0x0002, - SPECIAL = 0x0010, - }; - - static int GetFaceCount(); - static String GetFaceName(int index); - static int FindFaceNameIndex(const String& name); - static dword GetFaceInfo(int index); - - static void SetStdFont(Font font); - static Font GetStdFont(); - static Size GetStdFontSize(); - - enum { - STDFONT, - SERIF, - SANSSERIF, - MONOSPACE, - #ifdef PLATFORM_WIN32 - SYMBOL, - WINGDINGS, - TAHOMA, - #endif - OTHER, - - // Backward compatibility: - ROMAN = SERIF, - ARIAL = SANSSERIF, - COURIER = MONOSPACE, - SCREEN_SERIF = SERIF, - SCREEN_SANS = SANSSERIF, - SCREEN_FIXED = MONOSPACE, - }; - - int GetFace() const { return v.face; } - int GetHeight() const; - int GetWidth() const { return v.width; } - bool IsBold() const { return v.flags & 0x8000; } - bool IsItalic() const { return v.flags & 0x4000; } - bool IsUnderline() const { return v.flags & 0x2000; } - bool IsStrikeout() const { return v.flags & 0x1000; } - bool IsNonAntiAliased() const { return v.flags & 0x800; } - bool IsTrueTypeOnly() const { return v.flags & 0x400; } - String GetFaceName() const; - dword GetFaceInfo() const; - int64 AsInt64() const { return data; } - - Font& Face(int n) { v.face = n; return *this; } - Font& Height(int n) { v.height = n; return *this; } - Font& Width(int n) { v.width = n; return *this; } - Font& Bold() { v.flags |= 0x8000; return *this; } - Font& NoBold() { v.flags &= ~0x8000; return *this; } - Font& Bold(bool b) { return b ? Bold() : NoBold(); } - Font& Italic() { v.flags |= 0x4000; return *this; } - Font& NoItalic() { v.flags &= ~0x4000; return *this; } - Font& Italic(bool b) { return b ? Italic() : NoItalic(); } - Font& Underline() { v.flags |= 0x2000; return *this; } - Font& NoUnderline() { v.flags &= ~0x2000; return *this; } - Font& Underline(bool b) { return b ? Underline() : NoUnderline(); } - Font& Strikeout() { v.flags |= 0x1000; return *this; } - Font& NoStrikeout() { v.flags &= ~0x1000; return *this; } - Font& Strikeout(bool b) { return b ? Strikeout() : NoStrikeout(); } - Font& NonAntiAliased() { v.flags |= 0x800; return *this; } - Font& NoNonAntiAliased() { v.flags &= ~0x800; return *this; } - Font& NonAntiAliased(bool b) { return b ? NonAntiAliased() : NoNonAntiAliased(); } - Font& TrueTypeOnly() { v.flags |= 0x400; return *this; } - Font& NoTrueTypeOnly() { v.flags &= ~0x400; return *this; } - Font& TrueTypeOnly(bool b) { return b ? TrueTypeOnly() : NoTrueTypeOnly(); } - Font& FaceName(const String& name); - - Font operator()() const { return *this; } - Font operator()(int n) const { return Font(*this).Height(n); } - - - int GetAscent() const { return Fi().ascent; } - int GetDescent() const { return Fi().descent; } - int GetCy() const { return Fi().height; } - int GetExternal() const { return Fi().external; } - int GetInternal() const { return Fi().internal; } - int GetLineHeight() const { return Fi().lineheight; } - int GetOverhang() const { return Fi().overhang; } - int GetAveWidth() const { return Fi().avewidth; } - int GetMaxWidth() const { return Fi().maxwidth; } - bool IsNormal(int ch) const; - bool IsComposed(int ch) const; - bool IsReplaced(int ch) const; - bool IsMissing(int ch) const; - int HasChar(int ch) const; - int GetWidth(int c) const; - int operator[](int c) const { return GetWidth(c); } - int GetLeftSpace(int c) const; - int GetRightSpace(int c) const; - bool IsFixedPitch() const { return Fi().fixedpitch; } - bool IsScaleable() const { return Fi().scaleable; } - bool IsSpecial() const { return !(GetFaceInfo() & SPECIAL); } - -#ifdef PLATFORM_POSIX - String GetPath() const { return Fi().path; } -#endif - - void Serialize(Stream& s); - - bool operator==(Font f) const { return v.face == f.v.face && v.flags == f.v.flags && - v.width == f.v.width && v.height == f.v.height; } - bool operator!=(Font f) const { return !operator==(f); } - - dword GetHashValue() const { return CombineHash(v.width, v.flags, v.height, v.face); } - bool IsNull() const { return v.face == 0xffff; } - - Font() { v.height = v.width = 0; v.face = v.flags = 0; } - Font(int face, int height) { v.face = face; v.height = height; v.flags = 0; v.width = 0; } - Font(const Nuller&) { v.face = 0xffff; v.height = v.width = 0; v.flags = 0; } - - operator Value() const { return RichValue(*this); } - Font(const Value& q) { *this = RichValue::Extract(q); } - -// BW compatibility - FontInfo Info() const; -}; - -//BW compatibility -class FontInfo { - Font font; - friend class Font; -public: - int GetAscent() const { return font.GetAscent(); } - int GetDescent() const { return font.GetDescent(); } - int GetExternal() const { return font.GetExternal(); } - int GetInternal() const { return font.GetInternal(); } - int GetHeight() const { return font.GetCy(); } - int GetLineHeight() const { return font.GetLineHeight(); } - int GetOverhang() const { return font.GetOverhang(); } - int GetAveWidth() const { return font.GetAveWidth(); } - int GetMaxWidth() const { return font.GetMaxWidth(); } - int HasChar(int c) const { return font.HasChar(c); } - int GetWidth(int c) const { return font.GetWidth(c); } - int operator[](int c) const { return GetWidth(c); } - int GetLeftSpace(int c) const { return font.GetLeftSpace(c); } - int GetRightSpace(int c) const { return font.GetRightSpace(c); } - bool IsFixedPitch() const { return font.IsFixedPitch(); } - bool IsScaleable() const { return font.IsScaleable(); } - int GetFontHeight() const { return font.GetHeight(); } - Font GetFont() const { return font; } -#ifdef PLATFORM_POSIX - String GetFileName() const { return font.GetPath(); } -#endif -}; - -struct ComposedGlyph { - wchar basic_char; - Point mark_pos; - wchar mark_char; - Font mark_font; -}; - -bool Compose(Font fnt, int chr, ComposedGlyph& cs); - -template<> -inline bool IsNull(const Font& f) { return f.IsNull(); } - -template<> -inline unsigned GetHashValue(const Font& f) { return f.GetHashValue(); } - -template<> -String AsString(const Font& f); - -inline void SetStdFont(Font font) { Font::SetStdFont(font); } -inline Font GetStdFont() { return Font::GetStdFont(); } -inline Size GetStdFontSize() { return Font::GetStdFontSize(); } -inline int GetStdFontCy() { return GetStdFontSize().cy; } - -Font StdFont(); - -inline Font StdFont(int h) { return StdFont().Height(h); } - - -/* -struct ScreenSans : public Font { ScreenSans(int n = 0) : Font(SCREEN_SANS, n) {} }; -struct ScreenSerif : public Font { ScreenSerif(int n = 0) : Font(SCREEN_SERIF, n) {} }; -struct ScreenFixed : public Font { ScreenFixed(int n = 0) : Font(SCREEN_FIXED, n) {} }; - -struct Roman : public Font { Roman(int n) : Font(ROMAN, n) {} }; -struct Arial : public Font { Arial(int n) : Font(ARIAL, n) {} }; -struct Courier : public Font { Courier(int n) : Font(COURIER, n) {} }; - -#ifdef PLATFORM_WIN32 -struct Symbol : public Font { Symbol(int n) : Font(SYMBOL, n) {} }; -struct WingDings : public Font { WingDings(int n) : Font(WINGDINGS, n) {} }; -struct Tahoma : public Font { Tahoma(int n) : Font(TAHOMA, n) {} }; -#endif -*/ - -inline Font Serif(int n = 0) { return Font(Font::SCREEN_SERIF, n); } -inline Font SansSerif(int n = 0) { return Font(Font::SCREEN_SANS, n); } -inline Font Monospace(int n = 0) { return Font(Font::SCREEN_FIXED, n); } - -inline Font Roman(int n = 0) { return Font(Font::SCREEN_SERIF, n); } -inline Font Arial(int n = 0) { return Font(Font::SCREEN_SANS, n); } -inline Font Courier(int n = 0) { return Font(Font::SCREEN_FIXED, n); } - -inline Font ScreenSerif(int n = 0) { return Font(Font::SCREEN_SERIF, n); } -inline Font ScreenSans(int n = 0) { return Font(Font::SCREEN_SANS, n); } -inline Font ScreenFixed(int n = 0) { return Font(Font::SCREEN_FIXED, n); } - -#ifdef PLATFORM_WIN32 // backward comaptibility -inline Font Tahoma(int n = 0) { return Font(Font::TAHOMA, n); } -#endif - -Size GetTextSize(const wchar *text, Font font, int n = -1); -Size GetTextSize(const WString& text, Font font); -Size GetTextSize(const char *text, byte charset, Font font, int n = -1); -Size GetTextSize(const char *text, Font font, int n = -1); -Size GetTextSize(const String& text, Font font); - -enum { - PEN_NULL = -1, - PEN_SOLID = -2, - PEN_DASH = -3, -#ifndef PLATFORM_WINCE - PEN_DOT = -4, - PEN_DASHDOT = -5, - PEN_DASHDOTDOT = -6, -#endif -}; - -class Image; - -//DEPRECATED: TODO -Color SBlack(); -Color SGray(); -Color SLtGray(); -Color SWhiteGray(); -Color SWhite(); -Color SRed(); -Color SGreen(); -Color SBrown(); -Color SBlue(); -Color SMagenta(); -Color SCyan(); -Color SYellow(); -Color SLtRed(); -Color SLtGreen(); -Color SLtYellow(); -Color SLtBlue(); -Color SLtMagenta(); -Color SLtCyan(); -//END OF DEPRECATED - -Color SColorPaper(); -Color SColorText(); -Color SColorHighlight(); -Color SColorHighlightText();// -Color SColorMenu(); -Color SColorMenuText(); -Color SColorInfo(); -Color SColorInfoText();// -Color SColorMark(); -Color SColorDisabled(); -Color SColorLight(); -Color SColorFace(); -Color SColorLabel(); -Color SColorShadow(); - -Color SColorLtFace(); -Color SColorDkShadow(); - - -void SBlack_Write(Color c); -void SGray_Write(Color c); -void SLtGray_Write(Color c); -void SWhiteGray_Write(Color c); -void SWhite_Write(Color c); -void SRed_Write(Color c); -void SGreen_Write(Color c); -void SBrown_Write(Color c); -void SBlue_Write(Color c); -void SMagenta_Write(Color c); -void SCyan_Write(Color c); -void SYellow_Write(Color c); -void SLtRed_Write(Color c); -void SLtGreen_Write(Color c); -void SLtYellow_Write(Color c); -void SLtBlue_Write(Color c); -void SLtMagenta_Write(Color c); -void SLtCyan_Write(Color c); - -void SColorPaper_Write(Color c); -void SColorText_Write(Color c); -void SColorHighlight_Write(Color c); -void SColorHighlightText_Write(Color c);// -void SColorMenu_Write(Color c); -void SColorMenuText_Write(Color c); -void SColorInfo_Write(Color c); -void SColorInfoText_Write(Color c);// -void SColorMark_Write(Color c); -void SColorDisabled_Write(Color c); -void SColorLight_Write(Color c); -void SColorFace_Write(Color c); -void SColorLabel_Write(Color c); -void SColorShadow_Write(Color c); - -void SColorLtFace_Write(Color c); -void SColorDkShadow_Write(Color c); - - -inline Color InvertColor() { return Color(255, 0); } -inline Color DefaultInk() { return Black(); } //TODO! - -class Painting : AssignValueTypeNo > { - String cmd; - ValueArray data; - Sizef size; - - friend class PaintingPainter; - friend class Painter; - -public: - Sizef GetSize() const { return size; } - - void Clear() { size = Null; data.Clear(); cmd.Clear(); } - void Serialize(Stream& s) { s % cmd % data % size; } - bool IsNullInstance() const { return cmd.IsEmpty(); } - bool operator==(const Painting& b) const { return cmd == b.cmd && data == b.data && size == b.size; } - unsigned GetHashValue() const { return CombineHash(cmd, data); } - String ToString() const { return "painting " + AsString(size); } - - operator Value() const { return RichValue(*this); } - Painting(const Value& q) { *this = RichValue::Extract(q); } - - Painting() { size = Null; } - Painting(const Nuller&) { size = Null; } -}; - -enum { - MODE_ANTIALIASED = 0, - MODE_NOAA = 1, - MODE_SUBPIXEL = 2, -}; - -bool HasPainter(); -void PaintImageBuffer(ImageBuffer& ib, const Painting& p, Size sz, Point pos, int mode = MODE_ANTIALIASED); -void PaintImageBuffer(ImageBuffer& ib, const Painting& p, int mode = MODE_ANTIALIASED); -void PaintImageBuffer(ImageBuffer& ib, const Drawing& p, int mode = MODE_ANTIALIASED); - -class Draw : NoCopy { -private: - struct DrawingPos; - -public: - enum { - DOTS = 0x001, - GUI = 0x002, - PRINTER = 0x004, - NATIVE = 0x008, - DATABANDS = 0x010, - }; - - virtual dword GetInfo() const = 0; - - virtual Size GetPageSize() const; - virtual void StartPage(); - virtual void EndPage(); - - virtual void BeginOp() = 0; - virtual void EndOp() = 0; - virtual void OffsetOp(Point p) = 0; - virtual bool ClipOp(const Rect& r) = 0; - virtual bool ClipoffOp(const Rect& r) = 0; - virtual bool ExcludeClipOp(const Rect& r) = 0; - virtual bool IntersectClipOp(const Rect& r) = 0; - virtual bool IsPaintingOp(const Rect& r) const = 0; - virtual Rect GetPaintRect() const; - - virtual void DrawRectOp(int x, int y, int cx, int cy, Color color) = 0; - virtual void DrawImageOp(int x, int y, int cx, int cy, const Image& img, const Rect& src, Color color) = 0; - virtual void DrawDataOp(int x, int y, int cx, int cy, const String& data, const char *id); - virtual void DrawLineOp(int x1, int y1, int x2, int y2, int width, Color color) = 0; - - virtual void DrawPolyPolylineOp(const Point *vertices, int vertex_count, - const int *counts, int count_count, - int width, Color color, Color doxor) = 0; - virtual void DrawPolyPolyPolygonOp(const Point *vertices, int vertex_count, - const int *subpolygon_counts, int scc, - const int *disjunct_polygon_counts, int dpcc, - Color color, int width, Color outline, - uint64 pattern, Color doxor) = 0; - virtual void DrawArcOp(const Rect& rc, Point start, Point end, int width, Color color) = 0; - - virtual void DrawEllipseOp(const Rect& r, Color color, int pen, Color pencolor) = 0; - virtual void DrawTextOp(int x, int y, int angle, const wchar *text, Font font, - Color ink, int n, const int *dx) = 0; - virtual void DrawDrawingOp(const Rect& target, const Drawing& w); - virtual void DrawPaintingOp(const Rect& target, const Painting& w); - - virtual Size GetNativeDpi() const; - virtual void BeginNative(); - virtual void EndNative(); - - virtual int GetCloffLevel() const; - - virtual ~Draw(); - -// -------------- - Size GetPixelsPerInch() const; - Size GetPageMMs() const; - - bool Dots() const { return GetInfo() & DOTS; } - bool Pixels() const { return !Dots(); } - bool IsGui() const { return GetInfo() & GUI; } - bool IsPrinter() const { return GetInfo() & PRINTER; } - bool IsNative() const { return GetInfo() & NATIVE; } - - int GetNativeX(int x) const; - int GetNativeY(int y) const; - void Native(int& x, int& y) const; - void Native(Point& p) const; - void Native(Size& sz) const; - void Native(Rect& r) const; - - void Begin() { BeginOp(); } - void End() { EndOp(); } - void Offset(Point p) { OffsetOp(p); } - void Offset(int x, int y); - bool Clip(const Rect& r) { return ClipOp(r); } - bool Clip(int x, int y, int cx, int cy); - bool Clipoff(const Rect& r) { return ClipoffOp(r); } - bool Clipoff(int x, int y, int cx, int cy); - bool ExcludeClip(const Rect& r) { return ExcludeClipOp(r); } - bool ExcludeClip(int x, int y, int cx, int cy); - bool IntersectClip(const Rect& r) { return IntersectClipOp(r); } - bool IntersectClip(int x, int y, int cx, int cy); - bool IsPainting(const Rect& r) const { return IsPaintingOp(r); } - bool IsPainting(int x, int y, int cx, int cy) const; - - void DrawRect(int x, int y, int cx, int cy, Color color); - void DrawRect(const Rect& rect, Color color); - - void DrawImage(int x, int y, int cx, int cy, const Image& img, const Rect& src); - void DrawImage(int x, int y, int cx, int cy, const Image& img); - void DrawImage(int x, int y, int cx, int cy, const Image& img, const Rect& src, Color color); - void DrawImage(int x, int y, int cx, int cy, const Image& img, Color color); - - void DrawImage(const Rect& r, const Image& img, const Rect& src); - void DrawImage(const Rect& r, const Image& img); - void DrawImage(const Rect& r, const Image& img, const Rect& src, Color color); - void DrawImage(const Rect& r, const Image& img, Color color); - - void DrawImage(int x, int y, const Image& img, const Rect& src); - void DrawImage(int x, int y, const Image& img); - void DrawImage(int x, int y, const Image& img, const Rect& src, Color color); - void DrawImage(int x, int y, const Image& img, Color color); - - void DrawData(int x, int y, int cx, int cy, const String& data, const char *type); - void DrawData(const Rect& r, const String& data, const char *type); - - void DrawLine(int x1, int y1, int x2, int y2, int width = 0, Color color = DefaultInk); - void DrawLine(Point p1, Point p2, int width = 0, Color color = DefaultInk); - - void DrawEllipse(const Rect& r, Color color = DefaultInk, - int pen = Null, Color pencolor = DefaultInk); - void DrawEllipse(int x, int y, int cx, int cy, Color color = DefaultInk, - int pen = Null, Color pencolor = DefaultInk); - - void DrawArc(const Rect& rc, Point start, Point end, int width = 0, Color color = DefaultInk); - - void DrawPolyPolyline(const Point *vertices, int vertex_count, - const int *counts, int count_count, - int width = 0, Color color = DefaultInk, Color doxor = Null); - void DrawPolyPolyline(const Vector& vertices, const Vector& counts, - int width = 0, Color color = DefaultInk, Color doxor = Null); - void DrawPolyline(const Point *vertices, int count, - int width = 0, Color color = DefaultInk, Color doxor = Null); - void DrawPolyline(const Vector& vertices, - int width = 0, Color color = DefaultInk, Color doxor = Null); - - void DrawPolyPolyPolygon(const Point *vertices, int vertex_count, - const int *subpolygon_counts, int subpolygon_count_count, - const int *disjunct_polygon_counts, int disjunct_polygon_count_count, - Color color = DefaultInk, int width = 0, Color outline = Null, - uint64 pattern = 0, Color doxor = Null); - void DrawPolyPolyPolygon(const Vector& vertices, - const Vector& subpolygon_counts, - const Vector& disjunct_polygon_counts, - Color color = DefaultInk, int width = 0, Color outline = Null, uint64 pattern = 0, Color doxor = Null); - void DrawPolyPolygon(const Point *vertices, int vertex_count, - const int *subpolygon_counts, int subpolygon_count_count, - Color color = DefaultInk, int width = 0, Color outline = Null, uint64 pattern = 0, Color doxor = Null); - void DrawPolyPolygon(const Vector& vertices, const Vector& subpolygon_counts, - Color color = DefaultInk, int width = 0, Color outline = Null, uint64 pattern = 0, Color doxor = Null); - void DrawPolygons(const Point *vertices, int vertex_count, - const int *polygon_counts, int polygon_count_count, - Color color = DefaultInk, int width = 0, Color outline = Null, uint64 pattern = 0, Color doxor = Null); - void DrawPolygons(const Vector& vertices, const Vector& polygon_counts, - Color color = DefaultInk, int width = 0, Color outline = Null, uint64 pattern = 0, Color doxor = Null); - void DrawPolygon(const Point *vertices, int vertex_count, - Color color = DefaultInk, int width = 0, Color outline = Null, uint64 pattern = 0, Color doxor = Null); - void DrawPolygon(const Vector& vertices, - Color color = DefaultInk, int width = 0, Color outline = Null, uint64 pattern = 0, Color doxor = Null); - - void DrawDrawing(const Rect& r, const Drawing& iw) { DrawDrawingOp(r, iw); } - void DrawDrawing(int x, int y, int cx, int cy, const Drawing& iw); - - void DrawPainting(const Rect& r, const Painting& iw) { DrawPaintingOp(r, iw); } - void DrawPainting(int x, int y, int cx, int cy, const Painting& iw); - - void DrawText(int x, int y, int angle, const wchar *text, Font font = StdFont(), - Color ink = DefaultInk, int n = -1, const int *dx = NULL); - void DrawText(int x, int y, const wchar *text, Font font = StdFont(), - Color ink = DefaultInk, int n = -1, const int *dx = NULL); - - void DrawText(int x, int y, const WString& text, Font font = StdFont(), - Color ink = DefaultInk, const int *dx = NULL); - void DrawText(int x, int y, int angle, const WString& text, Font font = StdFont(), - Color ink = DefaultInk, const int *dx = NULL); - - void DrawText(int x, int y, int angle, const char *text, byte charset, - Font font = StdFont(), Color ink = DefaultInk, int n = -1, const int *dx = NULL); - void DrawText(int x, int y, const char *text, byte charset, Font font = StdFont(), - Color ink = DefaultInk, int n = -1, const int *dx = NULL); - - void DrawText(int x, int y, int angle, const char *text, - Font font = StdFont(), Color ink = DefaultInk, int n = -1, const int *dx = NULL); - void DrawText(int x, int y, const char *text, Font font = StdFont(), - Color ink = DefaultInk, int n = -1, const int *dx = NULL); - - void DrawText(int x, int y, const String& text, Font font = StdFont(), - Color ink = DefaultInk, const int *dx = NULL); - void DrawText(int x, int y, int angle, const String& text, Font font = StdFont(), - Color ink = DefaultInk, const int *dx = NULL); - - static void SinCos(int angle, double& sina, double& cosa); - - // deprecated: - static void SetStdFont(Font font) { UPP::SetStdFont(font); } - static Font GetStdFont() { return UPP::GetStdFont(); } - static Size GetStdFontSize() { return UPP::GetStdFontSize(); } - static int GetStdFontCy() { return GetStdFontSize().cy; } - Size GetPagePixels() const { return GetPageSize(); } - - -#ifdef PLATFORM_WIN32_ - static void Flush(); - HDC BeginGdi(); - void EndGdi(); -#endif -}; - -void DrawImageBandRLE(Draw& w, int x, int y, const Image& m, int minp); - -class DataDrawer { - typedef DataDrawer *(*Factory)(); - template static DataDrawer *FactoryFn() { return new T; } - static void AddFormat(const char *id, Factory f); - static VectorMap& Map(); - -public: - virtual void Open(const String& data, int cx, int cy) = 0; - virtual void Render(ImageBuffer& ib) = 0; - virtual ~DataDrawer(); - - static One Create(const String& id); - - template static void Register(const char *id) { AddFormat(id, &DataDrawer::FactoryFn); } -}; - -class Drawing : AssignValueTypeNo > { - Size size; - String data; - ValueArray val; - - friend class DrawingDraw; - friend class Draw; - -public: - operator bool() const { return !data.IsEmpty(); } - Size GetSize() const { return size; } - void SetSize(Size sz) { size = sz; } - void SetSize(int cx, int cy) { size = Size(cx, cy); } - - Size RatioSize(int cx, int cy) const; - Size RatioSize(Size sz) const { return RatioSize(sz.cx, sz.cy); } - - void Clear() { data.Clear(); size = Null; } - - void Append(Drawing& dw); - - void Serialize(Stream& s); - - bool IsNullInstance() const { return data.IsEmpty(); } - bool operator==(const Drawing& b) const { return val == b.val && data == b.data && size == b.size; } - String ToString() const { return "drawing " + AsString(size); } - unsigned GetHashValue() const { return CombineHash(data, val); } - - operator Value() const { return RichValue(*this); } - Drawing(const Value& src); - - Drawing() { size = Null; } - Drawing(const Nuller&) { size = Null; } -}; - -class DrawingDraw : public Draw { -public: - virtual dword GetInfo() const; - virtual Size GetPageSize() const; - virtual Rect GetPaintRect() const; - - virtual void BeginOp(); - virtual void EndOp(); - virtual void OffsetOp(Point p); - virtual bool ClipOp(const Rect& r); - virtual bool ClipoffOp(const Rect& r); - virtual bool ExcludeClipOp(const Rect& r); - virtual bool IntersectClipOp(const Rect& r); - virtual bool IsPaintingOp(const Rect& r) const; - - virtual void DrawRectOp(int x, int y, int cx, int cy, Color color); - virtual void DrawImageOp(int x, int y, int cx, int cy, const Image& img, const Rect& src, Color color); - virtual void DrawDataOp(int x, int y, int cx, int cy, const String& data, const char *id); - virtual void DrawLineOp(int x1, int y1, int x2, int y2, int width, Color color); - virtual void DrawPolyPolylineOp(const Point *vertices, int vertex_count, - const int *counts, int count_count, - int width, Color color, Color doxor); - virtual void DrawPolyPolyPolygonOp(const Point *vertices, int vertex_count, - const int *subpolygon_counts, int scc, - const int *disjunct_polygon_counts, int dpcc, - Color color, int width, Color outline, - uint64 pattern, Color doxor); - virtual void DrawEllipseOp(const Rect& r, Color color, int pen, Color pencolor); - virtual void DrawArcOp(const Rect& rc, Point start, Point end, int pen, Color pencolor); - virtual void DrawTextOp(int x, int y, int angle, const wchar *text, Font font, - Color ink, int n, const int *dx); - - virtual void DrawDrawingOp(const Rect& target, const Drawing& w); - virtual void DrawPaintingOp(const Rect& target, const Painting& w); - -private: - Size size; - bool dots; - StringStream drawing; - ValueArray val; - - Stream& DrawingOp(int code); - -public: - void Create(int cx, int cy, bool dots = true); - void Create(Size sz, bool dots = true); - - Size GetSize() const { return size; } - - Drawing GetResult(); - operator Drawing() { return GetResult(); } - - DrawingDraw(); - DrawingDraw(int cx, int cy, bool dots = true); - DrawingDraw(Size sz, bool dots = true); -}; - -class NilDraw : public Draw { -public: - virtual dword GetInfo() const; - virtual Size GetPageSize() const; - virtual void BeginOp(); - virtual void EndOp(); - virtual void OffsetOp(Point p); - virtual bool ClipOp(const Rect& r); - virtual bool ClipoffOp(const Rect& r); - virtual bool ExcludeClipOp(const Rect& r); - virtual bool IntersectClipOp(const Rect& r); - virtual bool IsPaintingOp(const Rect& r) const; - virtual Rect GetPaintRect() const; - - virtual void DrawRectOp(int x, int y, int cx, int cy, Color color); - virtual void DrawImageOp(int x, int y, int cx, int cy, const Image& img, const Rect& src, Color color); - virtual void DrawDataOp(int x, int y, int cx, int cy, const String& data, const char *id); - virtual void DrawLineOp(int x1, int y1, int x2, int y2, int width, Color color); - virtual void DrawPolyPolylineOp(const Point *vertices, int vertex_count, - const int *counts, int count_count, - int width, Color color, Color doxor); - virtual void DrawPolyPolyPolygonOp(const Point *vertices, int vertex_count, - const int *subpolygon_counts, int scc, - const int *disjunct_polygon_counts, int dpcc, - Color color, int width, Color outline, - uint64 pattern, Color doxor); - virtual void DrawArcOp(const Rect& rc, Point start, Point end, int width, Color color); - virtual void DrawEllipseOp(const Rect& r, Color color, int pen, Color pencolor); - virtual void DrawTextOp(int x, int y, int angle, const wchar *text, Font font, - Color ink, int n, const int *dx); - virtual void DrawDrawingOp(const Rect& target, const Drawing& w); - virtual void DrawPaintingOp(const Rect& target, const Painting& w); -}; - -class ImageAnyDraw : public Draw { - Draw *draw; - - void Init(Size sz); - -public: - virtual dword GetInfo() const; - virtual Size GetPageSize() const; - virtual void BeginOp(); - virtual void EndOp(); - virtual void OffsetOp(Point p); - virtual bool ClipOp(const Rect& r); - virtual bool ClipoffOp(const Rect& r); - virtual bool ExcludeClipOp(const Rect& r); - virtual bool IntersectClipOp(const Rect& r); - virtual bool IsPaintingOp(const Rect& r) const; - virtual Rect GetPaintRect() const; - - virtual void DrawRectOp(int x, int y, int cx, int cy, Color color); - virtual void DrawImageOp(int x, int y, int cx, int cy, const Image& img, const Rect& src, Color color); - virtual void DrawDataOp(int x, int y, int cx, int cy, const String& data, const char *id); - virtual void DrawLineOp(int x1, int y1, int x2, int y2, int width, Color color); - virtual void DrawPolyPolylineOp(const Point *vertices, int vertex_count, - const int *counts, int count_count, - int width, Color color, Color doxor); - virtual void DrawPolyPolyPolygonOp(const Point *vertices, int vertex_count, - const int *subpolygon_counts, int scc, - const int *disjunct_polygon_counts, int dpcc, - Color color, int width, Color outline, - uint64 pattern, Color doxor); - virtual void DrawArcOp(const Rect& rc, Point start, Point end, int width, Color color); - virtual void DrawEllipseOp(const Rect& r, Color color, int pen, Color pencolor); - virtual void DrawTextOp(int x, int y, int angle, const wchar *text, Font font, - Color ink, int n, const int *dx); - virtual void DrawDrawingOp(const Rect& target, const Drawing& w); - virtual void DrawPaintingOp(const Rect& target, const Painting& w); - -public: - operator Image() const; - - ImageAnyDraw(Size sz); - ImageAnyDraw(int cx, int cy); - - ~ImageAnyDraw(); -}; - -void AddNotEmpty(Vector& result, int left, int right, int top, int bottom); -bool Subtract(const Rect& r, const Rect& sub, Vector& result); -bool Subtract(const Vector& rr, const Rect& sub, Vector& result); -Vector Subtract(const Vector& rr, const Rect& sub, bool& changed); -Vector Intersect(const Vector& b, const Rect& a, bool& changed); - -void Subtract(Vector& rr, const Rect& sub); -void Union(Vector& rr, const Rect& add); - -void DrawRect(Draw& w, const Rect& rect, const Image& img, bool ralgn = false); //??? TODO -void DrawRect(Draw& w, int x, int y, int cx, int cy, const Image& img, bool ra = false); - -void DrawTiles(Draw& w, int x, int y, int cx, int cy, const Image& img); -void DrawTiles(Draw& w, const Rect& rect, const Image& img); - -void DrawFatFrame(Draw& w, int x, int y, int cx, int cy, Color color, int n); -void DrawFatFrame(Draw& w, const Rect& r, Color color, int n); - -void DrawFrame(Draw& w, int x, int y, int cx, int cy, - Color leftcolor, Color topcolor, Color rightcolor, Color bottomcolor); -void DrawFrame(Draw& w, const Rect& r, - Color leftcolor, Color topcolor, Color rightcolor, Color bottomcolor); -void DrawFrame(Draw& w, int x, int y, int cx, int cy, - Color topleftcolor, Color bottomrightcolor); -void DrawFrame(Draw& w, const Rect& r, - Color topleftcolor, Color bottomrightcolor); -void DrawFrame(Draw& w, int x, int y, int cx, int cy, Color color); -void DrawFrame(Draw& w, const Rect& r, Color color); - -void DrawBorder(Draw& w, int x, int y, int cx, int cy, const ColorF *colors_ltrd); //TODO -void DrawBorder(Draw& w, const Rect& r, const ColorF *colors_ltrd); - -const ColorF *BlackBorder(); -const ColorF *ButtonPushBorder(); -const ColorF *EdgeButtonBorder(); -const ColorF *DefButtonBorder(); -const ColorF *ButtonBorder(); -const ColorF *InsetBorder(); -const ColorF *OutsetBorder(); -const ColorF *ThinOutsetBorder(); -const ColorF *ThinInsetBorder(); - -void DrawBorder(Draw& w, int x, int y, int cx, int cy, const ColorF *(*colors_ltrd)()); -void DrawBorder(Draw& w, const Rect& r, const ColorF *(*colors_ltrd)()); - -void DrawRectMinusRect(Draw& w, const Rect& rect, const Rect& inner, Color color); - -void DrawHighlightImage(Draw& w, int x, int y, const Image& img, bool highlight = true, - bool enabled = true, Color maskcolor = SColorPaper); - -Color GradientColor(Color fc, Color tc, int i, int n); - -enum { - BUTTON_NORMAL, BUTTON_OK, BUTTON_HIGHLIGHT, BUTTON_PUSH, BUTTON_DISABLED, BUTTON_CHECKED, - BUTTON_VERTICAL = 0x100, - BUTTON_EDGE = 0x200, - BUTTON_TOOL = 0x400, - BUTTON_SCROLL = 0x800, -}; - -void DrawXPButton(Draw& w, Rect r, int type); - -void DrawTextEllipsis(Draw& w, int x, int y, int cx, const char *text, const char *ellipsis, - Font font = StdFont(), Color ink = SColorText(), int n = -1); -void DrawTextEllipsis(Draw& w, int x, int y, int cx, const wchar *text, const char *ellipsis, - Font font = StdFont(), Color ink = SColorText(), int n = -1); -Size GetTLTextSize(const wchar *text, Font font = StdFont()); -int GetTLTextHeight(const wchar *s, Font font = StdFont()); -void DrawTLText(Draw& draw, int x, int y, int cx, const wchar *text, Font font = StdFont(), - Color ink = SColorText(), int accesskey = 0); - - -typedef String (*DrawingToPdfFnType)(const Array& report, Size pagesize, int margin); - -void SetDrawingToPdfFn(DrawingToPdfFnType Pdf); -DrawingToPdfFnType GetDrawingToPdfFn(); - -#include "Display.h" -#include "Cham.h" - -END_UPP_NAMESPACE - -#endif +#ifndef DRAW_H +#define DRAW_H + +#define SYSTEMDRAW 1 + +#include + +NAMESPACE_UPP + +class Drawing; +class Draw; +class Painting; +class SystemDraw; +class ImageDraw; + +#ifdef _MULTITHREADED +void EnterGMutex(); +void EnterGMutex(int n); +void LeaveGMutex(); +int LeaveGMutexAll(); + +struct DrawLock { + DrawLock() { EnterGMutex(); } + ~DrawLock() { LeaveGMutex(); } +}; +#else +inline void EnterGMutex() {} +inline void EnterGMutex(int n) {} +inline void LeaveGMutex() {} +inline int LeaveGMutexAll() { return 0; } + +struct DrawLock { + DrawLock() {} + ~DrawLock() {} +}; +#endif + +#include "Image.h" + +const int FONT_V = 40; + +#include "FontInt.h" + +class FontInfo; + +class Font : AssignValueTypeNo >{ + union { + int64 data; + struct { + word face; + word flags; + int16 height; + int16 width; + } v; + }; + + static Font AStdFont; + static Size StdFontSize; + + static const Vector& List(); + static void SyncStdFont(); + static void InitStdFont(); + + const CommonFontInfo& Fi() const; + + friend void sInitFonts(); + +public: + enum { + FIXEDPITCH = 0x0001, + SCALEABLE = 0x0002, + SPECIAL = 0x0010, + }; + + static int GetFaceCount(); + static String GetFaceName(int index); + static int FindFaceNameIndex(const String& name); + static dword GetFaceInfo(int index); + + static void SetStdFont(Font font); + static Font GetStdFont(); + static Size GetStdFontSize(); + + enum { + STDFONT, + SERIF, + SANSSERIF, + MONOSPACE, + #ifdef PLATFORM_WIN32 + SYMBOL, + WINGDINGS, + TAHOMA, + #endif + OTHER, + + // Backward compatibility: + ROMAN = SERIF, + ARIAL = SANSSERIF, + COURIER = MONOSPACE, + SCREEN_SERIF = SERIF, + SCREEN_SANS = SANSSERIF, + SCREEN_FIXED = MONOSPACE, + }; + + int GetFace() const { return v.face; } + int GetHeight() const; + int GetWidth() const { return v.width; } + bool IsBold() const { return v.flags & 0x8000; } + bool IsItalic() const { return v.flags & 0x4000; } + bool IsUnderline() const { return v.flags & 0x2000; } + bool IsStrikeout() const { return v.flags & 0x1000; } + bool IsNonAntiAliased() const { return v.flags & 0x800; } + bool IsTrueTypeOnly() const { return v.flags & 0x400; } + String GetFaceName() const; + dword GetFaceInfo() const; + int64 AsInt64() const { return data; } + + Font& Face(int n) { v.face = n; return *this; } + Font& Height(int n) { v.height = n; return *this; } + Font& Width(int n) { v.width = n; return *this; } + Font& Bold() { v.flags |= 0x8000; return *this; } + Font& NoBold() { v.flags &= ~0x8000; return *this; } + Font& Bold(bool b) { return b ? Bold() : NoBold(); } + Font& Italic() { v.flags |= 0x4000; return *this; } + Font& NoItalic() { v.flags &= ~0x4000; return *this; } + Font& Italic(bool b) { return b ? Italic() : NoItalic(); } + Font& Underline() { v.flags |= 0x2000; return *this; } + Font& NoUnderline() { v.flags &= ~0x2000; return *this; } + Font& Underline(bool b) { return b ? Underline() : NoUnderline(); } + Font& Strikeout() { v.flags |= 0x1000; return *this; } + Font& NoStrikeout() { v.flags &= ~0x1000; return *this; } + Font& Strikeout(bool b) { return b ? Strikeout() : NoStrikeout(); } + Font& NonAntiAliased() { v.flags |= 0x800; return *this; } + Font& NoNonAntiAliased() { v.flags &= ~0x800; return *this; } + Font& NonAntiAliased(bool b) { return b ? NonAntiAliased() : NoNonAntiAliased(); } + Font& TrueTypeOnly() { v.flags |= 0x400; return *this; } + Font& NoTrueTypeOnly() { v.flags &= ~0x400; return *this; } + Font& TrueTypeOnly(bool b) { return b ? TrueTypeOnly() : NoTrueTypeOnly(); } + Font& FaceName(const String& name); + + Font operator()() const { return *this; } + Font operator()(int n) const { return Font(*this).Height(n); } + + + int GetAscent() const { return Fi().ascent; } + int GetDescent() const { return Fi().descent; } + int GetCy() const { return Fi().height; } + int GetExternal() const { return Fi().external; } + int GetInternal() const { return Fi().internal; } + int GetLineHeight() const { return Fi().lineheight; } + int GetOverhang() const { return Fi().overhang; } + int GetAveWidth() const { return Fi().avewidth; } + int GetMaxWidth() const { return Fi().maxwidth; } + bool IsNormal(int ch) const; + bool IsComposed(int ch) const; + bool IsReplaced(int ch) const; + bool IsMissing(int ch) const; + int HasChar(int ch) const; + int GetWidth(int c) const; + int operator[](int c) const { return GetWidth(c); } + int GetLeftSpace(int c) const; + int GetRightSpace(int c) const; + bool IsFixedPitch() const { return Fi().fixedpitch; } + bool IsScaleable() const { return Fi().scaleable; } + bool IsSpecial() const { return !(GetFaceInfo() & SPECIAL); } + +#ifdef PLATFORM_POSIX + String GetPath() const { return Fi().path; } +#endif + + void Serialize(Stream& s); + + bool operator==(Font f) const { return v.face == f.v.face && v.flags == f.v.flags && + v.width == f.v.width && v.height == f.v.height; } + bool operator!=(Font f) const { return !operator==(f); } + + dword GetHashValue() const { return CombineHash(v.width, v.flags, v.height, v.face); } + bool IsNull() const { return v.face == 0xffff; } + + Font() { v.height = v.width = 0; v.face = v.flags = 0; } + Font(int face, int height) { v.face = face; v.height = height; v.flags = 0; v.width = 0; } + Font(const Nuller&) { v.face = 0xffff; v.height = v.width = 0; v.flags = 0; } + + operator Value() const { return RichValue(*this); } + Font(const Value& q) { *this = RichValue::Extract(q); } + +// BW compatibility + FontInfo Info() const; +}; + +//BW compatibility +class FontInfo { + Font font; + friend class Font; +public: + int GetAscent() const { return font.GetAscent(); } + int GetDescent() const { return font.GetDescent(); } + int GetExternal() const { return font.GetExternal(); } + int GetInternal() const { return font.GetInternal(); } + int GetHeight() const { return font.GetCy(); } + int GetLineHeight() const { return font.GetLineHeight(); } + int GetOverhang() const { return font.GetOverhang(); } + int GetAveWidth() const { return font.GetAveWidth(); } + int GetMaxWidth() const { return font.GetMaxWidth(); } + int HasChar(int c) const { return font.HasChar(c); } + int GetWidth(int c) const { return font.GetWidth(c); } + int operator[](int c) const { return GetWidth(c); } + int GetLeftSpace(int c) const { return font.GetLeftSpace(c); } + int GetRightSpace(int c) const { return font.GetRightSpace(c); } + bool IsFixedPitch() const { return font.IsFixedPitch(); } + bool IsScaleable() const { return font.IsScaleable(); } + int GetFontHeight() const { return font.GetHeight(); } + Font GetFont() const { return font; } +#ifdef PLATFORM_POSIX + String GetFileName() const { return font.GetPath(); } +#endif +}; + +struct ComposedGlyph { + wchar basic_char; + Point mark_pos; + wchar mark_char; + Font mark_font; +}; + +bool Compose(Font fnt, int chr, ComposedGlyph& cs); + +template<> +inline bool IsNull(const Font& f) { return f.IsNull(); } + +template<> +inline unsigned GetHashValue(const Font& f) { return f.GetHashValue(); } + +template<> +String AsString(const Font& f); + +inline void SetStdFont(Font font) { Font::SetStdFont(font); } +inline Font GetStdFont() { return Font::GetStdFont(); } +inline Size GetStdFontSize() { return Font::GetStdFontSize(); } +inline int GetStdFontCy() { return GetStdFontSize().cy; } + +Font StdFont(); + +inline Font StdFont(int h) { return StdFont().Height(h); } + + +/* +struct ScreenSans : public Font { ScreenSans(int n = 0) : Font(SCREEN_SANS, n) {} }; +struct ScreenSerif : public Font { ScreenSerif(int n = 0) : Font(SCREEN_SERIF, n) {} }; +struct ScreenFixed : public Font { ScreenFixed(int n = 0) : Font(SCREEN_FIXED, n) {} }; + +struct Roman : public Font { Roman(int n) : Font(ROMAN, n) {} }; +struct Arial : public Font { Arial(int n) : Font(ARIAL, n) {} }; +struct Courier : public Font { Courier(int n) : Font(COURIER, n) {} }; + +#ifdef PLATFORM_WIN32 +struct Symbol : public Font { Symbol(int n) : Font(SYMBOL, n) {} }; +struct WingDings : public Font { WingDings(int n) : Font(WINGDINGS, n) {} }; +struct Tahoma : public Font { Tahoma(int n) : Font(TAHOMA, n) {} }; +#endif +*/ + +inline Font Serif(int n = 0) { return Font(Font::SCREEN_SERIF, n); } +inline Font SansSerif(int n = 0) { return Font(Font::SCREEN_SANS, n); } +inline Font Monospace(int n = 0) { return Font(Font::SCREEN_FIXED, n); } + +inline Font Roman(int n = 0) { return Font(Font::SCREEN_SERIF, n); } +inline Font Arial(int n = 0) { return Font(Font::SCREEN_SANS, n); } +inline Font Courier(int n = 0) { return Font(Font::SCREEN_FIXED, n); } + +inline Font ScreenSerif(int n = 0) { return Font(Font::SCREEN_SERIF, n); } +inline Font ScreenSans(int n = 0) { return Font(Font::SCREEN_SANS, n); } +inline Font ScreenFixed(int n = 0) { return Font(Font::SCREEN_FIXED, n); } + +#ifdef PLATFORM_WIN32 // backward comaptibility +inline Font Tahoma(int n = 0) { return Font(Font::TAHOMA, n); } +#endif + +Size GetTextSize(const wchar *text, Font font, int n = -1); +Size GetTextSize(const WString& text, Font font); +Size GetTextSize(const char *text, byte charset, Font font, int n = -1); +Size GetTextSize(const char *text, Font font, int n = -1); +Size GetTextSize(const String& text, Font font); + +enum { + PEN_NULL = -1, + PEN_SOLID = -2, + PEN_DASH = -3, +#ifndef PLATFORM_WINCE + PEN_DOT = -4, + PEN_DASHDOT = -5, + PEN_DASHDOTDOT = -6, +#endif +}; + +class Image; + +//DEPRECATED: TODO +Color SBlack(); +Color SGray(); +Color SLtGray(); +Color SWhiteGray(); +Color SWhite(); +Color SRed(); +Color SGreen(); +Color SBrown(); +Color SBlue(); +Color SMagenta(); +Color SCyan(); +Color SYellow(); +Color SLtRed(); +Color SLtGreen(); +Color SLtYellow(); +Color SLtBlue(); +Color SLtMagenta(); +Color SLtCyan(); +//END OF DEPRECATED + +Color SColorPaper(); +Color SColorText(); +Color SColorHighlight(); +Color SColorHighlightText();// +Color SColorMenu(); +Color SColorMenuText(); +Color SColorInfo(); +Color SColorInfoText();// +Color SColorMark(); +Color SColorMenuMark(); +Color SColorDisabled(); +Color SColorLight(); +Color SColorFace(); +Color SColorLabel(); +Color SColorShadow(); + +Color SColorLtFace(); +Color SColorDkShadow(); + + +void SBlack_Write(Color c); +void SGray_Write(Color c); +void SLtGray_Write(Color c); +void SWhiteGray_Write(Color c); +void SWhite_Write(Color c); +void SRed_Write(Color c); +void SGreen_Write(Color c); +void SBrown_Write(Color c); +void SBlue_Write(Color c); +void SMagenta_Write(Color c); +void SCyan_Write(Color c); +void SYellow_Write(Color c); +void SLtRed_Write(Color c); +void SLtGreen_Write(Color c); +void SLtYellow_Write(Color c); +void SLtBlue_Write(Color c); +void SLtMagenta_Write(Color c); +void SLtCyan_Write(Color c); + +void SColorPaper_Write(Color c); +void SColorText_Write(Color c); +void SColorHighlight_Write(Color c); +void SColorHighlightText_Write(Color c);// +void SColorMenu_Write(Color c); +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); +void SColorLabel_Write(Color c); +void SColorShadow_Write(Color c); + +void SColorLtFace_Write(Color c); +void SColorDkShadow_Write(Color c); + + +inline Color InvertColor() { return Color(255, 0); } +inline Color DefaultInk() { return Black(); } //TODO! + +class Painting : AssignValueTypeNo > { + String cmd; + ValueArray data; + Sizef size; + + friend class PaintingPainter; + friend class Painter; + +public: + Sizef GetSize() const { return size; } + + void Clear() { size = Null; data.Clear(); cmd.Clear(); } + void Serialize(Stream& s) { s % cmd % data % size; } + bool IsNullInstance() const { return cmd.IsEmpty(); } + bool operator==(const Painting& b) const { return cmd == b.cmd && data == b.data && size == b.size; } + unsigned GetHashValue() const { return CombineHash(cmd, data); } + String ToString() const { return "painting " + AsString(size); } + + operator Value() const { return RichValue(*this); } + Painting(const Value& q) { *this = RichValue::Extract(q); } + + Painting() { size = Null; } + Painting(const Nuller&) { size = Null; } +}; + +enum { + MODE_ANTIALIASED = 0, + MODE_NOAA = 1, + MODE_SUBPIXEL = 2, +}; + +bool HasPainter(); +void PaintImageBuffer(ImageBuffer& ib, const Painting& p, Size sz, Point pos, int mode = MODE_ANTIALIASED); +void PaintImageBuffer(ImageBuffer& ib, const Painting& p, int mode = MODE_ANTIALIASED); +void PaintImageBuffer(ImageBuffer& ib, const Drawing& p, int mode = MODE_ANTIALIASED); + +class Draw : NoCopy { +private: + struct DrawingPos; + +public: + enum { + DOTS = 0x001, + GUI = 0x002, + PRINTER = 0x004, + NATIVE = 0x008, + DATABANDS = 0x010, + }; + + virtual dword GetInfo() const = 0; + + virtual Size GetPageSize() const; + virtual void StartPage(); + virtual void EndPage(); + + virtual void BeginOp() = 0; + virtual void EndOp() = 0; + virtual void OffsetOp(Point p) = 0; + virtual bool ClipOp(const Rect& r) = 0; + virtual bool ClipoffOp(const Rect& r) = 0; + virtual bool ExcludeClipOp(const Rect& r) = 0; + virtual bool IntersectClipOp(const Rect& r) = 0; + virtual bool IsPaintingOp(const Rect& r) const = 0; + virtual Rect GetPaintRect() const; + + virtual void DrawRectOp(int x, int y, int cx, int cy, Color color) = 0; + virtual void DrawImageOp(int x, int y, int cx, int cy, const Image& img, const Rect& src, Color color) = 0; + virtual void DrawDataOp(int x, int y, int cx, int cy, const String& data, const char *id); + virtual void DrawLineOp(int x1, int y1, int x2, int y2, int width, Color color) = 0; + + virtual void DrawPolyPolylineOp(const Point *vertices, int vertex_count, + const int *counts, int count_count, + int width, Color color, Color doxor) = 0; + virtual void DrawPolyPolyPolygonOp(const Point *vertices, int vertex_count, + const int *subpolygon_counts, int scc, + const int *disjunct_polygon_counts, int dpcc, + Color color, int width, Color outline, + uint64 pattern, Color doxor) = 0; + virtual void DrawArcOp(const Rect& rc, Point start, Point end, int width, Color color) = 0; + + virtual void DrawEllipseOp(const Rect& r, Color color, int pen, Color pencolor) = 0; + virtual void DrawTextOp(int x, int y, int angle, const wchar *text, Font font, + Color ink, int n, const int *dx) = 0; + virtual void DrawDrawingOp(const Rect& target, const Drawing& w); + virtual void DrawPaintingOp(const Rect& target, const Painting& w); + + virtual Size GetNativeDpi() const; + virtual void BeginNative(); + virtual void EndNative(); + + virtual int GetCloffLevel() const; + + virtual ~Draw(); + +// -------------- + Size GetPixelsPerInch() const; + Size GetPageMMs() const; + + bool Dots() const { return GetInfo() & DOTS; } + bool Pixels() const { return !Dots(); } + bool IsGui() const { return GetInfo() & GUI; } + bool IsPrinter() const { return GetInfo() & PRINTER; } + bool IsNative() const { return GetInfo() & NATIVE; } + + int GetNativeX(int x) const; + int GetNativeY(int y) const; + void Native(int& x, int& y) const; + void Native(Point& p) const; + void Native(Size& sz) const; + void Native(Rect& r) const; + + void Begin() { BeginOp(); } + void End() { EndOp(); } + void Offset(Point p) { OffsetOp(p); } + void Offset(int x, int y); + bool Clip(const Rect& r) { return ClipOp(r); } + bool Clip(int x, int y, int cx, int cy); + bool Clipoff(const Rect& r) { return ClipoffOp(r); } + bool Clipoff(int x, int y, int cx, int cy); + bool ExcludeClip(const Rect& r) { return ExcludeClipOp(r); } + bool ExcludeClip(int x, int y, int cx, int cy); + bool IntersectClip(const Rect& r) { return IntersectClipOp(r); } + bool IntersectClip(int x, int y, int cx, int cy); + bool IsPainting(const Rect& r) const { return IsPaintingOp(r); } + bool IsPainting(int x, int y, int cx, int cy) const; + + void DrawRect(int x, int y, int cx, int cy, Color color); + void DrawRect(const Rect& rect, Color color); + + void DrawImage(int x, int y, int cx, int cy, const Image& img, const Rect& src); + void DrawImage(int x, int y, int cx, int cy, const Image& img); + void DrawImage(int x, int y, int cx, int cy, const Image& img, const Rect& src, Color color); + void DrawImage(int x, int y, int cx, int cy, const Image& img, Color color); + + void DrawImage(const Rect& r, const Image& img, const Rect& src); + void DrawImage(const Rect& r, const Image& img); + void DrawImage(const Rect& r, const Image& img, const Rect& src, Color color); + void DrawImage(const Rect& r, const Image& img, Color color); + + void DrawImage(int x, int y, const Image& img, const Rect& src); + void DrawImage(int x, int y, const Image& img); + void DrawImage(int x, int y, const Image& img, const Rect& src, Color color); + void DrawImage(int x, int y, const Image& img, Color color); + + void DrawData(int x, int y, int cx, int cy, const String& data, const char *type); + void DrawData(const Rect& r, const String& data, const char *type); + + void DrawLine(int x1, int y1, int x2, int y2, int width = 0, Color color = DefaultInk); + void DrawLine(Point p1, Point p2, int width = 0, Color color = DefaultInk); + + void DrawEllipse(const Rect& r, Color color = DefaultInk, + int pen = Null, Color pencolor = DefaultInk); + void DrawEllipse(int x, int y, int cx, int cy, Color color = DefaultInk, + int pen = Null, Color pencolor = DefaultInk); + + void DrawArc(const Rect& rc, Point start, Point end, int width = 0, Color color = DefaultInk); + + void DrawPolyPolyline(const Point *vertices, int vertex_count, + const int *counts, int count_count, + int width = 0, Color color = DefaultInk, Color doxor = Null); + void DrawPolyPolyline(const Vector& vertices, const Vector& counts, + int width = 0, Color color = DefaultInk, Color doxor = Null); + void DrawPolyline(const Point *vertices, int count, + int width = 0, Color color = DefaultInk, Color doxor = Null); + void DrawPolyline(const Vector& vertices, + int width = 0, Color color = DefaultInk, Color doxor = Null); + + void DrawPolyPolyPolygon(const Point *vertices, int vertex_count, + const int *subpolygon_counts, int subpolygon_count_count, + const int *disjunct_polygon_counts, int disjunct_polygon_count_count, + Color color = DefaultInk, int width = 0, Color outline = Null, + uint64 pattern = 0, Color doxor = Null); + void DrawPolyPolyPolygon(const Vector& vertices, + const Vector& subpolygon_counts, + const Vector& disjunct_polygon_counts, + Color color = DefaultInk, int width = 0, Color outline = Null, uint64 pattern = 0, Color doxor = Null); + void DrawPolyPolygon(const Point *vertices, int vertex_count, + const int *subpolygon_counts, int subpolygon_count_count, + Color color = DefaultInk, int width = 0, Color outline = Null, uint64 pattern = 0, Color doxor = Null); + void DrawPolyPolygon(const Vector& vertices, const Vector& subpolygon_counts, + Color color = DefaultInk, int width = 0, Color outline = Null, uint64 pattern = 0, Color doxor = Null); + void DrawPolygons(const Point *vertices, int vertex_count, + const int *polygon_counts, int polygon_count_count, + Color color = DefaultInk, int width = 0, Color outline = Null, uint64 pattern = 0, Color doxor = Null); + void DrawPolygons(const Vector& vertices, const Vector& polygon_counts, + Color color = DefaultInk, int width = 0, Color outline = Null, uint64 pattern = 0, Color doxor = Null); + void DrawPolygon(const Point *vertices, int vertex_count, + Color color = DefaultInk, int width = 0, Color outline = Null, uint64 pattern = 0, Color doxor = Null); + void DrawPolygon(const Vector& vertices, + Color color = DefaultInk, int width = 0, Color outline = Null, uint64 pattern = 0, Color doxor = Null); + + void DrawDrawing(const Rect& r, const Drawing& iw) { DrawDrawingOp(r, iw); } + void DrawDrawing(int x, int y, int cx, int cy, const Drawing& iw); + + void DrawPainting(const Rect& r, const Painting& iw) { DrawPaintingOp(r, iw); } + void DrawPainting(int x, int y, int cx, int cy, const Painting& iw); + + void DrawText(int x, int y, int angle, const wchar *text, Font font = StdFont(), + Color ink = DefaultInk, int n = -1, const int *dx = NULL); + void DrawText(int x, int y, const wchar *text, Font font = StdFont(), + Color ink = DefaultInk, int n = -1, const int *dx = NULL); + + void DrawText(int x, int y, const WString& text, Font font = StdFont(), + Color ink = DefaultInk, const int *dx = NULL); + void DrawText(int x, int y, int angle, const WString& text, Font font = StdFont(), + Color ink = DefaultInk, const int *dx = NULL); + + void DrawText(int x, int y, int angle, const char *text, byte charset, + Font font = StdFont(), Color ink = DefaultInk, int n = -1, const int *dx = NULL); + void DrawText(int x, int y, const char *text, byte charset, Font font = StdFont(), + Color ink = DefaultInk, int n = -1, const int *dx = NULL); + + void DrawText(int x, int y, int angle, const char *text, + Font font = StdFont(), Color ink = DefaultInk, int n = -1, const int *dx = NULL); + void DrawText(int x, int y, const char *text, Font font = StdFont(), + Color ink = DefaultInk, int n = -1, const int *dx = NULL); + + void DrawText(int x, int y, const String& text, Font font = StdFont(), + Color ink = DefaultInk, const int *dx = NULL); + void DrawText(int x, int y, int angle, const String& text, Font font = StdFont(), + Color ink = DefaultInk, const int *dx = NULL); + + static void SinCos(int angle, double& sina, double& cosa); + + // deprecated: + static void SetStdFont(Font font) { UPP::SetStdFont(font); } + static Font GetStdFont() { return UPP::GetStdFont(); } + static Size GetStdFontSize() { return UPP::GetStdFontSize(); } + static int GetStdFontCy() { return GetStdFontSize().cy; } + Size GetPagePixels() const { return GetPageSize(); } + + +#ifdef PLATFORM_WIN32_ + static void Flush(); + HDC BeginGdi(); + void EndGdi(); +#endif +}; + +void DrawImageBandRLE(Draw& w, int x, int y, const Image& m, int minp); + +class DataDrawer { + typedef DataDrawer *(*Factory)(); + template static DataDrawer *FactoryFn() { return new T; } + static void AddFormat(const char *id, Factory f); + static VectorMap& Map(); + +public: + virtual void Open(const String& data, int cx, int cy) = 0; + virtual void Render(ImageBuffer& ib) = 0; + virtual ~DataDrawer(); + + static One Create(const String& id); + + template static void Register(const char *id) { AddFormat(id, &DataDrawer::FactoryFn); } +}; + +class Drawing : AssignValueTypeNo > { + Size size; + String data; + ValueArray val; + + friend class DrawingDraw; + friend class Draw; + +public: + operator bool() const { return !data.IsEmpty(); } + Size GetSize() const { return size; } + void SetSize(Size sz) { size = sz; } + void SetSize(int cx, int cy) { size = Size(cx, cy); } + + Size RatioSize(int cx, int cy) const; + Size RatioSize(Size sz) const { return RatioSize(sz.cx, sz.cy); } + + void Clear() { data.Clear(); size = Null; } + + void Append(Drawing& dw); + + void Serialize(Stream& s); + + bool IsNullInstance() const { return data.IsEmpty(); } + bool operator==(const Drawing& b) const { return val == b.val && data == b.data && size == b.size; } + String ToString() const { return "drawing " + AsString(size); } + unsigned GetHashValue() const { return CombineHash(data, val); } + + operator Value() const { return RichValue(*this); } + Drawing(const Value& src); + + Drawing() { size = Null; } + Drawing(const Nuller&) { size = Null; } +}; + +class DrawingDraw : public Draw { +public: + virtual dword GetInfo() const; + virtual Size GetPageSize() const; + virtual Rect GetPaintRect() const; + + virtual void BeginOp(); + virtual void EndOp(); + virtual void OffsetOp(Point p); + virtual bool ClipOp(const Rect& r); + virtual bool ClipoffOp(const Rect& r); + virtual bool ExcludeClipOp(const Rect& r); + virtual bool IntersectClipOp(const Rect& r); + virtual bool IsPaintingOp(const Rect& r) const; + + virtual void DrawRectOp(int x, int y, int cx, int cy, Color color); + virtual void DrawImageOp(int x, int y, int cx, int cy, const Image& img, const Rect& src, Color color); + virtual void DrawDataOp(int x, int y, int cx, int cy, const String& data, const char *id); + virtual void DrawLineOp(int x1, int y1, int x2, int y2, int width, Color color); + virtual void DrawPolyPolylineOp(const Point *vertices, int vertex_count, + const int *counts, int count_count, + int width, Color color, Color doxor); + virtual void DrawPolyPolyPolygonOp(const Point *vertices, int vertex_count, + const int *subpolygon_counts, int scc, + const int *disjunct_polygon_counts, int dpcc, + Color color, int width, Color outline, + uint64 pattern, Color doxor); + virtual void DrawEllipseOp(const Rect& r, Color color, int pen, Color pencolor); + virtual void DrawArcOp(const Rect& rc, Point start, Point end, int pen, Color pencolor); + virtual void DrawTextOp(int x, int y, int angle, const wchar *text, Font font, + Color ink, int n, const int *dx); + + virtual void DrawDrawingOp(const Rect& target, const Drawing& w); + virtual void DrawPaintingOp(const Rect& target, const Painting& w); + +private: + Size size; + bool dots; + StringStream drawing; + ValueArray val; + + Stream& DrawingOp(int code); + +public: + void Create(int cx, int cy, bool dots = true); + void Create(Size sz, bool dots = true); + + Size GetSize() const { return size; } + + Drawing GetResult(); + operator Drawing() { return GetResult(); } + + DrawingDraw(); + DrawingDraw(int cx, int cy, bool dots = true); + DrawingDraw(Size sz, bool dots = true); +}; + +class NilDraw : public Draw { +public: + virtual dword GetInfo() const; + virtual Size GetPageSize() const; + virtual void BeginOp(); + virtual void EndOp(); + virtual void OffsetOp(Point p); + virtual bool ClipOp(const Rect& r); + virtual bool ClipoffOp(const Rect& r); + virtual bool ExcludeClipOp(const Rect& r); + virtual bool IntersectClipOp(const Rect& r); + virtual bool IsPaintingOp(const Rect& r) const; + virtual Rect GetPaintRect() const; + + virtual void DrawRectOp(int x, int y, int cx, int cy, Color color); + virtual void DrawImageOp(int x, int y, int cx, int cy, const Image& img, const Rect& src, Color color); + virtual void DrawDataOp(int x, int y, int cx, int cy, const String& data, const char *id); + virtual void DrawLineOp(int x1, int y1, int x2, int y2, int width, Color color); + virtual void DrawPolyPolylineOp(const Point *vertices, int vertex_count, + const int *counts, int count_count, + int width, Color color, Color doxor); + virtual void DrawPolyPolyPolygonOp(const Point *vertices, int vertex_count, + const int *subpolygon_counts, int scc, + const int *disjunct_polygon_counts, int dpcc, + Color color, int width, Color outline, + uint64 pattern, Color doxor); + virtual void DrawArcOp(const Rect& rc, Point start, Point end, int width, Color color); + virtual void DrawEllipseOp(const Rect& r, Color color, int pen, Color pencolor); + virtual void DrawTextOp(int x, int y, int angle, const wchar *text, Font font, + Color ink, int n, const int *dx); + virtual void DrawDrawingOp(const Rect& target, const Drawing& w); + virtual void DrawPaintingOp(const Rect& target, const Painting& w); +}; + +class ImageAnyDraw : public Draw { + Draw *draw; + + void Init(Size sz); + +public: + virtual dword GetInfo() const; + virtual Size GetPageSize() const; + virtual void BeginOp(); + virtual void EndOp(); + virtual void OffsetOp(Point p); + virtual bool ClipOp(const Rect& r); + virtual bool ClipoffOp(const Rect& r); + virtual bool ExcludeClipOp(const Rect& r); + virtual bool IntersectClipOp(const Rect& r); + virtual bool IsPaintingOp(const Rect& r) const; + virtual Rect GetPaintRect() const; + + virtual void DrawRectOp(int x, int y, int cx, int cy, Color color); + virtual void DrawImageOp(int x, int y, int cx, int cy, const Image& img, const Rect& src, Color color); + virtual void DrawDataOp(int x, int y, int cx, int cy, const String& data, const char *id); + virtual void DrawLineOp(int x1, int y1, int x2, int y2, int width, Color color); + virtual void DrawPolyPolylineOp(const Point *vertices, int vertex_count, + const int *counts, int count_count, + int width, Color color, Color doxor); + virtual void DrawPolyPolyPolygonOp(const Point *vertices, int vertex_count, + const int *subpolygon_counts, int scc, + const int *disjunct_polygon_counts, int dpcc, + Color color, int width, Color outline, + uint64 pattern, Color doxor); + virtual void DrawArcOp(const Rect& rc, Point start, Point end, int width, Color color); + virtual void DrawEllipseOp(const Rect& r, Color color, int pen, Color pencolor); + virtual void DrawTextOp(int x, int y, int angle, const wchar *text, Font font, + Color ink, int n, const int *dx); + virtual void DrawDrawingOp(const Rect& target, const Drawing& w); + virtual void DrawPaintingOp(const Rect& target, const Painting& w); + +public: + operator Image() const; + + ImageAnyDraw(Size sz); + ImageAnyDraw(int cx, int cy); + + ~ImageAnyDraw(); +}; + +void AddNotEmpty(Vector& result, int left, int right, int top, int bottom); +bool Subtract(const Rect& r, const Rect& sub, Vector& result); +bool Subtract(const Vector& rr, const Rect& sub, Vector& result); +Vector Subtract(const Vector& rr, const Rect& sub, bool& changed); +Vector Intersect(const Vector& b, const Rect& a, bool& changed); + +void Subtract(Vector& rr, const Rect& sub); +void Union(Vector& rr, const Rect& add); + +void DrawRect(Draw& w, const Rect& rect, const Image& img, bool ralgn = false); //??? TODO +void DrawRect(Draw& w, int x, int y, int cx, int cy, const Image& img, bool ra = false); + +void DrawTiles(Draw& w, int x, int y, int cx, int cy, const Image& img); +void DrawTiles(Draw& w, const Rect& rect, const Image& img); + +void DrawFatFrame(Draw& w, int x, int y, int cx, int cy, Color color, int n); +void DrawFatFrame(Draw& w, const Rect& r, Color color, int n); + +void DrawFrame(Draw& w, int x, int y, int cx, int cy, + Color leftcolor, Color topcolor, Color rightcolor, Color bottomcolor); +void DrawFrame(Draw& w, const Rect& r, + Color leftcolor, Color topcolor, Color rightcolor, Color bottomcolor); +void DrawFrame(Draw& w, int x, int y, int cx, int cy, + Color topleftcolor, Color bottomrightcolor); +void DrawFrame(Draw& w, const Rect& r, + Color topleftcolor, Color bottomrightcolor); +void DrawFrame(Draw& w, int x, int y, int cx, int cy, Color color); +void DrawFrame(Draw& w, const Rect& r, Color color); + +void DrawBorder(Draw& w, int x, int y, int cx, int cy, const ColorF *colors_ltrd); //TODO +void DrawBorder(Draw& w, const Rect& r, const ColorF *colors_ltrd); + +const ColorF *BlackBorder(); +const ColorF *ButtonPushBorder(); +const ColorF *EdgeButtonBorder(); +const ColorF *DefButtonBorder(); +const ColorF *ButtonBorder(); +const ColorF *InsetBorder(); +const ColorF *OutsetBorder(); +const ColorF *ThinOutsetBorder(); +const ColorF *ThinInsetBorder(); + +void DrawBorder(Draw& w, int x, int y, int cx, int cy, const ColorF *(*colors_ltrd)()); +void DrawBorder(Draw& w, const Rect& r, const ColorF *(*colors_ltrd)()); + +void DrawRectMinusRect(Draw& w, const Rect& rect, const Rect& inner, Color color); + +void DrawHighlightImage(Draw& w, int x, int y, const Image& img, bool highlight = true, + bool enabled = true, Color maskcolor = SColorPaper); + +Color GradientColor(Color fc, Color tc, int i, int n); + +enum { + BUTTON_NORMAL, BUTTON_OK, BUTTON_HIGHLIGHT, BUTTON_PUSH, BUTTON_DISABLED, BUTTON_CHECKED, + BUTTON_VERTICAL = 0x100, + BUTTON_EDGE = 0x200, + BUTTON_TOOL = 0x400, + BUTTON_SCROLL = 0x800, +}; + +void DrawXPButton(Draw& w, Rect r, int type); + +void DrawTextEllipsis(Draw& w, int x, int y, int cx, const char *text, const char *ellipsis, + Font font = StdFont(), Color ink = SColorText(), int n = -1); +void DrawTextEllipsis(Draw& w, int x, int y, int cx, const wchar *text, const char *ellipsis, + Font font = StdFont(), Color ink = SColorText(), int n = -1); +Size GetTLTextSize(const wchar *text, Font font = StdFont()); +int GetTLTextHeight(const wchar *s, Font font = StdFont()); +void DrawTLText(Draw& draw, int x, int y, int cx, const wchar *text, Font font = StdFont(), + Color ink = SColorText(), int accesskey = 0); + + +typedef String (*DrawingToPdfFnType)(const Array& report, Size pagesize, int margin); + +void SetDrawingToPdfFn(DrawingToPdfFnType Pdf); +DrawingToPdfFnType GetDrawingToPdfFn(); + +#include "Display.h" +#include "Cham.h" + +END_UPP_NAMESPACE + +#endif diff --git a/uppsrc/Draw/SSettings.cpp b/uppsrc/Draw/SSettings.cpp index 618ee5b55..6322bd639 100644 --- a/uppsrc/Draw/SSettings.cpp +++ b/uppsrc/Draw/SSettings.cpp @@ -1,42 +1,43 @@ -#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(SColorLtFace, Blend(SColorFace, SColorLight)); -CH_COLOR(SColorDkShadow, Blend(SColorShadow, SColorText)); -CH_COLOR(SColorLabel, SColorText()); - -END_UPP_NAMESPACE +#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, IsDark(SColorPaper()) ? LtYellow() : LtBlue()); +CH_COLOR(SColorMenuMark, IsDark(SColorMenu()) ? LtYellow() : LtBlue()); + +CH_COLOR(SColorLtFace, Blend(SColorFace, SColorLight)); +CH_COLOR(SColorDkShadow, Blend(SColorShadow, SColorText)); +CH_COLOR(SColorLabel, SColorText()); + +END_UPP_NAMESPACE diff --git a/uppsrc/plugin/ndisasm/lib/inttypes.h b/uppsrc/plugin/ndisasm/lib/inttypes.h index 22f036898..e353aa93c 100644 --- a/uppsrc/plugin/ndisasm/lib/inttypes.h +++ b/uppsrc/plugin/ndisasm/lib/inttypes.h @@ -1,201 +1,201 @@ -/* - * inttypes.h - * - * Small ersatz subset of , deriving the types from - * . - * - * Important: the preprocessor may truncate numbers too large for it. - * Therefore, test the signed types only ... truncation won't generate - * a 01111111... bit pattern. - */ - -#ifndef INTTYPES_H -#define INTTYPES_H - -#include - -/*** 64-bit type: long or long long ***/ - -/* Some old versions of gcc omit LLONG_MAX */ -#ifndef LLONG_MAX -# ifdef __LONG_LONG_MAX__ -# define LLONG_MAX __LONG_LONG_MAX__ -# else -# define LLONG_MAX 0 /* Assume long long is unusable */ -# endif -#endif - -#if LONG_MAX == 9223372036854775807L - -/* long is 64 bits */ -typedef signed long int64_t; -typedef unsigned long uint64_t; -#define _scn64 "l" -#define _pri64 "l" -#define INT64_C(x) x ## L -#define UINT64_C(x) x ## UL - -#elif LLONG_MAX == 9223372036854775807LL - -/* long long is 64 bits */ -typedef signed long long int64_t; -typedef unsigned long long uint64_t; -#define _scn64 "ll" -#define _pri64 "ll" -#define INT64_C(x) x ## LL -#define UINT64_C(x) x ## ULL - -#else - -#error "Neither long nor long long is 64 bits in size" - -#endif - -/*** 32-bit type: int or long ***/ - -#if INT_MAX == 2147483647 - -/* int is 32 bits */ -typedef signed int int32_t; -typedef unsigned int uint32_t; -#define _scn32 "" -#define _pri32 "" -#define INT32_C(x) x -#define UINT32_C(x) x ## U - -#elif LONG_MAX == 2147483647L - -/* long is 32 bits */ -typedef signed long int32_t; -typedef unsigned long uint32_t; -#define _scn32 "l" -#define _pri32 "l" -#define INT32_C(x) x ## L -#define UINT32_C(x) x ## UL - -#else - -#error "Neither int nor long is 32 bits in size" - -#endif - -/*** 16-bit size: int or short ***/ - -#if INT_MAX == 32767 - -/* int is 16 bits */ -typedef signed int int16_t; -typedef unsigned int uint16_t; -#define _scn16 "" -#define _pri16 "" -#define INT16_C(x) x -#define UINT16_C(x) x ## U - -#elif SHRT_MAX == 32767 - -/* short is 16 bits */ -typedef signed short int16_t; -typedef unsigned short uint16_t; -#define _scn16 "h" -#define _pri16 "" -#define INT16_C(x) x -#define UINT16_C(x) x ## U - -#else - -#error "Neither short nor int is 16 bits in size" - -#endif - -/*** 8-bit size: char ***/ - -#if SCHAR_MAX == 127 - -/* char is 8 bits */ -typedef signed char int8_t; -typedef unsigned char uint8_t; -#define _scn8 "hh" -#define _pri8 "" -#define INT8_C(x) x -#define UINT8_C(x) x ## U - -#else - -#error "char is not 8 bits in size" - -#endif - -/* The rest of this is common to all models */ - -#define PRId8 _pri8 "d" -#define PRId16 _pri16 "d" -#define PRId32 _pri32 "d" -#define PRId64 _pri64 "d" - -#define PRIi8 _pri8 "i" -#define PRIi16 _pri16 "i" -#define PRIi32 _pri32 "i" -#define PRIi64 _pri64 "i" - -#define PRIo8 _pri8 "o" -#define PRIo16 _pri16 "o" -#define PRIo32 _pri32 "o" -#define PRIo64 _pri64 "o" - -#define PRIu8 _pri8 "u" -#define PRIu16 _pri16 "u" -#define PRIu32 _pri32 "u" -#define PRIu64 _pri64 "u" - -#define PRIx8 _pri8 "x" -#define PRIx16 _pri16 "x" -#define PRIx32 _pri32 "x" -#define PRIx64 _pri64 "x" - -#define PRIX8 _pri8 "X" -#define PRIX16 _pri16 "X" -#define PRIX32 _pri32 "X" -#define PRIX64 _pri64 "X" - -#define SCNd8 _scn8 "d" -#define SCNd16 _scn16 "d" -#define SCNd32 _scn32 "d" -#define SCNd64 _scn64 "d" - -#define SCNi8 _scn8 "i" -#define SCNi16 _scn16 "i" -#define SCNi32 _scn32 "i" -#define SCNi64 _scn64 "i" - -#define SCNo8 _scn8 "o" -#define SCNo16 _scn16 "o" -#define SCNo32 _scn32 "o" -#define SCNo64 _scn64 "o" - -#define SCNu8 _scn8 "u" -#define SCNu16 _scn16 "u" -#define SCNu32 _scn32 "u" -#define SCNu64 _scn64 "u" - -#define SCNx8 _scn8 "x" -#define SCNx16 _scn16 "x" -#define SCNx32 _scn32 "x" -#define SCNx64 _scn64 "x" - -#define INT8_MIN INT8_C(-128) -#define INT8_MAX INT8_C(127) -#define UINT8_MAX UINT8_C(255) - -#define INT16_MIN INT16_C(-32768) -#define INT16_MAX INT16_C(32767) -#define UINT16_MAX UINT16_C(65535) - -#define INT32_MIN INT32_C(-2147483648) -#define INT32_MAX INT32_C(2147483647) -#define UINT32_MAX UINT32_C(4294967295) - -#define INT64_MIN INT64_C(-9223372036854775808) -#define INT64_MAX INT64_C(9223372036854775807) -#define UINT64_MAX UINT64_C(18446744073709551615) - -#endif /* INTTYPES_H */ +/* + * inttypes.h + * + * Small ersatz subset of , deriving the types from + * . + * + * Important: the preprocessor may truncate numbers too large for it. + * Therefore, test the signed types only ... truncation won't generate + * a 01111111... bit pattern. + */ + +#ifndef INTTYPES_H +#define INTTYPES_H + +#include + +/*** 64-bit type: long or long long ***/ + +/* Some old versions of gcc omit LLONG_MAX */ +#ifndef LLONG_MAX +# ifdef __LONG_LONG_MAX__ +# define LLONG_MAX __LONG_LONG_MAX__ +# else +# define LLONG_MAX 0 /* Assume long long is unusable */ +# endif +#endif + +#if LONG_MAX == 9223372036854775807L + +/* long is 64 bits */ +typedef signed long int64_t; +typedef unsigned long uint64_t; +#define _scn64 "l" +#define _pri64 "l" +#define INT64_C(x) x ## L +#define UINT64_C(x) x ## UL + +#elif LLONG_MAX == 9223372036854775807LL + +/* long long is 64 bits */ +typedef signed long long int64_t; +typedef unsigned long long uint64_t; +#define _scn64 "ll" +#define _pri64 "ll" +#define INT64_C(x) x ## LL +#define UINT64_C(x) x ## ULL + +#else + +#error "Neither long nor long long is 64 bits in size" + +#endif + +/*** 32-bit type: int or long ***/ + +#if INT_MAX == 2147483647 + +/* int is 32 bits */ +typedef signed int int32_t; +typedef unsigned int uint32_t; +#define _scn32 "" +#define _pri32 "" +#define INT32_C(x) x +#define UINT32_C(x) x ## U + +#elif LONG_MAX == 2147483647L + +/* long is 32 bits */ +typedef signed long int32_t; +typedef unsigned long uint32_t; +#define _scn32 "l" +#define _pri32 "l" +#define INT32_C(x) x ## L +#define UINT32_C(x) x ## UL + +#else + +#error "Neither int nor long is 32 bits in size" + +#endif + +/*** 16-bit size: int or short ***/ + +#if INT_MAX == 32767 + +/* int is 16 bits */ +typedef signed int int16_t; +typedef unsigned int uint16_t; +#define _scn16 "" +#define _pri16 "" +#define INT16_C(x) x +#define UINT16_C(x) x ## U + +#elif SHRT_MAX == 32767 + +/* short is 16 bits */ +typedef signed short int16_t; +typedef unsigned short uint16_t; +#define _scn16 "h" +#define _pri16 "" +#define INT16_C(x) x +#define UINT16_C(x) x ## U + +#else + +#error "Neither short nor int is 16 bits in size" + +#endif + +/*** 8-bit size: char ***/ + +#if SCHAR_MAX == 127 + +/* char is 8 bits */ +typedef signed char int8_t; +typedef unsigned char uint8_t; +#define _scn8 "hh" +#define _pri8 "" +#define INT8_C(x) x +#define UINT8_C(x) x ## U + +#else + +#error "char is not 8 bits in size" + +#endif + +/* The rest of this is common to all models */ + +#define PRId8 _pri8 "d" +#define PRId16 _pri16 "d" +#define PRId32 _pri32 "d" +#define PRId64 _pri64 "d" + +#define PRIi8 _pri8 "i" +#define PRIi16 _pri16 "i" +#define PRIi32 _pri32 "i" +#define PRIi64 _pri64 "i" + +#define PRIo8 _pri8 "o" +#define PRIo16 _pri16 "o" +#define PRIo32 _pri32 "o" +#define PRIo64 _pri64 "o" + +#define PRIu8 _pri8 "u" +#define PRIu16 _pri16 "u" +#define PRIu32 _pri32 "u" +#define PRIu64 _pri64 "u" + +#define PRIx8 _pri8 "x" +#define PRIx16 _pri16 "x" +#define PRIx32 _pri32 "x" +#define PRIx64 _pri64 "x" + +#define PRIX8 _pri8 "X" +#define PRIX16 _pri16 "X" +#define PRIX32 _pri32 "X" +#define PRIX64 _pri64 "X" + +#define SCNd8 _scn8 "d" +#define SCNd16 _scn16 "d" +#define SCNd32 _scn32 "d" +#define SCNd64 _scn64 "d" + +#define SCNi8 _scn8 "i" +#define SCNi16 _scn16 "i" +#define SCNi32 _scn32 "i" +#define SCNi64 _scn64 "i" + +#define SCNo8 _scn8 "o" +#define SCNo16 _scn16 "o" +#define SCNo32 _scn32 "o" +#define SCNo64 _scn64 "o" + +#define SCNu8 _scn8 "u" +#define SCNu16 _scn16 "u" +#define SCNu32 _scn32 "u" +#define SCNu64 _scn64 "u" + +#define SCNx8 _scn8 "x" +#define SCNx16 _scn16 "x" +#define SCNx32 _scn32 "x" +#define SCNx64 _scn64 "x" + +#define INT8_MIN INT8_C(-128) +#define INT8_MAX INT8_C(127) +#define UINT8_MAX UINT8_C(255) + +#define INT16_MIN INT16_C(-32768) +#define INT16_MAX INT16_C(32767) +#define UINT16_MAX UINT16_C(65535) + +#define INT32_MIN INT32_C(-2147483648) +#define INT32_MAX INT32_C(2147483647) +#define UINT32_MAX UINT32_C(4294967295) + +#define INT64_MIN INT64_C(-9223372036854775808) +#define INT64_MAX INT64_C(9223372036854775807) +#define UINT64_MAX UINT64_C(18446744073709551615) + +#endif /* INTTYPES_H */ diff --git a/uppsrc/plugin/ndisasm/ndisupp.cpp b/uppsrc/plugin/ndisasm/ndisupp.cpp index 655e3b423..a62d2a1cd 100644 --- a/uppsrc/plugin/ndisasm/ndisupp.cpp +++ b/uppsrc/plugin/ndisasm/ndisupp.cpp @@ -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"