]> git.mdlowis.com Git - archive/afm.git/commitdiff
partial implementation of window handling
authorMichael D. Lowis <mike@mdlowis.com>
Sun, 20 Jul 2014 23:44:23 +0000 (19:44 -0400)
committerMichael D. Lowis <mike@mdlowis.com>
Sun, 20 Jul 2014 23:44:23 +0000 (19:44 -0400)
source/input.c
source/main.c
source/screen.c
source/screen.h

index 1606ec3d14ac1ea20f096ade6cd04c518766eb7a..2f147d298cb9b3bd121ba5f3915d106f666a3134 100644 (file)
@@ -1,6 +1,7 @@
 #include "input.h"
 #include "state.h"
 #include "workdir.h"
+#include "screen.h"
 
 void input_handle_key(char ch) {
     /* Assume screen is dirty by default */
@@ -16,6 +17,10 @@ void input_handle_key(char ch) {
                   break;
         case 'e': workdir_cd();
                   break;
+        case 'n': screen_open();
+                  break;
+        case 'c': screen_close();
+                  break;
         default:  is_screen_dirty = false;
                   break;
     }
index 1144df3c89640162eb63ad3d7d52d80995ff12c4..8417d56869499672a36964138796a3e993ed8dba 100644 (file)
@@ -29,6 +29,7 @@ int main(int argc, char** argv) {
     noecho();
     timeout(25);
     refresh();
+    screen_init();
     while(state_get_running()) {
         if(state_get_screen_dirty()) screen_update();
         input_handle_key(getch());
index 3e82e35aa480b6742a9b8685413a6d29ba394052..e2096cdd842ed4888f3f009c965d7c9627d9254b 100644 (file)
@@ -3,6 +3,24 @@
 #include "aardvark.h"
 #include "workdir.h"
 #include <ncurses.h>
+#include "vec.h"
+#include "mem.h"
+
+typedef struct {
+    WINDOW* p_win;
+} frame_t;
+
+static void screen_place_windows(void);
+static frame_t* screen_frame_new(void);
+static void screen_frame_free(void* p_frame);
+
+static int Master_Idx;
+static vec_t* Screen_List;
+
+void screen_init(void) {
+    Screen_List = vec_new(1, screen_frame_new());
+    Master_Idx = 0;
+}
 
 void screen_update(void) {
     /* Clear screen and update LINES and COLS */
@@ -11,19 +29,52 @@ void screen_update(void) {
         state_set_screen_resized(false);
     }
     clear();
-    //should probably redraw all, but since only one window exists, it doesn't matter
-    workdir_ls();
+    refresh();
+    screen_place_windows();
     if(state_get_aardvark_mode()) aardvark_draw();
-    /* Draw the Border */
-    mvaddch(0,       0,      ACS_ULCORNER);
-    mvhline(0,       1,      ACS_HLINE, COLS-2);
-    mvaddch(0,       COLS-1, ACS_URCORNER);
-    mvvline(1,       0,      ACS_VLINE, LINES-2);
-    mvaddch(LINES-1, 0,      ACS_LLCORNER);
-    mvhline(LINES-1, 1,      ACS_HLINE, COLS-2);
-    mvaddch(LINES-1, COLS-1, ACS_LRCORNER);
-    mvvline(1,       COLS-1, ACS_VLINE, LINES-2);
     /* Refresh and mark complete */
-    refresh();
     state_set_screen_dirty(false);
 }
+
+void screen_open(void) {
+    vec_push_back(Screen_List, screen_frame_new());
+}
+
+void screen_close(void) {
+    vec_erase(Screen_List, 0, 1);
+}
+
+static void screen_place_windows(void) {
+    frame_t* p_frame;
+    int i, lines, cols;
+    getmaxyx(stdscr, lines, cols);
+    move(0,0);
+    for(i = 0; i < vec_size(Screen_List); i++) {
+        p_frame = (frame_t*)vec_at(Screen_List, i);
+        printw("%d", vec_size(Screen_List));
+        if(i == Master_Idx) {
+            wmove(p_frame->p_win, 0, 0);
+            wresize(p_frame->p_win, lines, (vec_size(Screen_List) == 1) ? cols : cols/2);
+            box(p_frame->p_win, 0 , 0);
+            wrefresh(p_frame->p_win);
+        } else {
+            wmove(p_frame->p_win, 0, cols/2);
+            wresize(p_frame->p_win, lines, cols/2);
+            box(p_frame->p_win, 0 , 0);
+            wrefresh(p_frame->p_win);
+        }
+    }
+}
+
+static frame_t* screen_frame_new(void) {
+    frame_t* p_frame = (frame_t*)mem_allocate(sizeof(frame_t),&screen_frame_free);
+    p_frame->p_win = newwin(LINES, COLS, 0, 0);
+    return p_frame;
+}
+
+static void screen_frame_free(void* p_frame_ptr) {
+    frame_t* p_frame = (frame_t*)p_frame_ptr;
+    wborder(p_frame->p_win, ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ');
+    wrefresh(p_frame->p_win);
+    delwin(p_frame->p_win);
+}
index d400a41f70b0415a5fa43233137fbc0419de55c7..44f7114f70926ff9eb25fda956bdaf62e16b4e7d 100644 (file)
@@ -7,6 +7,9 @@
 #ifndef SCREEN_H
 #define SCREEN_H
 
+void screen_init(void);
 void screen_update(void);
+void screen_open(void);
+void screen_close(void);
 
 #endif /* SCREEN_H */