tty-solitaire/lib/frame.c

43 lines
941 B
C
Raw Normal View History

#include <stdio.h>
#include <stdlib.h>
2010-04-01 05:28:00 +00:00
#include <malloc.h>
#include <string.h>
#include <errno.h>
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
void allocate_frame(struct frame **frame) {
if (!(*frame = malloc(sizeof(**frame)))) {
2011-05-08 23:20:22 +00:00
fprintf(stderr, tty_solitaire_error_message(errno, __FILE__, __LINE__));
exit(errno);
}
(*frame)->window = newwin(FRAME_HEIGHT, FRAME_WIDTH, 0, 0);
}
2010-04-01 05:28:00 +00:00
void initialize_frame(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-05-01 06:06:43 +00:00
struct frame *duplicate_frame(struct frame *frame) {
struct frame *new_frame;
allocate_frame(&new_frame);
2011-05-09 03:38:31 +00:00
set_frame(new_frame, frame->begin_y, frame->begin_x);
2011-05-01 06:06:43 +00:00
return(new_frame);
}
2011-02-14 02:10:47 +00:00
void free_frame(struct frame *frame) {
2011-02-12 03:26:03 +00:00
if (frame) {
2011-05-09 03:50:56 +00:00
delwin(frame->window);
2011-02-12 03:26:03 +00:00
}
2010-04-01 05:28:00 +00:00
free(frame);
}
2011-05-09 03:38:31 +00:00
void set_frame(struct frame *frame, int begin_y, int begin_x) {
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
}