diff --git a/apps/calculation/additional_outputs/complex_graph_cell.cpp b/apps/calculation/additional_outputs/complex_graph_cell.cpp index ce9deae9a..aabe9b630 100644 --- a/apps/calculation/additional_outputs/complex_graph_cell.cpp +++ b/apps/calculation/additional_outputs/complex_graph_cell.cpp @@ -70,7 +70,7 @@ void ComplexGraphView::drawRect(KDContext * ctx, KDRect rect) const { drawSegment(ctx, rect, Axis::Horizontal, imag, 0.0f, real, Palette::Red, 1, 3); // Draw complex position on the plan - drawDot(ctx, rect, real, imag, Palette::Red, true); + drawDot(ctx, rect, real, imag, Palette::Red, Size::Large); // Draw labels // 're(z)' label diff --git a/apps/calculation/additional_outputs/trigonometry_graph_cell.cpp b/apps/calculation/additional_outputs/trigonometry_graph_cell.cpp index 6d2f808c1..41deb62bf 100644 --- a/apps/calculation/additional_outputs/trigonometry_graph_cell.cpp +++ b/apps/calculation/additional_outputs/trigonometry_graph_cell.cpp @@ -25,7 +25,7 @@ void TrigonometryGraphView::drawRect(KDContext * ctx, KDRect rect) const { drawSegment(ctx, rect, Axis::Vertical, c, 0.0f, s, Palette::Red, 1, 3); drawSegment(ctx, rect, Axis::Horizontal, s, 0.0f, c, Palette::Red, 1, 3); // Draw angle position on the circle - drawDot(ctx, rect, c, s, Palette::Red, true); + drawDot(ctx, rect, c, s, Palette::Red, Size::Large); // Draw graduations drawLabelsAndGraduations(ctx, rect, Axis::Vertical, false, true); drawLabelsAndGraduations(ctx, rect, Axis::Horizontal, false, true); diff --git a/apps/regression/graph_view.cpp b/apps/regression/graph_view.cpp index e1d31d590..afdbdab0c 100644 --- a/apps/regression/graph_view.cpp +++ b/apps/regression/graph_view.cpp @@ -35,7 +35,7 @@ void GraphView::drawRect(KDContext * ctx, KDRect rect) const { for (int index = 0; index < m_store->numberOfPairsOfSeries(series); index++) { drawDot(ctx, rect, m_store->get(series, 0, index), m_store->get(series, 1, index), color); } - drawDot(ctx, rect, m_store->meanOfColumn(series, 0), m_store->meanOfColumn(series, 1), color, true); + drawDot(ctx, rect, m_store->meanOfColumn(series, 0), m_store->meanOfColumn(series, 1), color, Size::Medium); drawDot(ctx, rect, m_store->meanOfColumn(series, 0), m_store->meanOfColumn(series, 1), KDColorWhite); } } diff --git a/apps/shared/Makefile b/apps/shared/Makefile index 2c4f2a951..b08dd1f4d 100644 --- a/apps/shared/Makefile +++ b/apps/shared/Makefile @@ -19,6 +19,7 @@ app_shared_src = $(addprefix apps/shared/,\ buffer_function_title_cell.cpp \ buffer_text_view_with_text_field.cpp \ button_with_separator.cpp \ + dots.cpp \ cursor_view.cpp \ curve_view.cpp \ curve_view_cursor.cpp \ diff --git a/apps/shared/curve_view.cpp b/apps/shared/curve_view.cpp index 89d8be428..50d16f06f 100644 --- a/apps/shared/curve_view.cpp +++ b/apps/shared/curve_view.cpp @@ -1,5 +1,6 @@ #include "curve_view.h" #include "../constant.h" +#include "dots.h" #include #include #include @@ -416,40 +417,31 @@ void CurveView::drawSegment(KDContext * ctx, KDRect rect, Axis axis, float coord } } -constexpr KDCoordinate dotDiameter = 5; -const uint8_t dotMask[dotDiameter][dotDiameter] = { - {0xE1, 0x45, 0x0C, 0x45, 0xE1}, - {0x45, 0x00, 0x00, 0x00, 0x45}, - {0x00, 0x00, 0x00, 0x00, 0x00}, - {0x45, 0x00, 0x00, 0x00, 0x45}, - {0xE1, 0x45, 0x0C, 0x45, 0xE1}, -}; - -constexpr KDCoordinate oversizeDotDiameter = 7; -const uint8_t oversizeDotMask[oversizeDotDiameter][oversizeDotDiameter] = { - {0xE1, 0x45, 0x0C, 0x00, 0x0C, 0x45, 0xE1}, - {0x45, 0x0C, 0x00, 0x00, 0x00, 0x0C, 0x45}, - {0x0C, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0C}, - {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, - {0x0C, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0C}, - {0x45, 0x0C, 0x00, 0x00, 0x00, 0x0C, 0x45}, - {0xE1, 0x45, 0x0C, 0x00, 0x0C, 0x45, 0xE1}, -}; - -void CurveView::drawDot(KDContext * ctx, KDRect rect, float x, float y, KDColor color, bool oversize) const { - const KDCoordinate diameter = oversize ? oversizeDotDiameter : dotDiameter; +void CurveView::drawDot(KDContext * ctx, KDRect rect, float x, float y, KDColor color, Size size) const { + KDCoordinate diameter = 0; + const uint8_t * mask = nullptr; + switch (size) { + case Size::Small: + diameter = Dots::SmallDotDiameter; + mask = (const uint8_t *)Dots::SmallDotMask; + break; + case Size::Medium: + diameter = Dots::MediumDotDiameter; + mask = (const uint8_t *)Dots::MediumDotMask; + break; + default: + assert(size == Size::Large); + diameter = Dots::LargeDotDiameter; + mask = (const uint8_t *)Dots::LargeDotMask; + } KDCoordinate px = std::round(floatToPixel(Axis::Horizontal, x)); KDCoordinate py = std::round(floatToPixel(Axis::Vertical, y)); KDRect dotRect(px - diameter/2, py - diameter/2, diameter, diameter); if (!rect.intersects(dotRect)) { return; } - KDColor workingBuffer[oversizeDotDiameter*oversizeDotDiameter]; - ctx->blendRectWithMask( - dotRect, color, - oversize ? (const uint8_t *)oversizeDotMask : (const uint8_t *)dotMask, - workingBuffer - ); + KDColor workingBuffer[Dots::LargeDotDiameter*Dots::LargeDotDiameter]; + ctx->blendRectWithMask(dotRect, color, mask, workingBuffer); } void CurveView::drawGrid(KDContext * ctx, KDRect rect) const { diff --git a/apps/shared/curve_view.h b/apps/shared/curve_view.h index 1d86abe31..2637dc945 100644 --- a/apps/shared/curve_view.h +++ b/apps/shared/curve_view.h @@ -65,7 +65,12 @@ protected: void drawSegment(KDContext * ctx, KDRect rect, Axis axis, float coordinate, float lowerBound, float upperBound, KDColor color, KDCoordinate thickness = 1, KDCoordinate dashSize = -1) const; - void drawDot(KDContext * ctx, KDRect rect, float x, float y, KDColor color, bool oversize = false) const; + enum class Size : uint8_t { + Small, + Medium, + Large + }; + void drawDot(KDContext * ctx, KDRect rect, float x, float y, KDColor color, Size size = Size::Small) const; void drawGrid(KDContext * ctx, KDRect rect) const; void drawAxes(KDContext * ctx, KDRect rect) const; void drawAxis(KDContext * ctx, KDRect rect, Axis axis) const; diff --git a/apps/shared/dots.cpp b/apps/shared/dots.cpp new file mode 100644 index 000000000..0f178b44e --- /dev/null +++ b/apps/shared/dots.cpp @@ -0,0 +1,36 @@ +#include "dots.h" + +namespace Shared { + +const uint8_t Dots::SmallDotMask[Dots::SmallDotDiameter][Dots::SmallDotDiameter] = { + {0xE1, 0x45, 0x0C, 0x45, 0xE1}, + {0x45, 0x00, 0x00, 0x00, 0x45}, + {0x00, 0x00, 0x00, 0x00, 0x00}, + {0x45, 0x00, 0x00, 0x00, 0x45}, + {0xE1, 0x45, 0x0C, 0x45, 0xE1}, +}; + +const uint8_t Dots::MediumDotMask[Dots::MediumDotDiameter][Dots::MediumDotDiameter] = { + {0xE1, 0x45, 0x0C, 0x00, 0x0C, 0x45, 0xE1}, + {0x45, 0x0C, 0x00, 0x00, 0x00, 0x0C, 0x45}, + {0x0C, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0C}, + {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, + {0x0C, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0C}, + {0x45, 0x0C, 0x00, 0x00, 0x00, 0x0C, 0x45}, + {0xE1, 0x45, 0x0C, 0x00, 0x0C, 0x45, 0xE1}, +}; + +const uint8_t Dots::LargeDotMask[Dots::LargeDotDiameter][Dots::LargeDotDiameter] = { + {0xFF, 0xFF, 0xFF, 0xED, 0xB6, 0xB6, 0xED, 0xFF, 0xFF, 0xFF}, + {0xFF, 0xFF, 0x7C, 0x06, 0x00, 0x00, 0x06, 0x7C, 0xFF, 0xFF}, + {0xFF, 0x7C, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x7C, 0xFF}, + {0xED, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xE5}, + {0xB6, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xB6}, + {0xB6, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xB6}, + {0xED, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xE5}, + {0xFF, 0x7C, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x7C, 0xFF}, + {0xFF, 0xFF, 0x7C, 0x06, 0x00, 0x00, 0x06, 0x7C, 0xFF, 0xFF}, + {0xFF, 0xFF, 0xFF, 0xED, 0xB6, 0xB6, 0xED, 0xFF, 0xFF, 0xFF}, +}; + +} diff --git a/apps/shared/dots.h b/apps/shared/dots.h new file mode 100644 index 000000000..07d65ff44 --- /dev/null +++ b/apps/shared/dots.h @@ -0,0 +1,20 @@ +#ifndef SHARED_DOTS_H +#define SHARED_DOTS_H + +#include + +namespace Shared { + +class Dots { +public: + static constexpr KDCoordinate SmallDotDiameter = 5; + static const uint8_t SmallDotMask[SmallDotDiameter][SmallDotDiameter]; + static constexpr KDCoordinate MediumDotDiameter = 7; + static const uint8_t MediumDotMask[MediumDotDiameter][MediumDotDiameter]; + static constexpr KDCoordinate LargeDotDiameter = 10; + static const uint8_t LargeDotMask[LargeDotDiameter][LargeDotDiameter]; +}; + +} + +#endif diff --git a/apps/shared/round_cursor_view.cpp b/apps/shared/round_cursor_view.cpp index d3f6316ce..7722b85d3 100644 --- a/apps/shared/round_cursor_view.cpp +++ b/apps/shared/round_cursor_view.cpp @@ -2,31 +2,17 @@ namespace Shared { -static constexpr KDCoordinate cursorSize = 10; -static const uint8_t cursorMask[cursorSize][cursorSize] = { - {0xFF, 0xFF, 0xFF, 0xED, 0xB6, 0xB6, 0xED, 0xFF, 0xFF, 0xFF}, - {0xFF, 0xFF, 0x7C, 0x06, 0x00, 0x00, 0x06, 0x7C, 0xFF, 0xFF}, - {0xFF, 0x7C, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x7C, 0xFF}, - {0xED, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xE5}, - {0xB6, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xB6}, - {0xB6, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xB6}, - {0xED, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xE5}, - {0xFF, 0x7C, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x7C, 0xFF}, - {0xFF, 0xFF, 0x7C, 0x06, 0x00, 0x00, 0x06, 0x7C, 0xFF, 0xFF}, - {0xFF, 0xFF, 0xFF, 0xED, 0xB6, 0xB6, 0xED, 0xFF, 0xFF, 0xFF}, -}; - -static KDColor s_cursorWorkingBuffer[cursorSize*cursorSize]; +static KDColor s_cursorWorkingBuffer[Dots::LargeDotDiameter*Dots::LargeDotDiameter]; void RoundCursorView::drawRect(KDContext * ctx, KDRect rect) const { KDRect r = bounds(); ctx->getPixels(r, m_underneathPixelBuffer); m_underneathPixelBufferLoaded = true; - ctx->blendRectWithMask(r, m_color, (const uint8_t *)cursorMask, s_cursorWorkingBuffer); + ctx->blendRectWithMask(r, m_color, (const uint8_t *)Dots::LargeDotMask, s_cursorWorkingBuffer); } KDSize RoundCursorView::minimalSizeForOptimalDisplay() const { - return KDSize(cursorSize, cursorSize); + return KDSize(k_cursorSize, k_cursorSize); } void RoundCursorView::setColor(KDColor color) { diff --git a/apps/shared/round_cursor_view.h b/apps/shared/round_cursor_view.h index 8bde981ed..25539702a 100644 --- a/apps/shared/round_cursor_view.h +++ b/apps/shared/round_cursor_view.h @@ -2,6 +2,7 @@ #define SHARED_ROUND_CURSOR_VIEW_H #include "cursor_view.h" +#include "dots.h" namespace Shared { @@ -21,7 +22,7 @@ private: #ifdef GRAPH_CURSOR_SPEEDUP bool eraseCursorIfPossible(); #endif - constexpr static int k_cursorSize = 10; + constexpr static int k_cursorSize = Dots::LargeDotDiameter; mutable KDColor m_underneathPixelBuffer[k_cursorSize*k_cursorSize]; KDColor m_color; mutable bool m_underneathPixelBufferLoaded;