summaryrefslogtreecommitdiff
path: root/main.c
diff options
context:
space:
mode:
Diffstat (limited to 'main.c')
-rw-r--r--main.c257
1 files changed, 0 insertions, 257 deletions
diff --git a/main.c b/main.c
deleted file mode 100644
index 4c43245..0000000
--- a/main.c
+++ /dev/null
@@ -1,257 +0,0 @@
1#include <X11/X.h>
2#include <X11/Xlib.h>
3#include <stdint.h>
4#include <string.h>
5#include <time.h>
6#include <unistd.h>
7#include <stdio.h>
8
9#include "base/base.h"
10#include "base/base_arena.h"
11
12#include "base/base.c"
13#include "base/base_arena.c"
14
15
16#define NIL 0
17
18typedef struct
19{
20i32 x;
21i32 y;
22u32 height;
23u32 width;
24u32 border_width;
25i32 window_depth;
26u32 window_class;
27u64 value_mask;
28
29} WindowProperties;
30
31typedef struct
32{
33i32 x;
34i32 y;
35i32 z;
36
37} vertex;
38
39void
40sleep_ms(long ms)
41{
42struct timespec ts;
43ts.tv_sec = ms / 1000;
44ts.tv_nsec = (ms % 1000) * 1000000L;
45
46while (nanosleep(&ts, &ts))
47{
48NULL;
49}
50}
51
52void
53move_down(double *y)
54{
55++*y;
56}
57
58void
59move_up(double *y)
60{
61--*y;
62}
63
64void
65move_left(double *x)
66{
67--*x;
68}
69
70void
71move_right(double *x)
72{
73++*x;
74}
75
76
77
78typedef struct
79{
80void (*move)(double *a);
81} movement;
82
83void
84handle_destroy(Display *display, GC *gc)
85{
86XFreeGC(display, *gc);
87XCloseDisplay(display);
88}
89
90typedef struct
91{
92i32 x;
93i32 y;
94
95} display_pos;
96
97typedef struct
98{
99i32 x;
100i32 y;
101i32 z;
102
103} pos;
104
105
106int
107main()
108{
109Display *MainDisplay = XOpenDisplay(0);
110mem_arena *arena = arena_create(MiB(8));
111
112Window root = XDefaultRootWindow(MainDisplay);
113int screen = DefaultScreen(MainDisplay);
114
115Visual *v = DefaultVisual(MainDisplay, screen);
116
117XSetWindowAttributes wa = {
118.background_pixmap = None,
119.background_pixel = BlackPixel(MainDisplay, DefaultScreen(MainDisplay)),
120.border_pixmap = CopyFromParent,
121.border_pixel = 0,
122.bit_gravity = ForgetGravity,
123.win_gravity = NorthWestGravity,
124.backing_store = NotUseful,
125.backing_planes = 1,
126.backing_pixel = 0,
127.save_under = False,
128.event_mask = {},
129.do_not_propagate_mask = {},
130.override_redirect = False,
131.colormap = CopyFromParent,
132.cursor = None
133};
134
135i32 dp_heigth = DisplayHeight(MainDisplay, screen);
136i32 dp_width = DisplayWidth(MainDisplay, screen);
137
138WindowProperties p = {
139
140.x = dp_width / 2,
141.y = dp_heigth / 2,
142.height = (u32)800,
143.width = (u32)1200,
144.border_width = 0,
145.window_depth = CopyFromParent,
146.window_class = CopyFromParent,
147.value_mask = CWBackPixel,
148
149};
150
151
152Window window =
153XCreateWindow(
154MainDisplay,
155root,
156p.x,
157p.y,
158p.width,
159p.height,
160p.border_width,
161p.window_depth,
162p.window_class,
163v,
164p.value_mask,
165&wa);
166
167Pixmap pixmap = XCreatePixmap(MainDisplay, window, dp_width, dp_heigth, 1);
168
169XSetWindowBorder(MainDisplay, window, 60);
170XSelectInput(MainDisplay, window, ExposureMask | StructureNotifyMask);
171XMapWindow(MainDisplay, window);
172
173
174double x = p.width / 2;
175double y = p.height / 2;
176
177u32 rect_width = 50;
178u32 rect_height = 50;
179
180u64 color = 0x0000ff00;
181
182GC gc = XCreateGC(MainDisplay, window, 0, NIL);
183XSetForeground(MainDisplay, gc, color);
184
185
186double *pX = &x;
187double *pY = &y;
188
189movement m = {
190.move = move_down
191};
192
193XEvent event;
194XNextEvent(MainDisplay, &event);
195
196for (;;)
197{
198switch (event.type)
199case KeyPress:
200case KeyRelease:
201{
202
203
204}
205default:
206{
207if (*pX + rect_width >= p.width)
208{
209m.move = move_left;
210}
211else if (*pX <= 0)
212{
213m.move = move_right;
214}
215
216char words[] = "working";
217
218XTextItem ti = {
219.chars = words,
220.nchars = (int)strlen(words),
221.delta = 0,
222.font = None
223};
224
225XClearWindow(MainDisplay, window);
226
227pos *p = arena_push(arena, sizeof(*p), 0);
228
229p->z = 10;
230p->x = ((i32)*pX * 10) / p->z;
231p->y = ((i32)*pY * 10) / p->z;
232
233XFillRectangle(
234MainDisplay,
235window,
236gc,
237(i32)p->x,
238(i32)p->y,
239rect_height,
240rect_width);
241
242m.move(&x);
243
244sleep_ms(1);
245
246XFlush(MainDisplay);
247}
248
249case DestroyNotify:
250{
251// handle_destroy(MainDisplay, &gc);
252}
253}
254
255arena_clear(arena);
256return 0;
257}