forked from geoffmoss0/VisiCalc
-
Notifications
You must be signed in to change notification settings - Fork 0
/
layout.c
166 lines (146 loc) · 3.23 KB
/
layout.c
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
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
#include <ncurses.h>
#include <string.h>
#include <stdlib.h>
#include "layout.h"
#include "functions.h"
#include "data.h"
static int draw_size;
static int x_start;
static int y_start;
void color_on() {
attroff(COLOR_PAIR(1));
attron(COLOR_PAIR(2));
}
void color_off() {
attroff(COLOR_PAIR(2));
attron(COLOR_PAIR(1));
}
///Draw the axes, with y as the starting row and x as the starting column (converted to letters)
///This function is a goddamn mess and I should never touch it once it works
void draw_axes(int yn, int xn) {
xn--; //don't
yn--; //ask
x_start = xn;
y_start = yn;
int max_x, max_y;
getmaxyx(curscr, max_y, max_x);
move(4, 0);
int b = 4;
attron(COLOR_PAIR(2));
for (int a = yn+1; a < max_y - 3 + yn; a++) {
if (a >= 100) {
printw("%d", a);
} else if (a >= 10) {
printw(" %d", a);
} else {
printw(" %d", a);
}
move(b + 1, 0);
b++;
}
move(3, 3);
int k = 0;
while ( ((k+1) * draw_size) + 3 < max_x) {
for (int j = 0; j < draw_size; j++) {
if (k + xn < 26) {
if (j != ((draw_size / 2)) )
printw(" ");
else {
char *letters = to_char(k + xn);
printw("%s", letters);
free(letters);
}
} else {
if (j != (int) ((draw_size - 0.5) / 2)) {
printw(" ");
} else {
char *letters = to_char(k + xn);
printw("%s", letters);
j++;
free(letters);
}
}
}
k++;
}
//move(4, 4);
//draw_cells(start_y, start_x);
}
///Draws the data inside the cells
void draw_cells(int row, int col, int max_y, int max_x, int draw_size, cell (**table)[64]) {
//make sure to keep track of cursor position locally
int draw = (max_x - 3) / draw_size;
color_off();
for (int i = 0; i < (max_y - 4); i++) {
move(4 + i, 3);
for (int j = 0; j < draw; j++) {
printw("%s", print_data(row+i, col+j, draw_size, *table));
//printw("AAAAAAAA");
}
}
}
///Initial setup for the screen, at some point I might make this work with
///the modular drawing functions. However, that day is not today
int draw_screenyx() {
//Do I really need these parameters?
if (curscr == NULL) {
fprintf(stderr, "Window has not yet been initialized\n");
return 0;
}
move(0, 0);
start_color();
//Background: 36, 76, 122
//Foreground: 143, 199, 240
//init_color(COLOR_BLACK, 141, 297, 477);
init_color(COLOR_BLACK, 187, 39, 141);
init_color(COLOR_BLUE, 334, 627, 845);
init_pair(2, COLOR_BLACK, COLOR_BLUE); //Light background
init_pair(1, COLOR_BLUE, COLOR_BLACK); //Dark background
attron(COLOR_PAIR(2));
printw(" A1 ");
int max_x, max_y;
getmaxyx(curscr, max_y, max_x);
for (int x = 6; x < max_x; x++) {
printw(" ");
}
move(1, 0);
for (int x = 0; x < max_x; x++) {
printw(" ");
}
attroff(COLOR_PAIR(2));
attron(COLOR_PAIR(1));
for (int x = 0; x < max_x; x++) {
printw(" ");
}
attroff(COLOR_PAIR(1));
attron(COLOR_PAIR(2));
printw(" ");
draw_axes(1, 1);
refresh();
return 0;
}
void setup() {
noecho();
curs_set(0);
draw_size = 8;
}
/*
int main(void) {
draw_size = 8;
initscr();
refresh();
noecho();
curs_set(0);
draw_size = 8;
//attron(COLOR_PAIR(1));
//printw("Works ");
//attroff(COLOR_PAIR(1));
draw_screenyx();
refresh();
char cursor[9] = " ";
draw_axes(20, 20);
char ch = getch();
endwin();
return 0;
}
*/