diff --git a/escher/src/view.cpp b/escher/src/view.cpp index 46a12a371..964a5773d 100644 --- a/escher/src/view.cpp +++ b/escher/src/view.cpp @@ -40,7 +40,8 @@ void View::redraw(KDRect rect) { KDPoint absOrigin = absoluteOrigin(); KDRect absRect = KDRectTranslate(rectNeedingRedraw, absOrigin); KDRect absClippingRect = KDRectIntersection(absoluteVisibleFrame(), absRect); - KDSetDrawingArea(absOrigin, absClippingRect); + KDCurrentContext->origin = absOrigin; + KDCurrentContext->clippingRect = absClippingRect; this->drawRect(rectNeedingRedraw); } diff --git a/kandinsky/Makefile b/kandinsky/Makefile index 914b8502c..c361f6fe0 100644 --- a/kandinsky/Makefile +++ b/kandinsky/Makefile @@ -1,6 +1,6 @@ SFLAGS += -Ikandinsky/include objs += $(addprefix kandinsky/src/,\ - drawing_area.o\ + context.o\ font.o\ line.o\ pixel.o\ diff --git a/kandinsky/include/kandinsky.h b/kandinsky/include/kandinsky.h index 2da081651..b3c7d5abe 100644 --- a/kandinsky/include/kandinsky.h +++ b/kandinsky/include/kandinsky.h @@ -2,7 +2,7 @@ #define KANDINSKY_KANDINSKY_H #include -#include +#include #include #include #include diff --git a/kandinsky/include/kandinsky/context.h b/kandinsky/include/kandinsky/context.h new file mode 100644 index 000000000..a55406063 --- /dev/null +++ b/kandinsky/include/kandinsky/context.h @@ -0,0 +1,18 @@ +#ifndef KANDINSKY_CONTEXT_H +#define KANDINSKY_CONTEXT_H + +#include "types.h" +#include "rect.h" + +typedef struct { + void (*setPixel)(KDCoordinate x, KDCoordinate y, KDColor color); + void (*fillRect)(KDCoordinate x, KDCoordinate y, + KDCoordinate width, KDCoordinate height, + KDColor color); + KDPoint origin; + KDRect clippingRect; +} KDContext; + +extern KDContext * KDCurrentContext; + +#endif diff --git a/kandinsky/include/kandinsky/drawing_area.h b/kandinsky/include/kandinsky/drawing_area.h deleted file mode 100644 index a8e8bbb60..000000000 --- a/kandinsky/include/kandinsky/drawing_area.h +++ /dev/null @@ -1,12 +0,0 @@ -#ifndef KANDINSKY_DRAWING_AREA -#define KANDINSKY_DRAWING_AREA 1 - -#include - -/* The drawing area is a very important yet simple concept. - * When you set a drawing area (using absolute coordinates), two things happen: - * - No drawing will ever happen outside of the specified rect - * - All coordinates will then be interpreted as relative to the rect origin */ -void KDSetDrawingArea(KDPoint origin, KDRect clippingRect); - -#endif diff --git a/kandinsky/src/context.c b/kandinsky/src/context.c new file mode 100644 index 000000000..f9303b77b --- /dev/null +++ b/kandinsky/src/context.c @@ -0,0 +1,19 @@ +#include +#include + +KDContext KDIonContext = { + .setPixel = &ion_set_pixel, + .fillRect = &ion_fill_rect, + .origin = { + .x = 0, + .y = 0 + }, + .clippingRect = { + .x = 0, + .y = 0, + .width = ION_SCREEN_WIDTH, + .height = ION_SCREEN_HEIGHT + } +}; + +KDContext * KDCurrentContext = &KDIonContext; diff --git a/kandinsky/src/drawing_area.c b/kandinsky/src/drawing_area.c deleted file mode 100644 index fd67ac75e..000000000 --- a/kandinsky/src/drawing_area.c +++ /dev/null @@ -1,19 +0,0 @@ -#include -#include - -KDPoint KDDrawingAreaOrigin = { - .x = 0, - .y = 0 -}; - -KDRect KDDrawingAreaClippingRect = { - .x = 0, - .y = 0, - .width = ION_SCREEN_WIDTH, - .height = ION_SCREEN_HEIGHT -}; - -void KDSetDrawingArea(KDPoint origin, KDRect clippingRect) { - KDDrawingAreaOrigin = origin; - KDDrawingAreaClippingRect = clippingRect; -} diff --git a/kandinsky/src/pixel.c b/kandinsky/src/pixel.c index 13ab38f2a..76198b31a 100644 --- a/kandinsky/src/pixel.c +++ b/kandinsky/src/pixel.c @@ -1,12 +1,12 @@ #include #include +#include #include #include -#include "private/drawing_area.h" void KDSetPixel(KDPoint p, KDColor c) { - KDPoint absolutePoint = KDPointTranslate(p, KDDrawingAreaOrigin); - if (KDRectContains(KDDrawingAreaClippingRect, absolutePoint)) { - ion_set_pixel(absolutePoint.x, absolutePoint.y, c); + KDPoint absolutePoint = KDPointTranslate(p, KDCurrentContext->origin); + if (KDRectContains(KDCurrentContext->clippingRect, absolutePoint)) { + KDCurrentContext->setPixel(absolutePoint.x, absolutePoint.y, c); } } diff --git a/kandinsky/src/private/drawing_area.h b/kandinsky/src/private/drawing_area.h deleted file mode 100644 index 4392d1aaf..000000000 --- a/kandinsky/src/private/drawing_area.h +++ /dev/null @@ -1,10 +0,0 @@ -#ifndef KANDINSKY_PRIVATE_DRAWING_AREA -#define KANDINSKY_PRIVATE_DRAWING_AREA 1 - -#include -#include - -extern KDPoint KDDrawingAreaOrigin; -extern KDRect KDDrawingAreaClippingRect; - -#endif diff --git a/kandinsky/src/rect.c b/kandinsky/src/rect.c index b0d803a23..2d9992491 100644 --- a/kandinsky/src/rect.c +++ b/kandinsky/src/rect.c @@ -1,8 +1,7 @@ #include #include +#include #include -#include "private/drawing_area.h" -#include KDRect KDRectZero = {.x = 0, .y = 0, .width = 0, .height = 0}; @@ -103,11 +102,11 @@ KDRect KDRectTranslate(KDRect r, KDPoint p) { void KDFillRect(KDRect rect, KDColor color) { KDRect absolutRect = rect; - absolutRect.origin = KDPointTranslate(absolutRect.origin, KDDrawingAreaOrigin); + absolutRect.origin = KDPointTranslate(absolutRect.origin, KDCurrentContext->origin); - KDRect rectToBeFilled = KDRectIntersection(absolutRect, KDDrawingAreaClippingRect); + KDRect rectToBeFilled = KDRectIntersection(absolutRect, KDCurrentContext->clippingRect); - ion_fill_rect(rectToBeFilled.x, rectToBeFilled.y, + KDCurrentContext->fillRect(rectToBeFilled.x, rectToBeFilled.y, rectToBeFilled.width, rectToBeFilled.height, color); }