#include "aardvark.h"
#include "workdir.h"
#include <ncurses.h>
-#include "vec.h"
+#include "list.h"
#include "mem.h"
typedef struct {
static frame_t* screen_frame_new(void);
static void screen_frame_free(void* p_frame);
-static frame_t* Master;
-static vec_t* Screen_List;
+static list_t* Screen_List;
void screen_init(void) {
- Master = screen_frame_new();
- Screen_List = vec_new(0);
+ Screen_List = list_new();
+ list_push_back(Screen_List, screen_frame_new());
+}
+
+void screen_deinit(void) {
+ mem_release(Screen_List);
}
void screen_update(void) {
}
void screen_open(void) {
- vec_push_back(Screen_List, screen_frame_new());
+ list_push_back(Screen_List, screen_frame_new());
}
void screen_close(void) {
- vec_erase(Screen_List, 0, 0);
+ int num_frames = list_size(Screen_List);
+ if(num_frames > 1)
+ list_delete(Screen_List, 0);
}
static void screen_place_windows(void) {
frame_t* p_frame;
- int i, lines, cols;
+ int id, pos, lines, cols;
+ int num_frames = list_size(Screen_List);
+ list_node_t* p_node;
getmaxyx(stdscr, lines, cols);
/* Print the master frame */
- p_frame = Master;
+ p_frame = list_at(Screen_List,0)->contents;
mvwin(p_frame->p_win, 0, 0);
- wresize(p_frame->p_win, lines, (vec_size(Screen_List) > 0) ? cols/2 : cols);
+ wresize(p_frame->p_win, lines, (num_frames > 1) ? cols/2 : cols);
wclear(p_frame->p_win);
box(p_frame->p_win, 0 , 0);
wrefresh(p_frame->p_win);
/* Print any other frames we might have */
- int pos = 0;
- for(i = 0; i < vec_size(Screen_List); i++) {
- int remain = (lines % vec_size(Screen_List));
- int height = (lines / vec_size(Screen_List)) + (i < remain ? 1 : 0);
- p_frame = (frame_t*)vec_at(Screen_List, i);
+ p_node = list_at(Screen_List,1);
+ pos = 0;
+ id = 1;
+ while(p_node != NULL) {
+ /* Get the frame and it's properties */
+ int remain = (lines % (num_frames-1));
+ int height = (lines / (num_frames-1)) + (id <= remain ? 1 : 0);
+ p_frame = p_node->contents;
+ /* Place the frame */
mvwin(p_frame->p_win, pos, cols/2);
wresize(p_frame->p_win, height, cols/2);
wclear(p_frame->p_win);
wmove(p_frame->p_win, 1, 1);
- wprintw(p_frame->p_win, "(%d, %d)", i*height, cols/2);
box(p_frame->p_win, 0 , 0);
wrefresh(p_frame->p_win);
+ /* Get the next one */
+ id++;
pos += height;
+ p_node = p_node->next;
}
}