Skip to content

Commit

Permalink
drawText overrideColor
Browse files Browse the repository at this point in the history
  • Loading branch information
mvladic committed Nov 5, 2019
1 parent 02b443f commit 3be594d
Show file tree
Hide file tree
Showing 16 changed files with 54 additions and 41 deletions.
3 changes: 2 additions & 1 deletion modular-psu-firmware.eez-project
Original file line number Diff line number Diff line change
Expand Up @@ -50309,7 +50309,8 @@
{
"type": "Text",
"style": {
"inheritFrom": "overlay"
"inheritFrom": "overlay",
"color": "bar_graph_voltage"
},
"activeStyle": {
"inheritFrom": "overlay_drag"
Expand Down
10 changes: 5 additions & 5 deletions src/eez/apps/psu/gui/data.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4110,8 +4110,8 @@ void data_channel_history_values(data::DataOperationEnum operation, data::Cursor
value = getMin(cursor, value.getUInt8() == 0 ? DATA_ID_CHANNEL_DISPLAY_VALUE1 : DATA_ID_CHANNEL_DISPLAY_VALUE2);
} else if (operation == DATA_OPERATION_YT_DATA_GET_MAX) {
value = getMax(cursor, value.getUInt8() == 0 ? DATA_ID_CHANNEL_DISPLAY_VALUE1 : DATA_ID_CHANNEL_DISPLAY_VALUE2);
} else if (operation == DATA_OPERATION_YT_DATA_GET_VALUE) {
value = g_appContext->getHistoryValue(cursor, cursor.i == 0 ? DATA_ID_CHANNEL_DISPLAY_VALUE1 : DATA_ID_CHANNEL_DISPLAY_VALUE2, value.getUInt32());
} else if (operation >= DATA_OPERATION_YT_DATA_GET_VALUE1 && operation <= DATA_OPERATION_YT_DATA_GET_VALUE2) {
value = g_appContext->getHistoryValue(cursor, operation - DATA_OPERATION_YT_DATA_GET_VALUE1 == 0 ? DATA_ID_CHANNEL_DISPLAY_VALUE1 : DATA_ID_CHANNEL_DISPLAY_VALUE2, value.getUInt32());
} else if (operation == DATA_OPERATION_YT_DATA_GET_GRAPH_UPDATE_METHOD) {
value = Value(psu::persist_conf::devConf2.ytGraphUpdateMethod, VALUE_TYPE_UINT8);
}
Expand All @@ -4126,8 +4126,8 @@ void data_recording_ready(data::DataOperationEnum operation, data::Cursor &curso
void data_recording(data::DataOperationEnum operation, data::Cursor &cursor, data::Value &value) {
uint32_t size = dlog::getSize();

if (operation == DATA_OPERATION_YT_DATA_GET_VALUE) {
uint8_t valueIndex = cursor.i;
if (operation == DATA_OPERATION_YT_DATA_GET_VALUE1 && operation <= DATA_OPERATION_YT_DATA_GET_VALUE4) {
uint8_t valueIndex = operation - DATA_OPERATION_YT_DATA_GET_VALUE1;
Unit unit = dlog::g_dlogValues[valueIndex].offset.getUnit();
if (value.getUInt32() >= size) {
value = Value(NAN, unit);
Expand Down Expand Up @@ -4280,7 +4280,7 @@ void data_dlog_time_div(data::DataOperationEnum operation, data::Cursor &cursor,

void data_dlog_value_cursor(data::DataOperationEnum operation, data::Cursor &cursor, data::Value &value) {
if (operation == data::DATA_OPERATION_GET) {
value = data::ytDataGetValue(cursor, DATA_ID_RECORDING, ytDataGetPosition(cursor, DATA_ID_RECORDING) + dlog::g_cursorOffset);
value = data::ytDataGetValue(cursor, DATA_ID_RECORDING, ytDataGetPosition(cursor, DATA_ID_RECORDING) + dlog::g_cursorOffset, cursor.i);
}
}

Expand Down
4 changes: 2 additions & 2 deletions src/eez/gui/data.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -624,9 +624,9 @@ float ytDataGetOffset(const Cursor &cursor, uint16_t id, uint8_t valueIndex) {
return value.getFloat();
}

Value ytDataGetValue(const Cursor &cursor, uint16_t id, uint32_t position) {
Value ytDataGetValue(const Cursor &cursor, uint16_t id, uint32_t position, uint8_t valueIndex) {
Value value(position, VALUE_TYPE_UINT32);
g_dataOperationsFunctions[id]((DataOperationEnum)(data::DATA_OPERATION_YT_DATA_GET_VALUE), (Cursor &)cursor, value);
g_dataOperationsFunctions[id]((DataOperationEnum)(data::DATA_OPERATION_YT_DATA_GET_VALUE1 + valueIndex), (Cursor &)cursor, value);
return value;
}

Expand Down
7 changes: 5 additions & 2 deletions src/eez/gui/data.h
Original file line number Diff line number Diff line change
Expand Up @@ -326,7 +326,10 @@ enum DataOperationEnum {
DATA_OPERATION_YT_DATA_GET_VERT_DIVISIONS,
DATA_OPERATION_YT_DATA_GET_PER_DIV,
DATA_OPERATION_YT_DATA_GET_OFFSET,
DATA_OPERATION_YT_DATA_GET_VALUE,
DATA_OPERATION_YT_DATA_GET_VALUE1,
DATA_OPERATION_YT_DATA_GET_VALUE2,
DATA_OPERATION_YT_DATA_GET_VALUE3,
DATA_OPERATION_YT_DATA_GET_VALUE4,
DATA_OPERATION_YT_DATA_GET_GRAPH_UPDATE_METHOD,
DATA_OPERATION_YT_DATA_GET_PERIOD,
DATA_OPERATION_YT_DATA_IS_CURSOR_VISIBLE,
Expand Down Expand Up @@ -371,7 +374,7 @@ int ytDataGetVertDivisions(const Cursor &cursor, uint16_t id);
int ytDataGetHorzDivisions(const Cursor &cursor, uint16_t id);
float ytDataGetPerDiv(const Cursor &cursor, uint16_t id, uint8_t valueIndex);
float ytDataGetOffset(const Cursor &cursor, uint16_t id, uint8_t valueIndex);
Value ytDataGetValue(const Cursor &cursor, uint16_t id, uint32_t position);
Value ytDataGetValue(const Cursor &cursor, uint16_t id, uint32_t position, uint8_t valueIndex);
uint8_t ytDataGetGraphUpdateMethod(const Cursor &cursor, uint16_t id);
float ytDataGetPeriod(const Cursor &cursor, uint16_t id);
bool ytDataIsCursorVisible(const Cursor &cursor, uint16_t id);
Expand Down
8 changes: 6 additions & 2 deletions src/eez/gui/draw.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ bool styleIsBlink(const Style *style) {

void drawText(const char *text, int textLength, int x, int y, int w, int h, const Style *style,
const Style *activeStyle, bool active, bool blink, bool ignoreLuminocity,
uint16_t *overrideBackgroundColor) {
uint16_t *overrideColor, uint16_t *overrideBackgroundColor) {
int x1 = x;
int y1 = y;
int x2 = x + w - 1;
Expand Down Expand Up @@ -137,7 +137,11 @@ void drawText(const char *text, int textLength, int x, int y, int w, int h, cons
display::setColor(backgroundColor, ignoreLuminocity);
}
} else {
display::setColor(style->color, ignoreLuminocity);
if (overrideColor) {
display::setColor(*overrideColor, ignoreLuminocity);
} else {
display::setColor(style->color, ignoreLuminocity);
}
}
display::drawStr(text, textLength, x_offset, y_offset, x1, y1, x2, y2, font);
}
Expand Down
2 changes: 1 addition & 1 deletion src/eez/gui/draw.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ bool styleIsBlink(const Style *style);

void drawText(const char *text, int textLength, int x, int y, int w, int h, const Style *style,
const Style *activeStyle, bool active, bool blink, bool ignoreLuminocity,
uint16_t *overrideBackgroundColor);
uint16_t *overrideColor, uint16_t *overrideBackgroundColor);

void drawMultilineText(const char *text, int x, int y, int w, int h, const Style *style,
const Style *activeStyle, bool active, int firstLineIndent, int hangingIndent);
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 @@ -439,7 +439,7 @@ void SelectFromEnumPage::refresh() {
getItemLabel(i, text, sizeof(text));
drawText(text, -1, xItem, yItem, itemWidth, itemHeight,
isDisabled(i) ? disabledItemStyle : itemStyle, nullptr, false, false, false,
nullptr);
nullptr, nullptr);
}

dirty = false;
Expand Down
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 @@ -173,7 +173,7 @@ void BarGraphWidget_draw(const WidgetCursor &widgetCursor) {
}

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

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

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

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

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

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

drawText(valueText, -1, x, y - (pText + hText - 1), w, hText, &textStyle, nullptr,
false, false, false, nullptr);
false, false, false, 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, nullptr,
widgetCursor.currentState->flags.active,
widgetCursor.currentState->flags.blinking, false, nullptr);
widgetCursor.currentState->flags.blinking, false, nullptr, nullptr);
} else {
drawText(GET_WIDGET_PROPERTY(button_widget, text, const char *), -1, widgetCursor.x, widgetCursor.y, (int)widget->w, (int)widget->h,
style, nullptr, widgetCursor.currentState->flags.active,
widgetCursor.currentState->flags.blinking, false, nullptr);
widgetCursor.currentState->flags.blinking, false, 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, nullptr, widgetCursor.currentState->flags.active,
widgetCursor.currentState->flags.blinking, false, nullptr);
widgetCursor.currentState->flags.blinking, false, 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 @@ -47,7 +47,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, w, h, style, nullptr, i == selectedButton, false, false,
nullptr);
nullptr, nullptr);
x += w;
}
} else {
Expand Down Expand Up @@ -77,7 +77,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, nullptr, i == selectedButton,
false, false, nullptr);
false, false, nullptr, nullptr);

