Default button chrome improvement

This commit is contained in:
elasota
2020-05-17 23:02:08 -04:00
parent c0878fe66d
commit f590613f83
5 changed files with 116 additions and 35 deletions

View File

@@ -6,6 +6,7 @@
#include "DialogManager.h" #include "DialogManager.h"
#include "PLArrayView.h" #include "PLArrayView.h"
#include "PLButtonWidget.h"
#include "PLControlDefinitions.h" #include "PLControlDefinitions.h"
#include "PLNumberFormatting.h" #include "PLNumberFormatting.h"
#include "PLPasStr.h" #include "PLPasStr.h"
@@ -347,9 +348,9 @@ void FlashDialogButton (Dialog *theDialog, short itemNumber)
PortabilityLayer::Widget *widget = theDialog->GetItems()[itemNumber - 1].GetWidget(); PortabilityLayer::Widget *widget = theDialog->GetItems()[itemNumber - 1].GetWidget();
widget->SetHighlightStyle(kControlButtonPart); widget->SetHighlightStyle(kControlButtonPart, true);
Delay(8, &dummyLong); Delay(8, &dummyLong);
widget->SetHighlightStyle(0); widget->SetHighlightStyle(kControlButtonPart, false);
} }
//-------------------------------------------------------------- DrawDefaultButton //-------------------------------------------------------------- DrawDefaultButton
@@ -362,18 +363,7 @@ void DrawDefaultButton (Dialog *theDialog)
Rect itemRect = firstItem.GetWidget()->GetRect(); Rect itemRect = firstItem.GetWidget()->GetRect();
DrawSurface *surface = theDialog->GetWindow()->GetDrawSurface(); DrawSurface *surface = theDialog->GetWindow()->GetDrawSurface();
InsetRect(&itemRect, -4, -4); PortabilityLayer::ButtonWidget::DrawDefaultButtonChrome(itemRect, surface);
surface->SetForeColor(StdColors::Black());
for (int xOffset = -1; xOffset <= 1; xOffset++)
{
for (int yOffset = -1; yOffset <= 1; yOffset++)
{
const Rect offsetRect = itemRect + Point::Create(xOffset, yOffset);
surface->FrameRect(offsetRect);
}
}
} }
//-------------------------------------------------------------- GetDialogString //-------------------------------------------------------------- GetDialogString

View File

