1
0
mirror of https://github.com/pevans/erc-c.git synced 2025-01-02 09:29:58 +00:00

Rename vm_screen_context to vm_screen

This commit is contained in:
Peter Evans 2017-12-17 16:42:05 -06:00
parent 8beb761535
commit a73c15c37c
4 changed files with 62 additions and 62 deletions

View File

@ -9,8 +9,8 @@
* abstract away the need to indicate the x/y dimensions (as those must * abstract away the need to indicate the x/y dimensions (as those must
* necessarily be 1x1). * necessarily be 1x1).
*/ */
#define vm_screen_draw_pixel(context, xpos, ypos) \ #define vm_screen_draw_pixel(screen, xpos, ypos) \
vm_screen_draw_rect(context, xpos, ypos, 1, 1) vm_screen_draw_rect(screen, xpos, ypos, 1, 1)
typedef struct { typedef struct {
GLFWwindow *window; GLFWwindow *window;
@ -22,16 +22,16 @@ typedef struct {
int color_green; int color_green;
int color_blue; int color_blue;
int color_alpha; int color_alpha;
} vm_screen_context; } vm_screen;
extern int vm_screen_add_window(vm_screen_context *); extern int vm_screen_add_window(vm_screen *);
extern int vm_screen_init(); extern int vm_screen_init();
extern void vm_screen_finish(); extern void vm_screen_finish();
extern void vm_screen_refresh(vm_screen_context *); extern void vm_screen_refresh(vm_screen *);
extern bool vm_screen_active(vm_screen_context *); extern bool vm_screen_active(vm_screen *);
extern void vm_screen_draw_rect(vm_screen_context *, int, int, int, int); extern void vm_screen_draw_rect(vm_screen *, int, int, int, int);
extern void vm_screen_free_context(vm_screen_context *); extern void vm_screen_free(vm_screen *);
extern vm_screen_context *vm_screen_new_context(); extern vm_screen *vm_screen_create();
extern void vm_screen_set_color(vm_screen_context *, int, int, int, int); extern void vm_screen_set_color(vm_screen *, int, int, int, int);
#endif #endif

View File

@ -76,7 +76,7 @@ int
main(int argc, char **argv) main(int argc, char **argv)
{ {
apple2 *mach; apple2 *mach;
vm_screen_context *context; vm_screen *screen;
int err; int err;
init(argc, argv); init(argc, argv);
@ -94,19 +94,19 @@ main(int argc, char **argv)
exit(1); exit(1);
} }
context = vm_screen_new_context(); screen = vm_screen_create();
if (context == NULL) { if (screen == NULL) {
fprintf(stderr, "Screen context failed!\n"); fprintf(stderr, "Screen creation failed!\n");
exit(1); exit(1);
} }
if (!vm_screen_add_window(context)) { if (!vm_screen_add_window(screen)) {
fprintf(stderr, "Window creation failed!\n"); fprintf(stderr, "Window creation failed!\n");
exit(1); exit(1);
} }
while (vm_screen_active(context)) { while (vm_screen_active(screen)) {
vm_screen_refresh(context); vm_screen_refresh(screen);
} }
// ha ha ha ha #nervous #laughter // ha ha ha ha #nervous #laughter

View File

@ -28,84 +28,84 @@ vm_screen_finish()
} }
/* /*
* Return a new screen context. We also set the color to black. * Return a new screen. We also set the color to black.
*/ */
vm_screen_context * vm_screen *
vm_screen_new_context() vm_screen_create()
{ {
vm_screen_context *context; vm_screen *screen;
context = (vm_screen_context *)malloc(sizeof(vm_screen_context)); screen = (vm_screen *)malloc(sizeof(vm_screen));
if (context == NULL) { if (screen == NULL) {
log_critical("Failed to allocate vm_screen_context"); log_critical("Failed to allocate vm_screen");
exit(1); exit(1);
} }
vm_screen_set_color(context, 0, 0, 0, 0); vm_screen_set_color(screen, 0, 0, 0, 0);
return context; return screen;
} }
int int
vm_screen_add_window(vm_screen_context *context) vm_screen_add_window(vm_screen *screen)
{ {
context->window = glfwCreateWindow(320, 240, "erc", NULL, NULL); screen->window = glfwCreateWindow(320, 240, "erc", NULL, NULL);
if (context->window == NULL) { if (screen->window == NULL) {
log_critical("Could not create a window"); log_critical("Could not create a window");
return ERR_GFXINIT; return ERR_GFXINIT;
} }
glfwMakeContextCurrent(context->window); glfwMakeContextCurrent(screen->window);
return OK; return OK;
} }
/* /*
* Free the contents of a screen context. * Free the contents of a screen.
*/ */
void void
vm_screen_free_context(vm_screen_context *context) vm_screen_free(vm_screen *screen)
{ {
free(context); free(screen);
} }
bool bool
vm_screen_active(vm_screen_context *context) vm_screen_active(vm_screen *screen)
{ {
return !glfwWindowShouldClose(context->window); return !glfwWindowShouldClose(screen->window);
} }
void void
vm_screen_refresh(vm_screen_context *context) vm_screen_refresh(vm_screen *screen)
{ {
glClear(GL_COLOR_BUFFER_BIT); glClear(GL_COLOR_BUFFER_BIT);
glfwSwapBuffers(context->window); glfwSwapBuffers(screen->window);
glfwPollEvents(); glfwPollEvents();
} }
/* /*
* Set the color of a screen context to a given RGBA value. * Set the color of a screen screen to a given RGBA value.
*/ */
void void
vm_screen_set_color(vm_screen_context *context, vm_screen_set_color(vm_screen *screen,
int red, int red,
int green, int green,
int blue, int blue,
int alpha) int alpha)
{ {
context->color_red = red; screen->color_red = red;
context->color_green = green; screen->color_green = green;
context->color_blue = blue; screen->color_blue = blue;
context->color_alpha = alpha; screen->color_alpha = alpha;
} }
/* /*
* Draw a rectangle on the screen at a given x/y position, with a given * Draw a rectangle on the screen at a given x/y position, with a given
* set of x/y dimensions, with a given screen context. * set of x/y dimensions, with a given screen.
*/ */
void void
vm_screen_draw_rect(vm_screen_context *context, vm_screen_draw_rect(vm_screen *screen,
int xpos, int xpos,
int ypos, int ypos,
int xsize, int xsize,

View File

@ -2,36 +2,36 @@
#include "vm_screen.h" #include "vm_screen.h"
Test(vm_screen, new_context) { Test(vm_screen, create) {
vm_screen_context *context; vm_screen *screen;
context = vm_screen_new_context(); screen = vm_screen_create();
cr_assert_neq(context, NULL); cr_assert_neq(screen, NULL);
cr_assert_eq(context->color_red, 0); cr_assert_eq(screen->color_red, 0);
cr_assert_eq(context->color_blue, 0); cr_assert_eq(screen->color_blue, 0);
cr_assert_eq(context->color_green, 0); cr_assert_eq(screen->color_green, 0);
cr_assert_eq(context->color_alpha, 0); cr_assert_eq(screen->color_alpha, 0);
vm_screen_free_context(context); vm_screen_free(screen);
} }
Test(vm_screen, set_color) { Test(vm_screen, set_color) {
vm_screen_context *context; vm_screen *screen;
int red = 0xDE; int red = 0xDE;
int green = 0xAD; int green = 0xAD;
int blue = 0xBE; int blue = 0xBE;
int alpha = 0xEF; int alpha = 0xEF;
context = vm_screen_new_context(); screen = vm_screen_create();
vm_screen_set_color(context, red, green, blue, alpha); vm_screen_set_color(screen, red, green, blue, alpha);
cr_assert_eq(context->color_red, red); cr_assert_eq(screen->color_red, red);
cr_assert_eq(context->color_green, green); cr_assert_eq(screen->color_green, green);
cr_assert_eq(context->color_blue, blue); cr_assert_eq(screen->color_blue, blue);
cr_assert_eq(context->color_alpha, alpha); cr_assert_eq(screen->color_alpha, alpha);
vm_screen_free_context(context); vm_screen_free(screen);
} }
Test(vm_screen, draw_rect) { Test(vm_screen, draw_rect) {