2011-02-06 05:44:45 +00:00
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
2010-04-01 05:28:00 +00:00
|
|
|
#include <malloc.h>
|
2011-02-06 05:44:45 +00:00
|
|
|
#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
|
|
|
|
2010-04-05 07:33:10 +00:00
|
|
|
void allocate_frame(struct frame **frame) {
|
2011-02-06 05:44:45 +00:00
|
|
|
if (!(*frame = malloc(sizeof(**frame)))) {
|
2011-05-08 23:20:22 +00:00
|
|
|
fprintf(stderr, tty_solitaire_error_message(errno, __FILE__, __LINE__));
|
2011-02-06 05:44:45 +00:00
|
|
|
exit(errno);
|
|
|
|
}
|
2010-04-05 07:33:10 +00:00
|
|
|
}
|
2010-04-01 05:28:00 +00:00
|
|
|
|
2010-04-05 07:33:10 +00:00
|
|
|
void initialize_frame(struct frame *frame) {
|
2011-05-09 03:50:56 +00:00
|
|
|
frame->window = NULL;
|
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;
|
2011-05-09 03:50:56 +00:00
|
|
|
frame->window = newwin(FRAME_HEIGHT,
|
|
|
|
FRAME_WIDTH,
|
|
|
|
frame->begin_y,
|
|
|
|
frame->begin_x);
|
2010-04-01 05:28:00 +00:00
|
|
|
}
|