@@ -1,5 +1,6 @@
#include "PLButtonWidget.h" #include "PLButtonWidget.h"
#include "PLCore.h" #include "PLCore.h"
#include "PLControlDefinitions.h"
#include "PLTimeTaggedVOSEvent.h" #include "PLTimeTaggedVOSEvent.h"
#include "PLStandardColors.h" #include "PLStandardColors.h"
#include "FontFamily.h" #include "FontFamily.h"
@@ -97,6 +98,43 @@ static const PortabilityLayer::RGBAColor gs_buttonDisabledBottomRightCornerGraph
{ kDarkGray, kDarkGray, kDarkGray, 255 }, { kDarkGray, kDarkGray, kDarkGray, 255 }, { kDarkGray, kDarkGray, kDarkGray, 255 } { kDarkGray, kDarkGray, kDarkGray, 255 }, { kDarkGray, kDarkGray, kDarkGray, 255 }, { kDarkGray, kDarkGray, kDarkGray, 255 }
}; };
// Default boundary
static const PortabilityLayer::RGBAColor gs_buttonDefaultTopLeftCornerGraphicPixels[] =
{
{ 0, 0, 0, 255 }, { 0, 0, 0, 255 }, { 0, 0, 0, 255 }, { 0, 0, 0, 255 }, { 0, 0, 0, 255 },
{ 0, 0, 0, 255 }, { 0, 0, 0, 255 }, { 0, 0, 0, 255 }, { 0, 0, 0, 255 }, { 255, 255, 255, 255 },
{ 0, 0, 0, 255 }, { 0, 0, 0, 255 }, { 0, 0, 0, 255 }, { 255, 255, 255, 255 }, { kMidGray, kMidGray, kMidGray, 255 },
{ 0, 0, 0, 255 }, { 0, 0, 0, 255 }, { 255, 255, 255, 255 }, { kMidGray, kMidGray, kMidGray, 255 }, { kMidGray, kMidGray, kMidGray, 255 },
{ 0, 0, 0, 255 }, { 255, 255, 255, 255 }, { kMidGray, kMidGray, kMidGray, 255 }, { kMidGray, kMidGray, kMidGray, 255 }, { 0, 0, 0, 255 },
};
static const PortabilityLayer::RGBAColor gs_buttonDefaultTopRightCornerGraphicPixels[] =
{
{ 0, 0, 0, 255 }, { 0, 0, 0, 255 }, { 0, 0, 0, 255 }, { 0, 0, 0, 255 }, { 0, 0, 0, 255 },
{ 255, 255, 255, 255 }, { 0, 0, 0, 255 }, { 0, 0, 0, 255 }, { 0, 0, 0, 255 }, { 0, 0, 0, 255 },
{ kMidGray, kMidGray, kMidGray, 255 }, { kMidGray, kMidGray, kMidGray, 255 }, { 0, 0, 0, 255 }, { 0, 0, 0, 255 }, { 0, 0, 0, 255 },
{ kMidGray, kMidGray, kMidGray, 255 }, { kMidGray, kMidGray, kMidGray, 255 }, { kMidGray, kMidGray, kMidGray, 255 }, { 0, 0, 0, 255 }, { 0, 0, 0, 255 },
{ 0, 0, 0, 255 }, { kMidGray, kMidGray, kMidGray, 255 }, { kMidGray, kMidGray, kMidGray, 255 }, { kDarkGray, kDarkGray, kDarkGray, 255 }, { 0, 0, 0, 255 },
};
static const PortabilityLayer::RGBAColor gs_buttonDefaultBottomLeftCornerGraphicPixels[] =
{
{ 0, 0, 0, 255 }, { 255, 255, 255, 255 }, { kMidGray, kMidGray, kMidGray, 255 }, { kMidGray, kMidGray, kMidGray, 255 }, { 0, 0, 0, 255 },
{ 0, 0, 0, 255 }, { 0, 0, 0, 255 }, { kMidGray, kMidGray, kMidGray, 255 }, { kMidGray, kMidGray, kMidGray, 255 }, { kMidGray, kMidGray, kMidGray, 255 },
{ 0, 0, 0, 255 }, { 0, 0, 0, 255 }, { 0, 0, 0, 255 }, { kMidGray, kMidGray, kMidGray, 255 }, { kMidGray, kMidGray, kMidGray, 255 },
{ 0, 0, 0, 255 }, { 0, 0, 0, 255 }, { 0, 0, 0, 255 }, { 0, 0, 0, 255 }, { kDarkGray, kDarkGray, kDarkGray, 255 },
{ 0, 0, 0, 255 }, { 0, 0, 0, 255 }, { 0, 0, 0, 255 }, { 0, 0, 0, 255 }, { 0, 0, 0, 255 },
};
static const PortabilityLayer::RGBAColor gs_buttonDefaultBottomRightCornerGraphicPixels[] =
{
{ 0, 0, 0, 255 }, { kMidGray, kMidGray, kMidGray, 255 }, { kMidGray, kMidGray, kMidGray, 255 }, { kDarkGray, kDarkGray, kDarkGray, 255 }, { 0, 0, 0, 255 },
{ kMidGray, kMidGray, kMidGray, 255 }, { kMidGray, kMidGray, kMidGray, 255 }, { kDarkGray, kDarkGray, kDarkGray, 255 }, { 0, 0, 0, 255 }, { 0, 0, 0, 255 },
{ kMidGray, kMidGray, kMidGray, 255 }, { kDarkGray, kDarkGray, kDarkGray, 255 }, { 0, 0, 0, 255 }, { 0, 0, 0, 255 }, { 0, 0, 0, 255 },
{ kDarkGray, kDarkGray, kDarkGray, 255 }, { 0, 0, 0, 255 }, { 0, 0, 0, 255 }, { 0, 0, 0, 255 }, { 0, 0, 0, 255 },
{ 0, 0, 0, 255 }, { 0, 0, 0, 255 }, { 0, 0, 0, 255 }, { 0, 0, 0, 255 }, { 0, 0, 0, 255 },
};
static PortabilityLayer::SimpleGraphicInstanceRGBA<3, 3> gs_buttonCornerGraphics[4] = static PortabilityLayer::SimpleGraphicInstanceRGBA<3, 3> gs_buttonCornerGraphics[4] =
@@ -123,17 +161,31 @@ static PortabilityLayer::SimpleGraphicInstanceRGBA<3, 3> gs_buttonDisabledCorner
PortabilityLayer::SimpleGraphicInstanceRGBA<3, 3>(gs_buttonDisabledBottomRightCornerGraphicPixels), PortabilityLayer::SimpleGraphicInstanceRGBA<3, 3>(gs_buttonDisabledBottomRightCornerGraphicPixels),
}; };
static PortabilityLayer::SimpleGraphicInstanceRGBA<5, 5> gs_buttonDefaultCornerGraphics[4] =
{
PortabilityLayer::SimpleGraphicInstanceRGBA<5, 5>(gs_buttonDefaultTopLeftCornerGraphicPixels),
PortabilityLayer::SimpleGraphicInstanceRGBA<5, 5>(gs_buttonDefaultTopRightCornerGraphicPixels),
PortabilityLayer::SimpleGraphicInstanceRGBA<5, 5>(gs_buttonDefaultBottomLeftCornerGraphicPixels),
PortabilityLayer::SimpleGraphicInstanceRGBA<5, 5>(gs_buttonDefaultBottomRightCornerGraphicPixels),
};
static const uint8_t gs_buttonTopLeftGraphicMask[] = { 0x2f, 0xff }; static const uint8_t gs_buttonTopLeftGraphicMask[] = { 0x2f, 0xff };
static const uint8_t gs_buttonTopRightGraphicMask[] = { 0x9b, 0xff }; static const uint8_t gs_buttonTopRightGraphicMask[] = { 0x9b, 0xff };
static const uint8_t gs_buttonBottomLeftGraphicMask[] = { 0xec, 0xff }; static const uint8_t gs_buttonBottomLeftGraphicMask[] = { 0xec, 0xff };
static const uint8_t gs_buttonBottomRightGraphicMask[] = { 0xfa, 0x7f }; static const uint8_t gs_buttonBottomRightGraphicMask[] = { 0xfa, 0x7f };
static const uint8_t gs_buttonDefaultTopLeftGraphicMask[] = { 0x08, 0xCE, 0xFF, 0xFF };
static const uint8_t gs_buttonDefaultTopRightGraphicMask[] = { 0x86, 0x39, 0xEF, 0xFF };
static const uint8_t gs_buttonDefaultBottomLeftGraphicMask[] = { 0xFB, 0xCE, 0x30, 0xFF };
static const uint8_t gs_buttonDefaultBottomRightGraphicMask[] = { 0xFF, 0xB9, 0x88, 0x7F };
namespace PortabilityLayer namespace PortabilityLayer
{ {
ButtonWidget::ButtonWidget(const WidgetBasicState &state) ButtonWidget::ButtonWidget(const WidgetBasicState &state)
: WidgetSpec<ButtonWidget>(state) : WidgetSpec<ButtonWidget>(state)
, m_text(state.m_text) , m_text(state.m_text)
, m_haveHighlightOverride(false)
{ {
} }
@@ -244,7 +296,7 @@ namespace PortabilityLayer
textColor = PortabilityLayer::RGBAColor::Create(kDarkGray, kDarkGray, kDarkGray, 255); textColor = PortabilityLayer::RGBAColor::Create(kDarkGray, kDarkGray, kDarkGray, 255);
borderColor = PortabilityLayer::RGBAColor::Create(kDarkGray, kDarkGray, kDarkGray, 255); borderColor = PortabilityLayer::RGBAColor::Create(kDarkGray, kDarkGray, kDarkGray, 255);
} }
else if (inverted) else if (inverted || m_haveHighlightOverride)
{ {
cornerGraphics = gs_buttonPressedCornerGraphics; cornerGraphics = gs_buttonPressedCornerGraphics;
topStripeColors[0] = PortabilityLayer::RGBAColor::Create(kDarkGray, kDarkGray, kDarkGray, 255); topStripeColors[0] = PortabilityLayer::RGBAColor::Create(kDarkGray, kDarkGray, kDarkGray, 255);
@@ -310,24 +362,6 @@ namespace PortabilityLayer
surface->SetForeColor(centerColor); surface->SetForeColor(centerColor);
surface->FillRect(rect.Inset(3, 3)); surface->FillRect(rect.Inset(3, 3));
/*
surface->SetForeColor(inverted ? StdColors::Black() : StdColors::White());
surface->FillRect(this->m_rect.Inset(1, 1));
if (m_enabled)
surface->SetForeColor(StdColors::Black());
else
surface->SetForeColor(RGBAColor::Create(136, 136, 136, 255));
surface->FrameRect(this->m_rect);
if (m_enabled)
surface->SetForeColor(inverted ? StdColors::White() : StdColors::Black());
else
surface->SetForeColor(RGBAColor::Create(136, 136, 136, 255));
*/
surface->SetForeColor(textColor); surface->SetForeColor(textColor);
surface->SetSystemFont(12, PortabilityLayer::FontFamilyFlag_Bold); surface->SetSystemFont(12, PortabilityLayer::FontFamilyFlag_Bold);
@@ -335,4 +369,56 @@ namespace PortabilityLayer
int32_t y = (m_rect.top + m_rect.bottom + static_cast<int32_t>(surface->MeasureFontAscender())) / 2; int32_t y = (m_rect.top + m_rect.bottom + static_cast<int32_t>(surface->MeasureFontAscender())) / 2;
surface->DrawString(Point::Create(x, y), m_text.ToShortStr(), true); surface->DrawString(Point::Create(x, y), m_text.ToShortStr(), true);
} }
void ButtonWidget::DrawDefaultButtonChrome(const Rect &rectRef, DrawSurface *surface)
{
const Rect rect = rectRef;
PixMap **pixMap = surface->m_port.GetPixMap();
gs_buttonDefaultCornerGraphics[0].DrawToPixMapWithMask(pixMap, gs_buttonDefaultTopLeftGraphicMask, rect.left - 3, rect.top - 3);
gs_buttonDefaultCornerGraphics[1].DrawToPixMapWithMask(pixMap, gs_buttonDefaultTopRightGraphicMask, rect.right - 2, rect.top - 3);
gs_buttonDefaultCornerGraphics[2].DrawToPixMapWithMask(pixMap, gs_buttonDefaultBottomLeftGraphicMask, rect.left - 3, rect.bottom - 2);
gs_buttonDefaultCornerGraphics[3].DrawToPixMapWithMask(pixMap, gs_buttonDefaultBottomRightGraphicMask, rect.right - 2, rect.bottom - 2);
RGBAColor upperLeftStripeColors[3] =
{
RGBAColor::Create(kMidGray, kMidGray, kMidGray, 255),
StdColors::White(),
StdColors::Black(),
};
RGBAColor bottomRightStripeColors[3] =
{
RGBAColor::Create(kMidGray, kMidGray, kMidGray, 255),
RGBAColor::Create(kDarkGray, kDarkGray, kDarkGray, 255),
StdColors::Black(),
};
for (int i = 0; i < 3; i++)
{
surface->SetForeColor(upperLeftStripeColors[i]);
surface->FillRect(Rect::Create(rect.top - 1 - i, rect.left + 2, rect.top - i, rect.right - 2));
surface->FillRect(Rect::Create(rect.top + 2, rect.left - 1 - i, rect.bottom - 2, rect.left - i));
}
for (int i = 0; i < 3; i++)
{
surface->SetForeColor(bottomRightStripeColors[i]);
surface->FillRect(Rect::Create(rect.bottom + i, rect.left + 2, rect.bottom + i + 1, rect.right - 2));
surface->FillRect(Rect::Create(rect.top + 2, rect.right + i, rect.bottom - 2, rect.right + i + 1));
}
}
void ButtonWidget::SetHighlightStyle(int16_t style, bool enabled)
{
if (style == kControlButtonPart)
{
if (m_haveHighlightOverride != enabled)
{
m_haveHighlightOverride = enabled;
DrawControl(&m_window->m_surface);
}
}
}
} }

