mirror of
https://github.com/UpsilonNumworks/Upsilon.git
synced 2026-03-21 06:40:37 +01:00
43 lines
1.8 KiB
C++
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);
|
|
}
|
|
|
|
}
|