tty-solitaire/src/frame.c

39 lines
831 B
C
Raw Normal View History

#include <stdio.h>
#include <stdlib.h>
#include <errno.h>
2011-06-03 05:48:26 +00:00
2010-04-01 05:28:00 +00:00
#include "frame.h"
2011-05-08 23:20:22 +00:00
#include "common.h"
2010-04-01 05:28:00 +00:00
2011-06-06 05:16:54 +00:00
void frame_malloc(struct frame **frame) {
if (!(*frame = malloc(sizeof(**frame)))) {
2011-06-19 22:36:29 +00:00
tty_solitaire_generic_error(errno, __FILE__, __LINE__);
}
(*frame)->window = newwin(FRAME_HEIGHT, FRAME_WIDTH, 0, 0);
}
2010-04-01 05:28:00 +00:00
2011-06-06 05:16:54 +00:00
void frame_init(struct frame *frame) {
2011-05-09 03:38:31 +00:00
frame->begin_y = 0;
frame->begin_x = 0;
2010-04-01 05:28:00 +00:00
}
2011-06-06 05:16:54 +00:00
void frame_free(struct frame *frame) {
2011-06-03 05:48:26 +00:00
delwin(frame->window);
2010-04-01 05:28:00 +00:00
free(frame);
}
2011-06-06 05:16:54 +00:00
void frame_set(struct frame *frame, int begin_y, int begin_x) {
2011-05-09 03:38:31 +00:00
frame->begin_y = begin_y;
frame->begin_x = begin_x;
mvwin(frame->window, begin_y, begin_x);
2010-04-01 05:28:00 +00:00
}
2011-06-03 05:48:26 +00:00
2011-06-06 05:16:54 +00:00
struct frame *frame_dup(struct frame *frame) {
2011-06-03 05:48:26 +00:00
struct frame *new_frame;
2011-06-06 05:16:54 +00:00
frame_malloc(&new_frame);
frame_set(new_frame, frame->begin_y, frame->begin_x);
2011-06-03 05:48:26 +00:00
return(new_frame);
}