View File

@@ -20,9 +20,14 @@ namespace PortabilityLayer
int16_t Capture(const Point &pos, WidgetUpdateCallback_t callback) override; int16_t Capture(const Point &pos, WidgetUpdateCallback_t callback) override;
void SetHighlightStyle(int16_t style, bool enabled) override;
static void DrawDefaultButtonChrome(const Rect &rect, DrawSurface *surface);
private: private:
void DrawControlInternal(DrawSurface *surface, bool inverted); void DrawControlInternal(DrawSurface *surface, bool inverted);
PascalStr<255> m_text; PascalStr<255> m_text;
bool m_haveHighlightOverride;
}; };
} }

View File

@@ -85,7 +85,7 @@ namespace PortabilityLayer
return m_visible; return m_visible;
} }
void Widget::SetHighlightStyle(int16_t style) void Widget::SetHighlightStyle(int16_t style, bool enabled)
{ {
(void)style; (void)style;
} }

View File

@@ -69,7 +69,7 @@ namespace PortabilityLayer
uint32_t GetReferenceConstant() const; uint32_t GetReferenceConstant() const;
virtual void SetHighlightStyle(int16_t style); virtual void SetHighlightStyle(int16_t style, bool enabled);
virtual bool HandlesTickEvents() const; virtual bool HandlesTickEvents() const;
virtual Rect GetExpandedRect() const; virtual Rect GetExpandedRect() const;