Resize the window. Need to figure out scaling still.

This commit is contained in:
kvothe. 2020-08-31 22:14:44 -04:00
parent 8f68462d36
commit f7c267390c
3 changed files with 43 additions and 0 deletions

View File

@ -34,6 +34,8 @@ void main(void)
if(initdraw(nil, nil, "Another Plan") < 0) {
sysfatal("initdraw failed: %r");
}
resizewin(Pt(SCREEN_WIDTH * DEFAULT_SCALE, SCREEN_HEIGHT * DEFAULT_SCALE));
initGraphics(&ballPos);
einit(Emouse | Ekeyboard);

View File

@ -20,6 +20,39 @@ void initGraphics(Point *pBallPos)
freeimage(brush);
}
/* shamelessly lifted from page.c and modified to suit */
void
resizewin(Point size)
{
int wctl;
if((wctl = open("/dev/wctl", OWRITE)) < 0)
return;
/* add rio border */
size = addpt(size, Pt(Borderwidth*2, Borderwidth*2));
if(display->image != nil){
Point dsize = subpt(display->image->r.max, display->image->r.min);
if(size.x > dsize.x)
size.x = dsize.x;
if(size.y > dsize.y)
size.y = dsize.y;
/* can't just conver whole display */
if(eqpt(size, dsize))
size.y--;
}
fprint(wctl, "resize -dx %d -dy %d\n", size.x, size.y);
close(wctl);
/* initdraw() must also be called after resizing. */
if(initdraw(nil, nil, "Another Plan") < 0) {
sysfatal("initdraw failed: %r");
}
/*
* TODO: use something like libdraw's scalesize()
* to upscale the native 320x200 res.
*/
}
void render(void)
{
draw(

View File

@ -1,5 +1,13 @@
#ifndef GRAPHICS_H
#define GRAPHICS_H
enum {
SCREEN_WIDTH = 320,
SCREEN_HEIGHT = 200,
DEFAULT_SCALE = 2
};
void initGraphics(Point *pBallPos);
void resizewin(Point size);
void render(void);
#endif /* GRAPHICS_H */