int b = y + yOffset + labelHeight;

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 @@ -99,7 +99,7 @@ void DisplayDataWidget_draw(const WidgetCursor &widgetCursor) {
drawText(start, -1, widgetCursor.x, widgetCursor.y, (int)widget->w, (int)widget->h,
style, activeStyle, widgetCursor.currentState->flags.active,
widgetCursor.currentState->flags.blinking, false,
&currentState->backgroundColor);
nullptr, &currentState->backgroundColor);
}
}

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 @@ -104,7 +104,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, nullptr, currentState->segment == SCROLL_BAR_WIDGET_SEGMENT_LEFT_BUTTON, false, false, nullptr);
drawText(GET_WIDGET_PROPERTY(scrollBarWidget, leftButtonText, const char *), -1, widgetCursor.x, widgetCursor.y, buttonWidth, (int)widget->h, buttonsStyle, nullptr, currentState->segment == SCROLL_BAR_WIDGET_SEGMENT_LEFT_BUTTON, false, false, nullptr, nullptr);

// draw track
int xTrack = widgetCursor.x + buttonWidth;
Expand All @@ -124,7 +124,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, nullptr, currentState->segment == SCROLL_BAR_WIDGET_SEGMENT_RIGHT_BUTTON, false, false, nullptr);
drawText(GET_WIDGET_PROPERTY(scrollBarWidget, rightButtonText, const char *), -1, widgetCursor.x + widget->w - buttonWidth, widgetCursor.y, buttonWidth, (int)widget->h, buttonsStyle, nullptr, currentState->segment == SCROLL_BAR_WIDGET_SEGMENT_RIGHT_BUTTON, false, false, nullptr, nullptr);
} else {
// scroll bar is hidden
const Style *trackStyle = getStyle(widget->style);
Expand Down
13 changes: 10 additions & 3 deletions src/eez/gui/widgets/text.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -58,26 +58,33 @@ void TextWidget_draw(const WidgetCursor &widgetCursor) {
widgetCursor.previousState->data != widgetCursor.currentState->data;

if (refresh) {
uint16_t overrideColor = style->color;

// TODO
if (widget->data == DATA_ID_DLOG_VALUE_LABEL) {
overrideColor = widgetCursor.cursor.i == 0 ? COLOR_ID_BAR_GRAPH_VOLTAGE : COLOR_ID_BAR_GRAPH_CURRENT;
}

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, activeStyle, widgetCursor.currentState->flags.active,
widgetCursor.currentState->flags.blinking,
ignoreLuminosity, nullptr);
ignoreLuminosity, &overrideColor, 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, activeStyle,
widgetCursor.currentState->flags.active,
widgetCursor.currentState->flags.blinking,
ignoreLuminosity, nullptr);
ignoreLuminosity, &overrideColor, 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, activeStyle, widgetCursor.currentState->flags.active,
widgetCursor.currentState->flags.blinking,
ignoreLuminosity, nullptr);
ignoreLuminosity, &overrideColor, 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,
nullptr, widgetCursor.currentState->flags.active, false, false, nullptr);
nullptr, widgetCursor.currentState->flags.active, false, false, 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, nullptr,
widgetCursor.currentState->flags.active &&
g_segment == UP_DOWN_WIDGET_SEGMENT_DOWN_BUTTON,
false, false, nullptr);
false, false, 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, nullptr, false, false,
false, nullptr);
false, nullptr, nullptr);

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

