2017-11-22 05:24:51 +00:00
|
|
|
#ifndef _VM_SCREEN_H_
|
|
|
|
#define _VM_SCREEN_H_
|
|
|
|
|
2017-12-17 04:45:39 +00:00
|
|
|
#include <stdbool.h>
|
2017-12-18 05:31:56 +00:00
|
|
|
#include <SDL.h>
|
2017-12-17 04:45:39 +00:00
|
|
|
|
2017-12-27 22:31:02 +00:00
|
|
|
typedef struct {
|
2017-12-27 22:59:56 +00:00
|
|
|
/*
|
|
|
|
* These are the x and y coordinate offsets in the logical dimension
|
|
|
|
* established in a vm_screen. An offset of (0, 0) would be in the
|
|
|
|
* top-left; (5, 5) would be 5 pixels down, and 5 pixels to the
|
|
|
|
* right, of that top-left corner.
|
|
|
|
*/
|
2017-12-27 22:31:02 +00:00
|
|
|
int xoff;
|
|
|
|
int yoff;
|
|
|
|
|
2017-12-27 22:59:56 +00:00
|
|
|
/*
|
|
|
|
* These are the width and height of the area we're defining. A
|
|
|
|
* single pixel in the logical area would have a width and height of
|
|
|
|
* (1, 1); use larger numbers to indicate a larger square (if the
|
|
|
|
* two are equal) or rectangle (if unequal).
|
|
|
|
*/
|
2017-12-27 22:31:02 +00:00
|
|
|
int width;
|
|
|
|
int height;
|
|
|
|
} vm_area;
|
|
|
|
|
2017-11-22 05:24:51 +00:00
|
|
|
typedef struct {
|
2017-12-27 23:14:54 +00:00
|
|
|
/*
|
|
|
|
* This is the window in SDL that we're displaying. It's fine for a
|
|
|
|
* screen to be headless; that is, not to have a window. Screen
|
|
|
|
* functions which deal with SDL will simply not run that code if
|
|
|
|
* headless.
|
|
|
|
*/
|
2017-12-18 05:31:56 +00:00
|
|
|
SDL_Window *window;
|
2017-12-27 23:14:54 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* In SDL, the renderer is comparable to the old SDL_Surface type
|
|
|
|
* (which is still there!). A renderer is a little more stateful; it
|
|
|
|
* contains its own color information to be used when rendering
|
|
|
|
* shapes, for example.
|
|
|
|
*/
|
2017-12-18 05:31:56 +00:00
|
|
|
SDL_Renderer *render;
|
|
|
|
|
2017-12-27 23:14:54 +00:00
|
|
|
/*
|
|
|
|
* These are the x and y coordinates of the window we're creating.
|
|
|
|
* FIXME: this should probably be renamed to width and height...
|
|
|
|
*/
|
2017-12-18 05:31:56 +00:00
|
|
|
int xcoords;
|
|
|
|
int ycoords;
|
2017-12-17 22:42:05 +00:00
|
|
|
} vm_screen;
|
2017-11-22 05:24:51 +00:00
|
|
|
|
2017-12-27 23:14:54 +00:00
|
|
|
/*
|
|
|
|
* Set the contents of an SDL_Rect to the equivalent fields contained in
|
|
|
|
* a vm_area.
|
|
|
|
*/
|
2017-12-27 22:31:02 +00:00
|
|
|
#define SET_SDL_RECT(name, a) \
|
|
|
|
(name).x = (a).xoff; \
|
|
|
|
(name).y = (a).yoff; \
|
|
|
|
(name).w = (a).width; \
|
|
|
|
(name).h = (a).height
|
|
|
|
|
2017-12-27 23:14:54 +00:00
|
|
|
/*
|
|
|
|
* Much like SET_SDL_RECT(), except this will (as a side-effect!)
|
|
|
|
* declare an SDL_Rect variable (`name`) and pass that into the SET
|
|
|
|
* macro.
|
|
|
|
*/
|
2017-12-27 22:31:02 +00:00
|
|
|
#define MAKE_SDL_RECT(name, a) \
|
|
|
|
SDL_Rect name; \
|
|
|
|
SET_SDL_RECT(name, a)
|
|
|
|
|
2017-12-26 22:47:34 +00:00
|
|
|
extern bool vm_screen_active(vm_screen *);
|
2017-12-27 23:10:51 +00:00
|
|
|
extern void vm_area_set(vm_area *, int, int, int, int);
|
2017-12-20 22:44:24 +00:00
|
|
|
extern int vm_screen_add_window(vm_screen *, int, int);
|
2017-12-26 22:47:34 +00:00
|
|
|
extern int vm_screen_init();
|
2017-12-20 22:44:24 +00:00
|
|
|
extern int vm_screen_xcoords(vm_screen *);
|
|
|
|
extern int vm_screen_ycoords(vm_screen *);
|
2017-12-26 22:47:34 +00:00
|
|
|
extern vm_screen *vm_screen_create();
|
2017-12-27 22:42:30 +00:00
|
|
|
extern void vm_screen_draw_rect(vm_screen *, vm_area *);
|
2017-12-26 22:47:34 +00:00
|
|
|
extern void vm_screen_finish();
|
2017-12-17 22:42:05 +00:00
|
|
|
extern void vm_screen_free(vm_screen *);
|
2017-12-26 22:47:34 +00:00
|
|
|
extern void vm_screen_refresh(vm_screen *);
|
2017-12-18 05:31:56 +00:00
|
|
|
extern void vm_screen_set_color(vm_screen *, uint8_t, uint8_t, uint8_t, uint8_t);
|
2017-12-26 22:47:34 +00:00
|
|
|
extern void vm_screen_set_logical_coords(vm_screen *, int, int);
|
2017-11-22 05:24:51 +00:00
|
|
|
|
|
|
|
#endif
|