]> git.mdlowis.com Git - archive/afm.git/commitdiff
Window resizing works better now
authorMichael D. Lowis <mike@mdlowis.com>
Fri, 18 Jul 2014 02:12:51 +0000 (22:12 -0400)
committerMichael D. Lowis <mike@mdlowis.com>
Fri, 18 Jul 2014 02:12:51 +0000 (22:12 -0400)
source/main.c

index 392118c40de5be418db19e676ca4a49687213110..f01f251c37be45c92d7acc9ed85e0fec9739c517 100644 (file)
@@ -2,9 +2,17 @@
 #include <stdbool.h>
 #include <signal.h>
 
+typedef struct {
+    char* title;
+} Window_T;
+
 static bool Running = true;
-//static int Term_X = 0;
-//static int Term_Y = 0;
+static bool Screen_Dirty = true;
+Window_T Windows[2] = {
+    { "Left" },
+    { "Right" }
+};
+
 static WINDOW* WindowLeft;
 static WINDOW* WindowRight;
 
@@ -28,20 +36,55 @@ void destroy_window(WINDOW* p_win) {
     delwin(p_win);
 }
 
+/*
+ * This routine draws a frame around a specified part of the console
+ * screen, using special characters such as ACS_ULCORNER and ACS_VLINE.
+ * The frame extends from startrow to endrow vertically and from
+ * startcol to endcol horizontally.  (Rows and columns are numbered
+ * starting from 0.)  Note that the interior of the frame extends
+ * from startrow+1 to endrow-1 vertically and from startcol+1 to
+ * endcol-1 horizontally.
+ */
+void drawFrame(char* p_label, int startrow, int startcol, int endrow, int endcol) {
+   //int saverow, savecol;
+   //getyx(stdscr,saverow,savecol);
+   //mvaddch(startrow,startcol,ACS_ULCORNER);
+   //for (int i = startcol + 1; i < endcol; i++)
+   //   addch(ACS_HLINE);
+   //addch(ACS_URCORNER);
+   //for (int i = startrow +1; i < endrow; i++) {
+   //   mvaddch(i,startcol,ACS_VLINE);
+   //   mvaddch(i,endcol,ACS_VLINE);
+   //}
+   //mvaddch(endrow,startcol,ACS_LLCORNER);
+   //for (int i = startcol + 1; i < endcol; i++)
+   //   addch(ACS_HLINE);
+   //addch(ACS_LRCORNER);
+   //move(saverow,savecol);
+   //refresh();
+}
+
 void update_screen(void) {
+    int rows, cols;
     endwin();
-    /* Create the left and right windows */
-    WindowLeft  = create_window(0,0,LINES,COLS/2);
-    wprintw(WindowLeft,  "\rLeft");
-    wrefresh(WindowLeft);
-    WindowRight = create_window(COLS/2,0,LINES,COLS/2);
-    wprintw(WindowRight, "\rRight");
-    wrefresh(WindowRight);
+    clear();
+    getmaxyx(stdscr,rows,cols);
+    //move(5,5);      printw("%d %d",rows,cols);
+    mvaddch(0,      0,      ACS_ULCORNER);
+    mvhline(0,      1,      ACS_HLINE, cols-2);
+    mvaddch(0,      cols-1, ACS_URCORNER);
+    mvvline(1,      0,      ACS_VLINE, rows-2);
+    mvaddch(rows-1, 0,      ACS_LLCORNER);
+    mvhline(rows-1, 1,      ACS_HLINE, cols-2);
+    mvaddch(rows-1, cols-1, ACS_LRCORNER);
+    mvvline(1,      cols-1, ACS_VLINE, rows-2);
+    refresh();
+    Screen_Dirty = false;
 }
 
 void handle_signal(int sig) {
-    update_screen();
     signal(SIGWINCH, handle_signal);
+    Screen_Dirty = true;
 }
 
 int main(int argc, char** argv) {
@@ -52,9 +95,10 @@ int main(int argc, char** argv) {
     raw();
     keypad(stdscr, TRUE);
     noecho();
+    timeout(25);
     refresh();
     while(Running) {
-        update_screen();
+        if(Screen_Dirty) update_screen();
         handle_input(getch());
     }
     destroy_window(WindowLeft);