mirror of
https://github.com/UpsilonNumworks/Upsilon.git
synced 2026-03-18 21:30:38 +01:00
Kandinsky: Use a KDContext
Change-Id: I91055c7b59586b0dec08a426a9c617a12d8128dc
This commit is contained in:
@@ -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);
|
||||
}
|
||||
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
SFLAGS += -Ikandinsky/include
|
||||
objs += $(addprefix kandinsky/src/,\
|
||||
drawing_area.o\
|
||||
context.o\
|
||||
font.o\
|
||||
line.o\
|
||||
pixel.o\
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
#define KANDINSKY_KANDINSKY_H
|
||||
|
||||
#include <kandinsky/color.h>
|
||||
#include <kandinsky/drawing_area.h>
|
||||
#include <kandinsky/context.h>
|
||||
#include <kandinsky/line.h>
|
||||
#include <kandinsky/pixel.h>
|
||||
#include <kandinsky/rect.h>
|
||||
|
||||
18
kandinsky/include/kandinsky/context.h
Normal file
18
kandinsky/include/kandinsky/context.h
Normal file
@@ -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
|
||||
@@ -1,12 +0,0 @@
|
||||
#ifndef KANDINSKY_DRAWING_AREA
|
||||
#define KANDINSKY_DRAWING_AREA 1
|
||||
|
||||
#include <kandinsky/rect.h>
|
||||
|
||||
/* 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
|
||||
19
kandinsky/src/context.c
Normal file
19
kandinsky/src/context.c
Normal file
@@ -0,0 +1,19 @@
|
||||
#include <kandinsky/context.h>
|
||||
#include <ion.h>
|
||||
|
||||
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;
|
||||
@@ -1,19 +0,0 @@
|
||||
#include <kandinsky/drawing_area.h>
|
||||
#include <ion.h>
|
||||
|
||||
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;
|
||||
}
|
||||
@@ -1,12 +1,12 @@
|
||||
#include <kandinsky/pixel.h>
|
||||
#include <kandinsky/rect.h>
|
||||
#include <kandinsky/context.h>
|
||||
#include <assert.h>
|
||||
#include <ion.h>
|
||||
#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);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,10 +0,0 @@
|
||||
#ifndef KANDINSKY_PRIVATE_DRAWING_AREA
|
||||
#define KANDINSKY_PRIVATE_DRAWING_AREA 1
|
||||
|
||||
#include <kandinsky/types.h>
|
||||
#include <kandinsky/rect.h>
|
||||
|
||||
extern KDPoint KDDrawingAreaOrigin;
|
||||
extern KDRect KDDrawingAreaClippingRect;
|
||||
|
||||
#endif
|
||||
@@ -1,8 +1,7 @@
|
||||
#include <kandinsky/rect.h>
|
||||
#include <kandinsky/pixel.h>
|
||||
#include <kandinsky/context.h>
|
||||
#include <string.h>
|
||||
#include "private/drawing_area.h"
|
||||
#include <ion.h>
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user