Files
Upsilon/apps/graph/graph/cursor_view.cpp
Émilie Feral 4b84f63ef1 [apps/graph/graph] anti-aliasing on the cursor in graph view
Change-Id: I9943d0dc09b0b950910b988f348374b1fcfc3d85
2016-12-08 15:21:52 +01:00

43 lines
1.8 KiB
C++

#include "cursor_view.h"
#include <math.h>
namespace Graph {
constexpr KDCoordinate cursorDiameter = 9;
constexpr KDCoordinate cursorStampSize = cursorDiameter+1;
const uint8_t cursorStampMask[cursorStampSize+1][cursorStampSize+1] = {
{0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF},
{0xFF, 0xFF, 0xFF, 0xFF, 0x7A, 0x0C, 0x7A, 0xFF, 0xFF, 0xFF, 0xFF},
{0xFF, 0xFF, 0xFF, 0xFF, 0x0C, 0x00, 0x0C, 0xFF, 0xFF, 0xFF, 0xFF},
{0xFF, 0xFF, 0xFF, 0xFF, 0x0C, 0x00, 0x0C, 0xFF, 0xFF, 0xFF, 0xFF},
{0xFF, 0x7A, 0x0C, 0x0C, 0x0C, 0x00, 0x0C, 0x0C, 0x0C, 0x7A, 0xFF},
{0xFF, 0x0C, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0C, 0xFF},
{0xFF, 0x7A, 0x0C, 0x0C, 0x0C, 0x00, 0x0C, 0x0C, 0x0C, 0x7A, 0xFF},
{0xFF, 0xFF, 0xFF, 0xFF, 0x0C, 0x00, 0x0C, 0xFF, 0xFF, 0xFF, 0xFF},
{0xFF, 0xFF, 0xFF, 0xFF, 0x0C, 0x00, 0x0C, 0xFF, 0xFF, 0xFF, 0xFF},
{0xFF, 0xFF, 0xFF, 0xFF, 0x7A, 0x0C, 0x7A, 0xFF, 0xFF, 0xFF, 0xFF},
{0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF},
};
void CursorView::setPosition(float xPosition, float yPosition) {
m_xPosition = xPosition;
m_yPosition = yPosition;
}
void CursorView::drawRect(KDContext * ctx, KDRect rect) const {
uint8_t shiftedMask[cursorStampSize][cursorStampSize];
KDColor workingBuffer[cursorStampSize*cursorStampSize];
float dx = m_xPosition- floorf(m_xPosition);
float dy = m_yPosition - floorf(m_yPosition);
for (int i=0; i<cursorStampSize; i++) {
for (int j=0; j<cursorStampSize; j++) {
shiftedMask[i][j] = dx * (cursorStampMask[i][j]*dy+cursorStampMask[i+1][j]*(1.0f-dy))
+ (1.0f-dx) * (cursorStampMask[i][j+1]*dy + cursorStampMask[i+1][j+1]*(1.0f-dy));
}
}
KDRect cursorRect(0, 0, cursorStampSize, cursorStampSize);
ctx->blendRectWithMask(cursorRect, KDColorBlack, (const uint8_t *)shiftedMask, workingBuffer);
}
}