1
0
mirror of https://github.com/pevans/erc-c.git synced 2024-06-25 12:29:34 +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
* necessarily be 1x1).
*/
#define vm_screen_draw_pixel(context, xpos, ypos) \
vm_screen_draw_rect(context, xpos, ypos, 1, 1)
#define vm_screen_draw_pixel(screen, xpos, ypos) \
vm_screen_draw_rect(screen, xpos, ypos, 1, 1)
typedef struct {
GLFWwindow *window;
@ -22,16 +22,16 @@ typedef struct {
int color_green;
int color_blue;
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 void vm_screen_finish();
extern void vm_screen_refresh(vm_screen_context *);
extern bool vm_screen_active(vm_screen_context *);
extern void vm_screen_draw_rect(vm_screen_context *, int, int, int, int);
extern void vm_screen_free_context(vm_screen_context *);
extern vm_screen_context *vm_screen_new_context();
extern void vm_screen_set_color(vm_screen_context *, int, int, int, int);
extern void vm_screen_refresh(vm_screen *);
extern bool vm_screen_active(vm_screen *);
extern void vm_screen_draw_rect(vm_screen *, int, int, int, int);
extern void vm_screen_free(vm_screen *);
extern vm_screen *vm_screen_create();
extern void vm_screen_set_color(vm_screen *, int, int, int, int);
#endif

View File

@ -76,7 +76,7 @@ int
main(int argc, char **argv)
{
apple2 *mach;
vm_screen_context *context;
vm_screen *screen;
int err;
init(argc, argv);
@ -94,19 +94,19 @@ main(int argc, char **argv)
exit(1);
}
context = vm_screen_new_context();
if (context == NULL) {
fprintf(stderr, "Screen context failed!\n");
screen = vm_screen_create();
if (screen == NULL) {
fprintf(stderr, "Screen creation failed!\n");
exit(1);
}
if (!vm_screen_add_window(context)) {
if (!vm_screen_add_window(screen)) {
fprintf(stderr, "Window creation failed!\n");
exit(1);
}
while (vm_screen_active(context)) {
vm_screen_refresh(context);
while (vm_screen_active(screen)) {
vm_screen_refresh(screen);
}
// 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_new_context()
vm_screen *
vm_screen_create()
{
vm_screen_context *context;
vm_screen *screen;
context = (vm_screen_context *)malloc(sizeof(vm_screen_context));
if (context == NULL) {
log_critical("Failed to allocate vm_screen_context");
screen = (vm_screen *)malloc(sizeof(vm_screen));
if (screen == NULL) {
log_critical("Failed to allocate vm_screen");
exit(1);
}
vm_screen_set_color(context, 0, 0, 0, 0);
return context;
vm_screen_set_color(screen, 0, 0, 0, 0);
return screen;
}
int
vm_screen_add_window(vm_screen_context *context)
vm_screen_add_window(vm_screen *screen)
{
context->window = glfwCreateWindow(320, 240, "erc", NULL, NULL);
if (context->window == NULL) {
screen->window = glfwCreateWindow(320, 240, "erc", NULL, NULL);
if (screen->window == NULL) {
log_critical("Could not create a window");
return ERR_GFXINIT;
}
glfwMakeContextCurrent(context->window);
glfwMakeContextCurrent(screen->window);
return OK;
}
/*
* Free the contents of a screen context.
* Free the contents of a screen.
*/
void
vm_screen_free_context(vm_screen_context *context)
vm_screen_free(vm_screen *screen)
{
free(context);
free(screen);
}
bool
vm_screen_active(vm_screen_context *context)
vm_screen_active(vm_screen *screen)
{
return !glfwWindowShouldClose(context->window);
return !glfwWindowShouldClose(screen->window);
}
void
vm_screen_refresh(vm_screen_context *context)
vm_screen_refresh(vm_screen *screen)
{
glClear(GL_COLOR_BUFFER_BIT);
glfwSwapBuffers(context->window);
glfwSwapBuffers(screen->window);
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
vm_screen_set_color(vm_screen_context *context,
vm_screen_set_color(vm_screen *screen,
int red,
int green,
int blue,
int alpha)
{
context->color_red = red;
context->color_green = green;
context->color_blue = blue;
context->color_alpha = alpha;
screen->color_red = red;
screen->color_green = green;
screen->color_blue = blue;
screen->color_alpha = alpha;
}
/*
* 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
vm_screen_draw_rect(vm_screen_context *context,
vm_screen_draw_rect(vm_screen *screen,
int xpos,
int ypos,
int xsize,

View File

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