annotate postdog/main.c @ 115:96db6c3f38d6

[Postdog] Got history working.
author June Park <parkjune1995@gmail.com>
date Tue, 06 Jan 2026 08:19:07 -0800
parents e2a73e64e8e6
children 7bd795bac997
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
54
b3e82d22f961 [PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1 #include <stdio.h>
b3e82d22f961 [PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff changeset
2 #include <stdlib.h>
b3e82d22f961 [PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff changeset
3 #include <string.h>
b3e82d22f961 [PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff changeset
4 #include <time.h>
b3e82d22f961 [PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff changeset
5 #include <sys/stat.h>
111
48f260576059 [PostDog] Rewriting it from scratch as it is unreadable for me.
June Park <parkjune1995@gmail.com>
parents: 63
diff changeset
6 #include "dowa/dowa.h"
58
ccb42d5bf8fd [PostDog] Somewhat working copy. That would use for testing.
June Park <parkjune1995@gmail.com>
parents: 57
diff changeset
7
54
b3e82d22f961 [PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff changeset
8 #include <curl/curl.h>
b3e82d22f961 [PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff changeset
9 #include "third_party/raylib/include/raylib.h"
b3e82d22f961 [PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff changeset
10 #define RAYGUI_IMPLEMENTATION
b3e82d22f961 [PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff changeset
11 #include "third_party/raylib/include/raygui.h"
b3e82d22f961 [PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff changeset
12
114
e2a73e64e8e6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 112
diff changeset
13 #ifndef POSTDOG_PATHS
e2a73e64e8e6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 112
diff changeset
14 #define POSTDOG_PATHS "/Users/mrjunejune/zenbu/postdog/history"
e2a73e64e8e6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 112
diff changeset
15 #endif
e2a73e64e8e6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 112
diff changeset
16
54
b3e82d22f961 [PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff changeset
17 #define SCREEN_WIDTH 1280
b3e82d22f961 [PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff changeset
18 #define SCREEN_HEIGHT 780
b3e82d22f961 [PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff changeset
19 #define TEXT_SIZE 10
b3e82d22f961 [PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff changeset
20
b3e82d22f961 [PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff changeset
21 #define JSON_INPUT_BUFFER_LEN 8192
b3e82d22f961 [PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff changeset
22 #define HEADER_INPUT_BUFFER_LEN 4096
b3e82d22f961 [PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff changeset
23 #define PARAM_INPUT_BUFFER_LEN 4096
b3e82d22f961 [PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff changeset
24 #define MAX_HISTORY_ITEMS 100
b3e82d22f961 [PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff changeset
25
112
d6d578b49a19 [PostDog] Got CRUD working.
June Park <parkjune1995@gmail.com>
parents: 111
diff changeset
26 #define HEADER_BUFFER_LENGTH 1024 * 4
d6d578b49a19 [PostDog] Got CRUD working.
June Park <parkjune1995@gmail.com>
parents: 111
diff changeset
27 #define DEFAULT_TEXT_BUFFER_LENGTH 1024 * 4
d6d578b49a19 [PostDog] Got CRUD working.
June Park <parkjune1995@gmail.com>
parents: 111
diff changeset
28 #define URL_TEXT_BUFFER 1024 * 10
d6d578b49a19 [PostDog] Got CRUD working.
June Park <parkjune1995@gmail.com>
parents: 111
diff changeset
29 #define BODY_BUFFER_LENGTH 1024 * 1025 * 5
d6d578b49a19 [PostDog] Got CRUD working.
June Park <parkjune1995@gmail.com>
parents: 111
diff changeset
30 #define RESULT_BUFFER_LENGTH 1024 * 1025 * 5
d6d578b49a19 [PostDog] Got CRUD working.
June Park <parkjune1995@gmail.com>
parents: 111
diff changeset
31 #define AREANA_BUFFER_LENGTH 1024 * 1025 * 15
d6d578b49a19 [PostDog] Got CRUD working.
June Park <parkjune1995@gmail.com>
parents: 111
diff changeset
32
114
e2a73e64e8e6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 112
diff changeset
33
e2a73e64e8e6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 112
diff changeset
34 #ifdef _WIN32
e2a73e64e8e6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 112
diff changeset
35 #include <direct.h>
e2a73e64e8e6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 112
diff changeset
36 #include <io.h>
e2a73e64e8e6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 112
diff changeset
37 #define mkdir(path, mode) _mkdir(path)
e2a73e64e8e6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 112
diff changeset
38 #define access _access
e2a73e64e8e6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 112
diff changeset
39 #define F_OK 0
e2a73e64e8e6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 112
diff changeset
40 #else
e2a73e64e8e6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 112
diff changeset
41 #include <sys/stat.h>
e2a73e64e8e6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 112
diff changeset
42 #include <dirent.h>
e2a73e64e8e6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 112
diff changeset
43 #include <unistd.h>
e2a73e64e8e6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 112
diff changeset
44 #endif
e2a73e64e8e6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 112
diff changeset
45
112
d6d578b49a19 [PostDog] Got CRUD working.
June Park <parkjune1995@gmail.com>
parents: 111
diff changeset
46 typedef Dowa_KV(char*, char*) INPUT_HASHMAP;
d6d578b49a19 [PostDog] Got CRUD working.
June Park <parkjune1995@gmail.com>
parents: 111
diff changeset
47
54
b3e82d22f961 [PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff changeset
48 typedef struct {
b3e82d22f961 [PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff changeset
49 char *data;
b3e82d22f961 [PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff changeset
50 size_t size;
b3e82d22f961 [PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff changeset
51 } ResponseBuffer;
b3e82d22f961 [PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff changeset
52
b3e82d22f961 [PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff changeset
53 typedef struct {
114
e2a73e64e8e6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 112
diff changeset
54 char *filename;
e2a73e64e8e6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 112
diff changeset
55 Rectangle rect;
e2a73e64e8e6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 112
diff changeset
56 long time_modified;
54
b3e82d22f961 [PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff changeset
57 } HistoryItem;
b3e82d22f961 [PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff changeset
58
114
e2a73e64e8e6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 112
diff changeset
59 typedef struct {
e2a73e64e8e6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 112
diff changeset
60 Rectangle rectangle;
e2a73e64e8e6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 112
diff changeset
61 char *label;
e2a73e64e8e6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 112
diff changeset
62 bool active;
e2a73e64e8e6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 112
diff changeset
63 } TabItem;
e2a73e64e8e6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 112
diff changeset
64
e2a73e64e8e6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 112
diff changeset
65 typedef enum {
e2a73e64e8e6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 112
diff changeset
66 TAB_HEADER = 0,
e2a73e64e8e6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 112
diff changeset
67 TAB_BODY,
e2a73e64e8e6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 112
diff changeset
68 TAB_GET_PARAMS,
e2a73e64e8e6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 112
diff changeset
69 TAB_BAR,
e2a73e64e8e6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 112
diff changeset
70 TAB_LENGTH
e2a73e64e8e6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 112
diff changeset
71 } PostDog_Tab_Enum;
e2a73e64e8e6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 112
diff changeset
72
e2a73e64e8e6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 112
diff changeset
73 static uint32 counter = 0;
e2a73e64e8e6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 112
diff changeset
74 HistoryItem *history_items = NULL;
e2a73e64e8e6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 112
diff changeset
75 HistoryItem *new_history_items = NULL;
e2a73e64e8e6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 112
diff changeset
76
e2a73e64e8e6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 112
diff changeset
77 int CompareHistoryItemsByDate(const void *a, const void *b) {
e2a73e64e8e6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 112
diff changeset
78 HistoryItem *itemA = (HistoryItem *)a;
e2a73e64e8e6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 112
diff changeset
79 HistoryItem *itemB = (HistoryItem *)b;
e2a73e64e8e6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 112
diff changeset
80 return (itemB->time_modified - itemA->time_modified);
e2a73e64e8e6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 112
diff changeset
81 }
e2a73e64e8e6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 112
diff changeset
82
e2a73e64e8e6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 112
diff changeset
83 // TODO: Make this into generic fucntion so I can use it across different thing.
e2a73e64e8e6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 112
diff changeset
84 void PostDog_List_Directory(const char *path, HistoryItem **p_file_arr)
e2a73e64e8e6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 112
diff changeset
85 {
e2a73e64e8e6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 112
diff changeset
86 HistoryItem *file_arr = *p_file_arr;
e2a73e64e8e6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 112
diff changeset
87 #ifdef _WIN32
e2a73e64e8e6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 112
diff changeset
88 struct _finddata_t fileinfo;
e2a73e64e8e6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 112
diff changeset
89 intptr_t handle;
e2a73e64e8e6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 112
diff changeset
90 char search_path[256];
e2a73e64e8e6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 112
diff changeset
91 sprintf(search_path, "%s\\*", path);
e2a73e64e8e6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 112
diff changeset
92
e2a73e64e8e6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 112
diff changeset
93 if ((handle = _findfirst(search_path, &fileinfo)) == -1L) {
e2a73e64e8e6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 112
diff changeset
94 printf("Directory is empty or cannot be read.\n");
e2a73e64e8e6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 112
diff changeset
95 } else {
e2a73e64e8e6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 112
diff changeset
96 do {
e2a73e64e8e6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 112
diff changeset
97 HistoryItem item = {0};
e2a73e64e8e6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 112
diff changeset
98 item.filename = strdup(fileinfo.name);
e2a73e64e8e6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 112
diff changeset
99 item.rect = (Rectangle){0};
e2a73e64e8e6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 112
diff changeset
100 item.time_modified = fileinfo.time_write;
e2a73e64e8e6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 112
diff changeset
101 Dowa_Array_Push(file_arr, item);
e2a73e64e8e6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 112
diff changeset
102 } while (_findnext(handle, &fileinfo) == 0);
e2a73e64e8e6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 112
diff changeset
103 _findclose(handle);
e2a73e64e8e6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 112
diff changeset
104 }
e2a73e64e8e6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 112
diff changeset
105 #else
e2a73e64e8e6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 112
diff changeset
106 struct dirent *entry;
e2a73e64e8e6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 112
diff changeset
107 struct stat file_stat;
e2a73e64e8e6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 112
diff changeset
108 DIR *dp = opendir(path);
e2a73e64e8e6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 112
diff changeset
109 if (dp == NULL) return;
e2a73e64e8e6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 112
diff changeset
110
e2a73e64e8e6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 112
diff changeset
111 char full_path[256];
e2a73e64e8e6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 112
diff changeset
112 while ((entry = readdir(dp)))
e2a73e64e8e6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 112
diff changeset
113 {
e2a73e64e8e6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 112
diff changeset
114 if (strcmp(entry->d_name, ".") == 0 || strcmp(entry->d_name, "..") == 0)
e2a73e64e8e6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 112
diff changeset
115 continue;
e2a73e64e8e6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 112
diff changeset
116 snprintf(full_path, sizeof(full_path), "%s/%s", path, entry->d_name);
e2a73e64e8e6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 112
diff changeset
117 if (stat(full_path, &file_stat) == 0)
e2a73e64e8e6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 112
diff changeset
118 {
e2a73e64e8e6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 112
diff changeset
119 HistoryItem item = {0};
e2a73e64e8e6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 112
diff changeset
120 item.filename = strdup(entry->d_name);
e2a73e64e8e6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 112
diff changeset
121 item.time_modified = file_stat.st_mtime;
e2a73e64e8e6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 112
diff changeset
122 Dowa_Array_Push(file_arr, item);
e2a73e64e8e6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 112
diff changeset
123 }
e2a73e64e8e6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 112
diff changeset
124 }
e2a73e64e8e6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 112
diff changeset
125 closedir(dp);
e2a73e64e8e6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 112
diff changeset
126 #endif
e2a73e64e8e6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 112
diff changeset
127 int count = Dowa_Array_Length(file_arr);
e2a73e64e8e6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 112
diff changeset
128 if (count > 1) {
e2a73e64e8e6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 112
diff changeset
129 qsort(file_arr, count, sizeof(HistoryItem), CompareHistoryItemsByDate);
e2a73e64e8e6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 112
diff changeset
130 }
e2a73e64e8e6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 112
diff changeset
131 }
e2a73e64e8e6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 112
diff changeset
132
e2a73e64e8e6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 112
diff changeset
133 int PostDog_History_Load(HistoryItem **p_history_files)
e2a73e64e8e6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 112
diff changeset
134 {
e2a73e64e8e6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 112
diff changeset
135 if (access(POSTDOG_PATHS, F_OK) == -1)
e2a73e64e8e6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 112
diff changeset
136 {
e2a73e64e8e6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 112
diff changeset
137 printf("Directory '%s' not found. Creating it...\n", POSTDOG_PATHS);
e2a73e64e8e6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 112
diff changeset
138 if (mkdir(POSTDOG_PATHS, 0777) != 0)
e2a73e64e8e6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 112
diff changeset
139 return -1;
e2a73e64e8e6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 112
diff changeset
140 return 0;
e2a73e64e8e6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 112
diff changeset
141 }
e2a73e64e8e6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 112
diff changeset
142 printf("Directory '%s' already exists.\n", POSTDOG_PATHS);
e2a73e64e8e6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 112
diff changeset
143 PostDog_List_Directory(POSTDOG_PATHS, p_history_files);
e2a73e64e8e6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 112
diff changeset
144 return 0;
e2a73e64e8e6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 112
diff changeset
145 }
e2a73e64e8e6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 112
diff changeset
146
e2a73e64e8e6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 112
diff changeset
147 bool InArea(Vector2 mouse_position, Rectangle area)
e2a73e64e8e6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 112
diff changeset
148 {
e2a73e64e8e6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 112
diff changeset
149 return (
e2a73e64e8e6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 112
diff changeset
150 mouse_position.x >= area.x &&
e2a73e64e8e6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 112
diff changeset
151 mouse_position.x < area.x + area.width &&
e2a73e64e8e6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 112
diff changeset
152 mouse_position.y >= area.y &&
e2a73e64e8e6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 112
diff changeset
153 mouse_position.y < area.y + area.height
e2a73e64e8e6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 112
diff changeset
154 );
e2a73e64e8e6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 112
diff changeset
155 }
e2a73e64e8e6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 112
diff changeset
156
e2a73e64e8e6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 112
diff changeset
157 bool Clicked(Vector2 mouse_position, Rectangle area)
e2a73e64e8e6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 112
diff changeset
158 {
e2a73e64e8e6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 112
diff changeset
159 return (InArea(mouse_position, area) && IsMouseButtonPressed(MOUSE_BUTTON_LEFT));
e2a73e64e8e6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 112
diff changeset
160 }
e2a73e64e8e6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 112
diff changeset
161
112
d6d578b49a19 [PostDog] Got CRUD working.
June Park <parkjune1995@gmail.com>
parents: 111
diff changeset
162 char *PostDog_Enum_To_String(int active_enum)
d6d578b49a19 [PostDog] Got CRUD working.
June Park <parkjune1995@gmail.com>
parents: 111
diff changeset
163 {
d6d578b49a19 [PostDog] Got CRUD working.
June Park <parkjune1995@gmail.com>
parents: 111
diff changeset
164 switch(active_enum)
d6d578b49a19 [PostDog] Got CRUD working.
June Park <parkjune1995@gmail.com>
parents: 111
diff changeset
165 {
d6d578b49a19 [PostDog] Got CRUD working.
June Park <parkjune1995@gmail.com>
parents: 111
diff changeset
166 case 0: return "GET";
d6d578b49a19 [PostDog] Got CRUD working.
June Park <parkjune1995@gmail.com>
parents: 111
diff changeset
167 case 1: return "POST";
d6d578b49a19 [PostDog] Got CRUD working.
June Park <parkjune1995@gmail.com>
parents: 111
diff changeset
168 case 2: return "PUT";
d6d578b49a19 [PostDog] Got CRUD working.
June Park <parkjune1995@gmail.com>
parents: 111
diff changeset
169 case 3: return "DELETE";
d6d578b49a19 [PostDog] Got CRUD working.
June Park <parkjune1995@gmail.com>
parents: 111
diff changeset
170 }
114
e2a73e64e8e6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 112
diff changeset
171 return 0;
e2a73e64e8e6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 112
diff changeset
172 }
e2a73e64e8e6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 112
diff changeset
173
e2a73e64e8e6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 112
diff changeset
174 void PostDog_History_CreateFile(char *filename, char* values)
e2a73e64e8e6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 112
diff changeset
175 {
e2a73e64e8e6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 112
diff changeset
176 char full_file_path[512] = {0};
e2a73e64e8e6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 112
diff changeset
177 snprintf(full_file_path, 512, "%s/%s", POSTDOG_PATHS, filename);
e2a73e64e8e6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 112
diff changeset
178 FILE *file = fopen(full_file_path, "w");
e2a73e64e8e6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 112
diff changeset
179 if (!file)
e2a73e64e8e6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 112
diff changeset
180 {
e2a73e64e8e6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 112
diff changeset
181 printf("Failed to create a file: %s\n", full_file_path);
e2a73e64e8e6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 112
diff changeset
182 return;
e2a73e64e8e6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 112
diff changeset
183 }
e2a73e64e8e6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 112
diff changeset
184 fwrite(values, 1, strlen(values), file);
e2a73e64e8e6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 112
diff changeset
185 fclose(file);
e2a73e64e8e6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 112
diff changeset
186 }
e2a73e64e8e6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 112
diff changeset
187
e2a73e64e8e6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 112
diff changeset
188 void PostDog_Request_SaveFile(
e2a73e64e8e6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 112
diff changeset
189 const char *url,
e2a73e64e8e6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 112
diff changeset
190 const char *method,
e2a73e64e8e6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 112
diff changeset
191 const char *headers,
e2a73e64e8e6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 112
diff changeset
192 const char *body,
e2a73e64e8e6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 112
diff changeset
193 const char *response)
e2a73e64e8e6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 112
diff changeset
194 {
e2a73e64e8e6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 112
diff changeset
195 size_t new_file_size = 1024 * 1024;
e2a73e64e8e6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 112
diff changeset
196 Dowa_Arena *arena = Dowa_Arena_Create(1024 * 1024 * 2);
e2a73e64e8e6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 112
diff changeset
197 char *new_file = Dowa_Arena_Allocate(arena, 1024 * 1024);
e2a73e64e8e6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 112
diff changeset
198 snprintf(
e2a73e64e8e6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 112
diff changeset
199 new_file,
e2a73e64e8e6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 112
diff changeset
200 new_file_size,
e2a73e64e8e6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 112
diff changeset
201 "%s\n"
e2a73e64e8e6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 112
diff changeset
202 "---\n"
e2a73e64e8e6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 112
diff changeset
203 "%s\n"
e2a73e64e8e6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 112
diff changeset
204 "---\n"
e2a73e64e8e6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 112
diff changeset
205 "%s\n"
e2a73e64e8e6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 112
diff changeset
206 "---\n"
e2a73e64e8e6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 112
diff changeset
207 "%s\n"
e2a73e64e8e6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 112
diff changeset
208 "---\n"
e2a73e64e8e6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 112
diff changeset
209 "%s\n",
e2a73e64e8e6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 112
diff changeset
210 url,
e2a73e64e8e6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 112
diff changeset
211 method,
e2a73e64e8e6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 112
diff changeset
212 headers,
e2a73e64e8e6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 112
diff changeset
213 body,
e2a73e64e8e6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 112
diff changeset
214 response
e2a73e64e8e6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 112
diff changeset
215 );
e2a73e64e8e6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 112
diff changeset
216 char *filename = Dowa_Arena_Allocate(arena, 1024);
e2a73e64e8e6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 112
diff changeset
217 if (!filename)
e2a73e64e8e6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 112
diff changeset
218 {
e2a73e64e8e6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 112
diff changeset
219 perror("Error opening file");
e2a73e64e8e6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 112
diff changeset
220 exit(EXIT_FAILURE);
e2a73e64e8e6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 112
diff changeset
221 }
e2a73e64e8e6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 112
diff changeset
222 char *uuid4 = (char *)Dowa_Arena_Allocate(arena, 37);
e2a73e64e8e6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 112
diff changeset
223 if (!uuid4)
e2a73e64e8e6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 112
diff changeset
224 {
e2a73e64e8e6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 112
diff changeset
225 perror("Error uuid");
e2a73e64e8e6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 112
diff changeset
226 exit(EXIT_FAILURE);
e2a73e64e8e6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 112
diff changeset
227 }
e2a73e64e8e6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 112
diff changeset
228
e2a73e64e8e6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 112
diff changeset
229 int32 seed = (uint32)time(NULL) ^ counter++;
e2a73e64e8e6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 112
diff changeset
230 Dowa_String_UUID(seed, uuid4);
e2a73e64e8e6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 112
diff changeset
231 snprintf(filename, 1024, "%s.txt", uuid4);
e2a73e64e8e6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 112
diff changeset
232 PostDog_History_CreateFile(filename, new_file);
e2a73e64e8e6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 112
diff changeset
233
e2a73e64e8e6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 112
diff changeset
234 HistoryItem item = (HistoryItem){ .filename = malloc(sizeof(char) * strlen(filename) + 1), .rect = (Rectangle){0} };
e2a73e64e8e6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 112
diff changeset
235 memcpy(item.filename, filename, strlen(filename) + 1);
e2a73e64e8e6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 112
diff changeset
236 Dowa_Array_Push(new_history_items, item);
e2a73e64e8e6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 112
diff changeset
237
e2a73e64e8e6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 112
diff changeset
238 Dowa_Arena_Free(arena);
112
d6d578b49a19 [PostDog] Got CRUD working.
June Park <parkjune1995@gmail.com>
parents: 111
diff changeset
239 }
54
b3e82d22f961 [PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff changeset
240
b3e82d22f961 [PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff changeset
241 static size_t Postdog_Curl_Callback(void *contents, size_t size, size_t nmemb, void *userp)
b3e82d22f961 [PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff changeset
242 {
b3e82d22f961 [PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff changeset
243 size_t real_size = size * nmemb;
b3e82d22f961 [PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff changeset
244 ResponseBuffer *buf = (ResponseBuffer *)userp;
b3e82d22f961 [PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff changeset
245
b3e82d22f961 [PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff changeset
246 char *ptr = realloc(buf->data, buf->size + real_size + 1);
b3e82d22f961 [PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff changeset
247 if (ptr == NULL)
b3e82d22f961 [PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff changeset
248 {
b3e82d22f961 [PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff changeset
249 printf("Not enough memory for response\n");
b3e82d22f961 [PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff changeset
250 return 0;
b3e82d22f961 [PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff changeset
251 }
b3e82d22f961 [PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff changeset
252
b3e82d22f961 [PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff changeset
253 buf->data = ptr;
b3e82d22f961 [PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff changeset
254 memcpy(&(buf->data[buf->size]), contents, real_size);
b3e82d22f961 [PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff changeset
255 buf->size += real_size;
b3e82d22f961 [PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff changeset
256 buf->data[buf->size] = 0;
b3e82d22f961 [PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff changeset
257
b3e82d22f961 [PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff changeset
258 return real_size;
b3e82d22f961 [PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff changeset
259 }
b3e82d22f961 [PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff changeset
260
114
e2a73e64e8e6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 112
diff changeset
261 int PostDog_Http_Request(
112
d6d578b49a19 [PostDog] Got CRUD working.
June Park <parkjune1995@gmail.com>
parents: 111
diff changeset
262 const char *url,
d6d578b49a19 [PostDog] Got CRUD working.
June Park <parkjune1995@gmail.com>
parents: 111
diff changeset
263 const char *method,
d6d578b49a19 [PostDog] Got CRUD working.
June Park <parkjune1995@gmail.com>
parents: 111
diff changeset
264 const char *headers,
d6d578b49a19 [PostDog] Got CRUD working.
June Park <parkjune1995@gmail.com>
parents: 111
diff changeset
265 const char *body,
d6d578b49a19 [PostDog] Got CRUD working.
June Park <parkjune1995@gmail.com>
parents: 111
diff changeset
266 char *response, size_t responseSize)
54
b3e82d22f961 [PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff changeset
267 {
b3e82d22f961 [PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff changeset
268 CURL *curl;
b3e82d22f961 [PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff changeset
269 CURLcode res;
b3e82d22f961 [PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff changeset
270 ResponseBuffer buffer = { .data = malloc(1), .size = 0 };
b3e82d22f961 [PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff changeset
271
112
d6d578b49a19 [PostDog] Got CRUD working.
June Park <parkjune1995@gmail.com>
parents: 111
diff changeset
272 response[0] = '\n';
d6d578b49a19 [PostDog] Got CRUD working.
June Park <parkjune1995@gmail.com>
parents: 111
diff changeset
273
54
b3e82d22f961 [PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff changeset
274 if (buffer.data == NULL)
b3e82d22f961 [PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff changeset
275 {
b3e82d22f961 [PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff changeset
276 snprintf(response, responseSize, "Error: Failed to allocate memory");
b3e82d22f961 [PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff changeset
277 return -1;
b3e82d22f961 [PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff changeset
278 }
b3e82d22f961 [PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff changeset
279 buffer.data[0] = '\0';
b3e82d22f961 [PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff changeset
280
b3e82d22f961 [PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff changeset
281 curl_global_init(CURL_GLOBAL_DEFAULT);
b3e82d22f961 [PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff changeset
282 curl = curl_easy_init();
b3e82d22f961 [PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff changeset
283
b3e82d22f961 [PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff changeset
284 if (curl)
b3e82d22f961 [PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff changeset
285 {
b3e82d22f961 [PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff changeset
286 struct curl_slist *headerList = NULL;
b3e82d22f961 [PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff changeset
287
b3e82d22f961 [PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff changeset
288 // Set URL
b3e82d22f961 [PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff changeset
289 curl_easy_setopt(curl, CURLOPT_URL, url);
b3e82d22f961 [PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff changeset
290
b3e82d22f961 [PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff changeset
291 // Set HTTP method
b3e82d22f961 [PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff changeset
292 if (strcmp(method, "POST") == 0)
b3e82d22f961 [PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff changeset
293 {
b3e82d22f961 [PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff changeset
294 curl_easy_setopt(curl, CURLOPT_POST, 1L);
114
e2a73e64e8e6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 112
diff changeset
295 if (body && strlen(body) > 0)
54
b3e82d22f961 [PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff changeset
296 curl_easy_setopt(curl, CURLOPT_POSTFIELDS, body);
b3e82d22f961 [PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff changeset
297 }
b3e82d22f961 [PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff changeset
298 else if (strcmp(method, "PUT") == 0)
b3e82d22f961 [PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff changeset
299 {
b3e82d22f961 [PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff changeset
300 curl_easy_setopt(curl, CURLOPT_CUSTOMREQUEST, "PUT");
114
e2a73e64e8e6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 112
diff changeset
301 if (body && strlen(body) > 0)
54
b3e82d22f961 [PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff changeset
302 curl_easy_setopt(curl, CURLOPT_POSTFIELDS, body);
b3e82d22f961 [PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff changeset
303 }
b3e82d22f961 [PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff changeset
304 else if (strcmp(method, "DELETE") == 0)
b3e82d22f961 [PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff changeset
305 {
b3e82d22f961 [PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff changeset
306 curl_easy_setopt(curl, CURLOPT_CUSTOMREQUEST, "DELETE");
b3e82d22f961 [PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff changeset
307 }
b3e82d22f961 [PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff changeset
308 // Default is GET
b3e82d22f961 [PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff changeset
309
b3e82d22f961 [PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff changeset
310 // Parse and add headers
b3e82d22f961 [PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff changeset
311 if (headers && strlen(headers) > 0)
b3e82d22f961 [PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff changeset
312 {
b3e82d22f961 [PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff changeset
313 char *headersCopy = strdup(headers);
b3e82d22f961 [PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff changeset
314 char *line = strtok(headersCopy, "\n");
b3e82d22f961 [PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff changeset
315 while (line != NULL) {
b3e82d22f961 [PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff changeset
316 // Trim whitespace
b3e82d22f961 [PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff changeset
317 while (*line == ' ' || *line == '\t') line++;
114
e2a73e64e8e6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 112
diff changeset
318 if (strlen(line) > 0)
54
b3e82d22f961 [PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff changeset
319 headerList = curl_slist_append(headerList, line);
b3e82d22f961 [PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff changeset
320 line = strtok(NULL, "\n");
b3e82d22f961 [PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff changeset
321 }
b3e82d22f961 [PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff changeset
322 curl_easy_setopt(curl, CURLOPT_HTTPHEADER, headerList);
b3e82d22f961 [PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff changeset
323 free(headersCopy);
b3e82d22f961 [PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff changeset
324 }
b3e82d22f961 [PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff changeset
325
b3e82d22f961 [PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff changeset
326 // Set write callback
b3e82d22f961 [PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff changeset
327 curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, Postdog_Curl_Callback);
b3e82d22f961 [PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff changeset
328 curl_easy_setopt(curl, CURLOPT_WRITEDATA, (void *)&buffer);
b3e82d22f961 [PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff changeset
329
b3e82d22f961 [PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff changeset
330 // Follow redirects
b3e82d22f961 [PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff changeset
331 curl_easy_setopt(curl, CURLOPT_FOLLOWLOCATION, 1L);
b3e82d22f961 [PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff changeset
332 // Set timeout
b3e82d22f961 [PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff changeset
333 curl_easy_setopt(curl, CURLOPT_TIMEOUT, 30L);
b3e82d22f961 [PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff changeset
334 // Perform request
b3e82d22f961 [PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff changeset
335 res = curl_easy_perform(curl);
b3e82d22f961 [PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff changeset
336
111
48f260576059 [PostDog] Rewriting it from scratch as it is unreadable for me.
June Park <parkjune1995@gmail.com>
parents: 63
diff changeset
337 if (res != CURLE_OK)
54
b3e82d22f961 [PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff changeset
338 snprintf(response, responseSize, "Error: %s\n", curl_easy_strerror(res));
111
48f260576059 [PostDog] Rewriting it from scratch as it is unreadable for me.
June Park <parkjune1995@gmail.com>
parents: 63
diff changeset
339 else
48f260576059 [PostDog] Rewriting it from scratch as it is unreadable for me.
June Park <parkjune1995@gmail.com>
parents: 63
diff changeset
340 {
54
b3e82d22f961 [PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff changeset
341 long response_code;
b3e82d22f961 [PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff changeset
342 curl_easy_getinfo(curl, CURLINFO_RESPONSE_CODE, &response_code);
b3e82d22f961 [PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff changeset
343
b3e82d22f961 [PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff changeset
344 snprintf(response, responseSize, "HTTP Status: %ld\n\n%s",
b3e82d22f961 [PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff changeset
345 response_code, buffer.data ? buffer.data : "");
b3e82d22f961 [PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff changeset
346 }
b3e82d22f961 [PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff changeset
347
b3e82d22f961 [PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff changeset
348 // Cleanup
b3e82d22f961 [PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff changeset
349 if (headerList) curl_slist_free_all(headerList);
b3e82d22f961 [PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff changeset
350 curl_easy_cleanup(curl);
b3e82d22f961 [PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff changeset
351 } else {
b3e82d22f961 [PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff changeset
352 snprintf(response, responseSize, "Error: Failed to initialize curl");
b3e82d22f961 [PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff changeset
353 }
b3e82d22f961 [PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff changeset
354
b3e82d22f961 [PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff changeset
355 free(buffer.data);
b3e82d22f961 [PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff changeset
356 curl_global_cleanup();
b3e82d22f961 [PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff changeset
357
114
e2a73e64e8e6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 112
diff changeset
358 PostDog_Request_SaveFile(
e2a73e64e8e6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 112
diff changeset
359 url,
e2a73e64e8e6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 112
diff changeset
360 method,
e2a73e64e8e6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 112
diff changeset
361 headers,
e2a73e64e8e6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 112
diff changeset
362 body,
e2a73e64e8e6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 112
diff changeset
363 response);
54
b3e82d22f961 [PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff changeset
364 return 0;
b3e82d22f961 [PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff changeset
365 }
b3e82d22f961 [PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff changeset
366
112
d6d578b49a19 [PostDog] Got CRUD working.
June Park <parkjune1995@gmail.com>
parents: 111
diff changeset
367 void PostDog_Update_URL(char **p_url_input_text, char* get_params)
d6d578b49a19 [PostDog] Got CRUD working.
June Park <parkjune1995@gmail.com>
parents: 111
diff changeset
368 {
d6d578b49a19 [PostDog] Got CRUD working.
June Park <parkjune1995@gmail.com>
parents: 111
diff changeset
369 char *url_input_text = *p_url_input_text;
d6d578b49a19 [PostDog] Got CRUD working.
June Park <parkjune1995@gmail.com>
parents: 111
diff changeset
370
114
e2a73e64e8e6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 112
diff changeset
371 // Reset
112
d6d578b49a19 [PostDog] Got CRUD working.
June Park <parkjune1995@gmail.com>
parents: 111
diff changeset
372 char *question_mark = strchr(url_input_text, '?');
d6d578b49a19 [PostDog] Got CRUD working.
June Park <parkjune1995@gmail.com>
parents: 111
diff changeset
373 if (question_mark)
d6d578b49a19 [PostDog] Got CRUD working.
June Park <parkjune1995@gmail.com>
parents: 111
diff changeset
374 *question_mark = '\0';
d6d578b49a19 [PostDog] Got CRUD working.
June Park <parkjune1995@gmail.com>
parents: 111
diff changeset
375
d6d578b49a19 [PostDog] Got CRUD working.
June Park <parkjune1995@gmail.com>
parents: 111
diff changeset
376 int get_params_length = (int)strlen(get_params) ;
d6d578b49a19 [PostDog] Got CRUD working.
June Park <parkjune1995@gmail.com>
parents: 111
diff changeset
377 if (get_params_length == 0)
d6d578b49a19 [PostDog] Got CRUD working.
June Park <parkjune1995@gmail.com>
parents: 111
diff changeset
378 return;
d6d578b49a19 [PostDog] Got CRUD working.
June Park <parkjune1995@gmail.com>
parents: 111
diff changeset
379
d6d578b49a19 [PostDog] Got CRUD working.
June Park <parkjune1995@gmail.com>
parents: 111
diff changeset
380 char *separator = "?";
d6d578b49a19 [PostDog] Got CRUD working.
June Park <parkjune1995@gmail.com>
parents: 111
diff changeset
381
d6d578b49a19 [PostDog] Got CRUD working.
June Park <parkjune1995@gmail.com>
parents: 111
diff changeset
382 Dowa_Arena *arena = Dowa_Arena_Create(1024*1024);
d6d578b49a19 [PostDog] Got CRUD working.
June Park <parkjune1995@gmail.com>
parents: 111
diff changeset
383 char **lines = Dowa_String_Split(get_params, "\n", get_params_length, 1, arena);
d6d578b49a19 [PostDog] Got CRUD working.
June Park <parkjune1995@gmail.com>
parents: 111
diff changeset
384 for (int i = 0; i < Dowa_Array_Length(lines); i++)
d6d578b49a19 [PostDog] Got CRUD working.
June Park <parkjune1995@gmail.com>
parents: 111
diff changeset
385 {
d6d578b49a19 [PostDog] Got CRUD working.
June Park <parkjune1995@gmail.com>
parents: 111
diff changeset
386 char *line = lines[i];
d6d578b49a19 [PostDog] Got CRUD working.
June Park <parkjune1995@gmail.com>
parents: 111
diff changeset
387 char **key_value = Dowa_String_Split(line, " ", (int)strlen(line), 1, arena);
d6d578b49a19 [PostDog] Got CRUD working.
June Park <parkjune1995@gmail.com>
parents: 111
diff changeset
388
d6d578b49a19 [PostDog] Got CRUD working.
June Park <parkjune1995@gmail.com>
parents: 111
diff changeset
389 if (Dowa_Array_Length(key_value) < 2)
114
e2a73e64e8e6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 112
diff changeset
390 break;
112
d6d578b49a19 [PostDog] Got CRUD working.
June Park <parkjune1995@gmail.com>
parents: 111
diff changeset
391
d6d578b49a19 [PostDog] Got CRUD working.
June Park <parkjune1995@gmail.com>
parents: 111
diff changeset
392 strcat(url_input_text, separator);
d6d578b49a19 [PostDog] Got CRUD working.
June Park <parkjune1995@gmail.com>
parents: 111
diff changeset
393 strcat(url_input_text, key_value[0]);
d6d578b49a19 [PostDog] Got CRUD working.
June Park <parkjune1995@gmail.com>
parents: 111
diff changeset
394 strcat(url_input_text, "=");
d6d578b49a19 [PostDog] Got CRUD working.
June Park <parkjune1995@gmail.com>
parents: 111
diff changeset
395 for (int i = 1; i < Dowa_Array_Length(key_value); i++)
d6d578b49a19 [PostDog] Got CRUD working.
June Park <parkjune1995@gmail.com>
parents: 111
diff changeset
396 {
d6d578b49a19 [PostDog] Got CRUD working.
June Park <parkjune1995@gmail.com>
parents: 111
diff changeset
397 if (!key_value[i] || key_value[i][0] == '\0')
d6d578b49a19 [PostDog] Got CRUD working.
June Park <parkjune1995@gmail.com>
parents: 111
diff changeset
398 break;
d6d578b49a19 [PostDog] Got CRUD working.
June Park <parkjune1995@gmail.com>
parents: 111
diff changeset
399 if (i > 1) strcat(url_input_text, "%20");
d6d578b49a19 [PostDog] Got CRUD working.
June Park <parkjune1995@gmail.com>
parents: 111
diff changeset
400 strcat(url_input_text, key_value[i]);
d6d578b49a19 [PostDog] Got CRUD working.
June Park <parkjune1995@gmail.com>
parents: 111
diff changeset
401 }
d6d578b49a19 [PostDog] Got CRUD working.
June Park <parkjune1995@gmail.com>
parents: 111
diff changeset
402 separator = "&";
d6d578b49a19 [PostDog] Got CRUD working.
June Park <parkjune1995@gmail.com>
parents: 111
diff changeset
403 }
d6d578b49a19 [PostDog] Got CRUD working.
June Park <parkjune1995@gmail.com>
parents: 111
diff changeset
404
d6d578b49a19 [PostDog] Got CRUD working.
June Park <parkjune1995@gmail.com>
parents: 111
diff changeset
405 Dowa_Arena_Free(arena);
d6d578b49a19 [PostDog] Got CRUD working.
June Park <parkjune1995@gmail.com>
parents: 111
diff changeset
406 }
d6d578b49a19 [PostDog] Got CRUD working.
June Park <parkjune1995@gmail.com>
parents: 111
diff changeset
407
114
e2a73e64e8e6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 112
diff changeset
408 int PostDog_String_To_MethodEnum(char *value)
e2a73e64e8e6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 112
diff changeset
409 {
e2a73e64e8e6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 112
diff changeset
410 if (strstr(value, "GET"))
e2a73e64e8e6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 112
diff changeset
411 return 0;
e2a73e64e8e6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 112
diff changeset
412 if (strstr(value, "POST"))
e2a73e64e8e6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 112
diff changeset
413 return 1;
e2a73e64e8e6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 112
diff changeset
414 if (strstr(value, "PUT"))
e2a73e64e8e6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 112
diff changeset
415 return 2;
e2a73e64e8e6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 112
diff changeset
416 if (strstr(value, "DELETE"))
e2a73e64e8e6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 112
diff changeset
417 return 3;
e2a73e64e8e6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 112
diff changeset
418 return 0;
e2a73e64e8e6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 112
diff changeset
419 }
e2a73e64e8e6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 112
diff changeset
420
e2a73e64e8e6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 112
diff changeset
421 void PostDog_Params_Reset(
e2a73e64e8e6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 112
diff changeset
422 char **p_url_input_text,
e2a73e64e8e6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 112
diff changeset
423 int *p_active_method_dropdown,
e2a73e64e8e6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 112
diff changeset
424 char **url_body_map,
e2a73e64e8e6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 112
diff changeset
425 char **p_url_result_text
e2a73e64e8e6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 112
diff changeset
426 )
e2a73e64e8e6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 112
diff changeset
427 {
e2a73e64e8e6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 112
diff changeset
428 char *url_input_text = *p_url_input_text;
e2a73e64e8e6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 112
diff changeset
429 char *url_result_text = *p_url_result_text;
e2a73e64e8e6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 112
diff changeset
430 int active_method_dropdown = *p_active_method_dropdown;
e2a73e64e8e6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 112
diff changeset
431
e2a73e64e8e6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 112
diff changeset
432 url_input_text = "";
e2a73e64e8e6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 112
diff changeset
433 url_result_text = "";
e2a73e64e8e6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 112
diff changeset
434 active_method_dropdown = 0;
e2a73e64e8e6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 112
diff changeset
435 for (int i = 0; i < Dowa_Array_Length(url_body_map); i++)
e2a73e64e8e6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 112
diff changeset
436 url_body_map[i] = "";
e2a73e64e8e6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 112
diff changeset
437 }
e2a73e64e8e6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 112
diff changeset
438
e2a73e64e8e6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 112
diff changeset
439 void PostDog_Load_File(
e2a73e64e8e6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 112
diff changeset
440 const char *filename,
e2a73e64e8e6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 112
diff changeset
441 char **p_url_input_text,
e2a73e64e8e6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 112
diff changeset
442 int *p_active_method_dropdown,
e2a73e64e8e6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 112
diff changeset
443 char **url_body_map,
e2a73e64e8e6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 112
diff changeset
444 char **p_url_result_text
e2a73e64e8e6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 112
diff changeset
445 ) {
e2a73e64e8e6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 112
diff changeset
446 char *url_input_text = *p_url_input_text;
e2a73e64e8e6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 112
diff changeset
447 char *url_result_text = *p_url_result_text;
e2a73e64e8e6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 112
diff changeset
448 int active_method_dropdown = *p_active_method_dropdown;
e2a73e64e8e6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 112
diff changeset
449
e2a73e64e8e6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 112
diff changeset
450 char full_file_path[512] = {0};
e2a73e64e8e6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 112
diff changeset
451 snprintf(full_file_path, 512, "%s/%s", POSTDOG_PATHS, filename);
e2a73e64e8e6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 112
diff changeset
452 FILE *file = fopen(full_file_path, "r");
e2a73e64e8e6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 112
diff changeset
453 if (!file)
e2a73e64e8e6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 112
diff changeset
454 return;
e2a73e64e8e6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 112
diff changeset
455
e2a73e64e8e6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 112
diff changeset
456 fseek(file, 0, SEEK_END);
e2a73e64e8e6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 112
diff changeset
457 size_t file_size = ftell(file);
e2a73e64e8e6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 112
diff changeset
458 fseek(file, 0, SEEK_SET);
e2a73e64e8e6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 112
diff changeset
459
e2a73e64e8e6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 112
diff changeset
460 Dowa_Arena *init_arena = Dowa_Arena_Create(file_size + 2);
e2a73e64e8e6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 112
diff changeset
461 Dowa_Arena *split_arena = Dowa_Arena_Create(file_size * 2);
e2a73e64e8e6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 112
diff changeset
462 char *file_buffer = Dowa_Arena_Allocate(init_arena, file_size+1);
e2a73e64e8e6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 112
diff changeset
463 fread(file_buffer, 1, file_size, file);
e2a73e64e8e6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 112
diff changeset
464 char **values = Dowa_String_Split(file_buffer, "---\n", file_size, 4, split_arena);
e2a73e64e8e6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 112
diff changeset
465 Dowa_Arena_Free(init_arena);
e2a73e64e8e6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 112
diff changeset
466 for (int i = 0; i < Dowa_Array_Length(values); i++)
e2a73e64e8e6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 112
diff changeset
467 {
e2a73e64e8e6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 112
diff changeset
468 if (i == 0)
e2a73e64e8e6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 112
diff changeset
469 {
e2a73e64e8e6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 112
diff changeset
470 snprintf(url_input_text, strlen(values[i]) + 1, "%s", values[i]);
e2a73e64e8e6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 112
diff changeset
471 url_input_text[strcspn(url_input_text, "\n")] = '\0';
e2a73e64e8e6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 112
diff changeset
472 }
e2a73e64e8e6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 112
diff changeset
473 else if (i == 1)
e2a73e64e8e6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 112
diff changeset
474 active_method_dropdown = PostDog_String_To_MethodEnum(values[i]);
e2a73e64e8e6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 112
diff changeset
475 else if (i <= 3)
e2a73e64e8e6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 112
diff changeset
476 {
e2a73e64e8e6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 112
diff changeset
477 snprintf(url_body_map[i-2], strlen(values[i]) + 1, "%s", values[i]);
e2a73e64e8e6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 112
diff changeset
478 for (int j = strlen(values[i]); j > 0; j--)
e2a73e64e8e6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 112
diff changeset
479 {
e2a73e64e8e6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 112
diff changeset
480 if (url_body_map[i-2][j] == '\n')
e2a73e64e8e6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 112
diff changeset
481 {
e2a73e64e8e6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 112
diff changeset
482 url_body_map[i-2][j] = '\0';
e2a73e64e8e6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 112
diff changeset
483 break;
e2a73e64e8e6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 112
diff changeset
484 }
e2a73e64e8e6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 112
diff changeset
485 }
e2a73e64e8e6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 112
diff changeset
486 }
e2a73e64e8e6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 112
diff changeset
487 else
e2a73e64e8e6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 112
diff changeset
488 snprintf(url_result_text, strlen(values[i]) + 1, "%s", values[i]);
e2a73e64e8e6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 112
diff changeset
489 }
e2a73e64e8e6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 112
diff changeset
490 }
e2a73e64e8e6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 112
diff changeset
491
e2a73e64e8e6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 112
diff changeset
492 Rectangle AddPadding(Rectangle rect, float padding)
e2a73e64e8e6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 112
diff changeset
493 {
115
96db6c3f38d6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 114
diff changeset
494 return (Rectangle){
114
e2a73e64e8e6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 112
diff changeset
495 rect.x + padding,
e2a73e64e8e6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 112
diff changeset
496 rect.y + padding,
e2a73e64e8e6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 112
diff changeset
497 rect.width - (2 * padding),
e2a73e64e8e6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 112
diff changeset
498 rect.height - (2 * padding)
e2a73e64e8e6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 112
diff changeset
499 };
e2a73e64e8e6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 112
diff changeset
500 }
e2a73e64e8e6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 112
diff changeset
501
115
96db6c3f38d6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 114
diff changeset
502 // Layout helper functions
96db6c3f38d6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 114
diff changeset
503 Rectangle RightOf(Rectangle ref, float padding)
96db6c3f38d6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 114
diff changeset
504 {
96db6c3f38d6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 114
diff changeset
505 return (Rectangle){
96db6c3f38d6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 114
diff changeset
506 .x = ref.x + ref.width + padding,
96db6c3f38d6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 114
diff changeset
507 .y = ref.y,
96db6c3f38d6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 114
diff changeset
508 .width = 0,
96db6c3f38d6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 114
diff changeset
509 .height = ref.height
96db6c3f38d6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 114
diff changeset
510 };
96db6c3f38d6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 114
diff changeset
511 }
96db6c3f38d6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 114
diff changeset
512
96db6c3f38d6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 114
diff changeset
513 Rectangle Below(Rectangle ref, float padding)
96db6c3f38d6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 114
diff changeset
514 {
96db6c3f38d6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 114
diff changeset
515 return (Rectangle){
96db6c3f38d6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 114
diff changeset
516 .x = ref.x,
96db6c3f38d6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 114
diff changeset
517 .y = ref.y + ref.height + padding,
96db6c3f38d6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 114
diff changeset
518 .width = ref.width,
96db6c3f38d6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 114
diff changeset
519 .height = 0
96db6c3f38d6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 114
diff changeset
520 };
96db6c3f38d6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 114
diff changeset
521 }
96db6c3f38d6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 114
diff changeset
522
96db6c3f38d6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 114
diff changeset
523 Rectangle LeftColumn(Rectangle container, float ratio, float padding)
96db6c3f38d6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 114
diff changeset
524 {
96db6c3f38d6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 114
diff changeset
525 return (Rectangle){
96db6c3f38d6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 114
diff changeset
526 .x = container.x + padding,
96db6c3f38d6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 114
diff changeset
527 .y = container.y + padding,
96db6c3f38d6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 114
diff changeset
528 .width = (container.width * ratio) - padding,
96db6c3f38d6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 114
diff changeset
529 .height = container.height - (2 * padding)
96db6c3f38d6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 114
diff changeset
530 };
96db6c3f38d6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 114
diff changeset
531 }
96db6c3f38d6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 114
diff changeset
532
96db6c3f38d6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 114
diff changeset
533 Rectangle RightColumn(Rectangle container, Rectangle leftCol, float padding)
96db6c3f38d6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 114
diff changeset
534 {
96db6c3f38d6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 114
diff changeset
535 return (Rectangle){
96db6c3f38d6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 114
diff changeset
536 .x = leftCol.x + leftCol.width + padding,
96db6c3f38d6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 114
diff changeset
537 .y = container.y + padding,
96db6c3f38d6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 114
diff changeset
538 .width = container.width - leftCol.width - (3 * padding),
96db6c3f38d6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 114
diff changeset
539 .height = container.height - (2 * padding)
96db6c3f38d6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 114
diff changeset
540 };
96db6c3f38d6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 114
diff changeset
541 }
96db6c3f38d6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 114
diff changeset
542
96db6c3f38d6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 114
diff changeset
543 Rectangle HorizontalSplit(Rectangle container, float ratio)
96db6c3f38d6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 114
diff changeset
544 {
96db6c3f38d6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 114
diff changeset
545 return (Rectangle){
96db6c3f38d6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 114
diff changeset
546 .x = container.x,
96db6c3f38d6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 114
diff changeset
547 .y = container.y,
96db6c3f38d6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 114
diff changeset
548 .width = container.width * ratio,
96db6c3f38d6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 114
diff changeset
549 .height = container.height
96db6c3f38d6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 114
diff changeset
550 };
96db6c3f38d6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 114
diff changeset
551 }
96db6c3f38d6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 114
diff changeset
552
54
b3e82d22f961 [PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff changeset
553 int main()
b3e82d22f961 [PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff changeset
554 {
111
48f260576059 [PostDog] Rewriting it from scratch as it is unreadable for me.
June Park <parkjune1995@gmail.com>
parents: 63
diff changeset
555 // -- initizlied --//
48f260576059 [PostDog] Rewriting it from scratch as it is unreadable for me.
June Park <parkjune1995@gmail.com>
parents: 63
diff changeset
556 InitWindow(SCREEN_WIDTH, SCREEN_HEIGHT, "PostDog");
54
b3e82d22f961 [PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff changeset
557 SetWindowState(FLAG_WINDOW_RESIZABLE);
b3e82d22f961 [PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff changeset
558 SetTargetFPS(60);
b3e82d22f961 [PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff changeset
559
112
d6d578b49a19 [PostDog] Got CRUD working.
June Park <parkjune1995@gmail.com>
parents: 111
diff changeset
560 Dowa_Arena *arena = Dowa_Arena_Create(AREANA_BUFFER_LENGTH);
54
b3e82d22f961 [PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff changeset
561
114
e2a73e64e8e6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 112
diff changeset
562 Font customFont = LoadFontEx("postdog/Roboto-Regular.ttf", 20, 0, 0);
e2a73e64e8e6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 112
diff changeset
563 GuiSetFont(customFont);
e2a73e64e8e6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 112
diff changeset
564 GuiSetStyle(DEFAULT, TEXT_SIZE, 20);
e2a73e64e8e6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 112
diff changeset
565
111
48f260576059 [PostDog] Rewriting it from scratch as it is unreadable for me.
June Park <parkjune1995@gmail.com>
parents: 63
diff changeset
566 // -- Starting pos ---//
114
e2a73e64e8e6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 112
diff changeset
567 // Everyhting is relative to sidebar at this point lol
111
48f260576059 [PostDog] Rewriting it from scratch as it is unreadable for me.
June Park <parkjune1995@gmail.com>
parents: 63
diff changeset
568 float side_bar_x = 10;
48f260576059 [PostDog] Rewriting it from scratch as it is unreadable for me.
June Park <parkjune1995@gmail.com>
parents: 63
diff changeset
569 float side_bar_y = 10;
48f260576059 [PostDog] Rewriting it from scratch as it is unreadable for me.
June Park <parkjune1995@gmail.com>
parents: 63
diff changeset
570 Rectangle history_sidebar = { .x = side_bar_x, .y = side_bar_y, .width = 0, .height = 0 };
114
e2a73e64e8e6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 112
diff changeset
571 Dowa_Array_Reserve(history_items, 10);
e2a73e64e8e6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 112
diff changeset
572 Dowa_Array_Reserve(new_history_items, 10);
e2a73e64e8e6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 112
diff changeset
573 PostDog_History_Load(&history_items);
54
b3e82d22f961 [PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff changeset
574
111
48f260576059 [PostDog] Rewriting it from scratch as it is unreadable for me.
June Park <parkjune1995@gmail.com>
parents: 63
diff changeset
575 Rectangle url_area = { 0 };
48f260576059 [PostDog] Rewriting it from scratch as it is unreadable for me.
June Park <parkjune1995@gmail.com>
parents: 63
diff changeset
576 Rectangle textBounds = { 0 };
48f260576059 [PostDog] Rewriting it from scratch as it is unreadable for me.
June Park <parkjune1995@gmail.com>
parents: 63
diff changeset
577 Rectangle url_input_bounds = { 0 };
114
e2a73e64e8e6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 112
diff changeset
578 bool url_input_edit = false;
111
48f260576059 [PostDog] Rewriting it from scratch as it is unreadable for me.
June Park <parkjune1995@gmail.com>
parents: 63
diff changeset
579 Rectangle url_text_bounds = { 0 };
48f260576059 [PostDog] Rewriting it from scratch as it is unreadable for me.
June Park <parkjune1995@gmail.com>
parents: 63
diff changeset
580 Rectangle url_enter_button = { 0 };
112
d6d578b49a19 [PostDog] Got CRUD working.
June Park <parkjune1995@gmail.com>
parents: 111
diff changeset
581 Rectangle method_dropdown = { 0 };
54
b3e82d22f961 [PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff changeset
582
114
e2a73e64e8e6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 112
diff changeset
583
112
d6d578b49a19 [PostDog] Got CRUD working.
June Park <parkjune1995@gmail.com>
parents: 111
diff changeset
584 char *url_input_text = (char *)Dowa_Arena_Allocate(arena, URL_TEXT_BUFFER);
d6d578b49a19 [PostDog] Got CRUD working.
June Park <parkjune1995@gmail.com>
parents: 111
diff changeset
585 snprintf(url_input_text, URL_TEXT_BUFFER, "https://httpbin.org/get");
d6d578b49a19 [PostDog] Got CRUD working.
June Park <parkjune1995@gmail.com>
parents: 111
diff changeset
586
114
e2a73e64e8e6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 112
diff changeset
587 char **url_body_map = NULL;
e2a73e64e8e6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 112
diff changeset
588 Dowa_Array_Push_Arena(url_body_map, (char *)Dowa_Arena_Allocate(arena, HEADER_BUFFER_LENGTH), arena);
e2a73e64e8e6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 112
diff changeset
589 Dowa_Array_Push_Arena(url_body_map, (char *)Dowa_Arena_Allocate(arena, BODY_BUFFER_LENGTH), arena);
e2a73e64e8e6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 112
diff changeset
590 Dowa_Array_Push_Arena(url_body_map, (char *)Dowa_Arena_Allocate(arena, DEFAULT_TEXT_BUFFER_LENGTH), arena);
e2a73e64e8e6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 112
diff changeset
591 Dowa_Array_Push_Arena(url_body_map, (char *)Dowa_Arena_Allocate(arena, DEFAULT_TEXT_BUFFER_LENGTH), arena);
112
d6d578b49a19 [PostDog] Got CRUD working.
June Park <parkjune1995@gmail.com>
parents: 111
diff changeset
592
114
e2a73e64e8e6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 112
diff changeset
593 snprintf(url_body_map[TAB_HEADER], HEADER_BUFFER_LENGTH, "Content-Type: application/json");
e2a73e64e8e6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 112
diff changeset
594 snprintf(url_body_map[TAB_BODY], HEADER_BUFFER_LENGTH, "");
112
d6d578b49a19 [PostDog] Got CRUD working.
June Park <parkjune1995@gmail.com>
parents: 111
diff changeset
595
d6d578b49a19 [PostDog] Got CRUD working.
June Park <parkjune1995@gmail.com>
parents: 111
diff changeset
596 char *url_result_text = (char *)Dowa_Arena_Allocate(arena, RESULT_BUFFER_LENGTH);
d6d578b49a19 [PostDog] Got CRUD working.
June Park <parkjune1995@gmail.com>
parents: 111
diff changeset
597
d6d578b49a19 [PostDog] Got CRUD working.
June Park <parkjune1995@gmail.com>
parents: 111
diff changeset
598 int active_method_dropdown = 0;
d6d578b49a19 [PostDog] Got CRUD working.
June Park <parkjune1995@gmail.com>
parents: 111
diff changeset
599 bool method_edit = false;
d6d578b49a19 [PostDog] Got CRUD working.
June Park <parkjune1995@gmail.com>
parents: 111
diff changeset
600
111
48f260576059 [PostDog] Rewriting it from scratch as it is unreadable for me.
June Park <parkjune1995@gmail.com>
parents: 63
diff changeset
601 int sendRequest;
54
b3e82d22f961 [PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff changeset
602
112
d6d578b49a19 [PostDog] Got CRUD working.
June Park <parkjune1995@gmail.com>
parents: 111
diff changeset
603 // -- input --//
111
48f260576059 [PostDog] Rewriting it from scratch as it is unreadable for me.
June Park <parkjune1995@gmail.com>
parents: 63
diff changeset
604 Rectangle input_area = { 0 };
48f260576059 [PostDog] Rewriting it from scratch as it is unreadable for me.
June Park <parkjune1995@gmail.com>
parents: 63
diff changeset
605 Rectangle input_tab = { 0 };
112
d6d578b49a19 [PostDog] Got CRUD working.
June Park <parkjune1995@gmail.com>
parents: 111
diff changeset
606 Rectangle input_tab_item = { 0 };
111
48f260576059 [PostDog] Rewriting it from scratch as it is unreadable for me.
June Park <parkjune1995@gmail.com>
parents: 63
diff changeset
607 Rectangle input_body = { 0 };
112
d6d578b49a19 [PostDog] Got CRUD working.
June Park <parkjune1995@gmail.com>
parents: 111
diff changeset
608 bool input_body_bool = false;
54
b3e82d22f961 [PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff changeset
609
112
d6d578b49a19 [PostDog] Got CRUD working.
June Park <parkjune1995@gmail.com>
parents: 111
diff changeset
610 // -- result --//
111
48f260576059 [PostDog] Rewriting it from scratch as it is unreadable for me.
June Park <parkjune1995@gmail.com>
parents: 63
diff changeset
611 Rectangle result_area = { 0 };
48f260576059 [PostDog] Rewriting it from scratch as it is unreadable for me.
June Park <parkjune1995@gmail.com>
parents: 63
diff changeset
612 Rectangle result_body = { 0 };
54
b3e82d22f961 [PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff changeset
613
111
48f260576059 [PostDog] Rewriting it from scratch as it is unreadable for me.
June Park <parkjune1995@gmail.com>
parents: 63
diff changeset
614 // General styling.
114
e2a73e64e8e6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 112
diff changeset
615 float padding = 10; // TODO make it % based?
112
d6d578b49a19 [PostDog] Got CRUD working.
June Park <parkjune1995@gmail.com>
parents: 111
diff changeset
616 int active_input_tab = 0;
54
b3e82d22f961 [PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff changeset
617
b3e82d22f961 [PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff changeset
618 while (!WindowShouldClose())
b3e82d22f961 [PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff changeset
619 {
111
48f260576059 [PostDog] Rewriting it from scratch as it is unreadable for me.
June Park <parkjune1995@gmail.com>
parents: 63
diff changeset
620 int screen_width = GetScreenWidth();
48f260576059 [PostDog] Rewriting it from scratch as it is unreadable for me.
June Park <parkjune1995@gmail.com>
parents: 63
diff changeset
621 int screen_height = GetScreenHeight();
48f260576059 [PostDog] Rewriting it from scratch as it is unreadable for me.
June Park <parkjune1995@gmail.com>
parents: 63
diff changeset
622
115
96db6c3f38d6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 114
diff changeset
623 // Define main screen container
96db6c3f38d6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 114
diff changeset
624 Rectangle screen = { 0, 0, screen_width, screen_height };
114
e2a73e64e8e6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 112
diff changeset
625
115
96db6c3f38d6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 114
diff changeset
626 // Layout: Sidebar (left 15%) and Content Area (right 85%)
96db6c3f38d6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 114
diff changeset
627 history_sidebar = LeftColumn(screen, 0.15, padding);
96db6c3f38d6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 114
diff changeset
628 Rectangle content_area = RightColumn(screen, history_sidebar, padding);
96db6c3f38d6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 114
diff changeset
629
96db6c3f38d6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 114
diff changeset
630 // History items inside sidebar
114
e2a73e64e8e6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 112
diff changeset
631 int32 new_history_items_length = Dowa_Array_Length(new_history_items);
e2a73e64e8e6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 112
diff changeset
632 int32 history_item_length = Dowa_Array_Length(history_items);
115
96db6c3f38d6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 114
diff changeset
633 int32 total = new_history_items_length + history_item_length;
96db6c3f38d6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 114
diff changeset
634 float item_height = history_sidebar.height * 0.05;
96db6c3f38d6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 114
diff changeset
635
114
e2a73e64e8e6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 112
diff changeset
636 for (int i = 0; i < total; i++)
e2a73e64e8e6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 112
diff changeset
637 {
115
96db6c3f38d6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 114
diff changeset
638 HistoryItem *curr_history_items = i < new_history_items_length ?
96db6c3f38d6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 114
diff changeset
639 &new_history_items[i] : &history_items[i - new_history_items_length];
96db6c3f38d6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 114
diff changeset
640
96db6c3f38d6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 114
diff changeset
641 curr_history_items->rect = (Rectangle){
96db6c3f38d6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 114
diff changeset
642 .x = history_sidebar.x,
96db6c3f38d6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 114
diff changeset
643 .y = history_sidebar.y + (padding + item_height) * i,
96db6c3f38d6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 114
diff changeset
644 .width = history_sidebar.width,
96db6c3f38d6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 114
diff changeset
645 .height = item_height
96db6c3f38d6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 114
diff changeset
646 };
114
e2a73e64e8e6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 112
diff changeset
647 }
54
b3e82d22f961 [PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff changeset
648
115
96db6c3f38d6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 114
diff changeset
649 // Content area: split into URL bar (top 10%) and body (bottom 90%)
96db6c3f38d6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 114
diff changeset
650 url_area = (Rectangle){
96db6c3f38d6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 114
diff changeset
651 .x = content_area.x,
96db6c3f38d6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 114
diff changeset
652 .y = content_area.y,
96db6c3f38d6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 114
diff changeset
653 .width = content_area.width,
96db6c3f38d6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 114
diff changeset
654 .height = content_area.height * 0.1
96db6c3f38d6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 114
diff changeset
655 };
54
b3e82d22f961 [PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff changeset
656
115
96db6c3f38d6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 114
diff changeset
657 // URL bar elements laid out horizontally
96db6c3f38d6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 114
diff changeset
658 float url_control_y = url_area.y + (url_area.height - TEXT_SIZE * 2) / 2;
54
b3e82d22f961 [PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff changeset
659
115
96db6c3f38d6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 114
diff changeset
660 url_text_bounds = (Rectangle){
96db6c3f38d6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 114
diff changeset
661 .x = url_area.x + padding,
96db6c3f38d6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 114
diff changeset
662 .y = url_control_y,
96db6c3f38d6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 114
diff changeset
663 .width = 7 * (TEXT_SIZE / 2),
96db6c3f38d6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 114
diff changeset
664 .height = TEXT_SIZE * 2
96db6c3f38d6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 114
diff changeset
665 };
96db6c3f38d6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 114
diff changeset
666
96db6c3f38d6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 114
diff changeset
667 url_input_bounds = RightOf(url_text_bounds, padding);
96db6c3f38d6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 114
diff changeset
668 url_input_bounds.width = url_area.width * 0.7;
111
48f260576059 [PostDog] Rewriting it from scratch as it is unreadable for me.
June Park <parkjune1995@gmail.com>
parents: 63
diff changeset
669 url_input_bounds.height = TEXT_SIZE * 2;
48f260576059 [PostDog] Rewriting it from scratch as it is unreadable for me.
June Park <parkjune1995@gmail.com>
parents: 63
diff changeset
670
115
96db6c3f38d6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 114
diff changeset
671 url_enter_button = RightOf(url_input_bounds, padding);
96db6c3f38d6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 114
diff changeset
672 url_enter_button.width = url_area.width * 0.1;
111
48f260576059 [PostDog] Rewriting it from scratch as it is unreadable for me.
June Park <parkjune1995@gmail.com>
parents: 63
diff changeset
673 url_enter_button.height = TEXT_SIZE * 2;
54
b3e82d22f961 [PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff changeset
674
115
96db6c3f38d6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 114
diff changeset
675 method_dropdown = RightOf(url_enter_button, padding);
96db6c3f38d6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 114
diff changeset
676 method_dropdown.width = url_area.width * 0.1;
112
d6d578b49a19 [PostDog] Got CRUD working.
June Park <parkjune1995@gmail.com>
parents: 111
diff changeset
677 method_dropdown.height = TEXT_SIZE * 2;
d6d578b49a19 [PostDog] Got CRUD working.
June Park <parkjune1995@gmail.com>
parents: 111
diff changeset
678
115
96db6c3f38d6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 114
diff changeset
679 // Body area: split into input (left 50%) and result (right 50%)
96db6c3f38d6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 114
diff changeset
680 Rectangle body_area = Below(url_area, 0);
96db6c3f38d6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 114
diff changeset
681 body_area.height = content_area.height - url_area.height;
96db6c3f38d6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 114
diff changeset
682
96db6c3f38d6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 114
diff changeset
683 input_area = HorizontalSplit(body_area, 0.5);
96db6c3f38d6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 114
diff changeset
684 result_area = RightOf(input_area, 0);
96db6c3f38d6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 114
diff changeset
685 result_area.width = body_area.width - input_area.width;
54
b3e82d22f961 [PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff changeset
686
115
96db6c3f38d6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 114
diff changeset
687 // Input area: tabs at top (10%) and text box below (90%)
96db6c3f38d6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 114
diff changeset
688 input_tab = (Rectangle){
96db6c3f38d6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 114
diff changeset
689 .x = input_area.x + padding,
96db6c3f38d6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 114
diff changeset
690 .y = input_area.y + padding,
96db6c3f38d6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 114
diff changeset
691 .width = input_area.width - (2 * padding),
96db6c3f38d6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 114
diff changeset
692 .height = input_area.height * 0.1
96db6c3f38d6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 114
diff changeset
693 };
96db6c3f38d6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 114
diff changeset
694
112
d6d578b49a19 [PostDog] Got CRUD working.
June Park <parkjune1995@gmail.com>
parents: 111
diff changeset
695 input_tab_item = input_tab;
d6d578b49a19 [PostDog] Got CRUD working.
June Park <parkjune1995@gmail.com>
parents: 111
diff changeset
696 input_tab_item.width = input_tab.width / 4;
54
b3e82d22f961 [PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff changeset
697
115
96db6c3f38d6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 114
diff changeset
698 input_body = Below(input_tab, 0);
96db6c3f38d6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 114
diff changeset
699 input_body.width = input_tab.width;
96db6c3f38d6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 114
diff changeset
700 input_body.height = input_area.height - input_tab.height - (2 * padding);
54
b3e82d22f961 [PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff changeset
701
115
96db6c3f38d6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 114
diff changeset
702 // Result area: aligned with input tabs
96db6c3f38d6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 114
diff changeset
703 result_body = (Rectangle){
96db6c3f38d6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 114
diff changeset
704 .x = result_area.x + padding,
96db6c3f38d6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 114
diff changeset
705 .y = input_body.y,
96db6c3f38d6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 114
diff changeset
706 .width = result_area.width - (2 * padding),
96db6c3f38d6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 114
diff changeset
707 .height = input_body.height
96db6c3f38d6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 114
diff changeset
708 };
54
b3e82d22f961 [PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff changeset
709
114
e2a73e64e8e6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 112
diff changeset
710 Vector2 mouse_position = GetMousePosition();
e2a73e64e8e6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 112
diff changeset
711
54
b3e82d22f961 [PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff changeset
712 BeginDrawing();
b3e82d22f961 [PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff changeset
713 ClearBackground(GetColor(GuiGetStyle(DEFAULT, BACKGROUND_COLOR)));
b3e82d22f961 [PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff changeset
714
111
48f260576059 [PostDog] Rewriting it from scratch as it is unreadable for me.
June Park <parkjune1995@gmail.com>
parents: 63
diff changeset
715 DrawRectangleRec(history_sidebar, Fade(GRAY, 0.1f));
114
e2a73e64e8e6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 112
diff changeset
716 for (int i = 0; i < total; i++)
e2a73e64e8e6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 112
diff changeset
717 {
e2a73e64e8e6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 112
diff changeset
718 HistoryItem *curr_history_items = i < new_history_items_length ? &new_history_items[i] : &history_items[i - new_history_items_length];
e2a73e64e8e6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 112
diff changeset
719 DrawRectangleRec(curr_history_items->rect, Fade(RED, 0.1f));
e2a73e64e8e6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 112
diff changeset
720 GuiDrawText(curr_history_items->filename, AddPadding(curr_history_items->rect, padding), TEXT_ALIGN_CENTER, RED);
e2a73e64e8e6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 112
diff changeset
721 }
54
b3e82d22f961 [PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff changeset
722
111
48f260576059 [PostDog] Rewriting it from scratch as it is unreadable for me.
June Park <parkjune1995@gmail.com>
parents: 63
diff changeset
723 // URL area Rect
48f260576059 [PostDog] Rewriting it from scratch as it is unreadable for me.
June Park <parkjune1995@gmail.com>
parents: 63
diff changeset
724 GuiDrawText("URL: ", url_text_bounds, TEXT_ALIGN_CENTER, RED);
48f260576059 [PostDog] Rewriting it from scratch as it is unreadable for me.
June Park <parkjune1995@gmail.com>
parents: 63
diff changeset
725 DrawRectangleRec(url_area, Fade(RED, 0.1f));
114
e2a73e64e8e6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 112
diff changeset
726 if (GuiTextBox(url_input_bounds, url_input_text, DEFAULT_TEXT_BUFFER_LENGTH, url_input_edit))
e2a73e64e8e6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 112
diff changeset
727 url_input_edit = !url_input_edit;
e2a73e64e8e6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 112
diff changeset
728
111
48f260576059 [PostDog] Rewriting it from scratch as it is unreadable for me.
June Park <parkjune1995@gmail.com>
parents: 63
diff changeset
729 sendRequest = GuiButton(url_enter_button, "ENTER");
112
d6d578b49a19 [PostDog] Got CRUD working.
June Park <parkjune1995@gmail.com>
parents: 111
diff changeset
730 if (sendRequest)
114
e2a73e64e8e6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 112
diff changeset
731 PostDog_Http_Request(
112
d6d578b49a19 [PostDog] Got CRUD working.
June Park <parkjune1995@gmail.com>
parents: 111
diff changeset
732 url_input_text,
d6d578b49a19 [PostDog] Got CRUD working.
June Park <parkjune1995@gmail.com>
parents: 111
diff changeset
733 PostDog_Enum_To_String(active_method_dropdown),
114
e2a73e64e8e6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 112
diff changeset
734 url_body_map[TAB_HEADER],
e2a73e64e8e6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 112
diff changeset
735 url_body_map[TAB_BODY],
112
d6d578b49a19 [PostDog] Got CRUD working.
June Park <parkjune1995@gmail.com>
parents: 111
diff changeset
736 url_result_text,
d6d578b49a19 [PostDog] Got CRUD working.
June Park <parkjune1995@gmail.com>
parents: 111
diff changeset
737 RESULT_BUFFER_LENGTH
d6d578b49a19 [PostDog] Got CRUD working.
June Park <parkjune1995@gmail.com>
parents: 111
diff changeset
738 );
d6d578b49a19 [PostDog] Got CRUD working.
June Park <parkjune1995@gmail.com>
parents: 111
diff changeset
739 if (GuiDropdownBox(method_dropdown, "GET;POST;PUT;DELETE", &active_method_dropdown, method_edit))
d6d578b49a19 [PostDog] Got CRUD working.
June Park <parkjune1995@gmail.com>
parents: 111
diff changeset
740 method_edit = !method_edit;
54
b3e82d22f961 [PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff changeset
741
111
48f260576059 [PostDog] Rewriting it from scratch as it is unreadable for me.
June Park <parkjune1995@gmail.com>
parents: 63
diff changeset
742 // Input Tabs Rect
48f260576059 [PostDog] Rewriting it from scratch as it is unreadable for me.
June Park <parkjune1995@gmail.com>
parents: 63
diff changeset
743 DrawRectangleRec(input_area, Fade(BLUE, 0.1f));
48f260576059 [PostDog] Rewriting it from scratch as it is unreadable for me.
June Park <parkjune1995@gmail.com>
parents: 63
diff changeset
744 DrawRectangleRec(input_tab, Fade(DARKBLUE, 0.1f));
112
d6d578b49a19 [PostDog] Got CRUD working.
June Park <parkjune1995@gmail.com>
parents: 111
diff changeset
745 GuiSetStyle(TOGGLE, GROUP_PADDING, 0);
114
e2a73e64e8e6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 112
diff changeset
746 if (JUNE_GuiTextBox(input_body, url_body_map[active_input_tab], DEFAULT_TEXT_BUFFER_LENGTH, input_body_bool))
112
d6d578b49a19 [PostDog] Got CRUD working.
June Park <parkjune1995@gmail.com>
parents: 111
diff changeset
747 input_body_bool = !input_body_bool;
d6d578b49a19 [PostDog] Got CRUD working.
June Park <parkjune1995@gmail.com>
parents: 111
diff changeset
748 GuiToggleGroup(input_tab_item, "Header;Body;Get Param;Bar", &active_input_tab);
114
e2a73e64e8e6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 112
diff changeset
749
e2a73e64e8e6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 112
diff changeset
750 PostDog_Update_URL(&url_input_text, url_body_map[TAB_GET_PARAMS]);
54
b3e82d22f961 [PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff changeset
751
111
48f260576059 [PostDog] Rewriting it from scratch as it is unreadable for me.
June Park <parkjune1995@gmail.com>
parents: 63
diff changeset
752 // Result Rect
48f260576059 [PostDog] Rewriting it from scratch as it is unreadable for me.
June Park <parkjune1995@gmail.com>
parents: 63
diff changeset
753 DrawRectangleRec(result_area, Fade(GREEN, 0.1f));
48f260576059 [PostDog] Rewriting it from scratch as it is unreadable for me.
June Park <parkjune1995@gmail.com>
parents: 63
diff changeset
754 DrawRectangleRec(result_body, Fade(DARKGREEN, 0.1f));
112
d6d578b49a19 [PostDog] Got CRUD working.
June Park <parkjune1995@gmail.com>
parents: 111
diff changeset
755 GuiTextBoxMulti(result_body, url_result_text, RESULT_BUFFER_LENGTH, false);
114
e2a73e64e8e6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 112
diff changeset
756
e2a73e64e8e6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 112
diff changeset
757 if (url_input_edit && (IsKeyDown(KEY_LEFT_SUPER) || IsKeyDown(KEY_LEFT_CONTROL)) && IsKeyPressed(KEY_C))
e2a73e64e8e6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 112
diff changeset
758 {
e2a73e64e8e6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 112
diff changeset
759 SetClipboardText(url_input_text);
e2a73e64e8e6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 112
diff changeset
760 }
e2a73e64e8e6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 112
diff changeset
761 else if (input_body_bool && (IsKeyDown(KEY_LEFT_SUPER) || IsKeyDown(KEY_LEFT_CONTROL)) && IsKeyPressed(KEY_C))
e2a73e64e8e6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 112
diff changeset
762 {
e2a73e64e8e6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 112
diff changeset
763 SetClipboardText(url_body_map[active_input_tab]);
e2a73e64e8e6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 112
diff changeset
764 }
e2a73e64e8e6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 112
diff changeset
765 else if (InArea(mouse_position, result_body))
e2a73e64e8e6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 112
diff changeset
766 {
e2a73e64e8e6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 112
diff changeset
767 DrawRectangleRec(result_body, Fade(GREEN, 0.3f));
e2a73e64e8e6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 112
diff changeset
768 if ((IsKeyDown(KEY_LEFT_SUPER) || IsKeyDown(KEY_LEFT_CONTROL)) && IsKeyPressed(KEY_C))
e2a73e64e8e6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 112
diff changeset
769 SetClipboardText(url_result_text);
e2a73e64e8e6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 112
diff changeset
770 }
e2a73e64e8e6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 112
diff changeset
771
e2a73e64e8e6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 112
diff changeset
772 for (int i = 0; i < Dowa_Array_Length(history_items); i++)
e2a73e64e8e6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 112
diff changeset
773 {
e2a73e64e8e6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 112
diff changeset
774 if (Clicked(mouse_position, history_items[i].rect))
e2a73e64e8e6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 112
diff changeset
775 PostDog_Load_File(
e2a73e64e8e6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 112
diff changeset
776 history_items[i].filename,
e2a73e64e8e6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 112
diff changeset
777 &url_input_text,
e2a73e64e8e6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 112
diff changeset
778 &active_method_dropdown,
e2a73e64e8e6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 112
diff changeset
779 url_body_map,
e2a73e64e8e6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 112
diff changeset
780 &url_result_text
e2a73e64e8e6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 112
diff changeset
781 );
e2a73e64e8e6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 112
diff changeset
782 }
54
b3e82d22f961 [PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff changeset
783 EndDrawing();
b3e82d22f961 [PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff changeset
784 }
b3e82d22f961 [PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff changeset
785 CloseWindow();
b3e82d22f961 [PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff changeset
786 return 0;
b3e82d22f961 [PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff changeset
787 }