This repository was archived by the owner on Aug 8, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.h
More file actions
97 lines (87 loc) · 2.66 KB
/
Copy pathmain.h
File metadata and controls
97 lines (87 loc) · 2.66 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
#pragma once
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <ncurses.h>
/* MACROS */
#define DISP_ERR(e, s) {\
int err = e;\
if (err == ERR) { fprintf(stderr, "%d: ERROR: Function returned ERR: " #e s "\n", __LINE__); }\
}
/* DEFINES */
#define HOUR 60
#define QUARTER (HOUR / 4)
#define HALFHOUR (HOUR / 2)
#define LINESTEP QUARTER /* how many minutes a line represents */
#define DAY_START (0 * HOUR)
#define DAY_END (23 * HOUR)
#define DAY_VIRT_HEIGHT ((DAY_END - DAY_START + HOUR) / LINESTEP) /* + HOUR because inclusive */
#define DAY_PHYS_WIDTH 40 /* physical width of day ScrollWin */
#define SCROLLWIN_PADDING 1
/* additional ncurses colors */
#define COLOR_WHITE_BRIGHT 15
/* ncurses color pairs */
#define PAIR_SLOT_HEADER 1
#define PAIR_SLOT_BG 2
/* TYPE DEFINITIONS */
typedef int Minute;
typedef int Hour;
/* TODO: how to deal with different day lengths in a week ?
* just ban it ? seems easiest and most sensical) */
/* the container window is merely a border to the pad (if padding >= 1) */
typedef struct {
WINDOW* container;
WINDOW* pad;
int offset;
int container_dirty;
} ScrollWin;
typedef struct {
Minute start_time;
Minute duration;
char* msg;
} Slot;
typedef struct {
ScrollWin* win;
int slot_count;
Slot* slots;
} Day;
typedef struct {
int day_count;
Day* days;
} Week;
/* FUNCTION DECLARATIONS */
/* general */
void ncurses_init(void);
void loop(void);
/* slots */
Slot slot_create(Minute start_time, Minute duration, char const * const msg);
void slot_destroy(Slot slot);
void slot_draw(ScrollWin* win, Slot slot);
/* days */
Day day_create(int slot_count, Slot* slots, int virt_height,
int day_count, int index);
void day_destroy(Day day);
void day_draw(Day day);
/* weeks */
void week_destroy(Week week);
void week_draw(Week week);
/* scrollwins */
ScrollWin* scrollwin_create(int virt_height, int phys_height, int phys_width,
int begin_y, int begin_x);
void scrollwin_destroy(ScrollWin* win);
void scrollwin_draw(ScrollWin* win);
void scrollwin_clear_inner(ScrollWin* win);
void scrollwin_draw_slot_header(ScrollWin* win, Slot slot);
void scrollwin_draw_slot_bg(ScrollWin* win, Slot slot);
char* scrollwin_format_slot_header(ScrollWin* win, Slot slot);
void scrollwin_scroll(ScrollWin* win, int delta);
/* scrollwin gets */
int scrollwin_get_begin_y(ScrollWin* win);
int scrollwin_get_begin_x(ScrollWin* win);
int scrollwin_get_phys_height(ScrollWin* win);
int scrollwin_get_phys_width(ScrollWin* win);
int scrollwin_get_virt_height(ScrollWin* win);
int scrollwin_get_virt_width(ScrollWin* win);
/* utility */
int min_to_line(Minute m);
Hour min_to_hour(Minute m);