Numworks Epsilon  1.4.1
Graphing Calculator Operating System
tiled_view.cpp
Go to the documentation of this file.
1 #include <escher/tiled_view.h>
2 #include <assert.h>
3 
4 void TiledView::drawRect(KDContext * ctx, KDRect rect) const {
5  KDColor * pixels = tile();
6  KDSize size = tileSize();
7  KDFrameBuffer tileBuffer(pixels, size);
8  KDFrameBufferContext tileContext = KDFrameBufferContext(&tileBuffer);
9 
10  for (int i=0; i<(rect.width()/size.width()+1); i++) {
11  for (int j=0; j<(rect.height()/size.height()+1); j++) {
12  KDRect tileRect(
13  rect.x() + i*size.width(),
14  rect.y() + j*size.height(),
15  size.width(), size.height()
16  );
17  //tileRect = KDRectIntersection(tileRect, rect); // Optional
18  KDPoint origin = tileRect.origin().opposite();
19  tileContext.setOrigin(origin);
20 
21  drawTile(&tileContext, tileRect);
22 
23  ctx->fillRectWithPixels(tileRect, pixels, pixels);
24  }
25  }
26 }
KDCoordinate x() const
Definition: rect.h:36
constexpr KDCoordinate width() const
Definition: size.h:10
virtual void drawTile(KDContext *ctx, KDRect rect) const =0
void setOrigin(KDPoint origin)
Definition: context.cpp:10
Definition: point.h:6
Definition: size.h:6
void drawRect(KDContext *ctx, KDRect rect) const override
Definition: tiled_view.cpp:4
virtual KDSize tileSize() const =0
virtual KDColor * tile() const =0
void fillRectWithPixels(KDRect rect, const KDColor *pixels, KDColor *workingBuffer)
KDCoordinate y() const
Definition: rect.h:37
Definition: rect.h:26
Definition: color.h:6
KDPoint opposite() const
Definition: point.cpp:7
KDCoordinate width() const
Definition: rect.h:39
KDCoordinate height() const
Definition: rect.h:40
constexpr KDCoordinate height() const
Definition: size.h:11