mirror of
https://git.code.sf.net/p/quake/quakeforge
synced 2025-03-23 10:50:58 +00:00
[qwaq] Begin work on local drawing buffers
This commit is contained in:
parent
4978713dee
commit
e9eab68366
6 changed files with 148 additions and 21 deletions
|
@ -25,7 +25,9 @@ SUFFIXES=.o .r
|
|||
|
||||
qwaq_app_dat_src= \
|
||||
qwaq-app.r \
|
||||
qwaq-draw.r \
|
||||
qwaq-group.r \
|
||||
qwaq-rect.r \
|
||||
qwaq-screen.r \
|
||||
qwaq-textcontext.r \
|
||||
qwaq-view.r \
|
||||
|
|
|
@ -1,11 +1,26 @@
|
|||
#ifndef __qwaq_draw_h
|
||||
#define __qwaq_draw_h
|
||||
|
||||
@protocol Draw
|
||||
-draw;
|
||||
-redraw;
|
||||
-setOwner: owner;
|
||||
-(struct window_s*) getWindow;
|
||||
#include <Object.h>
|
||||
|
||||
#include "qwaq-rect.h"
|
||||
|
||||
@interface DrawBuffer : Object
|
||||
{
|
||||
int *buffer;
|
||||
Extent size;
|
||||
Point cursor;
|
||||
}
|
||||
+ (DrawBuffer *) buffer: (Extent) size;
|
||||
- initWithSize: (Extent) size;
|
||||
- blitFromBuffer: (DrawBuffer *) srcBuffer to: (Point) pos from: (Rect) rect;
|
||||
|
||||
- (void) printf: (string) fmt, ...;
|
||||
- (void) vprintf: (string) fmt, @va_list args;
|
||||
- (void) addch: (int) ch;
|
||||
- (void) mvprintf: (Point) pos, string fmt, ...;
|
||||
- (void) mvvprintf: (Point) pos, string fmt, @va_list args;
|
||||
- (void) mvaddch: (Point) pos, int ch;
|
||||
@end
|
||||
|
||||
#endif
|
||||
|
|
86
ruamoko/qwaq/qwaq-draw.r
Normal file
86
ruamoko/qwaq/qwaq-draw.r
Normal file
|
@ -0,0 +1,86 @@
|
|||
#include "qwaq-curses.h"
|
||||
#include "qwaq-draw.h"
|
||||
|
||||
@implementation DrawBuffer
|
||||
|
||||
+ (DrawBuffer *) buffer: (Extent) size
|
||||
{
|
||||
return [[self alloc] initWithSize: size];
|
||||
}
|
||||
|
||||
- initWithSize: (Extent) size
|
||||
{
|
||||
if (!(self = [super init])) {
|
||||
return nil;
|
||||
}
|
||||
buffer = obj_malloc (size.width * size.height);
|
||||
self.size = size;
|
||||
return self;
|
||||
}
|
||||
|
||||
- blitFromBuffer: (DrawBuffer *) srcBuffer to: (Point) pos from: (Rect) rect
|
||||
{
|
||||
Extent srcSize = srcBuffer.size;
|
||||
Rect r = { {}, srcBuffer.size };
|
||||
Rect t = { pos, rect.extent };
|
||||
|
||||
t = clipRect (r, t);
|
||||
if (t.extent.width < 0 || t.extent.height < 0) {
|
||||
return self;
|
||||
}
|
||||
|
||||
rect.offset.x += t.offset.x - pos.x;
|
||||
rect.offset.y += t.offset.y - pos.y;
|
||||
rect.extent = t.extent;
|
||||
pos = t.offset;
|
||||
|
||||
r.offset = nil;
|
||||
r.extent = size;
|
||||
|
||||
rect = clipRect (r, rect);
|
||||
if (rect.extent.width < 0 || rect.extent.height < 0) {
|
||||
return self;
|
||||
}
|
||||
|
||||
int *dst = buffer + pos.y * size.width + pos.x;
|
||||
int *src = srcBuffer.buffer
|
||||
+ rect.offset.y * srcSize.width + rect.offset.x;
|
||||
for (int y = 0; y < rect.extent.height; y++) {
|
||||
int *d = dst;
|
||||
int *s = src;
|
||||
dst += size.width;
|
||||
src += srcSize.width;
|
||||
for (int x = 0; x < rect.extent.width; x++) {
|
||||
// FIXME 1) need memcpy/memmove
|
||||
// 2) the generated code could be better
|
||||
*d++ = *s++;
|
||||
}
|
||||
}
|
||||
return self;
|
||||
}
|
||||
|
||||
- (void) printf: (string) fmt, ...
|
||||
{
|
||||
}
|
||||
|
||||
- (void) vprintf: (string) fmt, @va_list args
|
||||
{
|
||||
}
|
||||
|
||||
- (void) addch: (int) ch
|
||||
{
|
||||
}
|
||||
|
||||
- (void) mvprintf: (Point) pos, string fmt, ...
|
||||
{
|
||||
}
|
||||
|
||||
- (void) mvvprintf: (Point) pos, string fmt, @va_list args
|
||||
{
|
||||
}
|
||||
|
||||
- (void) mvaddch: (Point) pos, int ch
|
||||
{
|
||||
}
|
||||
|
||||
@end
|
|
@ -21,6 +21,7 @@ typedef struct Rect_s {
|
|||
//XXX will not work if point or rect point to a local variabl
|
||||
@extern int rectContainsPoint (Rect *rect, Point *point);
|
||||
@extern Rect getwrect (struct window_s *window);
|
||||
@extern Rect clipRect (Rect clipRect, Rect rect);
|
||||
#endif
|
||||
|
||||
#endif//__qwaq_rect_h
|
||||
|
|
39
ruamoko/qwaq/qwaq-rect.r
Normal file
39
ruamoko/qwaq/qwaq-rect.r
Normal file
|
@ -0,0 +1,39 @@
|
|||
#include "qwaq-rect.h"
|
||||
|
||||
Rect
|
||||
clipRect (Rect clipRect, Rect rect)
|
||||
{
|
||||
if (rect.offset.x < clipRect.offset.x) {
|
||||
int dist = clipRect.offset.x - rect.offset.x;
|
||||
rect.offset.x += dist;
|
||||
rect.extent.width -= dist;
|
||||
}
|
||||
if (rect.offset.y < clipRect.offset.y) {
|
||||
int dist = clipRect.offset.y - rect.offset.y;
|
||||
rect.offset.y += dist;
|
||||
rect.extent.height -= dist;
|
||||
}
|
||||
if (rect.offset.x + rect.extent.width > clipRect.extent.width) {
|
||||
rect.extent.width = clipRect.extent.width - rect.offset.x;
|
||||
}
|
||||
if (rect.offset.y + rect.extent.height > clipRect.extent.height) {
|
||||
rect.extent.height = clipRect.extent.height - rect.offset.y;
|
||||
}
|
||||
return rect;
|
||||
}
|
||||
|
||||
Rect
|
||||
makeRect (int xpos, int ypos, int xlen, int ylen)
|
||||
{
|
||||
Rect rect = {{xpos, ypos}, {xlen, ylen}};
|
||||
return rect;
|
||||
}
|
||||
|
||||
int
|
||||
rectContainsPoint (Rect *rect, Point *point)
|
||||
{
|
||||
return ((point.x >= rect.offset.x
|
||||
&& point.x < rect.offset.x + rect.extent.width)
|
||||
&& (point.y >= rect.offset.y
|
||||
&& point.y < rect.offset.y + rect.extent.height));
|
||||
}
|
|
@ -2,22 +2,6 @@
|
|||
#include "qwaq-view.h"
|
||||
#include "qwaq-group.h"
|
||||
|
||||
Rect
|
||||
makeRect (int xpos, int ypos, int xlen, int ylen)
|
||||
{
|
||||
Rect rect = {{xpos, ypos}, {xlen, ylen}};
|
||||
return rect;
|
||||
}
|
||||
|
||||
int
|
||||
rectContainsPoint (Rect *rect, Point *point)
|
||||
{
|
||||
return ((point.x >= rect.offset.x
|
||||
&& point.x < rect.offset.x + rect.extent.width)
|
||||
&& (point.y >= rect.offset.y
|
||||
&& point.y < rect.offset.y + rect.extent.height));
|
||||
}
|
||||
|
||||
@implementation View
|
||||
|
||||
-init
|
||||
|
|
Loading…
Reference in a new issue