#include "wxinc.h" #include "gtArt.h" #include #include extern wxColor wxAuiStepColour(const wxColor& c, int ialpha); /////////////////////////////////////////////////////////// // HSLColor /////////////////////////////////////////////////////////// inline wxColourBase::ChannelType Y601(wxColourBase::ChannelType r, wxColourBase::ChannelType g, wxColourBase::ChannelType b) { return 0.299*r + 0.587*g + 0.114*b; } inline wxColourBase::ChannelType Luma(const wxColour& col) { return Y601(col.Red(), col.Green(), col.Blue()); } static wxColourBase::ChannelType ModulatedChannel(wxColourBase::ChannelType c, int val) { int k = c; if (val > 0) k = (c * (100-val) + 255 * val) / 100; else k = c * (100+val) / 100; if (k < 0) k = 0; else if (k > 255) k = 255; return k; } // val: -100 = wxBLACK; 0 = Same color; +100 = wxWHITE wxColour ModulatedColor(const wxColour& col, int val) { // return col.ChangeLightness(100 + val); wxColourBase::ChannelType r = ModulatedChannel(col.Red(), val); wxColourBase::ChannelType g = ModulatedChannel(col.Green(), val); wxColourBase::ChannelType b = ModulatedChannel(col.Blue(), val); return wxColour(r, g, b); } inline wxColour GrayedColor(const wxColour& col) { const wxColourBase::ChannelType y1 = Luma(col); return wxColour(y1,y1,y1); } wxColour gtContrastingColor(const wxColour& col) { const wxColourBase::ChannelType y1 = Luma(col); return y1 > 128 ? *wxBLACK : *wxWHITE; } /////////////////////////////////////////////////////////// // gtToolBarArt /////////////////////////////////////////////////////////// void gtToolBarArt::DrawBackground(wxDC& dc, wxWindow* window, int orientation, const wxRect &rect) { if (!gtAuiManager::DrawBackground(dc, window, orientation, rect)) wxAuiDefaultDockArt::DrawBackground(dc, window, orientation, rect); } void gtToolBarArt::DrawSash(wxDC& dc, wxWindow *window, int orientation, const wxRect& rect) { DrawBackground(dc, window, orientation, rect); } gtToolBarArt::gtToolBarArt() { wxColour base, light, dark, text; if (gtAuiManager::BaseColours(base, light, dark, text)) { SetColour(wxAUI_DOCKART_BACKGROUND_COLOUR, base); SetColour(wxAUI_DOCKART_SASH_COLOUR, base); SetColour(wxAUI_DOCKART_ACTIVE_CAPTION_COLOUR, base); SetColour(wxAUI_DOCKART_ACTIVE_CAPTION_GRADIENT_COLOUR, light); SetColour(wxAUI_DOCKART_ACTIVE_CAPTION_TEXT_COLOUR, text); SetColour(wxAUI_DOCKART_INACTIVE_CAPTION_COLOUR, dark); SetColour(wxAUI_DOCKART_INACTIVE_CAPTION_GRADIENT_COLOUR, base); const wxColourBase::ChannelType g = Luma(dark) > 128 ? 64 : 192; SetColour(wxAUI_DOCKART_INACTIVE_CAPTION_TEXT_COLOUR, wxColour(g,g,g)); SetColour(wxAUI_DOCKART_BORDER_COLOUR, dark); } } /////////////////////////////////////////////////////////// // gtTabArt /////////////////////////////////////////////////////////// wxAuiTabArt* gtTabArt::Clone() { gtTabArt* ta = new gtTabArt; return ta; } gtTabArt::gtTabArt() { wxColour base, light, dark, text; if (gtAuiManager::BaseColours(base, light, dark, text)) { m_border_pen = wxPen(ModulatedColor(base, 75)); m_base_colour = base; m_base_colour_pen = wxPen(base); m_base_colour_brush = wxBrush(base); } } /////////////////////////////////////////////////////////// // gtAuiManager /////////////////////////////////////////////////////////// bool gtAuiManager::BaseColours(wxColour& base, wxColour& light, wxColour& dark, wxColour& text) { const wxSize sz(256,256); wxBitmap bmp = wxArtProvider::GetBitmap(wxArtID(wxT("Skin")), wxART_OTHER, sz); if (bmp.IsOk()) { wxColourBase::ChannelType ldark = 255, llight = 0; dark = *wxWHITE; light = *wxBLACK; wxNativePixelData data(bmp); const int dim = data.GetHeight(); wxNativePixelData::Iterator p(data); double r = 0, g = 0, b = 0; for (int i = 0; i < dim; i++) { p.MoveTo(data, i, i); r += p.Red(); g += p.Green(); b += p.Blue(); const wxColour col(p.Red(), p.Green(), p.Blue()); const wxColourBase::ChannelType lcol = Luma(col); if (lcol < ldark) { dark = col; ldark = lcol; } if (lcol > llight) { light = col; llight = lcol; } } r /= dim; g /= dim; b /= dim; base = wxColour(r, g, b); const wxColourBase::ChannelType lbase = Luma(base); if (lbase - ldark < 40) dark = ModulatedColor(dark, -(40 - lbase + ldark)); if (llight - lbase < 40) light = ModulatedColor(light, +(40 - llight + lbase)); text = gtContrastingColor(base); } return bmp.IsOk(); } bool gtAuiManager::DrawBackground(wxDC& dc, wxWindow* WXUNUSED(window), int WXUNUSED(orientation), const wxRect &rect) { const wxBitmap bmp = wxArtProvider::GetBitmap(wxArtID(wxT("Skin")), wxART_OTHER, wxSize(256,256)); if (bmp.IsOk()) { const wxSize szBm(bmp.GetWidth(), bmp.GetHeight()); for (wxCoord y = rect.y; y < rect.GetBottom(); y += szBm.y) { for (wxCoord x = rect.x; x < rect.GetRight(); x += szBm.x) dc.DrawBitmap(bmp, x, y); } } return bmp.IsOk(); } gtAuiManager::gtAuiManager() { SetArtProvider(new gtToolBarArt); } /////////////////////////////////////////////////////////// // plnHolidayAutority /////////////////////////////////////////////////////////// class gtHolidayAutority : public wxDateTimeWorkDays { protected: virtual bool DoIsHoliday(const wxDateTime& dt) const; virtual size_t DoGetHolidaysInRange(const wxDateTime& dtStart, const wxDateTime& dtEnd, wxDateTimeArray& holidays) const; }; bool gtHolidayAutority::DoIsHoliday(const wxDateTime& dt) const { const wxDateTime::Month m = dt.GetMonth(); const wxDateTime::wxDateTime_t d = dt.GetDay(); switch (m) { case wxDateTime::Jan: if (d == 1 || d == 6) // Capodanno ed Epifania return true; break; case wxDateTime::Apr: if (d == 25) // 25 Aprile return true; break; case wxDateTime::May: if (d == 1) return true; // I Maggio break; case wxDateTime::Jun: if (d == 2) // Festa della Repubblica return true; break; case wxDateTime::Aug: if (d == 15) // Ferragosto return true; break; case wxDateTime::Nov: if (d == 1) // Ognissanti return true; break; case wxDateTime::Dec: if (d == 8 || d == 25 || d == 26) // Immacolata, Natale e Santo Stefano return true; break; default: break; } const wxDateTime::WeekDay wd = dt.GetWeekDay(); if (wd == wxDateTime::Sun || wd == wxDateTime::Sat) return true; if (wd == wxDateTime::Mon && (m == wxDateTime::Mar || m == wxDateTime::Apr)) { const int y = dt.GetYear(); const int correction = y < 2100 ? 0 : 1; // Semplificazione tabella dal 1600 al 2500 int d = (19 * (y%19) + 24) % 30; d += 22 + ((2*(y%4) + 4*(y%7) + 6*d + 5 + correction) % 7); int m = 3; if (d > 31) { d -= 31; m++; } const wxDateTime easter(d, wxDateTime::Month(m-1), y); if (easter == dt - wxDateSpan(0,0,0,1)) return true; } return false; } size_t gtHolidayAutority::DoGetHolidaysInRange(const wxDateTime& dtStart, const wxDateTime& dtEnd, wxDateTimeArray& holidays) const { for (wxDateTime dt = dtStart; dt <= dtEnd; dt += wxDateSpan(0,0,0,1)) { if (DoIsHoliday(dt)) holidays.Add(dt); } return holidays.GetCount(); } /////////////////////////////////////////////////////////// // gtArtProvider /////////////////////////////////////////////////////////// class gtArtProvider : public wxArtProvider { wxString m_strSkin; protected: wxSize AdjustedSize(const wxArtClient& client, const wxSize& size) const; virtual wxBitmap CreateBitmap(const wxArtID& id, const wxArtClient& client, const wxSize& size); public: gtArtProvider(); }; wxSize gtArtProvider::AdjustedSize(const wxArtClient& client, const wxSize& size) const { if (size != wxDefaultSize) return size; if (client == wxART_MENU) return wxSize(16,16); if (client == wxART_TOOLBAR) return wxSize(48,48); wxSize sz = wxArtProvider::GetSizeHint(client); if (sz == wxDefaultSize) { if (client == wxART_OTHER) sz = size; else sz.x = sz.y = 32; } return sz; } wxBitmap gtArtProvider::CreateBitmap(const wxArtID& id, const wxArtClient& client, const wxSize& size) { const wxSize sz = AdjustedSize(client, size); wxString strName = id; long tool = 0; bool bOverriding = false; if (strName.StartsWith(wxT("wxART"))) { if (id == wxART_FILE_OPEN) tool = wxID_OPEN; else if (id == wxART_FILE_SAVE) tool = wxID_SAVE; else if (id == wxART_FILE_SAVE_AS) tool = wxID_SAVEAS; else if (id == wxART_NEW) tool = wxID_NEW; else if (id == wxART_HELP) tool = wxID_HELP; else return wxNullBitmap; bOverriding = true; } else { if (strName.CmpNoCase(wxT("Skin"))==0 && !m_strSkin.IsEmpty()) strName = m_strSkin; } if (tool > 0 || id.ToLong(&tool)) { if (client == wxART_TOOLBAR || client == wxART_BUTTON) strName.Printf(wxT("res/tool_%ld.png"), tool); else if (client == wxART_OTHER) strName.Printf(wxT("res/image_%ld.png"), tool); else strName.Printf(wxT("res/icon_%ld.png"), tool); } else strName.MakeLower(); if (!strName.EndsWith(wxT(".png"))) strName << wxT(".png"); bool bFound = wxFileName::FileExists(strName); if (!bFound && !strName.StartsWith(wxT("res/"))) { strName.Prepend(wxT("res/")); bFound = wxFileName::FileExists(strName); } if (!bFound && !bOverriding && tool > wxID_LOWEST && tool < wxID_HIGHEST) { switch (tool) { case wxID_OPEN : strName = wxART_FILE_OPEN; break; case wxID_SAVE : strName = wxART_FILE_SAVE; break; case wxID_SAVEAS : strName = wxART_FILE_SAVE_AS; break; case wxID_NEW : strName = wxART_NEW; break; case wxID_HELP : strName = wxART_HELP; break; case wxID_PREFERENCES : strName = wxART_HELP_SETTINGS; break; default : strName = wxEmptyString; break; } if (strName.StartsWith(wxT("wxART"))) return wxArtProvider::GetBitmap(strName, client, sz); } if (!bFound) return wxNullBitmap; wxBitmap bmp; if (bmp.LoadFile(strName, wxBITMAP_TYPE_ANY)) { const wxSize szOld(bmp.GetWidth(), bmp.GetHeight()); if (szOld != sz) { wxSize szNew = sz; if (szOld.x >= szOld.y) szNew.y = sz.x * szOld.y / szOld.x; else szNew.x = sz.y * szOld.x / szOld.y; bmp = wxBitmap(bmp.ConvertToImage().Scale(szNew.x, szNew.y, wxIMAGE_QUALITY_HIGH)); } } else bmp.Create(sz.x, sz.y); return bmp; } gtArtProvider::gtArtProvider() { const wxString strSkin = wxT("res/skin.png"); if (wxFileName::FileExists(strSkin)) m_strSkin = strSkin; } void gtInitArtProvider() { ::wxInitAllImageHandlers(); wxArtProvider::Push(new gtArtProvider); wxDateTimeHolidayAuthority::AddAuthority(new gtHolidayAutority); }