mirror of https://github.com/BOINC/boinc.git
MGR: Add 6 new tags to allow the backgrounds of the Simple View and Simple Preferences dialog to be anchored at any of 9 points, for flexibility in placement of the logo or other graphic element that should always be visible.
Vertical anchor is one of: <anchor_vertical_top>, <anchor_vertical_center> or <anchor_vertical_bottom>. Horizontal anchor is one of: <anchor_horizontal_left>, <anchor_horizontal_center>, <anchor_horizontal_right>. If none of the tags are present, these default values are used: The defaults for the main Simple View background are <anchor_vertical_top> and <anchor_horizontal_left>. The defaults for the Simple View Preferences dialog background are <anchor_vertical_center> and <anchor_horizontal_center>.
This commit is contained in:
parent
7d31c5a37c
commit
27f622ffc1
|
@ -94,6 +94,9 @@ void CSkinImage::Clear() {
|
|||
m_strDesiredBackgroundColor.Clear();
|
||||
m_bmpBitmap = wxNullBitmap;
|
||||
m_colBackgroundColor = wxNullColour;
|
||||
m_iAnchorHorizontal = -1;
|
||||
m_iAnchorVertical = -1;
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
@ -116,6 +119,18 @@ int CSkinImage::Parse(MIOFILE& in) {
|
|||
m_strDesiredBackgroundColor = wxString(strBuffer.c_str(), wxConvUTF8);
|
||||
}
|
||||
continue;
|
||||
} else if (match_tag(buf, "<anchor_horizontal_left>")) {
|
||||
m_iAnchorHorizontal = BKGD_ANCHOR_HORIZ_LEFT;
|
||||
} else if (match_tag(buf, "<anchor_horizontal_center>")) {
|
||||
m_iAnchorHorizontal = BKGD_ANCHOR_HORIZ_CENTER;
|
||||
} else if (match_tag(buf, "<anchor_horizontal_right>")) {
|
||||
m_iAnchorHorizontal = BKGD_ANCHOR_HORIZ_RIGHT;
|
||||
} else if (match_tag(buf, "<anchor_vertical_top>")) {
|
||||
m_iAnchorVertical = BKGD_ANCHOR_VERT_TOP;;
|
||||
} else if (match_tag(buf, "<anchor_vertical_center>")) {
|
||||
m_iAnchorVertical = BKGD_ANCHOR_VERT_CENTER;;
|
||||
} else if (match_tag(buf, "<anchor_vertical_bottom>")) {
|
||||
m_iAnchorVertical = BKGD_ANCHOR_VERT_BOTTOM;;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -142,10 +157,21 @@ bool CSkinImage::SetDefaults(wxString strComponentName, const char** ppDefaultBi
|
|||
}
|
||||
|
||||
|
||||
bool CSkinImage::SetDefaults(wxString strComponentName, const char** ppDefaultBitmap, wxString strBackgroundColor) {
|
||||
bool CSkinImage::SetDefaults(wxString strComponentName,
|
||||
const char** ppDefaultBitmap,
|
||||
wxString strBackgroundColor,
|
||||
int horizontalAnchor,
|
||||
int verticalAnchor
|
||||
) {
|
||||
m_strComponentName = strComponentName;
|
||||
m_ppDefaultBitmap = ppDefaultBitmap;
|
||||
m_strDefaultBackgroundColor = strBackgroundColor;
|
||||
if (m_iAnchorHorizontal < 0) {
|
||||
m_iAnchorHorizontal = horizontalAnchor;
|
||||
}
|
||||
if (m_iAnchorVertical < 0) {
|
||||
m_iAnchorVertical = verticalAnchor;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
|
@ -407,10 +433,12 @@ int CSkinSimple::Parse(MIOFILE& in) {
|
|||
|
||||
bool CSkinSimple::InitializeDelayedValidation() {
|
||||
m_BackgroundImage.SetDefaults(
|
||||
wxT("background"), (const char**)background_image_xpm, wxT("211:211:211")
|
||||
wxT("background"), (const char**)background_image_xpm,
|
||||
wxT("211:211:211"), BKGD_ANCHOR_HORIZ_LEFT, BKGD_ANCHOR_VERT_TOP
|
||||
);
|
||||
m_DialogBackgroundImage.SetDefaults(
|
||||
wxT("dialog background"), (const char**)dialog_background_image_xpm, wxT("255:255:255")
|
||||
wxT("dialog background"), (const char**)dialog_background_image_xpm,
|
||||
wxT("255:255:255"), BKGD_ANCHOR_HORIZ_CENTER, BKGD_ANCHOR_VERT_CENTER
|
||||
);
|
||||
m_ProjectImage.SetDefaults(
|
||||
wxT("project"), (const char**)project_image_xpm
|
||||
|
|
|
@ -24,6 +24,18 @@
|
|||
|
||||
#include "miofile.h"
|
||||
|
||||
enum {
|
||||
BKGD_ANCHOR_HORIZ_LEFT,
|
||||
BKGD_ANCHOR_HORIZ_CENTER,
|
||||
BKGD_ANCHOR_HORIZ_RIGHT
|
||||
};
|
||||
|
||||
enum {
|
||||
BKGD_ANCHOR_VERT_TOP,
|
||||
BKGD_ANCHOR_VERT_CENTER,
|
||||
BKGD_ANCHOR_VERT_BOTTOM
|
||||
};
|
||||
|
||||
class CSkinItem : public wxObject
|
||||
{
|
||||
DECLARE_DYNAMIC_CLASS( CSkinItem )
|
||||
|
@ -49,6 +61,8 @@ public:
|
|||
|
||||
wxBitmap* GetBitmap();
|
||||
wxColour* GetBackgroundColor();
|
||||
int GetHorizontalAnchor() { return m_iAnchorHorizontal; }
|
||||
int GetVerticalAnchor() { return m_iAnchorVertical; }
|
||||
|
||||
bool SetDefaults(
|
||||
wxString strComponentName,
|
||||
|
@ -58,7 +72,9 @@ public:
|
|||
bool SetDefaults(
|
||||
wxString strComponentName,
|
||||
const char** ppDefaultImage,
|
||||
wxString strBackgroundColor
|
||||
wxString strBackgroundColor,
|
||||
int horizontalAnchor = BKGD_ANCHOR_HORIZ_LEFT,
|
||||
int verticalAnchor = BKGD_ANCHOR_VERT_TOP
|
||||
);
|
||||
|
||||
bool Validate();
|
||||
|
@ -71,6 +87,9 @@ private:
|
|||
wxString m_strDefaultBackgroundColor;
|
||||
wxBitmap m_bmpBitmap;
|
||||
wxColour m_colBackgroundColor;
|
||||
// Anchors are used only by m_BackgroundImage and m_DialogBackgroundImage
|
||||
int m_iAnchorHorizontal;
|
||||
int m_iAnchorVertical;
|
||||
};
|
||||
|
||||
|
||||
|
|
|
@ -985,7 +985,6 @@ void CSimpleGUIPanel::SetBackgroundBitmap() {
|
|||
|
||||
wxColour bgColor(*pSkinSimple->GetBackgroundImage()->GetBackgroundColor());
|
||||
SetBackgroundColour(bgColor);
|
||||
|
||||
wxRect panelRect = GetRect();
|
||||
m_bmpBg = wxBitmap(panelRect.width, panelRect.height);
|
||||
wxMemoryDC dc(m_bmpBg);
|
||||
|
@ -1000,7 +999,68 @@ void CSimpleGUIPanel::SetBackgroundBitmap() {
|
|||
dc.SetPen(bgPen);
|
||||
dc.DrawRectangle(panelRect);
|
||||
#endif
|
||||
dc.DrawBitmap(*pSkinSimple->GetBackgroundImage()->GetBitmap(), 0, 0, false);
|
||||
|
||||
int srcX, srcY, destX, destY, h, w;
|
||||
wxBitmap* srcBmp = pSkinSimple->GetBackgroundImage()->GetBitmap();
|
||||
wxSize srcSize = srcBmp->GetSize();
|
||||
switch(pSkinSimple->GetBackgroundImage()->GetHorizontalAnchor()) {
|
||||
case BKGD_ANCHOR_HORIZ_LEFT:
|
||||
default:
|
||||
srcX = 0;
|
||||
destX = 0;
|
||||
break;
|
||||
case BKGD_ANCHOR_HORIZ_CENTER:
|
||||
if (panelRect.width < srcSize.GetWidth()) {
|
||||
srcX = (srcSize.GetWidth() - panelRect.width) / 2;
|
||||
destX = 0;
|
||||
} else {
|
||||
srcX = 0;
|
||||
destX = (panelRect.width - srcSize.GetWidth()) / 2;
|
||||
}
|
||||
break;
|
||||
case BKGD_ANCHOR_HORIZ_RIGHT:
|
||||
if (panelRect.width < srcSize.GetWidth()) {
|
||||
srcX = (srcSize.GetWidth() - panelRect.width);
|
||||
destX = 0;
|
||||
} else {
|
||||
srcX = 0;
|
||||
destX = (panelRect.width - srcSize.GetWidth());
|
||||
}
|
||||
break;
|
||||
}
|
||||
w = wxMin(panelRect.width, srcSize.GetWidth());
|
||||
|
||||
switch(pSkinSimple->GetBackgroundImage()->GetVerticalAnchor()) {
|
||||
case BKGD_ANCHOR_VERT_TOP:
|
||||
default:
|
||||
srcY = 0;
|
||||
destY = 0;
|
||||
break;
|
||||
case BKGD_ANCHOR_VERT_CENTER:
|
||||
if (panelRect.height < srcSize.GetHeight()) {
|
||||
srcY = (srcSize.GetHeight() - panelRect.height) / 2;
|
||||
destY = 0;
|
||||
} else {
|
||||
srcY = 0;
|
||||
destY = (panelRect.height - srcSize.GetHeight()) / 2;
|
||||
}
|
||||
break;
|
||||
case BKGD_ANCHOR_VERT_BOTTOM:
|
||||
if (panelRect.height < srcSize.GetHeight()) {
|
||||
srcY = (srcSize.GetHeight() - panelRect.height);
|
||||
destY = 0;
|
||||
} else {
|
||||
srcY = 0;
|
||||
destY = (panelRect.height - srcSize.GetHeight());
|
||||
}
|
||||
break;
|
||||
}
|
||||
h = wxMin(panelRect.height, srcSize.GetHeight());
|
||||
|
||||
wxMemoryDC srcDC(*srcBmp);
|
||||
dc.Blit(destX, destY, w, h, &srcDC, srcX, srcY, wxCOPY);
|
||||
|
||||
// dc.DrawBitmap(*pSkinSimple->GetBackgroundImage()->GetBitmap(), 0, 0, false);
|
||||
|
||||
wxLogTrace(wxT("Function Start/End"), wxT("CSimpleGUIPanel::SetBackgroundBitmap - Function End"));
|
||||
}
|
||||
|
|
|
@ -443,20 +443,41 @@ void CPanelPreferences::MakeBackgroundBitmap() {
|
|||
wxImage img = bmp.ConvertToImage();
|
||||
img.Rescale((int) sz.x, (int) sz.y);
|
||||
|
||||
// Draw our cool background (centered)
|
||||
// Draw our cool background (enlarged and centered)
|
||||
dc.DrawBitmap(wxBitmap(img), 0, 0);
|
||||
} else {
|
||||
// Snag the center of the bitmap and use it
|
||||
// for the background image
|
||||
x = wxMax(0, (w - sz.x)/2);
|
||||
y = wxMax(0, (h - sz.y)/2);
|
||||
switch(pSkinSimple->GetDialogBackgroundImage()->GetHorizontalAnchor()) {
|
||||
case BKGD_ANCHOR_HORIZ_LEFT:
|
||||
default:
|
||||
x = 0;
|
||||
break;
|
||||
case BKGD_ANCHOR_HORIZ_CENTER:
|
||||
x = (w - sz.x) / 2;
|
||||
break;
|
||||
case BKGD_ANCHOR_HORIZ_RIGHT:
|
||||
x = w - sz.x;
|
||||
break;
|
||||
}
|
||||
|
||||
switch(pSkinSimple->GetDialogBackgroundImage()->GetVerticalAnchor()) {
|
||||
case BKGD_ANCHOR_VERT_TOP:
|
||||
default:
|
||||
y = 0;
|
||||
break;
|
||||
case BKGD_ANCHOR_VERT_CENTER:
|
||||
y = (h - sz.y) /2;
|
||||
break;
|
||||
case BKGD_ANCHOR_VERT_BOTTOM:
|
||||
y = h - sz.y;
|
||||
break;
|
||||
}
|
||||
|
||||
// Select the desired bitmap into the memory DC so we can take
|
||||
// the center chunk of it.
|
||||
// the desired chunk of it.
|
||||
memDC.SelectObject(bmp);
|
||||
|
||||
// Draw the center chunk on the window
|
||||
dc.Blit(0, 0, w, h, &memDC, x, y, wxCOPY);
|
||||
// Draw the desired chunk on the window
|
||||
dc.Blit(0, 0, sz.x, sz.y, &memDC, x, y, wxCOPY);
|
||||
|
||||
// Drop the bitmap
|
||||
memDC.SelectObject(wxNullBitmap);
|
||||
|
|
Loading…
Reference in New Issue