Expand Down
14 changes: 6 additions & 8 deletions src/eez/gui/widgets/yt_graph.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -75,8 +75,7 @@ struct YTGraphDrawHelper {
return INT_MIN;
}

Cursor cursor(valueIndex);
float value = data::ytDataGetValue(cursor, widget->data, position).getFloat();
float value = data::ytDataGetValue(widgetCursor.cursor, widget->data, position, valueIndex).getFloat();

if (isNaN(value)) {
return INT_MIN;
Expand Down Expand Up @@ -212,11 +211,11 @@ struct YTGraphStaticDrawHelper {
uint32_t numPositions;
uint32_t position;

Cursor valueCursor;

float offset;
float scale;

int valueIndex;

int x;

int yPrev;
Expand All @@ -232,7 +231,7 @@ struct YTGraphStaticDrawHelper {
return INT_MIN;
}

float value = data::ytDataGetValue(valueCursor, widget->data, position).getFloat();
float value = data::ytDataGetValue(widgetCursor.cursor, widget->data, position, valueIndex).getFloat();

if (isNaN(value)) {
return INT_MIN;
Expand Down Expand Up @@ -313,8 +312,7 @@ struct YTGraphStaticDrawHelper {
YTGraphWidgetState *currentState = (YTGraphWidgetState *)widgetCursor.currentState;

int numValues = data::ytDataGetNumValues(widgetCursor.cursor, widget->data);
for (int valueIndex = 0; valueIndex < numValues; valueIndex++) {
valueCursor = valueIndex;
for (valueIndex = 0; valueIndex < numValues; valueIndex++) {

position = currentHistoryValuePosition;

Expand Down Expand Up @@ -351,7 +349,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, nullptr, false, false, false, nullptr);
drawText(text, -1, xTimeText, yTimeText, timeTextWidth, timeTextHeight, style, nullptr, false, false, false, nullptr, nullptr);
}
}
};
Expand Down

0 comments on commit 3be594d

Please sign in to comment.