Skip to content

Commit

Permalink
active color and active backround color
Browse files Browse the repository at this point in the history
  • Loading branch information
mvladic committed Nov 11, 2019
1 parent 341f83b commit f76faa5
Show file tree
Hide file tree
Showing 22 changed files with 5,487 additions and 2,332 deletions.
7,688 changes: 5,404 additions & 2,284 deletions modular-psu-firmware.eez-project

Large diffs are not rendered by default.

40 changes: 29 additions & 11 deletions src/eez/gui/draw.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,8 @@ bool styleIsBlink(const Style *style) {

void drawText(const char *text, int textLength, int x, int y, int w, int h, const Style *style,
bool active, bool blink, bool ignoreLuminocity,
uint16_t *overrideColor, uint16_t *overrideBackgroundColor) {
uint16_t *overrideColor, uint16_t *overrideBackgroundColor,
uint16_t *overrideActiveColor, uint16_t *overrideActiveBackgroundColor) {
int x1 = x;
int y1 = y;
int x2 = x + w - 1;
Expand Down Expand Up @@ -118,17 +119,29 @@ void drawText(const char *text, int textLength, int x, int y, int w, int h, cons
}

// fill background
if (active || blink) {
if (active) {
if (overrideActiveBackgroundColor) {
display::setColor(*overrideActiveBackgroundColor, ignoreLuminocity);
} else {
display::setColor(style->active_background_color, ignoreLuminocity);
}
} else if (blink) {
display::setColor(style->color, ignoreLuminocity);
} else {
}else {
display::setColor(backgroundColor, ignoreLuminocity);
}
display::fillRect(x1, y1, x2, y2, borderRadius);

// draw text
if (active || blink) {
if (active) {
if (overrideActiveColor) {
display::setColor(*overrideActiveColor, ignoreLuminocity);
} else {
display::setColor(style->active_color, ignoreLuminocity);
}
} else if (blink) {
display::setColor(backgroundColor, ignoreLuminocity);
} else {
}else {
if (overrideColor) {
display::setColor(*overrideColor, ignoreLuminocity);
} else {
Expand Down Expand Up @@ -281,7 +294,7 @@ struct MultilineTextRender {
}

// fill background
uint16_t background_color = active ? style->color : style->background_color;
uint16_t background_color = active ? style->active_background_color : style->background_color;
display::setColor(background_color);
display::fillRect(x1, y1, x2, y2, borderRadius);

Expand All @@ -298,7 +311,7 @@ struct MultilineTextRender {
spaceWidth = space_glyph.dx;

// draw text
display::setColor(active ? style->background_color : style->color);
display::setColor(active ? style->active_color : style->color);

x1 += style->padding_left;
x2 -= style->padding_right;
Expand Down Expand Up @@ -386,8 +399,8 @@ void drawBitmap(void *bitmapPixels, int bpp, int bitmapWidth, int bitmapHeight,
uint8_t savedOpacity = display::getOpacity();

if (active) {
display::setBackColor(style->color);
display::setColor(style->background_color);
display::setBackColor(style->active_background_color);
display::setColor(style->active_color);
display::setOpacity(style->opacity);
} else {
display::setBackColor(style->background_color);
Expand All @@ -402,7 +415,7 @@ void drawBitmap(void *bitmapPixels, int bpp, int bitmapWidth, int bitmapHeight,

////////////////////////////////////////////////////////////////////////////////

void drawRectangle(int x, int y, int w, int h, const Style *style, bool active, bool ignoreLuminocity) {
void drawRectangle(int x, int y, int w, int h, const Style *style, bool active, bool ignoreLuminocity, bool invertColors) {
if (w > 0 && h > 0) {
int x1 = x;
int y1 = y;
Expand All @@ -424,7 +437,12 @@ void drawRectangle(int x, int y, int w, int h, const Style *style, bool active,
y2 -= style->border_size_bottom;
}

display::setColor(active ? style->background_color : style->color, ignoreLuminocity);
if (invertColors) {
display::setColor(active ? style->active_background_color : style->background_color, ignoreLuminocity);
} else {
display::setColor(active ? style->active_color : style->color, ignoreLuminocity);
}

display::fillRect(x1, y1, x2, y2, borderRadius);
}
}
Expand Down
4 changes: 2 additions & 2 deletions src/eez/gui/draw.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,10 @@ namespace gui {
font::Font styleGetFont(const Style *style);
bool styleIsBlink(const Style *style);

void drawText(const char *text, int textLength, int x, int y, int w, int h, const Style *style, bool active, bool blink, bool ignoreLuminocity, uint16_t *overrideColor, uint16_t *overrideBackgroundColor);
void drawText(const char *text, int textLength, int x, int y, int w, int h, const Style *style, bool active, bool blink, bool ignoreLuminocity, uint16_t *overrideColor, uint16_t *overrideBackgroundColor, uint16_t *overrideActiveColor, uint16_t *overrideActiveBackgroundColor);
void drawMultilineText(const char *text, int x, int y, int w, int h, const Style *style, bool active, int firstLineIndent, int hangingIndent);
void drawBitmap(void *bitmapPixels, int bpp, int bitmapWidth, int bitmapHeight, int x, int y, int w, int h, const Style *style, bool active);
void drawRectangle(int x, int y, int w, int h, const Style *style, bool active, bool ignoreLuminocity);
void drawRectangle(int x, int y, int w, int h, const Style *style, bool active, bool ignoreLuminocity, bool invertColors);
void drawShadow(int x1, int y1, int x2, int y2);

} // namespace gui
Expand Down
2 changes: 1 addition & 1 deletion src/eez/gui/page.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -437,7 +437,7 @@ void SelectFromEnumPage::refresh() {
getItemPosition(i, xItem, yItem);

getItemLabel(i, text, sizeof(text));
drawText(text, -1, xItem, yItem, itemWidth, itemHeight, isDisabled(i) ? disabledItemStyle : itemStyle, false, false, false, nullptr, nullptr);
drawText(text, -1, xItem, yItem, itemWidth, itemHeight, isDisabled(i) ? disabledItemStyle : itemStyle, false, false, false, nullptr, nullptr, nullptr, nullptr);
}

dirty = false;
Expand Down
2 changes: 1 addition & 1 deletion src/eez/gui/widget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,7 @@ void defaultWidgetDraw(const WidgetCursor &widgetCursor) {
widgetCursor.previousState->flags.active != widgetCursor.currentState->flags.active;

if (refresh) {
drawRectangle(widgetCursor.x, widgetCursor.y, (int)widget->w, (int)widget->h, getStyle(widget->style), !widgetCursor.currentState->flags.active, false);
drawRectangle(widgetCursor.x, widgetCursor.y, (int)widget->w, (int)widget->h, getStyle(widget->style), widgetCursor.currentState->flags.active, false, true);
}
}

Expand Down
3 changes: 3 additions & 0 deletions src/eez/gui/widget.h
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,8 @@ struct Style {
uint16_t flags;
uint16_t background_color;
uint16_t color;
uint16_t active_background_color;
uint16_t active_color;
uint8_t border_size_top;
uint8_t border_size_right;
uint8_t border_size_bottom;
Expand Down Expand Up @@ -266,6 +268,7 @@ void drawWidgetCallback(const WidgetCursor &widgetCursor);
OnTouchFunctionType getTouchFunction(const WidgetCursor &widgetCursor);

uint16_t overrideStyleColorHook(const WidgetCursor &widgetCursor, const Style *style);
uint16_t overrideActiveStyleColorHook(const WidgetCursor &widgetCursor, const Style *style);

} // namespace gui
} // namespace eez
8 changes: 4 additions & 4 deletions src/eez/gui/widgets/bar_graph.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,7 @@ void BarGraphWidget_draw(const WidgetCursor &widgetCursor) {
display::fillRect(x, y, x + pText - 1, y + h - 1);
}

drawText(valueText, -1, x + pText, y, wText, h, &textStyle, false, false, false, nullptr, nullptr);
drawText(valueText, -1, x + pText, y, wText, h, &textStyle, false, false, false, nullptr, nullptr, nullptr, nullptr);

// draw background, but do not draw over line 1 and line 2
display::setColor(bg);
Expand Down Expand Up @@ -207,7 +207,7 @@ void BarGraphWidget_draw(const WidgetCursor &widgetCursor) {
display::fillRect(x - (pText - 1), y, x, y + h - 1);
}

drawText(valueText, -1, x - (pText + wText - 1), y, wText, h, &textStyle, false, false, false, nullptr, nullptr);
drawText(valueText, -1, x - (pText + wText - 1), y, wText, h, &textStyle, false, false, false, nullptr, nullptr, nullptr, nullptr);

// draw background, but do not draw over line 1 and line 2
display::setColor(bg);
Expand Down Expand Up @@ -272,7 +272,7 @@ void BarGraphWidget_draw(const WidgetCursor &widgetCursor) {
display::fillRect(x, y, x + w - 1, y + pText - 1);
}

drawText(valueText, -1, x, y + pText, w, hText, &textStyle, false, false, false, nullptr, nullptr);
drawText(valueText, -1, x, y + pText, w, hText, &textStyle, false, false, false, nullptr, nullptr, nullptr, nullptr);

// draw background, but do not draw over line 1 and line 2
display::setColor(bg);
Expand Down Expand Up @@ -307,7 +307,7 @@ void BarGraphWidget_draw(const WidgetCursor &widgetCursor) {
display::fillRect(x, y - (pText - 1), x + w - 1, y);
}

drawText(valueText, -1, x, y - (pText + hText - 1), w, hText, &textStyle, false, false, false, nullptr, nullptr);
drawText(valueText, -1, x, y - (pText + hText - 1), w, hText, &textStyle, false, false, false, nullptr, nullptr, nullptr, nullptr);

// draw background, but do not draw over line 1 and line 2
display::setColor(bg);
Expand Down
6 changes: 3 additions & 3 deletions src/eez/gui/widgets/button.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -63,17 +63,17 @@ void ButtonWidget_draw(const WidgetCursor &widgetCursor) {
drawText(widgetCursor.currentState->data.getString(), -1, widgetCursor.x,
widgetCursor.y, (int)widget->w, (int)widget->h, style,
widgetCursor.currentState->flags.active,
widgetCursor.currentState->flags.blinking, false, nullptr, nullptr);
widgetCursor.currentState->flags.blinking, false, nullptr, nullptr, nullptr, nullptr);
} else {
drawText(GET_WIDGET_PROPERTY(button_widget, text, const char *), -1, widgetCursor.x, widgetCursor.y, (int)widget->w, (int)widget->h,
style, widgetCursor.currentState->flags.active,
widgetCursor.currentState->flags.blinking, false, nullptr, nullptr);
widgetCursor.currentState->flags.blinking, false, nullptr, nullptr, nullptr, nullptr);
}
} else {
const Style *style = getStyle(widgetCursor.currentState->flags.enabled ? widget->style : button_widget->disabledStyle);
drawText(GET_WIDGET_PROPERTY(button_widget, text, const char *), -1, widgetCursor.x, widgetCursor.y, (int)widget->w, (int)widget->h,
style, widgetCursor.currentState->flags.active,
widgetCursor.currentState->flags.blinking, false, nullptr, nullptr);
widgetCursor.currentState->flags.blinking, false, nullptr, nullptr, nullptr, nullptr);
}
}
}
Expand Down
4 changes: 2 additions & 2 deletions src/eez/gui/widgets/button_group.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ void drawButtons(const Widget *widget, int x, int y, const Style *style, int sel
for (int i = 0; i < count; ++i) {
char text[32];
labels[i].toText(text, 32);
drawText(text, -1, x, y, w, h, style, i == selectedButton, false, false, nullptr, nullptr);
drawText(text, -1, x, y, w, h, style, i == selectedButton, false, false, nullptr, nullptr, nullptr, nullptr);
x += w;
}
} else {
Expand Down Expand Up @@ -75,7 +75,7 @@ void drawButtons(const Widget *widget, int x, int y, const Style *style, int sel

char text[32];
labels[i].toText(text, 32);
drawText(text, -1, x, y + yOffset, w, labelHeight, style, i == selectedButton, false, false, nullptr, nullptr);
drawText(text, -1, x, y + yOffset, w, labelHeight, style, i == selectedButton, false, false, nullptr, nullptr, nullptr, nullptr);

int b = y + yOffset + labelHeight;

Expand Down
4 changes: 2 additions & 2 deletions src/eez/gui/widgets/container.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -213,8 +213,8 @@ void ContainerWidget_draw(const WidgetCursor &widgetCursor) {

#if OPTION_SDRAM
if (!previousState || previousState->displayBufferIndex == -1) {
refresh = true;
currentState->displayBufferIndex = mcu::display::allocBuffer();
refresh = true;
} else {
currentState->displayBufferIndex = previousState->displayBufferIndex;
}
Expand All @@ -225,7 +225,7 @@ void ContainerWidget_draw(const WidgetCursor &widgetCursor) {
if (refresh) {
drawRectangle(
widgetCursor.x, widgetCursor.y, w, h,
getStyle(widget->style), !widgetCursor.currentState->flags.active, false
getStyle(widget->style), widgetCursor.currentState->flags.active, false, true
);
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/eez/gui/widgets/display_data.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ void DisplayDataWidget_draw(const WidgetCursor &widgetCursor) {
drawText(start, -1, widgetCursor.x, widgetCursor.y, (int)widget->w, (int)widget->h,
style, widgetCursor.currentState->flags.active,
widgetCursor.currentState->flags.blinking, false,
nullptr, &currentState->backgroundColor);
nullptr, &currentState->backgroundColor, nullptr, nullptr);
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/eez/gui/widgets/layout_view.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ void LayoutViewWidget_draw(const WidgetCursor &widgetCursor) {

if (refresh) {
const Style* style = getStyle(widget->style);
drawRectangle(widgetCursor.x, widgetCursor.y, (int)widget->w, (int)widget->h, style, !widgetCursor.currentState->flags.active, false);
drawRectangle(widgetCursor.x, widgetCursor.y, (int)widget->w, (int)widget->h, style, widgetCursor.currentState->flags.active, false, true);
}
}

Expand Down
5 changes: 3 additions & 2 deletions src/eez/gui/widgets/rectangle.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,9 @@ void RectangleWidget_draw(const WidgetCursor &widgetCursor) {
drawRectangle(
widgetCursor.x, widgetCursor.y, (int)widget->w, (int)widget->h,
style,
rectangle_widget->flags.invertColors ? !widgetCursor.currentState->flags.active : widgetCursor.currentState->flags.active,
rectangle_widget->flags.ignoreLuminosity);
widgetCursor.currentState->flags.active,
rectangle_widget->flags.ignoreLuminosity,
rectangle_widget->flags.invertColors);
}
}

Expand Down
4 changes: 2 additions & 2 deletions src/eez/gui/widgets/scroll_bar.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ void ScrollBarWidget_draw(const WidgetCursor &widgetCursor) {
int buttonWidth = buttonsFont.getHeight();

// draw left button
drawText(GET_WIDGET_PROPERTY(scrollBarWidget, leftButtonText, const char *), -1, widgetCursor.x, widgetCursor.y, buttonWidth, (int)widget->h, buttonsStyle, currentState->segment == SCROLL_BAR_WIDGET_SEGMENT_LEFT_BUTTON, false, false, nullptr, nullptr);
drawText(GET_WIDGET_PROPERTY(scrollBarWidget, leftButtonText, const char *), -1, widgetCursor.x, widgetCursor.y, buttonWidth, (int)widget->h, buttonsStyle, currentState->segment == SCROLL_BAR_WIDGET_SEGMENT_LEFT_BUTTON, false, false, nullptr, nullptr, nullptr, nullptr);

// draw track
int xTrack = widgetCursor.x + buttonWidth;
Expand All @@ -127,7 +127,7 @@ void ScrollBarWidget_draw(const WidgetCursor &widgetCursor) {
display::fillRect(xThumb, yTrack, xThumb + wThumb - 1, yTrack + hTrack - 1);

// draw right button
drawText(GET_WIDGET_PROPERTY(scrollBarWidget, rightButtonText, const char *), -1, widgetCursor.x + widget->w - buttonWidth, widgetCursor.y, buttonWidth, (int)widget->h, buttonsStyle, currentState->segment == SCROLL_BAR_WIDGET_SEGMENT_RIGHT_BUTTON, false, false, nullptr, nullptr);
drawText(GET_WIDGET_PROPERTY(scrollBarWidget, rightButtonText, const char *), -1, widgetCursor.x + widget->w - buttonWidth, widgetCursor.y, buttonWidth, (int)widget->h, buttonsStyle, currentState->segment == SCROLL_BAR_WIDGET_SEGMENT_RIGHT_BUTTON, false, false, nullptr, nullptr, nullptr, nullptr);
} else {
// scroll bar is hidden
const Style *trackStyle = getStyle(widget->style);
Expand Down
7 changes: 4 additions & 3 deletions src/eez/gui/widgets/text.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -58,27 +58,28 @@ void TextWidget_draw(const WidgetCursor &widgetCursor) {

if (refresh) {
uint16_t overrideColor = overrideStyleColorHook(widgetCursor, style);
uint16_t overrideActiveColor = overrideActiveStyleColorHook(widgetCursor, style);

bool ignoreLuminosity = (textWidget->flags & IGNORE_LUMINOSITY_FLAG) != 0;
if (text && text[0]) {
drawText(text, -1, widgetCursor.x, widgetCursor.y, (int)widget->w, (int)widget->h,
style, widgetCursor.currentState->flags.active,
widgetCursor.currentState->flags.blinking,
ignoreLuminosity, &overrideColor, nullptr);
ignoreLuminosity, &overrideColor, nullptr, nullptr, nullptr);
} else if (widget->data) {
if (widgetCursor.currentState->data.isString()) {
drawText(widgetCursor.currentState->data.getString(), -1, widgetCursor.x,
widgetCursor.y, (int)widget->w, (int)widget->h, style,
widgetCursor.currentState->flags.active,
widgetCursor.currentState->flags.blinking,
ignoreLuminosity, &overrideColor, nullptr);
ignoreLuminosity, &overrideColor, nullptr, nullptr, nullptr);
} else {
char text[64];
widgetCursor.currentState->data.toText(text, sizeof(text));
drawText(text, -1, widgetCursor.x, widgetCursor.y, (int)widget->w, (int)widget->h,
style, widgetCursor.currentState->flags.active,
widgetCursor.currentState->flags.blinking,
ignoreLuminosity, &overrideColor, nullptr);
ignoreLuminosity, &overrideColor, nullptr, &overrideActiveColor, nullptr);
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/eez/gui/widgets/toggle_button.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ void ToggleButtonWidget_draw(const WidgetCursor &widgetCursor) {
GET_WIDGET_PROPERTY(toggle_button_widget, text1, const char *),
-1,
widgetCursor.x, widgetCursor.y, (int)widget->w, (int)widget->h, style,
widgetCursor.currentState->flags.active, false, false, nullptr, nullptr);
widgetCursor.currentState->flags.active, false, false, nullptr, nullptr, nullptr, nullptr);
}
}

Expand Down
6 changes: 3 additions & 3 deletions src/eez/gui/widgets/up_down.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -68,20 +68,20 @@ void UpDownWidget_draw(const WidgetCursor &widgetCursor) {
buttonsStyle,
widgetCursor.currentState->flags.active &&
g_segment == UP_DOWN_WIDGET_SEGMENT_DOWN_BUTTON,
false, false, nullptr, nullptr);
false, false, nullptr, nullptr, nullptr, nullptr);

char text[64];
widgetCursor.currentState->data.toText(text, sizeof(text));
const Style *style = getStyle(widget->style);
drawText(text, -1, widgetCursor.x + buttonWidth, widgetCursor.y,
(int)(widget->w - 2 * buttonWidth), (int)widget->h, style, false, false,
false, nullptr, nullptr);
false, nullptr, nullptr, nullptr, nullptr);

drawText(GET_WIDGET_PROPERTY(upDownWidget, upButtonText, const char *), -1, widgetCursor.x + widget->w - buttonWidth, widgetCursor.y,
buttonWidth, (int)widget->h, buttonsStyle,
widgetCursor.currentState->flags.active &&
g_segment == UP_DOWN_WIDGET_SEGMENT_UP_BUTTON,
false, false, nullptr, nullptr);
false, false, nullptr, nullptr, nullptr, nullptr);
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/eez/gui/widgets/yt_graph.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -348,7 +348,7 @@ struct YTGraphStaticDrawHelper {

char text[64];
data::ytDataGetCursorTime(widgetCursor.cursor, widgetCursor.widget->data).toText(text, sizeof(text));
drawText(text, -1, xTimeText, yTimeText, timeTextWidth, timeTextHeight, style, false, false, false, nullptr, nullptr);
drawText(text, -1, xTimeText, yTimeText, timeTextWidth, timeTextHeight, style, false, false, false, nullptr, nullptr, nullptr, nullptr);
}
}
};
Expand Down
Loading

0 comments on commit f76faa5

Please sign in to comment.