1 /*
2  * Copyright (c) 2010, 2011 Ryan Flannery <ryan.flannery@gmail.com>
3  *
4  * Permission to use, copy, modify, and distribute this software for any
5  * purpose with or without fee is hereby granted, provided that the above
6  * copyright notice and this permission notice appear in all copies.
7  *
8  * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
9  * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
10  * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
11  * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
12  * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
13  * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
14  * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
15  */
16 
17 #ifndef UINTERFACE_H
18 #define UINTERFACE_H
19 
20 #include <sys/ioctl.h>
21 
22 #include <ctype.h>
23 #include <err.h>
24 #include <ncurses.h>
25 #include <stdbool.h>
26 #include <stdio.h>
27 #include <stdint.h>
28 #include <stdlib.h>
29 #include <string.h>
30 #include <termios.h>
31 #include <unistd.h>
32 
33 #include "debug.h"
34 #include "enums.h"
35 
36 #include "compat.h"
37 
38 /* struct & methods for a scrollable window */
39 typedef struct
40 {
41    WINDOW  *cwin;
42    int      w, h;    /* it's just handy to track these here */
43    int      crow;    /* current row in the window */
44    int      nrows;   /* number of rows in the window */
45    int      voffset; /* vertical & horizontal scroll offsets */
46    int      hoffset;
47 
48 } swindow;
49 
50 swindow *swindow_new(int h, int w, int y, int x);
51 void swindow_free(swindow *win);
52 void swindow_resize(swindow *win, int h, int w, int y, int x);
53 void swindow_scroll(swindow *win, Direction d, int n);
54 
55 
56 /* user interface struct & methods */
57 typedef struct
58 {
59    WINDOW   *player;
60    WINDOW   *command;
61 
62    swindow  *library;
63    swindow  *playlist;
64 
65    /* this is always a pointer to one of the two above swindow's */
66    swindow  *active;
67 
68    int  lwidth; /* width of the library pane on the left */
69    bool lhide;  /* if library window should be hidden or not */
70 
71 } uinterface;
72 extern uinterface ui;   /* the global ui struct */
73 
74 void ui_init(int library_width);
75 bool ui_is_init();
76 void ui_clear();
77 void ui_destroy();
78 void ui_resize();
79 
80 void ui_hide_library();
81 void ui_unhide_library();
82 
83 #endif
84