Kandinsky: KDFillRect takes a pattern, always

Change-Id: I32113345d742f21c0e238c1707bcee0116694d6f
This commit is contained in:
Romain Goyet
2016-07-05 13:32:47 +02:00
parent 1b4b2638f7
commit 8e4b1666bb
12 changed files with 55 additions and 30 deletions

View File

@@ -1,5 +1,6 @@
#include "cursor_view.h"
void CursorView::drawRect(KDRect rect) const {
KDFillRect(rect, KDColorRed);
KDColor cursorColor = KDColorRed;
KDFillRect(rect, &cursorColor, 1);
}

View File

@@ -40,7 +40,8 @@ void GraphView::layoutSubviews() {
}
void GraphView::drawRect(KDRect rect) const {
KDFillRect(rect, KDColorWhite);
KDColor backgroundColor = KDColorWhite;
KDFillRect(rect, &backgroundColor, 1);
drawGrid(rect);
drawAxes(rect);
drawFunction(rect);
@@ -62,7 +63,7 @@ void GraphView::drawLine(KDRect rect, Axis axis, float coordinate, KDColor color
lineRect.height = rect.height;
break;
}
KDFillRect(lineRect, color);
KDFillRect(lineRect, &color, 1);
}
void GraphView::drawAxes(KDRect rect) const {

View File

@@ -10,7 +10,7 @@ FunctionCell::FunctionCell() :
void FunctionCell::drawRect(KDRect rect) const {
KDColor background = m_even ? KDColorRGB(0xEE, 0xEE, 0xEE) : KDColorRGB(0x77,0x77,0x77);
KDFillRect(rect, background);
KDFillRect(rect, &background, 1);
KDDrawString(m_message, KDPointZero, m_focused);
}

View File

@@ -15,7 +15,7 @@ ScrollViewIndicator::ScrollViewIndicator(ScrollViewIndicator::Direction directio
}
void ScrollViewIndicator::drawRect(KDRect rect) const {
KDFillRect(bounds(), k_backgroundColor);
KDFillRect(bounds(), &k_backgroundColor, 1);
KDRect indicatorFrame;
if (m_direction == Direction::Horizontal) {
indicatorFrame.x = m_start*m_frame.width;
@@ -29,7 +29,7 @@ void ScrollViewIndicator::drawRect(KDRect rect) const {
indicatorFrame.width = m_frame.width;
indicatorFrame.height = (m_end-m_start)*m_frame.height;
}
KDFillRect(indicatorFrame, k_indicatorColor);
KDFillRect(indicatorFrame, &k_indicatorColor, 1);
}
void ScrollViewIndicator::setStart(float start) {

View File

@@ -7,7 +7,7 @@ SolidColorView::SolidColorView(KDColor color) :
}
void SolidColorView::drawRect(KDRect rect) const {
KDFillRect(rect, m_color);
KDFillRect(rect, &m_color, 1);
}
#if ESCHER_VIEW_LOGGING

View File

@@ -12,7 +12,8 @@ TabView::TabView() :
}
void TabView::drawRect(KDRect rect) const {
KDFillRect(rect, KDColorRGB(0xb5, 0x1d, 0xab));
KDColor backgroundColor = KDColorRGB(0xb5, 0x1d, 0xab);
KDFillRect(rect, &backgroundColor, 1);
}
void TabView::addTabNamed(const char * name) {

View File

@@ -12,6 +12,7 @@
* which results in a very consequent speedup (up to ~10x faster). */
#include <stdint.h>
#include <stddef.h>
/* ION manipulates RGB565 colors */
typedef uint16_t ion_color_t;
@@ -23,14 +24,7 @@ void ion_set_pixel(uint16_t x, uint16_t y, ion_color_t color);
void ion_fill_rect(
uint16_t x, uint16_t y,
uint16_t width, uint16_t height,
ion_color_t color
);
/* Fill a rect with a color buffer */
void ion_fill_rect_from_buffer(
uint16_t x, uint16_t y,
uint16_t width, uint16_t height,
ion_color_t * buffer
ion_color_t * pattern, size_t patternSize
);
#define ION_SCREEN_WIDTH 320

View File

@@ -48,11 +48,14 @@ void ion_set_pixel(uint16_t x, uint16_t y, ion_color_t color) {
void ion_fill_rect(
uint16_t x, uint16_t y,
uint16_t width, uint16_t height,
ion_color_t color)
ion_color_t * pattern, size_t patternSize)
{
st7789_set_drawing_area(&sDisplayController, x, y, width, height);
for (int i=0; i<width*height; i++) {
st7789_push_pixels(&sDisplayController, &color, 1);
size_t remainingSize = width*height;
while (remainingSize > 0) {
int32_t blockSize = remainingSize > patternSize ? patternSize : remainingSize;
st7789_push_pixels(&sDisplayController, pattern, blockSize);
remainingSize -= blockSize;
}
}

View File

@@ -3,6 +3,7 @@ extern "C" {
#include <assert.h>
#include <stdio.h>
#include <unistd.h>
#include <kandinsky.h>
#include "init.h"
}
#include <FL/Fl.H>
@@ -33,6 +34,8 @@ void init_platform() {
window->end();
window->show();
KDCurrentContext->fillRect = NULL;
}
void ion_set_pixel(uint16_t x, uint16_t y, ion_color_t color) {
@@ -50,13 +53,9 @@ void ion_set_pixel(uint16_t x, uint16_t y, ion_color_t color) {
void ion_fill_rect(
uint16_t x, uint16_t y,
uint16_t width, uint16_t height,
ion_color_t color)
ion_color_t * pattern, size_t patternSize)
{
for (int16_t i = x; i<(x+width); i++) {
for (int16_t j = y; j<(y+height); j++) {
ion_set_pixel(i, j, color);
}
}
assert(false);
}
bool ion_key_down(ion_key_t key) {

View File

@@ -6,9 +6,11 @@
typedef struct {
void (*setPixel)(KDCoordinate x, KDCoordinate y, KDColor color);
// fillRect can be left NULL.
// In that case, Kandinsky will fall back to using setPixel only
void (*fillRect)(KDCoordinate x, KDCoordinate y,
KDCoordinate width, KDCoordinate height,
KDColor color);
KDColor * pattern, size_t patternSize);
KDPoint origin;
KDRect clippingRect;
} KDContext;

View File

@@ -2,6 +2,7 @@
#define KANDINSKY_RECT_H
#include <stdbool.h>
#include <stddef.h>
#include <kandinsky/color.h>
#include <kandinsky/types.h>
@@ -33,7 +34,7 @@ KDRect KDRectUnion(KDRect r1, KDRect r2);
bool KDRectContains(KDRect r, KDPoint p);
KDRect KDRectTranslate(KDRect r, KDPoint p);
void KDFillRect(KDRect rect, KDColor color);
void KDFillRect(KDRect rect, const KDColor * pattern, size_t patternSize);
void KDDrawRect(KDRect rect, KDColor color);
#endif

View File

@@ -2,6 +2,7 @@
#include <kandinsky/pixel.h>
#include <kandinsky/context.h>
#include <string.h>
#include <assert.h>
KDRect KDRectZero = {.x = 0, .y = 0, .width = 0, .height = 0};
@@ -100,15 +101,37 @@ KDRect KDRectTranslate(KDRect r, KDPoint p) {
};
}
void KDFillRect(KDRect rect, KDColor color) {
void KDPerPixelFillRect(KDCoordinate x, KDCoordinate y,
KDCoordinate width, KDCoordinate height,
KDColor * pattern, size_t patternSize) {
size_t offset = 0;
for (KDCoordinate j=0; j<height; j++) {
for (KDCoordinate i=0; i<width; i++) {
KDCurrentContext->setPixel(x+i, y+j, pattern[offset++]);
if (offset >= patternSize) {
offset = 0;
}
}
}
}
void KDFillRect(KDRect rect, const KDColor * pattern, size_t patternSize) {
assert(patternSize >= 1);
KDRect absolutRect = rect;
absolutRect.origin = KDPointTranslate(absolutRect.origin, KDCurrentContext->origin);
KDRect rectToBeFilled = KDRectIntersection(absolutRect, KDCurrentContext->clippingRect);
KDCurrentContext->fillRect(rectToBeFilled.x, rectToBeFilled.y,
void (*fillRectFunction)(KDCoordinate x, KDCoordinate y,
KDCoordinate width, KDCoordinate height,
KDColor * pattern, size_t patternSize) = KDCurrentContext->fillRect;
if (fillRectFunction == NULL) {
fillRectFunction = KDPerPixelFillRect;
}
fillRectFunction(rectToBeFilled.x, rectToBeFilled.y,
rectToBeFilled.width, rectToBeFilled.height,
color);
pattern, patternSize);
}
void KDDrawRect(KDRect rect, KDColor color) {