Code

screen: moved more (de)initialization code to progress_bar.c
authorMax Kellermann <max@duempel.org>
Wed, 30 Sep 2009 06:21:57 +0000 (08:21 +0200)
committerMax Kellermann <max@duempel.org>
Wed, 30 Sep 2009 06:21:57 +0000 (08:21 +0200)
src/progress_bar.c
src/progress_bar.h
src/screen.c

index 8fe278468000e799b8e7972b87a64d31efa1b4b4..37a397715847f1c2105728cd8bc0d3d64434bfdd 100644 (file)
@@ -40,13 +40,11 @@ progress_bar_paint(const struct progress_bar *p)
        wnoutrefresh(p->window.w);
 }
 
-bool
-progress_bar_resize(struct progress_bar *p)
+static bool
+progress_bar_calc(struct progress_bar *p)
 {
        unsigned old_width;
 
-       assert(p != NULL);
-
        if (p->max == 0)
                return false;
 
@@ -57,6 +55,18 @@ progress_bar_resize(struct progress_bar *p)
        return p->width != old_width;
 }
 
+void
+progress_bar_resize(struct progress_bar *p, unsigned width, int y, int x)
+{
+       assert(p != NULL);
+
+       p->window.cols = width;
+       wresize(p->window.w, 1, width);
+       mvwin(p->window.w, y, x);
+
+       progress_bar_calc(p);
+}
+
 bool
 progress_bar_set(struct progress_bar *p, unsigned current, unsigned max)
 {
@@ -72,5 +82,5 @@ progress_bar_set(struct progress_bar *p, unsigned current, unsigned max)
        p->max = max;
        p->current = current;
 
-       return progress_bar_resize(p) || modified;
+       return progress_bar_calc(p) || modified;
 }
index d6fdba5b0235a967ab4b7eea539387f957181d06..94a76002bcf83d48d9849c81f37f1b44572dde88 100644 (file)
@@ -33,21 +33,27 @@ struct progress_bar {
 };
 
 static inline void
-progress_bar_init(struct progress_bar *p, unsigned height, unsigned width,
-                 int y, int x)
+progress_bar_init(struct progress_bar *p, unsigned width, int y, int x)
 {
-       window_init(&p->window, height, width, y, x);
+       window_init(&p->window, 1, width, y, x);
+       leaveok(p->window.w, TRUE);
 
        p->current = 0;
        p->max = 0;
        p->width = 0;
 }
 
+static inline void
+progress_bar_deinit(struct progress_bar *p)
+{
+       delwin(p->window.w);
+}
+
 void
 progress_bar_paint(const struct progress_bar *p);
 
-bool
-progress_bar_resize(struct progress_bar *p);
+void
+progress_bar_resize(struct progress_bar *p, unsigned width, int y, int x);
 
 bool
 progress_bar_set(struct progress_bar *p, unsigned current, unsigned max);
index 15a98d08e25b647f659fcb56bbd8567f94851c46..a4f0a89eb26bc730d45fec68c22c1cc527b1a512 100644 (file)
@@ -454,7 +454,7 @@ screen_exit(void)
 
        delwin(screen.top_window.w);
        delwin(screen.main_window.w);
-       delwin(screen.progress_bar.window.w);
+       progress_bar_deinit(&screen.progress_bar);
        delwin(screen.status_window.w);
 }
 
@@ -483,10 +483,8 @@ screen_resize(struct mpdclient *c)
        wclear(screen.main_window.w);
 
        /* progress window */
-       screen.progress_bar.window.cols = screen.cols;
-       wresize(screen.progress_bar.window.w, 1, screen.cols);
-       mvwin(screen.progress_bar.window.w, screen.rows-2, 0);
-       progress_bar_resize(&screen.progress_bar);
+       progress_bar_resize(&screen.progress_bar, screen.cols,
+                           screen.rows - 2, 0);
        progress_bar_paint(&screen.progress_bar);
 
        /* status window */
@@ -562,12 +560,10 @@ screen_init(struct mpdclient *c)
        keypad(screen.main_window.w, TRUE);
 
        /* create progress window */
-       progress_bar_init(&screen.progress_bar, 1, screen.cols,
+       progress_bar_init(&screen.progress_bar, screen.cols,
                          screen.rows - 2, 0);
        progress_bar_paint(&screen.progress_bar);
 
-       leaveok(screen.progress_bar.window.w, TRUE);
-
        /* create status window */
        window_init(&screen.status_window, 1, screen.cols,
                    screen.rows - 1, 0);