[apps/shared] Create a class Dots to share dots masks between CurveView

and RoundCursorView. Use the same dot for illustrations of additional
results in Calculation app and Function app
This commit is contained in:
Émilie Feral
2020-01-16 12:34:52 +01:00
committed by Léa Saviot
parent ba159de21d
commit d61336936e
10 changed files with 91 additions and 50 deletions

View File

@@ -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

View File

@@ -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);

View File

@@ -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);
}
}

View File

@@ -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 \

View File

@@ -1,5 +1,6 @@
#include "curve_view.h"
#include "../constant.h"
#include "dots.h"
#include <poincare/print_float.h>
#include <assert.h>
#include <string.h>
@@ -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 {

View File

@@ -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;

36
apps/shared/dots.cpp Normal file
View File

@@ -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},
};
}

20
apps/shared/dots.h Normal file
View File

@@ -0,0 +1,20 @@
#ifndef SHARED_DOTS_H
#define SHARED_DOTS_H
#include <kandinsky/coordinate.h>
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

View File

@@ -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) {

View File

@@ -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;