annotate postdog/main.c @ 155:3bb45eb67906

[Postdog] Updated variables names and padding sizes. Needs more work.
author June Park <parkjune1995@gmail.com>
date Mon, 12 Jan 2026 09:12:31 -0800
parents 790930d9bb90
children 05cf9467a1c3
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>
152
7387eec8e7f8 [Postdog] Updated to use Seobeo_Client instead of CURL. Updated to handle websocket connection.
June Park <parkjune1995@gmail.com>
parents: 118
diff changeset
6 #include <pthread.h>
58
ccb42d5bf8fd [PostDog] Somewhat working copy. That would use for testing.
June Park <parkjune1995@gmail.com>
parents: 57
diff changeset
7
152
7387eec8e7f8 [Postdog] Updated to use Seobeo_Client instead of CURL. Updated to handle websocket connection.
June Park <parkjune1995@gmail.com>
parents: 118
diff changeset
8 #ifdef _WIN32
7387eec8e7f8 [Postdog] Updated to use Seobeo_Client instead of CURL. Updated to handle websocket connection.
June Park <parkjune1995@gmail.com>
parents: 118
diff changeset
9 #include <direct.h>
7387eec8e7f8 [Postdog] Updated to use Seobeo_Client instead of CURL. Updated to handle websocket connection.
June Park <parkjune1995@gmail.com>
parents: 118
diff changeset
10 #include <io.h>
7387eec8e7f8 [Postdog] Updated to use Seobeo_Client instead of CURL. Updated to handle websocket connection.
June Park <parkjune1995@gmail.com>
parents: 118
diff changeset
11 #define mkdir(path, mode) _mkdir(path)
7387eec8e7f8 [Postdog] Updated to use Seobeo_Client instead of CURL. Updated to handle websocket connection.
June Park <parkjune1995@gmail.com>
parents: 118
diff changeset
12 #define access _access
7387eec8e7f8 [Postdog] Updated to use Seobeo_Client instead of CURL. Updated to handle websocket connection.
June Park <parkjune1995@gmail.com>
parents: 118
diff changeset
13 #define F_OK 0
7387eec8e7f8 [Postdog] Updated to use Seobeo_Client instead of CURL. Updated to handle websocket connection.
June Park <parkjune1995@gmail.com>
parents: 118
diff changeset
14 #else
7387eec8e7f8 [Postdog] Updated to use Seobeo_Client instead of CURL. Updated to handle websocket connection.
June Park <parkjune1995@gmail.com>
parents: 118
diff changeset
15 #include <sys/stat.h>
7387eec8e7f8 [Postdog] Updated to use Seobeo_Client instead of CURL. Updated to handle websocket connection.
June Park <parkjune1995@gmail.com>
parents: 118
diff changeset
16 #include <dirent.h>
7387eec8e7f8 [Postdog] Updated to use Seobeo_Client instead of CURL. Updated to handle websocket connection.
June Park <parkjune1995@gmail.com>
parents: 118
diff changeset
17 #include <unistd.h>
7387eec8e7f8 [Postdog] Updated to use Seobeo_Client instead of CURL. Updated to handle websocket connection.
June Park <parkjune1995@gmail.com>
parents: 118
diff changeset
18 #endif
7387eec8e7f8 [Postdog] Updated to use Seobeo_Client instead of CURL. Updated to handle websocket connection.
June Park <parkjune1995@gmail.com>
parents: 118
diff changeset
19
7387eec8e7f8 [Postdog] Updated to use Seobeo_Client instead of CURL. Updated to handle websocket connection.
June Park <parkjune1995@gmail.com>
parents: 118
diff changeset
20
54
b3e82d22f961 [PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff changeset
21 #include "third_party/raylib/include/raylib.h"
b3e82d22f961 [PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff changeset
22 #define RAYGUI_IMPLEMENTATION
b3e82d22f961 [PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff changeset
23 #include "third_party/raylib/include/raygui.h"
b3e82d22f961 [PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff changeset
24
152
7387eec8e7f8 [Postdog] Updated to use Seobeo_Client instead of CURL. Updated to handle websocket connection.
June Park <parkjune1995@gmail.com>
parents: 118
diff changeset
25 #include "dowa/dowa.h"
7387eec8e7f8 [Postdog] Updated to use Seobeo_Client instead of CURL. Updated to handle websocket connection.
June Park <parkjune1995@gmail.com>
parents: 118
diff changeset
26 #include "seobeo/seobeo.h"
7387eec8e7f8 [Postdog] Updated to use Seobeo_Client instead of CURL. Updated to handle websocket connection.
June Park <parkjune1995@gmail.com>
parents: 118
diff changeset
27
114
e2a73e64e8e6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 112
diff changeset
28 #ifndef POSTDOG_PATHS
e2a73e64e8e6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 112
diff changeset
29 #define POSTDOG_PATHS "/Users/mrjunejune/zenbu/postdog/history"
e2a73e64e8e6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 112
diff changeset
30 #endif
e2a73e64e8e6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 112
diff changeset
31
54
b3e82d22f961 [PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff changeset
32 #define SCREEN_WIDTH 1280
b3e82d22f961 [PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff changeset
33 #define SCREEN_HEIGHT 780
116
7bd795bac997 [Postdog] Added scrollable area to inputs and history files, buttons to delete and view.
June Park <parkjune1995@gmail.com>
parents: 115
diff changeset
34 #define MAX_SCROLL_HEIGHT 10000
54
b3e82d22f961 [PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff changeset
35
112
d6d578b49a19 [PostDog] Got CRUD working.
June Park <parkjune1995@gmail.com>
parents: 111
diff changeset
36 #define HEADER_BUFFER_LENGTH 1024 * 4
d6d578b49a19 [PostDog] Got CRUD working.
June Park <parkjune1995@gmail.com>
parents: 111
diff changeset
37 #define DEFAULT_TEXT_BUFFER_LENGTH 1024 * 4
116
7bd795bac997 [Postdog] Added scrollable area to inputs and history files, buttons to delete and view.
June Park <parkjune1995@gmail.com>
parents: 115
diff changeset
38 #define URL_TEXT_BUFFER_LENGTH 1024 * 10
7bd795bac997 [Postdog] Added scrollable area to inputs and history files, buttons to delete and view.
June Park <parkjune1995@gmail.com>
parents: 115
diff changeset
39 #define BODY_BUFFER_LENGTH 1024 * 1024 * 5
7bd795bac997 [Postdog] Added scrollable area to inputs and history files, buttons to delete and view.
June Park <parkjune1995@gmail.com>
parents: 115
diff changeset
40 #define RESULT_BUFFER_LENGTH 1024 * 1024 * 5
112
d6d578b49a19 [PostDog] Got CRUD working.
June Park <parkjune1995@gmail.com>
parents: 111
diff changeset
41
d6d578b49a19 [PostDog] Got CRUD working.
June Park <parkjune1995@gmail.com>
parents: 111
diff changeset
42 typedef Dowa_KV(char*, char*) INPUT_HASHMAP;
d6d578b49a19 [PostDog] Got CRUD working.
June Park <parkjune1995@gmail.com>
parents: 111
diff changeset
43
54
b3e82d22f961 [PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff changeset
44 typedef struct {
b3e82d22f961 [PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff changeset
45 char *data;
b3e82d22f961 [PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff changeset
46 size_t size;
b3e82d22f961 [PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff changeset
47 } ResponseBuffer;
b3e82d22f961 [PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff changeset
48
b3e82d22f961 [PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff changeset
49 typedef struct {
114
e2a73e64e8e6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 112
diff changeset
50 char *filename;
118
249881ceff7b [PostDog] Updated some core logic. Will create a bookmark for postdog until the launch as this is annoying to deal with.
June Park <parkjune1995@gmail.com>
parents: 117
diff changeset
51 char *title;
114
e2a73e64e8e6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 112
diff changeset
52 Rectangle rect;
e2a73e64e8e6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 112
diff changeset
53 long time_modified;
117
b91f2dd6f84d [PostDog] Fixed delete logic.
June Park <parkjune1995@gmail.com>
parents: 116
diff changeset
54 boolean deleted;
54
b3e82d22f961 [PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff changeset
55 } HistoryItem;
b3e82d22f961 [PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff changeset
56
114
e2a73e64e8e6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 112
diff changeset
57 typedef struct {
e2a73e64e8e6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 112
diff changeset
58 Rectangle rectangle;
e2a73e64e8e6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 112
diff changeset
59 char *label;
e2a73e64e8e6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 112
diff changeset
60 bool active;
e2a73e64e8e6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 112
diff changeset
61 } TabItem;
e2a73e64e8e6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 112
diff changeset
62
e2a73e64e8e6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 112
diff changeset
63 typedef enum {
e2a73e64e8e6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 112
diff changeset
64 TAB_HEADER = 0,
e2a73e64e8e6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 112
diff changeset
65 TAB_BODY,
e2a73e64e8e6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 112
diff changeset
66 TAB_GET_PARAMS,
152
7387eec8e7f8 [Postdog] Updated to use Seobeo_Client instead of CURL. Updated to handle websocket connection.
June Park <parkjune1995@gmail.com>
parents: 118
diff changeset
67 TAB_WEBSOCKET,
114
e2a73e64e8e6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 112
diff changeset
68 TAB_LENGTH
e2a73e64e8e6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 112
diff changeset
69 } PostDog_Tab_Enum;
e2a73e64e8e6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 112
diff changeset
70
e2a73e64e8e6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 112
diff changeset
71 static uint32 counter = 0;
e2a73e64e8e6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 112
diff changeset
72 HistoryItem *history_items = NULL;
e2a73e64e8e6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 112
diff changeset
73 HistoryItem *new_history_items = NULL;
e2a73e64e8e6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 112
diff changeset
74
118
249881ceff7b [PostDog] Updated some core logic. Will create a bookmark for postdog until the launch as this is annoying to deal with.
June Park <parkjune1995@gmail.com>
parents: 117
diff changeset
75 // Global UI state
249881ceff7b [PostDog] Updated some core logic. Will create a bookmark for postdog until the launch as this is annoying to deal with.
June Park <parkjune1995@gmail.com>
parents: 117
diff changeset
76 char *url_input_text = NULL;
155
3bb45eb67906 [Postdog] Updated variables names and padding sizes. Needs more work.
June Park <parkjune1995@gmail.com>
parents: 153
diff changeset
77 char *result_text = NULL;
3bb45eb67906 [Postdog] Updated variables names and padding sizes. Needs more work.
June Park <parkjune1995@gmail.com>
parents: 153
diff changeset
78 char **input_body_array = NULL;
118
249881ceff7b [PostDog] Updated some core logic. Will create a bookmark for postdog until the launch as this is annoying to deal with.
June Park <parkjune1995@gmail.com>
parents: 117
diff changeset
79 int active_method_dropdown = 0;
152
7387eec8e7f8 [Postdog] Updated to use Seobeo_Client instead of CURL. Updated to handle websocket connection.
June Park <parkjune1995@gmail.com>
parents: 118
diff changeset
80 int active_input_tab = 0;
7387eec8e7f8 [Postdog] Updated to use Seobeo_Client instead of CURL. Updated to handle websocket connection.
June Park <parkjune1995@gmail.com>
parents: 118
diff changeset
81 Seobeo_WebSocket *ws = NULL;
153
790930d9bb90 [PostDog] Adding websocket to be more usable.
June Park <parkjune1995@gmail.com>
parents: 152
diff changeset
82 boolean WS_BREAK = FALSE;
155
3bb45eb67906 [Postdog] Updated variables names and padding sizes. Needs more work.
June Park <parkjune1995@gmail.com>
parents: 153
diff changeset
83 Color TEXT_COLOR = BLACK;
118
249881ceff7b [PostDog] Updated some core logic. Will create a bookmark for postdog until the launch as this is annoying to deal with.
June Park <parkjune1995@gmail.com>
parents: 117
diff changeset
84
114
e2a73e64e8e6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 112
diff changeset
85 int CompareHistoryItemsByDate(const void *a, const void *b) {
e2a73e64e8e6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 112
diff changeset
86 HistoryItem *itemA = (HistoryItem *)a;
e2a73e64e8e6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 112
diff changeset
87 HistoryItem *itemB = (HistoryItem *)b;
118
249881ceff7b [PostDog] Updated some core logic. Will create a bookmark for postdog until the launch as this is annoying to deal with.
June Park <parkjune1995@gmail.com>
parents: 117
diff changeset
88 return (itemB->time_modified - itemA->time_modified);
249881ceff7b [PostDog] Updated some core logic. Will create a bookmark for postdog until the launch as this is annoying to deal with.
June Park <parkjune1995@gmail.com>
parents: 117
diff changeset
89 }
249881ceff7b [PostDog] Updated some core logic. Will create a bookmark for postdog until the launch as this is annoying to deal with.
June Park <parkjune1995@gmail.com>
parents: 117
diff changeset
90
249881ceff7b [PostDog] Updated some core logic. Will create a bookmark for postdog until the launch as this is annoying to deal with.
June Park <parkjune1995@gmail.com>
parents: 117
diff changeset
91 char *PostDog_Extract_Title(const char *filename)
249881ceff7b [PostDog] Updated some core logic. Will create a bookmark for postdog until the launch as this is annoying to deal with.
June Park <parkjune1995@gmail.com>
parents: 117
diff changeset
92 {
249881ceff7b [PostDog] Updated some core logic. Will create a bookmark for postdog until the launch as this is annoying to deal with.
June Park <parkjune1995@gmail.com>
parents: 117
diff changeset
93 char full_file_path[512] = {0};
249881ceff7b [PostDog] Updated some core logic. Will create a bookmark for postdog until the launch as this is annoying to deal with.
June Park <parkjune1995@gmail.com>
parents: 117
diff changeset
94 snprintf(full_file_path, 512, "%s/%s", POSTDOG_PATHS, filename);
249881ceff7b [PostDog] Updated some core logic. Will create a bookmark for postdog until the launch as this is annoying to deal with.
June Park <parkjune1995@gmail.com>
parents: 117
diff changeset
95 FILE *file = fopen(full_file_path, "r");
249881ceff7b [PostDog] Updated some core logic. Will create a bookmark for postdog until the launch as this is annoying to deal with.
June Park <parkjune1995@gmail.com>
parents: 117
diff changeset
96 if (!file)
249881ceff7b [PostDog] Updated some core logic. Will create a bookmark for postdog until the launch as this is annoying to deal with.
June Park <parkjune1995@gmail.com>
parents: 117
diff changeset
97 return strdup(filename);
249881ceff7b [PostDog] Updated some core logic. Will create a bookmark for postdog until the launch as this is annoying to deal with.
June Park <parkjune1995@gmail.com>
parents: 117
diff changeset
98
249881ceff7b [PostDog] Updated some core logic. Will create a bookmark for postdog until the launch as this is annoying to deal with.
June Park <parkjune1995@gmail.com>
parents: 117
diff changeset
99 char *title = malloc(sizeof(char) * 512);
249881ceff7b [PostDog] Updated some core logic. Will create a bookmark for postdog until the launch as this is annoying to deal with.
June Park <parkjune1995@gmail.com>
parents: 117
diff changeset
100 if (!fgets(title, 512, file)) {
249881ceff7b [PostDog] Updated some core logic. Will create a bookmark for postdog until the launch as this is annoying to deal with.
June Park <parkjune1995@gmail.com>
parents: 117
diff changeset
101 fclose(file);
249881ceff7b [PostDog] Updated some core logic. Will create a bookmark for postdog until the launch as this is annoying to deal with.
June Park <parkjune1995@gmail.com>
parents: 117
diff changeset
102 return strdup(filename);
249881ceff7b [PostDog] Updated some core logic. Will create a bookmark for postdog until the launch as this is annoying to deal with.
June Park <parkjune1995@gmail.com>
parents: 117
diff changeset
103 }
249881ceff7b [PostDog] Updated some core logic. Will create a bookmark for postdog until the launch as this is annoying to deal with.
June Park <parkjune1995@gmail.com>
parents: 117
diff changeset
104
249881ceff7b [PostDog] Updated some core logic. Will create a bookmark for postdog until the launch as this is annoying to deal with.
June Park <parkjune1995@gmail.com>
parents: 117
diff changeset
105 return title;
114
e2a73e64e8e6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 112
diff changeset
106 }
e2a73e64e8e6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 112
diff changeset
107
e2a73e64e8e6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 112
diff changeset
108 // 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
109 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
110 {
e2a73e64e8e6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 112
diff changeset
111 HistoryItem *file_arr = *p_file_arr;
e2a73e64e8e6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 112
diff changeset
112 #ifdef _WIN32
e2a73e64e8e6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 112
diff changeset
113 struct _finddata_t fileinfo;
e2a73e64e8e6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 112
diff changeset
114 intptr_t handle;
e2a73e64e8e6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 112
diff changeset
115 char search_path[256];
e2a73e64e8e6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 112
diff changeset
116 sprintf(search_path, "%s\\*", path);
e2a73e64e8e6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 112
diff changeset
117
e2a73e64e8e6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 112
diff changeset
118 if ((handle = _findfirst(search_path, &fileinfo)) == -1L) {
e2a73e64e8e6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 112
diff changeset
119 printf("Directory is empty or cannot be read.\n");
e2a73e64e8e6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 112
diff changeset
120 } else {
e2a73e64e8e6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 112
diff changeset
121 do {
e2a73e64e8e6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 112
diff changeset
122 HistoryItem item = {0};
e2a73e64e8e6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 112
diff changeset
123 item.filename = strdup(fileinfo.name);
118
249881ceff7b [PostDog] Updated some core logic. Will create a bookmark for postdog until the launch as this is annoying to deal with.
June Park <parkjune1995@gmail.com>
parents: 117
diff changeset
124 item.title = PostDog_Extract_Title(fileinfo.name);
249881ceff7b [PostDog] Updated some core logic. Will create a bookmark for postdog until the launch as this is annoying to deal with.
June Park <parkjune1995@gmail.com>
parents: 117
diff changeset
125 item.time_modified = fileinfo.time_write;
117
b91f2dd6f84d [PostDog] Fixed delete logic.
June Park <parkjune1995@gmail.com>
parents: 116
diff changeset
126 item.deleted = FALSE;
114
e2a73e64e8e6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 112
diff changeset
127 Dowa_Array_Push(file_arr, item);
e2a73e64e8e6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 112
diff changeset
128 } while (_findnext(handle, &fileinfo) == 0);
e2a73e64e8e6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 112
diff changeset
129 _findclose(handle);
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 #else
e2a73e64e8e6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 112
diff changeset
132 struct dirent *entry;
e2a73e64e8e6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 112
diff changeset
133 struct stat file_stat;
e2a73e64e8e6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 112
diff changeset
134 DIR *dp = opendir(path);
e2a73e64e8e6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 112
diff changeset
135 if (dp == NULL) return;
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 char full_path[256];
e2a73e64e8e6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 112
diff changeset
138 while ((entry = readdir(dp)))
e2a73e64e8e6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 112
diff changeset
139 {
e2a73e64e8e6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 112
diff changeset
140 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
141 continue;
e2a73e64e8e6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 112
diff changeset
142 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
143 if (stat(full_path, &file_stat) == 0)
e2a73e64e8e6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 112
diff changeset
144 {
e2a73e64e8e6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 112
diff changeset
145 HistoryItem item = {0};
e2a73e64e8e6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 112
diff changeset
146 item.filename = strdup(entry->d_name);
118
249881ceff7b [PostDog] Updated some core logic. Will create a bookmark for postdog until the launch as this is annoying to deal with.
June Park <parkjune1995@gmail.com>
parents: 117
diff changeset
147 item.title = PostDog_Extract_Title(entry->d_name);
114
e2a73e64e8e6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 112
diff changeset
148 item.time_modified = file_stat.st_mtime;
117
b91f2dd6f84d [PostDog] Fixed delete logic.
June Park <parkjune1995@gmail.com>
parents: 116
diff changeset
149 item.deleted = FALSE;
114
e2a73e64e8e6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 112
diff changeset
150 Dowa_Array_Push(file_arr, item);
e2a73e64e8e6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 112
diff changeset
151 }
e2a73e64e8e6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 112
diff changeset
152 }
e2a73e64e8e6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 112
diff changeset
153 closedir(dp);
e2a73e64e8e6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 112
diff changeset
154 #endif
e2a73e64e8e6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 112
diff changeset
155 int count = Dowa_Array_Length(file_arr);
e2a73e64e8e6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 112
diff changeset
156 if (count > 1) {
e2a73e64e8e6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 112
diff changeset
157 qsort(file_arr, count, sizeof(HistoryItem), CompareHistoryItemsByDate);
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 }
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 int PostDog_History_Load(HistoryItem **p_history_files)
e2a73e64e8e6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 112
diff changeset
162 {
e2a73e64e8e6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 112
diff changeset
163 if (access(POSTDOG_PATHS, F_OK) == -1)
e2a73e64e8e6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 112
diff changeset
164 {
e2a73e64e8e6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 112
diff changeset
165 printf("Directory '%s' not found. Creating it...\n", POSTDOG_PATHS);
e2a73e64e8e6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 112
diff changeset
166 if (mkdir(POSTDOG_PATHS, 0777) != 0)
e2a73e64e8e6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 112
diff changeset
167 return -1;
e2a73e64e8e6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 112
diff changeset
168 return 0;
e2a73e64e8e6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 112
diff changeset
169 }
e2a73e64e8e6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 112
diff changeset
170 printf("Directory '%s' already exists.\n", POSTDOG_PATHS);
e2a73e64e8e6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 112
diff changeset
171 PostDog_List_Directory(POSTDOG_PATHS, p_history_files);
e2a73e64e8e6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 112
diff changeset
172 return 0;
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
e2a73e64e8e6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 112
diff changeset
175 bool InArea(Vector2 mouse_position, Rectangle area)
e2a73e64e8e6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 112
diff changeset
176 {
e2a73e64e8e6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 112
diff changeset
177 return (
e2a73e64e8e6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 112
diff changeset
178 mouse_position.x >= area.x &&
e2a73e64e8e6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 112
diff changeset
179 mouse_position.x < area.x + area.width &&
e2a73e64e8e6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 112
diff changeset
180 mouse_position.y >= area.y &&
e2a73e64e8e6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 112
diff changeset
181 mouse_position.y < area.y + area.height
e2a73e64e8e6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 112
diff changeset
182 );
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
e2a73e64e8e6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 112
diff changeset
185 bool Clicked(Vector2 mouse_position, Rectangle area)
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 return (InArea(mouse_position, area) && IsMouseButtonPressed(MOUSE_BUTTON_LEFT));
e2a73e64e8e6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 112
diff changeset
188 }
e2a73e64e8e6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 112
diff changeset
189
112
d6d578b49a19 [PostDog] Got CRUD working.
June Park <parkjune1995@gmail.com>
parents: 111
diff changeset
190 char *PostDog_Enum_To_String(int active_enum)
d6d578b49a19 [PostDog] Got CRUD working.
June Park <parkjune1995@gmail.com>
parents: 111
diff changeset
191 {
d6d578b49a19 [PostDog] Got CRUD working.
June Park <parkjune1995@gmail.com>
parents: 111
diff changeset
192 switch(active_enum)
d6d578b49a19 [PostDog] Got CRUD working.
June Park <parkjune1995@gmail.com>
parents: 111
diff changeset
193 {
d6d578b49a19 [PostDog] Got CRUD working.
June Park <parkjune1995@gmail.com>
parents: 111
diff changeset
194 case 0: return "GET";
d6d578b49a19 [PostDog] Got CRUD working.
June Park <parkjune1995@gmail.com>
parents: 111
diff changeset
195 case 1: return "POST";
d6d578b49a19 [PostDog] Got CRUD working.
June Park <parkjune1995@gmail.com>
parents: 111
diff changeset
196 case 2: return "PUT";
d6d578b49a19 [PostDog] Got CRUD working.
June Park <parkjune1995@gmail.com>
parents: 111
diff changeset
197 case 3: return "DELETE";
d6d578b49a19 [PostDog] Got CRUD working.
June Park <parkjune1995@gmail.com>
parents: 111
diff changeset
198 }
114
e2a73e64e8e6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 112
diff changeset
199 return 0;
e2a73e64e8e6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 112
diff changeset
200 }
e2a73e64e8e6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 112
diff changeset
201
116
7bd795bac997 [Postdog] Added scrollable area to inputs and history files, buttons to delete and view.
June Park <parkjune1995@gmail.com>
parents: 115
diff changeset
202 char *PostDog_Construct_URL(char *filename)
7bd795bac997 [Postdog] Added scrollable area to inputs and history files, buttons to delete and view.
June Park <parkjune1995@gmail.com>
parents: 115
diff changeset
203 {
7bd795bac997 [Postdog] Added scrollable area to inputs and history files, buttons to delete and view.
June Park <parkjune1995@gmail.com>
parents: 115
diff changeset
204 char full_file_path[512] = {0};
7bd795bac997 [Postdog] Added scrollable area to inputs and history files, buttons to delete and view.
June Park <parkjune1995@gmail.com>
parents: 115
diff changeset
205 snprintf(full_file_path, 512, "%s/%s", POSTDOG_PATHS, filename);
7bd795bac997 [Postdog] Added scrollable area to inputs and history files, buttons to delete and view.
June Park <parkjune1995@gmail.com>
parents: 115
diff changeset
206 return &full_file_path;
7bd795bac997 [Postdog] Added scrollable area to inputs and history files, buttons to delete and view.
June Park <parkjune1995@gmail.com>
parents: 115
diff changeset
207 }
7bd795bac997 [Postdog] Added scrollable area to inputs and history files, buttons to delete and view.
June Park <parkjune1995@gmail.com>
parents: 115
diff changeset
208
114
e2a73e64e8e6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 112
diff changeset
209 void PostDog_History_CreateFile(char *filename, char* values)
e2a73e64e8e6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 112
diff changeset
210 {
e2a73e64e8e6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 112
diff changeset
211 char full_file_path[512] = {0};
e2a73e64e8e6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 112
diff changeset
212 snprintf(full_file_path, 512, "%s/%s", POSTDOG_PATHS, filename);
e2a73e64e8e6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 112
diff changeset
213 FILE *file = fopen(full_file_path, "w");
e2a73e64e8e6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 112
diff changeset
214 if (!file)
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 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
217 return;
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 fwrite(values, 1, strlen(values), file);
e2a73e64e8e6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 112
diff changeset
220 fclose(file);
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
118
249881ceff7b [PostDog] Updated some core logic. Will create a bookmark for postdog until the launch as this is annoying to deal with.
June Park <parkjune1995@gmail.com>
parents: 117
diff changeset
223 void PostDog_Request_SaveFile(void)
114
e2a73e64e8e6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 112
diff changeset
224 {
118
249881ceff7b [PostDog] Updated some core logic. Will create a bookmark for postdog until the launch as this is annoying to deal with.
June Park <parkjune1995@gmail.com>
parents: 117
diff changeset
225 const char *method = PostDog_Enum_To_String(active_method_dropdown);
114
e2a73e64e8e6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 112
diff changeset
226 size_t new_file_size = 1024 * 1024;
e2a73e64e8e6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 112
diff changeset
227 Dowa_Arena *arena = Dowa_Arena_Create(1024 * 1024 * 2);
e2a73e64e8e6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 112
diff changeset
228 char *new_file = Dowa_Arena_Allocate(arena, 1024 * 1024);
118
249881ceff7b [PostDog] Updated some core logic. Will create a bookmark for postdog until the launch as this is annoying to deal with.
June Park <parkjune1995@gmail.com>
parents: 117
diff changeset
229 char *title = malloc(strlen(method) + strlen(url_input_text) + 2);
249881ceff7b [PostDog] Updated some core logic. Will create a bookmark for postdog until the launch as this is annoying to deal with.
June Park <parkjune1995@gmail.com>
parents: 117
diff changeset
230 sprintf(title, "%s %s", method, url_input_text);
114
e2a73e64e8e6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 112
diff changeset
231 snprintf(
e2a73e64e8e6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 112
diff changeset
232 new_file,
e2a73e64e8e6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 112
diff changeset
233 new_file_size,
e2a73e64e8e6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 112
diff changeset
234 "%s\n"
e2a73e64e8e6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 112
diff changeset
235 "---\n"
e2a73e64e8e6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 112
diff changeset
236 "%s\n"
e2a73e64e8e6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 112
diff changeset
237 "---\n"
e2a73e64e8e6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 112
diff changeset
238 "%s\n"
e2a73e64e8e6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 112
diff changeset
239 "---\n"
e2a73e64e8e6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 112
diff changeset
240 "%s\n"
e2a73e64e8e6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 112
diff changeset
241 "---\n"
118
249881ceff7b [PostDog] Updated some core logic. Will create a bookmark for postdog until the launch as this is annoying to deal with.
June Park <parkjune1995@gmail.com>
parents: 117
diff changeset
242 "%s\n"
249881ceff7b [PostDog] Updated some core logic. Will create a bookmark for postdog until the launch as this is annoying to deal with.
June Park <parkjune1995@gmail.com>
parents: 117
diff changeset
243 "---\n"
249881ceff7b [PostDog] Updated some core logic. Will create a bookmark for postdog until the launch as this is annoying to deal with.
June Park <parkjune1995@gmail.com>
parents: 117
diff changeset
244 "%s\n"
249881ceff7b [PostDog] Updated some core logic. Will create a bookmark for postdog until the launch as this is annoying to deal with.
June Park <parkjune1995@gmail.com>
parents: 117
diff changeset
245 "---\n"
249881ceff7b [PostDog] Updated some core logic. Will create a bookmark for postdog until the launch as this is annoying to deal with.
June Park <parkjune1995@gmail.com>
parents: 117
diff changeset
246 "%s\n"
249881ceff7b [PostDog] Updated some core logic. Will create a bookmark for postdog until the launch as this is annoying to deal with.
June Park <parkjune1995@gmail.com>
parents: 117
diff changeset
247 "---\n"
114
e2a73e64e8e6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 112
diff changeset
248 "%s\n",
118
249881ceff7b [PostDog] Updated some core logic. Will create a bookmark for postdog until the launch as this is annoying to deal with.
June Park <parkjune1995@gmail.com>
parents: 117
diff changeset
249 title,
249881ceff7b [PostDog] Updated some core logic. Will create a bookmark for postdog until the launch as this is annoying to deal with.
June Park <parkjune1995@gmail.com>
parents: 117
diff changeset
250 url_input_text,
114
e2a73e64e8e6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 112
diff changeset
251 method,
155
3bb45eb67906 [Postdog] Updated variables names and padding sizes. Needs more work.
June Park <parkjune1995@gmail.com>
parents: 153
diff changeset
252 input_body_array[TAB_HEADER],
3bb45eb67906 [Postdog] Updated variables names and padding sizes. Needs more work.
June Park <parkjune1995@gmail.com>
parents: 153
diff changeset
253 input_body_array[TAB_BODY],
3bb45eb67906 [Postdog] Updated variables names and padding sizes. Needs more work.
June Park <parkjune1995@gmail.com>
parents: 153
diff changeset
254 input_body_array[TAB_GET_PARAMS],
3bb45eb67906 [Postdog] Updated variables names and padding sizes. Needs more work.
June Park <parkjune1995@gmail.com>
parents: 153
diff changeset
255 input_body_array[TAB_WEBSOCKET],
3bb45eb67906 [Postdog] Updated variables names and padding sizes. Needs more work.
June Park <parkjune1995@gmail.com>
parents: 153
diff changeset
256 result_text
114
e2a73e64e8e6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 112
diff changeset
257 );
e2a73e64e8e6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 112
diff changeset
258 char *filename = Dowa_Arena_Allocate(arena, 1024);
e2a73e64e8e6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 112
diff changeset
259 if (!filename)
e2a73e64e8e6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 112
diff changeset
260 {
e2a73e64e8e6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 112
diff changeset
261 perror("Error opening file");
e2a73e64e8e6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 112
diff changeset
262 exit(EXIT_FAILURE);
e2a73e64e8e6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 112
diff changeset
263 }
e2a73e64e8e6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 112
diff changeset
264 char *uuid4 = (char *)Dowa_Arena_Allocate(arena, 37);
e2a73e64e8e6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 112
diff changeset
265 if (!uuid4)
e2a73e64e8e6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 112
diff changeset
266 {
e2a73e64e8e6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 112
diff changeset
267 perror("Error uuid");
e2a73e64e8e6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 112
diff changeset
268 exit(EXIT_FAILURE);
e2a73e64e8e6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 112
diff changeset
269 }
e2a73e64e8e6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 112
diff changeset
270
e2a73e64e8e6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 112
diff changeset
271 int32 seed = (uint32)time(NULL) ^ counter++;
e2a73e64e8e6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 112
diff changeset
272 Dowa_String_UUID(seed, uuid4);
e2a73e64e8e6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 112
diff changeset
273 snprintf(filename, 1024, "%s.txt", uuid4);
e2a73e64e8e6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 112
diff changeset
274 PostDog_History_CreateFile(filename, new_file);
e2a73e64e8e6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 112
diff changeset
275
117
b91f2dd6f84d [PostDog] Fixed delete logic.
June Park <parkjune1995@gmail.com>
parents: 116
diff changeset
276 HistoryItem item = {0};
b91f2dd6f84d [PostDog] Fixed delete logic.
June Park <parkjune1995@gmail.com>
parents: 116
diff changeset
277 item.filename = strdup(filename);
118
249881ceff7b [PostDog] Updated some core logic. Will create a bookmark for postdog until the launch as this is annoying to deal with.
June Park <parkjune1995@gmail.com>
parents: 117
diff changeset
278 item.title = title;
117
b91f2dd6f84d [PostDog] Fixed delete logic.
June Park <parkjune1995@gmail.com>
parents: 116
diff changeset
279 item.deleted = FALSE;
114
e2a73e64e8e6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 112
diff changeset
280 Dowa_Array_Push(new_history_items, item);
e2a73e64e8e6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 112
diff changeset
281
e2a73e64e8e6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 112
diff changeset
282 Dowa_Arena_Free(arena);
112
d6d578b49a19 [PostDog] Got CRUD working.
June Park <parkjune1995@gmail.com>
parents: 111
diff changeset
283 }
54
b3e82d22f961 [PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff changeset
284
152
7387eec8e7f8 [Postdog] Updated to use Seobeo_Client instead of CURL. Updated to handle websocket connection.
June Park <parkjune1995@gmail.com>
parents: 118
diff changeset
285 int PostDog_Websocket_Send(void)
54
b3e82d22f961 [PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff changeset
286 {
152
7387eec8e7f8 [Postdog] Updated to use Seobeo_Client instead of CURL. Updated to handle websocket connection.
June Park <parkjune1995@gmail.com>
parents: 118
diff changeset
287 if (!ws)
7387eec8e7f8 [Postdog] Updated to use Seobeo_Client instead of CURL. Updated to handle websocket connection.
June Park <parkjune1995@gmail.com>
parents: 118
diff changeset
288 ws = Seobeo_WebSocket_Connect(url_input_text);
54
b3e82d22f961 [PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff changeset
289
152
7387eec8e7f8 [Postdog] Updated to use Seobeo_Client instead of CURL. Updated to handle websocket connection.
June Park <parkjune1995@gmail.com>
parents: 118
diff changeset
290 printf("URL %s\n", url_input_text);
155
3bb45eb67906 [Postdog] Updated variables names and padding sizes. Needs more work.
June Park <parkjune1995@gmail.com>
parents: 153
diff changeset
291 if (Seobeo_WebSocket_Send_Text(ws, input_body_array[active_input_tab]) < 0)
152
7387eec8e7f8 [Postdog] Updated to use Seobeo_Client instead of CURL. Updated to handle websocket connection.
June Park <parkjune1995@gmail.com>
parents: 118
diff changeset
292 printf("Failed to send message\n");
7387eec8e7f8 [Postdog] Updated to use Seobeo_Client instead of CURL. Updated to handle websocket connection.
June Park <parkjune1995@gmail.com>
parents: 118
diff changeset
293
7387eec8e7f8 [Postdog] Updated to use Seobeo_Client instead of CURL. Updated to handle websocket connection.
June Park <parkjune1995@gmail.com>
parents: 118
diff changeset
294 printf("Receiving responses...\n");
7387eec8e7f8 [Postdog] Updated to use Seobeo_Client instead of CURL. Updated to handle websocket connection.
June Park <parkjune1995@gmail.com>
parents: 118
diff changeset
295 int received = 0;
7387eec8e7f8 [Postdog] Updated to use Seobeo_Client instead of CURL. Updated to handle websocket connection.
June Park <parkjune1995@gmail.com>
parents: 118
diff changeset
296 while (TRUE)
54
b3e82d22f961 [PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff changeset
297 {
153
790930d9bb90 [PostDog] Adding websocket to be more usable.
June Park <parkjune1995@gmail.com>
parents: 152
diff changeset
298 if (WS_BREAK) break;
790930d9bb90 [PostDog] Adding websocket to be more usable.
June Park <parkjune1995@gmail.com>
parents: 152
diff changeset
299
152
7387eec8e7f8 [Postdog] Updated to use Seobeo_Client instead of CURL. Updated to handle websocket connection.
June Park <parkjune1995@gmail.com>
parents: 118
diff changeset
300 Seobeo_WebSocket_Message *p_msg = Seobeo_WebSocket_Receive(ws);
7387eec8e7f8 [Postdog] Updated to use Seobeo_Client instead of CURL. Updated to handle websocket connection.
June Park <parkjune1995@gmail.com>
parents: 118
diff changeset
301 if (p_msg)
7387eec8e7f8 [Postdog] Updated to use Seobeo_Client instead of CURL. Updated to handle websocket connection.
June Park <parkjune1995@gmail.com>
parents: 118
diff changeset
302 {
7387eec8e7f8 [Postdog] Updated to use Seobeo_Client instead of CURL. Updated to handle websocket connection.
June Park <parkjune1995@gmail.com>
parents: 118
diff changeset
303 if (p_msg->opcode == SEOBEO_WS_OPCODE_TEXT)
7387eec8e7f8 [Postdog] Updated to use Seobeo_Client instead of CURL. Updated to handle websocket connection.
June Park <parkjune1995@gmail.com>
parents: 118
diff changeset
304 {
7387eec8e7f8 [Postdog] Updated to use Seobeo_Client instead of CURL. Updated to handle websocket connection.
June Park <parkjune1995@gmail.com>
parents: 118
diff changeset
305 printf("Response %d: %.*s\n", received + 1, (int)p_msg->length, (char*)p_msg->data);
155
3bb45eb67906 [Postdog] Updated variables names and padding sizes. Needs more work.
June Park <parkjune1995@gmail.com>
parents: 153
diff changeset
306 snprintf(result_text + strlen(result_text), RESULT_BUFFER_LENGTH - strlen(result_text),
153
790930d9bb90 [PostDog] Adding websocket to be more usable.
June Park <parkjune1995@gmail.com>
parents: 152
diff changeset
307 "\n%s", (char*)p_msg->data);
152
7387eec8e7f8 [Postdog] Updated to use Seobeo_Client instead of CURL. Updated to handle websocket connection.
June Park <parkjune1995@gmail.com>
parents: 118
diff changeset
308 received++;
7387eec8e7f8 [Postdog] Updated to use Seobeo_Client instead of CURL. Updated to handle websocket connection.
June Park <parkjune1995@gmail.com>
parents: 118
diff changeset
309 }
7387eec8e7f8 [Postdog] Updated to use Seobeo_Client instead of CURL. Updated to handle websocket connection.
June Park <parkjune1995@gmail.com>
parents: 118
diff changeset
310 Seobeo_WebSocket_Message_Destroy(p_msg);
7387eec8e7f8 [Postdog] Updated to use Seobeo_Client instead of CURL. Updated to handle websocket connection.
June Park <parkjune1995@gmail.com>
parents: 118
diff changeset
311 }
7387eec8e7f8 [Postdog] Updated to use Seobeo_Client instead of CURL. Updated to handle websocket connection.
June Park <parkjune1995@gmail.com>
parents: 118
diff changeset
312 usleep(10000);
54
b3e82d22f961 [PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff changeset
313 }
152
7387eec8e7f8 [Postdog] Updated to use Seobeo_Client instead of CURL. Updated to handle websocket connection.
June Park <parkjune1995@gmail.com>
parents: 118
diff changeset
314 printf("Received %d/%d messages\n", received, 3);
153
790930d9bb90 [PostDog] Adding websocket to be more usable.
June Park <parkjune1995@gmail.com>
parents: 152
diff changeset
315 Seobeo_WebSocket_Destroy(ws);
152
7387eec8e7f8 [Postdog] Updated to use Seobeo_Client instead of CURL. Updated to handle websocket connection.
June Park <parkjune1995@gmail.com>
parents: 118
diff changeset
316 }
54
b3e82d22f961 [PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff changeset
317
153
790930d9bb90 [PostDog] Adding websocket to be more usable.
June Park <parkjune1995@gmail.com>
parents: 152
diff changeset
318 void *PostDog_Websocket_Thread(void *arg)
152
7387eec8e7f8 [Postdog] Updated to use Seobeo_Client instead of CURL. Updated to handle websocket connection.
June Park <parkjune1995@gmail.com>
parents: 118
diff changeset
319 {
153
790930d9bb90 [PostDog] Adding websocket to be more usable.
June Park <parkjune1995@gmail.com>
parents: 152
diff changeset
320 PostDog_Websocket_Send();
790930d9bb90 [PostDog] Adding websocket to be more usable.
June Park <parkjune1995@gmail.com>
parents: 152
diff changeset
321 printf("Websocket request finished.\n");
790930d9bb90 [PostDog] Adding websocket to be more usable.
June Park <parkjune1995@gmail.com>
parents: 152
diff changeset
322 return NULL;
152
7387eec8e7f8 [Postdog] Updated to use Seobeo_Client instead of CURL. Updated to handle websocket connection.
June Park <parkjune1995@gmail.com>
parents: 118
diff changeset
323 }
54
b3e82d22f961 [PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff changeset
324
153
790930d9bb90 [PostDog] Adding websocket to be more usable.
June Park <parkjune1995@gmail.com>
parents: 152
diff changeset
325 void PostDog_Websocket_Thread_Send()
152
7387eec8e7f8 [Postdog] Updated to use Seobeo_Client instead of CURL. Updated to handle websocket connection.
June Park <parkjune1995@gmail.com>
parents: 118
diff changeset
326 {
7387eec8e7f8 [Postdog] Updated to use Seobeo_Client instead of CURL. Updated to handle websocket connection.
June Park <parkjune1995@gmail.com>
parents: 118
diff changeset
327 pthread_t thread_id;
7387eec8e7f8 [Postdog] Updated to use Seobeo_Client instead of CURL. Updated to handle websocket connection.
June Park <parkjune1995@gmail.com>
parents: 118
diff changeset
328
7387eec8e7f8 [Postdog] Updated to use Seobeo_Client instead of CURL. Updated to handle websocket connection.
June Park <parkjune1995@gmail.com>
parents: 118
diff changeset
329 if (pthread_create(&thread_id, NULL, PostDog_Websocket_Thread, NULL) != 0)
7387eec8e7f8 [Postdog] Updated to use Seobeo_Client instead of CURL. Updated to handle websocket connection.
June Park <parkjune1995@gmail.com>
parents: 118
diff changeset
330 {
7387eec8e7f8 [Postdog] Updated to use Seobeo_Client instead of CURL. Updated to handle websocket connection.
June Park <parkjune1995@gmail.com>
parents: 118
diff changeset
331 perror("Failed to create thread");
7387eec8e7f8 [Postdog] Updated to use Seobeo_Client instead of CURL. Updated to handle websocket connection.
June Park <parkjune1995@gmail.com>
parents: 118
diff changeset
332 return;
7387eec8e7f8 [Postdog] Updated to use Seobeo_Client instead of CURL. Updated to handle websocket connection.
June Park <parkjune1995@gmail.com>
parents: 118
diff changeset
333 }
7387eec8e7f8 [Postdog] Updated to use Seobeo_Client instead of CURL. Updated to handle websocket connection.
June Park <parkjune1995@gmail.com>
parents: 118
diff changeset
334 pthread_detach(thread_id);
54
b3e82d22f961 [PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff changeset
335 }
b3e82d22f961 [PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff changeset
336
118
249881ceff7b [PostDog] Updated some core logic. Will create a bookmark for postdog until the launch as this is annoying to deal with.
June Park <parkjune1995@gmail.com>
parents: 117
diff changeset
337 int PostDog_Http_Request(void)
54
b3e82d22f961 [PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff changeset
338 {
152
7387eec8e7f8 [Postdog] Updated to use Seobeo_Client instead of CURL. Updated to handle websocket connection.
June Park <parkjune1995@gmail.com>
parents: 118
diff changeset
339 Seobeo_Client_Request *req = Seobeo_Client_Request_Create(url_input_text);
7387eec8e7f8 [Postdog] Updated to use Seobeo_Client instead of CURL. Updated to handle websocket connection.
June Park <parkjune1995@gmail.com>
parents: 118
diff changeset
340 Seobeo_Client_Response *res;
7387eec8e7f8 [Postdog] Updated to use Seobeo_Client instead of CURL. Updated to handle websocket connection.
June Park <parkjune1995@gmail.com>
parents: 118
diff changeset
341 switch (active_method_dropdown)
54
b3e82d22f961 [PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff changeset
342 {
152
7387eec8e7f8 [Postdog] Updated to use Seobeo_Client instead of CURL. Updated to handle websocket connection.
June Park <parkjune1995@gmail.com>
parents: 118
diff changeset
343 case 0:
7387eec8e7f8 [Postdog] Updated to use Seobeo_Client instead of CURL. Updated to handle websocket connection.
June Park <parkjune1995@gmail.com>
parents: 118
diff changeset
344 {
7387eec8e7f8 [Postdog] Updated to use Seobeo_Client instead of CURL. Updated to handle websocket connection.
June Park <parkjune1995@gmail.com>
parents: 118
diff changeset
345 Seobeo_Client_Request_Set_Method(req, "GET");
7387eec8e7f8 [Postdog] Updated to use Seobeo_Client instead of CURL. Updated to handle websocket connection.
June Park <parkjune1995@gmail.com>
parents: 118
diff changeset
346 break;
7387eec8e7f8 [Postdog] Updated to use Seobeo_Client instead of CURL. Updated to handle websocket connection.
June Park <parkjune1995@gmail.com>
parents: 118
diff changeset
347 }
7387eec8e7f8 [Postdog] Updated to use Seobeo_Client instead of CURL. Updated to handle websocket connection.
June Park <parkjune1995@gmail.com>
parents: 118
diff changeset
348 case 1:
7387eec8e7f8 [Postdog] Updated to use Seobeo_Client instead of CURL. Updated to handle websocket connection.
June Park <parkjune1995@gmail.com>
parents: 118
diff changeset
349 {
7387eec8e7f8 [Postdog] Updated to use Seobeo_Client instead of CURL. Updated to handle websocket connection.
June Park <parkjune1995@gmail.com>
parents: 118
diff changeset
350 Seobeo_Client_Request_Set_Method(req, "POST");
7387eec8e7f8 [Postdog] Updated to use Seobeo_Client instead of CURL. Updated to handle websocket connection.
June Park <parkjune1995@gmail.com>
parents: 118
diff changeset
351 break;
7387eec8e7f8 [Postdog] Updated to use Seobeo_Client instead of CURL. Updated to handle websocket connection.
June Park <parkjune1995@gmail.com>
parents: 118
diff changeset
352 }
7387eec8e7f8 [Postdog] Updated to use Seobeo_Client instead of CURL. Updated to handle websocket connection.
June Park <parkjune1995@gmail.com>
parents: 118
diff changeset
353 case 2:
7387eec8e7f8 [Postdog] Updated to use Seobeo_Client instead of CURL. Updated to handle websocket connection.
June Park <parkjune1995@gmail.com>
parents: 118
diff changeset
354 {
7387eec8e7f8 [Postdog] Updated to use Seobeo_Client instead of CURL. Updated to handle websocket connection.
June Park <parkjune1995@gmail.com>
parents: 118
diff changeset
355 Seobeo_Client_Request_Set_Method(req, "PUT");
7387eec8e7f8 [Postdog] Updated to use Seobeo_Client instead of CURL. Updated to handle websocket connection.
June Park <parkjune1995@gmail.com>
parents: 118
diff changeset
356 break;
7387eec8e7f8 [Postdog] Updated to use Seobeo_Client instead of CURL. Updated to handle websocket connection.
June Park <parkjune1995@gmail.com>
parents: 118
diff changeset
357 }
7387eec8e7f8 [Postdog] Updated to use Seobeo_Client instead of CURL. Updated to handle websocket connection.
June Park <parkjune1995@gmail.com>
parents: 118
diff changeset
358 case 3:
7387eec8e7f8 [Postdog] Updated to use Seobeo_Client instead of CURL. Updated to handle websocket connection.
June Park <parkjune1995@gmail.com>
parents: 118
diff changeset
359 {
7387eec8e7f8 [Postdog] Updated to use Seobeo_Client instead of CURL. Updated to handle websocket connection.
June Park <parkjune1995@gmail.com>
parents: 118
diff changeset
360 Seobeo_Client_Request_Set_Method(req, "DELETE");
7387eec8e7f8 [Postdog] Updated to use Seobeo_Client instead of CURL. Updated to handle websocket connection.
June Park <parkjune1995@gmail.com>
parents: 118
diff changeset
361 break;
7387eec8e7f8 [Postdog] Updated to use Seobeo_Client instead of CURL. Updated to handle websocket connection.
June Park <parkjune1995@gmail.com>
parents: 118
diff changeset
362 }
54
b3e82d22f961 [PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff changeset
363 }
b3e82d22f961 [PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff changeset
364
152
7387eec8e7f8 [Postdog] Updated to use Seobeo_Client instead of CURL. Updated to handle websocket connection.
June Park <parkjune1995@gmail.com>
parents: 118
diff changeset
365 {
155
3bb45eb67906 [Postdog] Updated variables names and padding sizes. Needs more work.
June Park <parkjune1995@gmail.com>
parents: 153
diff changeset
366 if (input_body_array[TAB_HEADER] && strlen(input_body_array[TAB_HEADER]) > 0)
54
b3e82d22f961 [PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff changeset
367 {
155
3bb45eb67906 [Postdog] Updated variables names and padding sizes. Needs more work.
June Park <parkjune1995@gmail.com>
parents: 153
diff changeset
368 char *headersCopy = strdup(input_body_array[TAB_HEADER]);
54
b3e82d22f961 [PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff changeset
369 char *line = strtok(headersCopy, "\n");
152
7387eec8e7f8 [Postdog] Updated to use Seobeo_Client instead of CURL. Updated to handle websocket connection.
June Park <parkjune1995@gmail.com>
parents: 118
diff changeset
370 while (line != NULL)
7387eec8e7f8 [Postdog] Updated to use Seobeo_Client instead of CURL. Updated to handle websocket connection.
June Park <parkjune1995@gmail.com>
parents: 118
diff changeset
371 {
54
b3e82d22f961 [PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff changeset
372 while (*line == ' ' || *line == '\t') line++;
114
e2a73e64e8e6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 112
diff changeset
373 if (strlen(line) > 0)
152
7387eec8e7f8 [Postdog] Updated to use Seobeo_Client instead of CURL. Updated to handle websocket connection.
June Park <parkjune1995@gmail.com>
parents: 118
diff changeset
374 Seobeo_Client_Request_Add_Header_Array(req, line);
54
b3e82d22f961 [PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff changeset
375 line = strtok(NULL, "\n");
b3e82d22f961 [PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff changeset
376 }
b3e82d22f961 [PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff changeset
377
152
7387eec8e7f8 [Postdog] Updated to use Seobeo_Client instead of CURL. Updated to handle websocket connection.
June Park <parkjune1995@gmail.com>
parents: 118
diff changeset
378 }
7387eec8e7f8 [Postdog] Updated to use Seobeo_Client instead of CURL. Updated to handle websocket connection.
June Park <parkjune1995@gmail.com>
parents: 118
diff changeset
379 Seobeo_Client_Request_Set_Follow_Redirects(req, TRUE, 5); // TODO: remove magic number;
7387eec8e7f8 [Postdog] Updated to use Seobeo_Client instead of CURL. Updated to handle websocket connection.
June Park <parkjune1995@gmail.com>
parents: 118
diff changeset
380 res = Seobeo_Client_Request_Execute(req);
54
b3e82d22f961 [PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff changeset
381
152
7387eec8e7f8 [Postdog] Updated to use Seobeo_Client instead of CURL. Updated to handle websocket connection.
June Park <parkjune1995@gmail.com>
parents: 118
diff changeset
382 if (res == NULL)
155
3bb45eb67906 [Postdog] Updated variables names and padding sizes. Needs more work.
June Park <parkjune1995@gmail.com>
parents: 153
diff changeset
383 snprintf(result_text, RESULT_BUFFER_LENGTH, "Error: Failed to send the request\n");
111
48f260576059 [PostDog] Rewriting it from scratch as it is unreadable for me.
June Park <parkjune1995@gmail.com>
parents: 63
diff changeset
384 else
155
3bb45eb67906 [Postdog] Updated variables names and padding sizes. Needs more work.
June Park <parkjune1995@gmail.com>
parents: 153
diff changeset
385 snprintf(result_text, RESULT_BUFFER_LENGTH, "HTTP Status: %d\n\n%s",
152
7387eec8e7f8 [Postdog] Updated to use Seobeo_Client instead of CURL. Updated to handle websocket connection.
June Park <parkjune1995@gmail.com>
parents: 118
diff changeset
386 res->status_code, res->body ? res->body : "");
54
b3e82d22f961 [PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff changeset
387 }
152
7387eec8e7f8 [Postdog] Updated to use Seobeo_Client instead of CURL. Updated to handle websocket connection.
June Park <parkjune1995@gmail.com>
parents: 118
diff changeset
388 Seobeo_Client_Request_Destroy(req);
7387eec8e7f8 [Postdog] Updated to use Seobeo_Client instead of CURL. Updated to handle websocket connection.
June Park <parkjune1995@gmail.com>
parents: 118
diff changeset
389 Seobeo_Client_Response_Destroy(res);
118
249881ceff7b [PostDog] Updated some core logic. Will create a bookmark for postdog until the launch as this is annoying to deal with.
June Park <parkjune1995@gmail.com>
parents: 117
diff changeset
390 PostDog_Request_SaveFile();
54
b3e82d22f961 [PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff changeset
391 return 0;
b3e82d22f961 [PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff changeset
392 }
b3e82d22f961 [PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff changeset
393
118
249881ceff7b [PostDog] Updated some core logic. Will create a bookmark for postdog until the launch as this is annoying to deal with.
June Park <parkjune1995@gmail.com>
parents: 117
diff changeset
394 void PostDog_Update_URL(void)
112
d6d578b49a19 [PostDog] Got CRUD working.
June Park <parkjune1995@gmail.com>
parents: 111
diff changeset
395 {
118
249881ceff7b [PostDog] Updated some core logic. Will create a bookmark for postdog until the launch as this is annoying to deal with.
June Park <parkjune1995@gmail.com>
parents: 117
diff changeset
396 // Save existing query string if present
112
d6d578b49a19 [PostDog] Got CRUD working.
June Park <parkjune1995@gmail.com>
parents: 111
diff changeset
397 char *question_mark = strchr(url_input_text, '?');
d6d578b49a19 [PostDog] Got CRUD working.
June Park <parkjune1995@gmail.com>
parents: 111
diff changeset
398 if (question_mark)
d6d578b49a19 [PostDog] Got CRUD working.
June Park <parkjune1995@gmail.com>
parents: 111
diff changeset
399 *question_mark = '\0';
d6d578b49a19 [PostDog] Got CRUD working.
June Park <parkjune1995@gmail.com>
parents: 111
diff changeset
400
155
3bb45eb67906 [Postdog] Updated variables names and padding sizes. Needs more work.
June Park <parkjune1995@gmail.com>
parents: 153
diff changeset
401 int get_params_length = (int)strlen(input_body_array[TAB_GET_PARAMS]);
112
d6d578b49a19 [PostDog] Got CRUD working.
June Park <parkjune1995@gmail.com>
parents: 111
diff changeset
402 if (get_params_length == 0)
d6d578b49a19 [PostDog] Got CRUD working.
June Park <parkjune1995@gmail.com>
parents: 111
diff changeset
403 return;
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 char *separator = "?";
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 Dowa_Arena *arena = Dowa_Arena_Create(1024*1024);
155
3bb45eb67906 [Postdog] Updated variables names and padding sizes. Needs more work.
June Park <parkjune1995@gmail.com>
parents: 153
diff changeset
408 char **lines = Dowa_String_Split(input_body_array[TAB_GET_PARAMS], "\n", get_params_length, 1, arena);
112
d6d578b49a19 [PostDog] Got CRUD working.
June Park <parkjune1995@gmail.com>
parents: 111
diff changeset
409 for (int i = 0; i < Dowa_Array_Length(lines); i++)
d6d578b49a19 [PostDog] Got CRUD working.
June Park <parkjune1995@gmail.com>
parents: 111
diff changeset
410 {
d6d578b49a19 [PostDog] Got CRUD working.
June Park <parkjune1995@gmail.com>
parents: 111
diff changeset
411 char *line = lines[i];
d6d578b49a19 [PostDog] Got CRUD working.
June Park <parkjune1995@gmail.com>
parents: 111
diff changeset
412 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
413
d6d578b49a19 [PostDog] Got CRUD working.
June Park <parkjune1995@gmail.com>
parents: 111
diff changeset
414 if (Dowa_Array_Length(key_value) < 2)
114
e2a73e64e8e6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 112
diff changeset
415 break;
112
d6d578b49a19 [PostDog] Got CRUD working.
June Park <parkjune1995@gmail.com>
parents: 111
diff changeset
416
d6d578b49a19 [PostDog] Got CRUD working.
June Park <parkjune1995@gmail.com>
parents: 111
diff changeset
417 strcat(url_input_text, separator);
d6d578b49a19 [PostDog] Got CRUD working.
June Park <parkjune1995@gmail.com>
parents: 111
diff changeset
418 strcat(url_input_text, key_value[0]);
d6d578b49a19 [PostDog] Got CRUD working.
June Park <parkjune1995@gmail.com>
parents: 111
diff changeset
419 strcat(url_input_text, "=");
d6d578b49a19 [PostDog] Got CRUD working.
June Park <parkjune1995@gmail.com>
parents: 111
diff changeset
420 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
421 {
d6d578b49a19 [PostDog] Got CRUD working.
June Park <parkjune1995@gmail.com>
parents: 111
diff changeset
422 if (!key_value[i] || key_value[i][0] == '\0')
d6d578b49a19 [PostDog] Got CRUD working.
June Park <parkjune1995@gmail.com>
parents: 111
diff changeset
423 break;
d6d578b49a19 [PostDog] Got CRUD working.
June Park <parkjune1995@gmail.com>
parents: 111
diff changeset
424 if (i > 1) strcat(url_input_text, "%20");
d6d578b49a19 [PostDog] Got CRUD working.
June Park <parkjune1995@gmail.com>
parents: 111
diff changeset
425 strcat(url_input_text, key_value[i]);
d6d578b49a19 [PostDog] Got CRUD working.
June Park <parkjune1995@gmail.com>
parents: 111
diff changeset
426 }
d6d578b49a19 [PostDog] Got CRUD working.
June Park <parkjune1995@gmail.com>
parents: 111
diff changeset
427 separator = "&";
d6d578b49a19 [PostDog] Got CRUD working.
June Park <parkjune1995@gmail.com>
parents: 111
diff changeset
428 }
d6d578b49a19 [PostDog] Got CRUD working.
June Park <parkjune1995@gmail.com>
parents: 111
diff changeset
429
d6d578b49a19 [PostDog] Got CRUD working.
June Park <parkjune1995@gmail.com>
parents: 111
diff changeset
430 Dowa_Arena_Free(arena);
d6d578b49a19 [PostDog] Got CRUD working.
June Park <parkjune1995@gmail.com>
parents: 111
diff changeset
431 }
d6d578b49a19 [PostDog] Got CRUD working.
June Park <parkjune1995@gmail.com>
parents: 111
diff changeset
432
114
e2a73e64e8e6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 112
diff changeset
433 int PostDog_String_To_MethodEnum(char *value)
e2a73e64e8e6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 112
diff changeset
434 {
e2a73e64e8e6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 112
diff changeset
435 if (strstr(value, "GET"))
e2a73e64e8e6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 112
diff changeset
436 return 0;
e2a73e64e8e6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 112
diff changeset
437 if (strstr(value, "POST"))
e2a73e64e8e6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 112
diff changeset
438 return 1;
e2a73e64e8e6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 112
diff changeset
439 if (strstr(value, "PUT"))
e2a73e64e8e6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 112
diff changeset
440 return 2;
e2a73e64e8e6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 112
diff changeset
441 if (strstr(value, "DELETE"))
e2a73e64e8e6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 112
diff changeset
442 return 3;
e2a73e64e8e6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 112
diff changeset
443 return 0;
e2a73e64e8e6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 112
diff changeset
444 }
e2a73e64e8e6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 112
diff changeset
445
118
249881ceff7b [PostDog] Updated some core logic. Will create a bookmark for postdog until the launch as this is annoying to deal with.
June Park <parkjune1995@gmail.com>
parents: 117
diff changeset
446 void PostDog_Params_Reset(void)
114
e2a73e64e8e6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 112
diff changeset
447 {
118
249881ceff7b [PostDog] Updated some core logic. Will create a bookmark for postdog until the launch as this is annoying to deal with.
June Park <parkjune1995@gmail.com>
parents: 117
diff changeset
448 url_input_text[0] = '\0';
155
3bb45eb67906 [Postdog] Updated variables names and padding sizes. Needs more work.
June Park <parkjune1995@gmail.com>
parents: 153
diff changeset
449 result_text[0] = '\0';
114
e2a73e64e8e6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 112
diff changeset
450 active_method_dropdown = 0;
155
3bb45eb67906 [Postdog] Updated variables names and padding sizes. Needs more work.
June Park <parkjune1995@gmail.com>
parents: 153
diff changeset
451 for (int i = 0; i < Dowa_Array_Length(input_body_array); i++)
3bb45eb67906 [Postdog] Updated variables names and padding sizes. Needs more work.
June Park <parkjune1995@gmail.com>
parents: 153
diff changeset
452 input_body_array[i][0] = '\0';
114
e2a73e64e8e6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 112
diff changeset
453 }
e2a73e64e8e6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 112
diff changeset
454
118
249881ceff7b [PostDog] Updated some core logic. Will create a bookmark for postdog until the launch as this is annoying to deal with.
June Park <parkjune1995@gmail.com>
parents: 117
diff changeset
455 void PostDog_Load_File(const char *filename)
249881ceff7b [PostDog] Updated some core logic. Will create a bookmark for postdog until the launch as this is annoying to deal with.
June Park <parkjune1995@gmail.com>
parents: 117
diff changeset
456 {
114
e2a73e64e8e6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 112
diff changeset
457 char full_file_path[512] = {0};
e2a73e64e8e6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 112
diff changeset
458 snprintf(full_file_path, 512, "%s/%s", POSTDOG_PATHS, filename);
e2a73e64e8e6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 112
diff changeset
459 FILE *file = fopen(full_file_path, "r");
e2a73e64e8e6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 112
diff changeset
460 if (!file)
e2a73e64e8e6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 112
diff changeset
461 return;
e2a73e64e8e6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 112
diff changeset
462
e2a73e64e8e6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 112
diff changeset
463 fseek(file, 0, SEEK_END);
e2a73e64e8e6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 112
diff changeset
464 size_t file_size = ftell(file);
e2a73e64e8e6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 112
diff changeset
465 fseek(file, 0, SEEK_SET);
e2a73e64e8e6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 112
diff changeset
466
e2a73e64e8e6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 112
diff changeset
467 Dowa_Arena *init_arena = Dowa_Arena_Create(file_size + 2);
e2a73e64e8e6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 112
diff changeset
468 Dowa_Arena *split_arena = Dowa_Arena_Create(file_size * 2);
e2a73e64e8e6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 112
diff changeset
469 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
470 fread(file_buffer, 1, file_size, file);
116
7bd795bac997 [Postdog] Added scrollable area to inputs and history files, buttons to delete and view.
June Park <parkjune1995@gmail.com>
parents: 115
diff changeset
471 fclose(file);
7bd795bac997 [Postdog] Added scrollable area to inputs and history files, buttons to delete and view.
June Park <parkjune1995@gmail.com>
parents: 115
diff changeset
472
114
e2a73e64e8e6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 112
diff changeset
473 char **values = Dowa_String_Split(file_buffer, "---\n", file_size, 4, split_arena);
116
7bd795bac997 [Postdog] Added scrollable area to inputs and history files, buttons to delete and view.
June Park <parkjune1995@gmail.com>
parents: 115
diff changeset
474
114
e2a73e64e8e6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 112
diff changeset
475 for (int i = 0; i < Dowa_Array_Length(values); i++)
e2a73e64e8e6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 112
diff changeset
476 {
118
249881ceff7b [PostDog] Updated some core logic. Will create a bookmark for postdog until the launch as this is annoying to deal with.
June Park <parkjune1995@gmail.com>
parents: 117
diff changeset
477 switch (i)
114
e2a73e64e8e6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 112
diff changeset
478 {
118
249881ceff7b [PostDog] Updated some core logic. Will create a bookmark for postdog until the launch as this is annoying to deal with.
June Park <parkjune1995@gmail.com>
parents: 117
diff changeset
479 case 0: // Title - skip
249881ceff7b [PostDog] Updated some core logic. Will create a bookmark for postdog until the launch as this is annoying to deal with.
June Park <parkjune1995@gmail.com>
parents: 117
diff changeset
480 break;
249881ceff7b [PostDog] Updated some core logic. Will create a bookmark for postdog until the launch as this is annoying to deal with.
June Park <parkjune1995@gmail.com>
parents: 117
diff changeset
481
249881ceff7b [PostDog] Updated some core logic. Will create a bookmark for postdog until the launch as this is annoying to deal with.
June Park <parkjune1995@gmail.com>
parents: 117
diff changeset
482 case 1: // URL
249881ceff7b [PostDog] Updated some core logic. Will create a bookmark for postdog until the launch as this is annoying to deal with.
June Park <parkjune1995@gmail.com>
parents: 117
diff changeset
483 snprintf(url_input_text, strlen(values[i]) + 1, "%s", values[i]);
249881ceff7b [PostDog] Updated some core logic. Will create a bookmark for postdog until the launch as this is annoying to deal with.
June Park <parkjune1995@gmail.com>
parents: 117
diff changeset
484 url_input_text[strcspn(url_input_text, "\n")] = '\0';
249881ceff7b [PostDog] Updated some core logic. Will create a bookmark for postdog until the launch as this is annoying to deal with.
June Park <parkjune1995@gmail.com>
parents: 117
diff changeset
485 break;
249881ceff7b [PostDog] Updated some core logic. Will create a bookmark for postdog until the launch as this is annoying to deal with.
June Park <parkjune1995@gmail.com>
parents: 117
diff changeset
486
249881ceff7b [PostDog] Updated some core logic. Will create a bookmark for postdog until the launch as this is annoying to deal with.
June Park <parkjune1995@gmail.com>
parents: 117
diff changeset
487 case 2: // Method
249881ceff7b [PostDog] Updated some core logic. Will create a bookmark for postdog until the launch as this is annoying to deal with.
June Park <parkjune1995@gmail.com>
parents: 117
diff changeset
488 active_method_dropdown = PostDog_String_To_MethodEnum(values[i]);
249881ceff7b [PostDog] Updated some core logic. Will create a bookmark for postdog until the launch as this is annoying to deal with.
June Park <parkjune1995@gmail.com>
parents: 117
diff changeset
489 break;
249881ceff7b [PostDog] Updated some core logic. Will create a bookmark for postdog until the launch as this is annoying to deal with.
June Park <parkjune1995@gmail.com>
parents: 117
diff changeset
490
249881ceff7b [PostDog] Updated some core logic. Will create a bookmark for postdog until the launch as this is annoying to deal with.
June Park <parkjune1995@gmail.com>
parents: 117
diff changeset
491 case 3: // Headers (TAB_HEADER)
249881ceff7b [PostDog] Updated some core logic. Will create a bookmark for postdog until the launch as this is annoying to deal with.
June Park <parkjune1995@gmail.com>
parents: 117
diff changeset
492 case 4: // Body (TAB_BODY)
249881ceff7b [PostDog] Updated some core logic. Will create a bookmark for postdog until the launch as this is annoying to deal with.
June Park <parkjune1995@gmail.com>
parents: 117
diff changeset
493 case 5: // Get Params (TAB_GET_PARAMS)
155
3bb45eb67906 [Postdog] Updated variables names and padding sizes. Needs more work.
June Park <parkjune1995@gmail.com>
parents: 153
diff changeset
494 case 6: // Websocket (TAB_WEBSOCKET)
114
e2a73e64e8e6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 112
diff changeset
495 {
118
249881ceff7b [PostDog] Updated some core logic. Will create a bookmark for postdog until the launch as this is annoying to deal with.
June Park <parkjune1995@gmail.com>
parents: 117
diff changeset
496 int map_index = i - 3; // 3->0, 4->1, 5->2, 6->3
155
3bb45eb67906 [Postdog] Updated variables names and padding sizes. Needs more work.
June Park <parkjune1995@gmail.com>
parents: 153
diff changeset
497 snprintf(input_body_array[map_index], strlen(values[i]) + 1, "%s", values[i]);
118
249881ceff7b [PostDog] Updated some core logic. Will create a bookmark for postdog until the launch as this is annoying to deal with.
June Park <parkjune1995@gmail.com>
parents: 117
diff changeset
498 // Trim trailing newlines
249881ceff7b [PostDog] Updated some core logic. Will create a bookmark for postdog until the launch as this is annoying to deal with.
June Park <parkjune1995@gmail.com>
parents: 117
diff changeset
499 for (int j = strlen(values[i]); j > 0; j--)
114
e2a73e64e8e6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 112
diff changeset
500 {
155
3bb45eb67906 [Postdog] Updated variables names and padding sizes. Needs more work.
June Park <parkjune1995@gmail.com>
parents: 153
diff changeset
501 if (input_body_array[map_index][j] == '\n')
118
249881ceff7b [PostDog] Updated some core logic. Will create a bookmark for postdog until the launch as this is annoying to deal with.
June Park <parkjune1995@gmail.com>
parents: 117
diff changeset
502 {
155
3bb45eb67906 [Postdog] Updated variables names and padding sizes. Needs more work.
June Park <parkjune1995@gmail.com>
parents: 153
diff changeset
503 input_body_array[map_index][j] = '\0';
118
249881ceff7b [PostDog] Updated some core logic. Will create a bookmark for postdog until the launch as this is annoying to deal with.
June Park <parkjune1995@gmail.com>
parents: 117
diff changeset
504 break;
249881ceff7b [PostDog] Updated some core logic. Will create a bookmark for postdog until the launch as this is annoying to deal with.
June Park <parkjune1995@gmail.com>
parents: 117
diff changeset
505 }
114
e2a73e64e8e6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 112
diff changeset
506 }
118
249881ceff7b [PostDog] Updated some core logic. Will create a bookmark for postdog until the launch as this is annoying to deal with.
June Park <parkjune1995@gmail.com>
parents: 117
diff changeset
507 break;
114
e2a73e64e8e6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 112
diff changeset
508 }
118
249881ceff7b [PostDog] Updated some core logic. Will create a bookmark for postdog until the launch as this is annoying to deal with.
June Park <parkjune1995@gmail.com>
parents: 117
diff changeset
509
249881ceff7b [PostDog] Updated some core logic. Will create a bookmark for postdog until the launch as this is annoying to deal with.
June Park <parkjune1995@gmail.com>
parents: 117
diff changeset
510 default: // Response (index 7+)
155
3bb45eb67906 [Postdog] Updated variables names and padding sizes. Needs more work.
June Park <parkjune1995@gmail.com>
parents: 153
diff changeset
511 snprintf(result_text, strlen(values[i]) + 1, "%s", values[i]);
118
249881ceff7b [PostDog] Updated some core logic. Will create a bookmark for postdog until the launch as this is annoying to deal with.
June Park <parkjune1995@gmail.com>
parents: 117
diff changeset
512 break;
114
e2a73e64e8e6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 112
diff changeset
513 }
e2a73e64e8e6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 112
diff changeset
514 }
116
7bd795bac997 [Postdog] Added scrollable area to inputs and history files, buttons to delete and view.
June Park <parkjune1995@gmail.com>
parents: 115
diff changeset
515
7bd795bac997 [Postdog] Added scrollable area to inputs and history files, buttons to delete and view.
June Park <parkjune1995@gmail.com>
parents: 115
diff changeset
516 Dowa_Arena_Free(init_arena);
7bd795bac997 [Postdog] Added scrollable area to inputs and history files, buttons to delete and view.
June Park <parkjune1995@gmail.com>
parents: 115
diff changeset
517 Dowa_Arena_Free(split_arena);
114
e2a73e64e8e6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 112
diff changeset
518 }
e2a73e64e8e6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 112
diff changeset
519
e2a73e64e8e6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 112
diff changeset
520 Rectangle AddPadding(Rectangle rect, float padding)
e2a73e64e8e6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 112
diff changeset
521 {
115
96db6c3f38d6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 114
diff changeset
522 return (Rectangle){
114
e2a73e64e8e6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 112
diff changeset
523 rect.x + padding,
e2a73e64e8e6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 112
diff changeset
524 rect.y + padding,
e2a73e64e8e6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 112
diff changeset
525 rect.width - (2 * padding),
e2a73e64e8e6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 112
diff changeset
526 rect.height - (2 * padding)
e2a73e64e8e6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 112
diff changeset
527 };
e2a73e64e8e6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 112
diff changeset
528 }
e2a73e64e8e6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 112
diff changeset
529
155
3bb45eb67906 [Postdog] Updated variables names and padding sizes. Needs more work.
June Park <parkjune1995@gmail.com>
parents: 153
diff changeset
530 Rectangle AddPaddingAll(Rectangle rect, float top, float right,float down, float left)
3bb45eb67906 [Postdog] Updated variables names and padding sizes. Needs more work.
June Park <parkjune1995@gmail.com>
parents: 153
diff changeset
531 {
3bb45eb67906 [Postdog] Updated variables names and padding sizes. Needs more work.
June Park <parkjune1995@gmail.com>
parents: 153
diff changeset
532 return (Rectangle){
3bb45eb67906 [Postdog] Updated variables names and padding sizes. Needs more work.
June Park <parkjune1995@gmail.com>
parents: 153
diff changeset
533 rect.x + left,
3bb45eb67906 [Postdog] Updated variables names and padding sizes. Needs more work.
June Park <parkjune1995@gmail.com>
parents: 153
diff changeset
534 rect.y + top,
3bb45eb67906 [Postdog] Updated variables names and padding sizes. Needs more work.
June Park <parkjune1995@gmail.com>
parents: 153
diff changeset
535 rect.width - (right + left),
3bb45eb67906 [Postdog] Updated variables names and padding sizes. Needs more work.
June Park <parkjune1995@gmail.com>
parents: 153
diff changeset
536 rect.height - (top + down),
3bb45eb67906 [Postdog] Updated variables names and padding sizes. Needs more work.
June Park <parkjune1995@gmail.com>
parents: 153
diff changeset
537 };
3bb45eb67906 [Postdog] Updated variables names and padding sizes. Needs more work.
June Park <parkjune1995@gmail.com>
parents: 153
diff changeset
538 }
3bb45eb67906 [Postdog] Updated variables names and padding sizes. Needs more work.
June Park <parkjune1995@gmail.com>
parents: 153
diff changeset
539
3bb45eb67906 [Postdog] Updated variables names and padding sizes. Needs more work.
June Park <parkjune1995@gmail.com>
parents: 153
diff changeset
540
3bb45eb67906 [Postdog] Updated variables names and padding sizes. Needs more work.
June Park <parkjune1995@gmail.com>
parents: 153
diff changeset
541
116
7bd795bac997 [Postdog] Added scrollable area to inputs and history files, buttons to delete and view.
June Park <parkjune1995@gmail.com>
parents: 115
diff changeset
542 Rectangle AddPaddingHorizontal(Rectangle rect, float padding)
7bd795bac997 [Postdog] Added scrollable area to inputs and history files, buttons to delete and view.
June Park <parkjune1995@gmail.com>
parents: 115
diff changeset
543 {
7bd795bac997 [Postdog] Added scrollable area to inputs and history files, buttons to delete and view.
June Park <parkjune1995@gmail.com>
parents: 115
diff changeset
544 return (Rectangle){
7bd795bac997 [Postdog] Added scrollable area to inputs and history files, buttons to delete and view.
June Park <parkjune1995@gmail.com>
parents: 115
diff changeset
545 rect.x + padding,
7bd795bac997 [Postdog] Added scrollable area to inputs and history files, buttons to delete and view.
June Park <parkjune1995@gmail.com>
parents: 115
diff changeset
546 rect.y,
7bd795bac997 [Postdog] Added scrollable area to inputs and history files, buttons to delete and view.
June Park <parkjune1995@gmail.com>
parents: 115
diff changeset
547 rect.width - (2 * padding),
7bd795bac997 [Postdog] Added scrollable area to inputs and history files, buttons to delete and view.
June Park <parkjune1995@gmail.com>
parents: 115
diff changeset
548 rect.height
7bd795bac997 [Postdog] Added scrollable area to inputs and history files, buttons to delete and view.
June Park <parkjune1995@gmail.com>
parents: 115
diff changeset
549 };
7bd795bac997 [Postdog] Added scrollable area to inputs and history files, buttons to delete and view.
June Park <parkjune1995@gmail.com>
parents: 115
diff changeset
550 }
7bd795bac997 [Postdog] Added scrollable area to inputs and history files, buttons to delete and view.
June Park <parkjune1995@gmail.com>
parents: 115
diff changeset
551
7bd795bac997 [Postdog] Added scrollable area to inputs and history files, buttons to delete and view.
June Park <parkjune1995@gmail.com>
parents: 115
diff changeset
552 Rectangle AddPaddingVertical(Rectangle rect, float padding)
7bd795bac997 [Postdog] Added scrollable area to inputs and history files, buttons to delete and view.
June Park <parkjune1995@gmail.com>
parents: 115
diff changeset
553 {
7bd795bac997 [Postdog] Added scrollable area to inputs and history files, buttons to delete and view.
June Park <parkjune1995@gmail.com>
parents: 115
diff changeset
554 return (Rectangle){
7bd795bac997 [Postdog] Added scrollable area to inputs and history files, buttons to delete and view.
June Park <parkjune1995@gmail.com>
parents: 115
diff changeset
555 rect.x,
7bd795bac997 [Postdog] Added scrollable area to inputs and history files, buttons to delete and view.
June Park <parkjune1995@gmail.com>
parents: 115
diff changeset
556 rect.y + padding,
7bd795bac997 [Postdog] Added scrollable area to inputs and history files, buttons to delete and view.
June Park <parkjune1995@gmail.com>
parents: 115
diff changeset
557 rect.width,
7bd795bac997 [Postdog] Added scrollable area to inputs and history files, buttons to delete and view.
June Park <parkjune1995@gmail.com>
parents: 115
diff changeset
558 rect.height - (2 * padding)
7bd795bac997 [Postdog] Added scrollable area to inputs and history files, buttons to delete and view.
June Park <parkjune1995@gmail.com>
parents: 115
diff changeset
559 };
7bd795bac997 [Postdog] Added scrollable area to inputs and history files, buttons to delete and view.
June Park <parkjune1995@gmail.com>
parents: 115
diff changeset
560 }
7bd795bac997 [Postdog] Added scrollable area to inputs and history files, buttons to delete and view.
June Park <parkjune1995@gmail.com>
parents: 115
diff changeset
561
115
96db6c3f38d6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 114
diff changeset
562 // Layout helper functions
96db6c3f38d6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 114
diff changeset
563 Rectangle RightOf(Rectangle ref, float padding)
96db6c3f38d6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 114
diff changeset
564 {
96db6c3f38d6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 114
diff changeset
565 return (Rectangle){
96db6c3f38d6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 114
diff changeset
566 .x = ref.x + ref.width + padding,
96db6c3f38d6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 114
diff changeset
567 .y = ref.y,
96db6c3f38d6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 114
diff changeset
568 .width = 0,
96db6c3f38d6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 114
diff changeset
569 .height = ref.height
96db6c3f38d6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 114
diff changeset
570 };
96db6c3f38d6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 114
diff changeset
571 }
96db6c3f38d6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 114
diff changeset
572
96db6c3f38d6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 114
diff changeset
573 Rectangle Below(Rectangle ref, float padding)
96db6c3f38d6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 114
diff changeset
574 {
96db6c3f38d6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 114
diff changeset
575 return (Rectangle){
96db6c3f38d6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 114
diff changeset
576 .x = ref.x,
96db6c3f38d6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 114
diff changeset
577 .y = ref.y + ref.height + padding,
96db6c3f38d6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 114
diff changeset
578 .width = ref.width,
96db6c3f38d6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 114
diff changeset
579 .height = 0
96db6c3f38d6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 114
diff changeset
580 };
96db6c3f38d6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 114
diff changeset
581 }
96db6c3f38d6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 114
diff changeset
582
96db6c3f38d6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 114
diff changeset
583 Rectangle LeftColumn(Rectangle container, float ratio, float padding)
96db6c3f38d6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 114
diff changeset
584 {
96db6c3f38d6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 114
diff changeset
585 return (Rectangle){
96db6c3f38d6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 114
diff changeset
586 .x = container.x + padding,
96db6c3f38d6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 114
diff changeset
587 .y = container.y + padding,
96db6c3f38d6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 114
diff changeset
588 .width = (container.width * ratio) - padding,
96db6c3f38d6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 114
diff changeset
589 .height = container.height - (2 * padding)
96db6c3f38d6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 114
diff changeset
590 };
96db6c3f38d6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 114
diff changeset
591 }
96db6c3f38d6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 114
diff changeset
592
96db6c3f38d6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 114
diff changeset
593 Rectangle RightColumn(Rectangle container, Rectangle leftCol, float padding)
96db6c3f38d6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 114
diff changeset
594 {
96db6c3f38d6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 114
diff changeset
595 return (Rectangle){
96db6c3f38d6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 114
diff changeset
596 .x = leftCol.x + leftCol.width + padding,
96db6c3f38d6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 114
diff changeset
597 .y = container.y + padding,
96db6c3f38d6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 114
diff changeset
598 .width = container.width - leftCol.width - (3 * padding),
96db6c3f38d6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 114
diff changeset
599 .height = container.height - (2 * padding)
96db6c3f38d6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 114
diff changeset
600 };
96db6c3f38d6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 114
diff changeset
601 }
96db6c3f38d6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 114
diff changeset
602
96db6c3f38d6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 114
diff changeset
603 Rectangle HorizontalSplit(Rectangle container, float ratio)
96db6c3f38d6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 114
diff changeset
604 {
96db6c3f38d6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 114
diff changeset
605 return (Rectangle){
96db6c3f38d6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 114
diff changeset
606 .x = container.x,
96db6c3f38d6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 114
diff changeset
607 .y = container.y,
96db6c3f38d6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 114
diff changeset
608 .width = container.width * ratio,
96db6c3f38d6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 114
diff changeset
609 .height = container.height
96db6c3f38d6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 114
diff changeset
610 };
96db6c3f38d6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 114
diff changeset
611 }
96db6c3f38d6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 114
diff changeset
612
54
b3e82d22f961 [PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff changeset
613 int main()
b3e82d22f961 [PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff changeset
614 {
111
48f260576059 [PostDog] Rewriting it from scratch as it is unreadable for me.
June Park <parkjune1995@gmail.com>
parents: 63
diff changeset
615 // -- initizlied --//
48f260576059 [PostDog] Rewriting it from scratch as it is unreadable for me.
June Park <parkjune1995@gmail.com>
parents: 63
diff changeset
616 InitWindow(SCREEN_WIDTH, SCREEN_HEIGHT, "PostDog");
54
b3e82d22f961 [PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff changeset
617 SetWindowState(FLAG_WINDOW_RESIZABLE);
b3e82d22f961 [PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff changeset
618 SetTargetFPS(60);
b3e82d22f961 [PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff changeset
619
114
e2a73e64e8e6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 112
diff changeset
620 Font customFont = LoadFontEx("postdog/Roboto-Regular.ttf", 20, 0, 0);
e2a73e64e8e6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 112
diff changeset
621 GuiSetFont(customFont);
153
790930d9bb90 [PostDog] Adding websocket to be more usable.
June Park <parkjune1995@gmail.com>
parents: 152
diff changeset
622 GuiSetStyle(DEFAULT, TEXT_SIZE, 15);
116
7bd795bac997 [Postdog] Added scrollable area to inputs and history files, buttons to delete and view.
June Park <parkjune1995@gmail.com>
parents: 115
diff changeset
623 Image logo_original = LoadImage("postdog/epi_all_colors.png");
7bd795bac997 [Postdog] Added scrollable area to inputs and history files, buttons to delete and view.
June Park <parkjune1995@gmail.com>
parents: 115
diff changeset
624 ImageResize(&logo_original, 60, 60);
118
249881ceff7b [PostDog] Updated some core logic. Will create a bookmark for postdog until the launch as this is annoying to deal with.
June Park <parkjune1995@gmail.com>
parents: 117
diff changeset
625 SetWindowIcon(logo_original);
116
7bd795bac997 [Postdog] Added scrollable area to inputs and history files, buttons to delete and view.
June Park <parkjune1995@gmail.com>
parents: 115
diff changeset
626 Texture2D logo_texture = LoadTextureFromImage(logo_original);
7bd795bac997 [Postdog] Added scrollable area to inputs and history files, buttons to delete and view.
June Park <parkjune1995@gmail.com>
parents: 115
diff changeset
627 UnloadImage(logo_original);
114
e2a73e64e8e6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 112
diff changeset
628
111
48f260576059 [PostDog] Rewriting it from scratch as it is unreadable for me.
June Park <parkjune1995@gmail.com>
parents: 63
diff changeset
629 // -- Starting pos ---//
155
3bb45eb67906 [Postdog] Updated variables names and padding sizes. Needs more work.
June Park <parkjune1995@gmail.com>
parents: 153
diff changeset
630 Rectangle history_sidebar_rect = { 0 };
114
e2a73e64e8e6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 112
diff changeset
631 Dowa_Array_Reserve(history_items, 10);
e2a73e64e8e6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 112
diff changeset
632 Dowa_Array_Reserve(new_history_items, 10);
e2a73e64e8e6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 112
diff changeset
633 PostDog_History_Load(&history_items);
116
7bd795bac997 [Postdog] Added scrollable area to inputs and history files, buttons to delete and view.
June Park <parkjune1995@gmail.com>
parents: 115
diff changeset
634 int32 *history_deleted_items = NULL;
54
b3e82d22f961 [PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff changeset
635
155
3bb45eb67906 [Postdog] Updated variables names and padding sizes. Needs more work.
June Park <parkjune1995@gmail.com>
parents: 153
diff changeset
636 Rectangle url_area_rect = { 0 };
3bb45eb67906 [Postdog] Updated variables names and padding sizes. Needs more work.
June Park <parkjune1995@gmail.com>
parents: 153
diff changeset
637 Rectangle url_input_bounds_rect = { 0 };
114
e2a73e64e8e6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 112
diff changeset
638 bool url_input_edit = false;
155
3bb45eb67906 [Postdog] Updated variables names and padding sizes. Needs more work.
June Park <parkjune1995@gmail.com>
parents: 153
diff changeset
639 Rectangle url_text_bounds_rect = { 0 };
3bb45eb67906 [Postdog] Updated variables names and padding sizes. Needs more work.
June Park <parkjune1995@gmail.com>
parents: 153
diff changeset
640 Rectangle url_enter_button_rect = { 0 };
3bb45eb67906 [Postdog] Updated variables names and padding sizes. Needs more work.
June Park <parkjune1995@gmail.com>
parents: 153
diff changeset
641 Rectangle method_dropdown_rect = { 0 };
54
b3e82d22f961 [PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff changeset
642
114
e2a73e64e8e6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 112
diff changeset
643
118
249881ceff7b [PostDog] Updated some core logic. Will create a bookmark for postdog until the launch as this is annoying to deal with.
June Park <parkjune1995@gmail.com>
parents: 117
diff changeset
644 // Initialize global UI state
249881ceff7b [PostDog] Updated some core logic. Will create a bookmark for postdog until the launch as this is annoying to deal with.
June Park <parkjune1995@gmail.com>
parents: 117
diff changeset
645 url_input_text = (char *)malloc(sizeof(char) * URL_TEXT_BUFFER_LENGTH);
152
7387eec8e7f8 [Postdog] Updated to use Seobeo_Client instead of CURL. Updated to handle websocket connection.
June Park <parkjune1995@gmail.com>
parents: 118
diff changeset
646 snprintf(url_input_text, URL_TEXT_BUFFER_LENGTH, "wss://mrjunejune.com/echo");
112
d6d578b49a19 [PostDog] Got CRUD working.
June Park <parkjune1995@gmail.com>
parents: 111
diff changeset
647
155
3bb45eb67906 [Postdog] Updated variables names and padding sizes. Needs more work.
June Park <parkjune1995@gmail.com>
parents: 153
diff changeset
648 Dowa_Array_Push(input_body_array, (char *)malloc(sizeof(char) * HEADER_BUFFER_LENGTH));
3bb45eb67906 [Postdog] Updated variables names and padding sizes. Needs more work.
June Park <parkjune1995@gmail.com>
parents: 153
diff changeset
649 Dowa_Array_Push(input_body_array, (char *)malloc(sizeof(char) * BODY_BUFFER_LENGTH));
3bb45eb67906 [Postdog] Updated variables names and padding sizes. Needs more work.
June Park <parkjune1995@gmail.com>
parents: 153
diff changeset
650 Dowa_Array_Push(input_body_array, (char *)malloc(sizeof(char) * DEFAULT_TEXT_BUFFER_LENGTH));
3bb45eb67906 [Postdog] Updated variables names and padding sizes. Needs more work.
June Park <parkjune1995@gmail.com>
parents: 153
diff changeset
651 Dowa_Array_Push(input_body_array, (char *)malloc(sizeof(char) * DEFAULT_TEXT_BUFFER_LENGTH));
112
d6d578b49a19 [PostDog] Got CRUD working.
June Park <parkjune1995@gmail.com>
parents: 111
diff changeset
652
155
3bb45eb67906 [Postdog] Updated variables names and padding sizes. Needs more work.
June Park <parkjune1995@gmail.com>
parents: 153
diff changeset
653 snprintf(input_body_array[TAB_HEADER], HEADER_BUFFER_LENGTH, "Content-Type: application/json");
3bb45eb67906 [Postdog] Updated variables names and padding sizes. Needs more work.
June Park <parkjune1995@gmail.com>
parents: 153
diff changeset
654 snprintf(input_body_array[TAB_BODY], HEADER_BUFFER_LENGTH, "");
112
d6d578b49a19 [PostDog] Got CRUD working.
June Park <parkjune1995@gmail.com>
parents: 111
diff changeset
655
155
3bb45eb67906 [Postdog] Updated variables names and padding sizes. Needs more work.
June Park <parkjune1995@gmail.com>
parents: 153
diff changeset
656 result_text = (char *)malloc(sizeof(char) * RESULT_BUFFER_LENGTH);
112
d6d578b49a19 [PostDog] Got CRUD working.
June Park <parkjune1995@gmail.com>
parents: 111
diff changeset
657
d6d578b49a19 [PostDog] Got CRUD working.
June Park <parkjune1995@gmail.com>
parents: 111
diff changeset
658 bool method_edit = false;
d6d578b49a19 [PostDog] Got CRUD working.
June Park <parkjune1995@gmail.com>
parents: 111
diff changeset
659
111
48f260576059 [PostDog] Rewriting it from scratch as it is unreadable for me.
June Park <parkjune1995@gmail.com>
parents: 63
diff changeset
660 int sendRequest;
54
b3e82d22f961 [PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff changeset
661
112
d6d578b49a19 [PostDog] Got CRUD working.
June Park <parkjune1995@gmail.com>
parents: 111
diff changeset
662 // -- input --//
155
3bb45eb67906 [Postdog] Updated variables names and padding sizes. Needs more work.
June Park <parkjune1995@gmail.com>
parents: 153
diff changeset
663 Rectangle input_area_rect = { 0 };
3bb45eb67906 [Postdog] Updated variables names and padding sizes. Needs more work.
June Park <parkjune1995@gmail.com>
parents: 153
diff changeset
664 Rectangle input_tab_rect = { 0 };
3bb45eb67906 [Postdog] Updated variables names and padding sizes. Needs more work.
June Park <parkjune1995@gmail.com>
parents: 153
diff changeset
665 Rectangle input_tab_item_rect = { 0 };
3bb45eb67906 [Postdog] Updated variables names and padding sizes. Needs more work.
June Park <parkjune1995@gmail.com>
parents: 153
diff changeset
666 Rectangle input_body_rect = { 0 };
112
d6d578b49a19 [PostDog] Got CRUD working.
June Park <parkjune1995@gmail.com>
parents: 111
diff changeset
667 bool input_body_bool = false;
54
b3e82d22f961 [PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff changeset
668
112
d6d578b49a19 [PostDog] Got CRUD working.
June Park <parkjune1995@gmail.com>
parents: 111
diff changeset
669 // -- result --//
155
3bb45eb67906 [Postdog] Updated variables names and padding sizes. Needs more work.
June Park <parkjune1995@gmail.com>
parents: 153
diff changeset
670 Rectangle result_area_rect = { 0 };
3bb45eb67906 [Postdog] Updated variables names and padding sizes. Needs more work.
June Park <parkjune1995@gmail.com>
parents: 153
diff changeset
671 Rectangle result_body_rect = { 0 };
54
b3e82d22f961 [PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff changeset
672
111
48f260576059 [PostDog] Rewriting it from scratch as it is unreadable for me.
June Park <parkjune1995@gmail.com>
parents: 63
diff changeset
673 // General styling.
114
e2a73e64e8e6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 112
diff changeset
674 float padding = 10; // TODO make it % based?
116
7bd795bac997 [Postdog] Added scrollable area to inputs and history files, buttons to delete and view.
June Park <parkjune1995@gmail.com>
parents: 115
diff changeset
675 int prev_input_tab = 0;
7bd795bac997 [Postdog] Added scrollable area to inputs and history files, buttons to delete and view.
June Park <parkjune1995@gmail.com>
parents: 115
diff changeset
676
7bd795bac997 [Postdog] Added scrollable area to inputs and history files, buttons to delete and view.
June Park <parkjune1995@gmail.com>
parents: 115
diff changeset
677 // Scroll offsets
7bd795bac997 [Postdog] Added scrollable area to inputs and history files, buttons to delete and view.
June Park <parkjune1995@gmail.com>
parents: 115
diff changeset
678 float history_scroll_offset = 0;
7bd795bac997 [Postdog] Added scrollable area to inputs and history files, buttons to delete and view.
June Park <parkjune1995@gmail.com>
parents: 115
diff changeset
679 float input_body_scroll_offset = 0;
7bd795bac997 [Postdog] Added scrollable area to inputs and history files, buttons to delete and view.
June Park <parkjune1995@gmail.com>
parents: 115
diff changeset
680 float result_body_scroll_offset = 0;
54
b3e82d22f961 [PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff changeset
681
b3e82d22f961 [PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff changeset
682 while (!WindowShouldClose())
b3e82d22f961 [PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff changeset
683 {
111
48f260576059 [PostDog] Rewriting it from scratch as it is unreadable for me.
June Park <parkjune1995@gmail.com>
parents: 63
diff changeset
684 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
685 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
686
116
7bd795bac997 [Postdog] Added scrollable area to inputs and history files, buttons to delete and view.
June Park <parkjune1995@gmail.com>
parents: 115
diff changeset
687 if ((IsKeyDown(KEY_LEFT_SUPER) || IsKeyDown(KEY_LEFT_CONTROL)) && IsKeyDown(KEY_EQUAL))
7bd795bac997 [Postdog] Added scrollable area to inputs and history files, buttons to delete and view.
June Park <parkjune1995@gmail.com>
parents: 115
diff changeset
688 GuiSetStyle(DEFAULT, TEXT_SIZE, GuiGetStyle(DEFAULT, TEXT_SIZE) + 1);
7bd795bac997 [Postdog] Added scrollable area to inputs and history files, buttons to delete and view.
June Park <parkjune1995@gmail.com>
parents: 115
diff changeset
689
7bd795bac997 [Postdog] Added scrollable area to inputs and history files, buttons to delete and view.
June Park <parkjune1995@gmail.com>
parents: 115
diff changeset
690 if ((IsKeyDown(KEY_LEFT_SUPER) || IsKeyDown(KEY_LEFT_CONTROL)) && IsKeyDown(KEY_MINUS))
7bd795bac997 [Postdog] Added scrollable area to inputs and history files, buttons to delete and view.
June Park <parkjune1995@gmail.com>
parents: 115
diff changeset
691 GuiSetStyle(DEFAULT, TEXT_SIZE, GuiGetStyle(DEFAULT, TEXT_SIZE) - 1);
7bd795bac997 [Postdog] Added scrollable area to inputs and history files, buttons to delete and view.
June Park <parkjune1995@gmail.com>
parents: 115
diff changeset
692
155
3bb45eb67906 [Postdog] Updated variables names and padding sizes. Needs more work.
June Park <parkjune1995@gmail.com>
parents: 153
diff changeset
693 Rectangle screen_rect = { 0, 0, screen_width, screen_height };
114
e2a73e64e8e6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 112
diff changeset
694
116
7bd795bac997 [Postdog] Added scrollable area to inputs and history files, buttons to delete and view.
June Park <parkjune1995@gmail.com>
parents: 115
diff changeset
695 // -- Side bar --//
155
3bb45eb67906 [Postdog] Updated variables names and padding sizes. Needs more work.
June Park <parkjune1995@gmail.com>
parents: 153
diff changeset
696 history_sidebar_rect = LeftColumn(screen_rect, 0.15, padding);
3bb45eb67906 [Postdog] Updated variables names and padding sizes. Needs more work.
June Park <parkjune1995@gmail.com>
parents: 153
diff changeset
697 Rectangle content_area_rect = RightColumn(screen_rect, history_sidebar_rect, padding);
3bb45eb67906 [Postdog] Updated variables names and padding sizes. Needs more work.
June Park <parkjune1995@gmail.com>
parents: 153
diff changeset
698 Rectangle logo_area_rect = (Rectangle){
3bb45eb67906 [Postdog] Updated variables names and padding sizes. Needs more work.
June Park <parkjune1995@gmail.com>
parents: 153
diff changeset
699 .x = history_sidebar_rect.x,
3bb45eb67906 [Postdog] Updated variables names and padding sizes. Needs more work.
June Park <parkjune1995@gmail.com>
parents: 153
diff changeset
700 .y = history_sidebar_rect.y,
3bb45eb67906 [Postdog] Updated variables names and padding sizes. Needs more work.
June Park <parkjune1995@gmail.com>
parents: 153
diff changeset
701 .width = history_sidebar_rect.width,
116
7bd795bac997 [Postdog] Added scrollable area to inputs and history files, buttons to delete and view.
June Park <parkjune1995@gmail.com>
parents: 115
diff changeset
702 .height = 80
7bd795bac997 [Postdog] Added scrollable area to inputs and history files, buttons to delete and view.
June Park <parkjune1995@gmail.com>
parents: 115
diff changeset
703 };
115
96db6c3f38d6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 114
diff changeset
704
155
3bb45eb67906 [Postdog] Updated variables names and padding sizes. Needs more work.
June Park <parkjune1995@gmail.com>
parents: 153
diff changeset
705 Rectangle history_list_area_rect = Below(logo_area_rect, padding);
3bb45eb67906 [Postdog] Updated variables names and padding sizes. Needs more work.
June Park <parkjune1995@gmail.com>
parents: 153
diff changeset
706 history_list_area_rect.x += padding;
3bb45eb67906 [Postdog] Updated variables names and padding sizes. Needs more work.
June Park <parkjune1995@gmail.com>
parents: 153
diff changeset
707 history_list_area_rect.width = history_sidebar_rect.width - (2 * padding);
3bb45eb67906 [Postdog] Updated variables names and padding sizes. Needs more work.
June Park <parkjune1995@gmail.com>
parents: 153
diff changeset
708 history_list_area_rect.height = history_sidebar_rect.height - logo_area_rect.height - padding;
116
7bd795bac997 [Postdog] Added scrollable area to inputs and history files, buttons to delete and view.
June Park <parkjune1995@gmail.com>
parents: 115
diff changeset
709
114
e2a73e64e8e6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 112
diff changeset
710 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
711 int32 history_item_length = Dowa_Array_Length(history_items);
115
96db6c3f38d6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 114
diff changeset
712 int32 total = new_history_items_length + history_item_length;
155
3bb45eb67906 [Postdog] Updated variables names and padding sizes. Needs more work.
June Park <parkjune1995@gmail.com>
parents: 153
diff changeset
713 float item_height = history_list_area_rect.height * 0.10;
115
96db6c3f38d6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 114
diff changeset
714
116
7bd795bac997 [Postdog] Added scrollable area to inputs and history files, buttons to delete and view.
June Park <parkjune1995@gmail.com>
parents: 115
diff changeset
715 int32 number_of_skipped_items = 0;
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 {
115
96db6c3f38d6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 114
diff changeset
718 HistoryItem *curr_history_items = i < new_history_items_length ?
118
249881ceff7b [PostDog] Updated some core logic. Will create a bookmark for postdog until the launch as this is annoying to deal with.
June Park <parkjune1995@gmail.com>
parents: 117
diff changeset
719 &new_history_items[i - new_history_items_length - 1] : &history_items[i - new_history_items_length];
115
96db6c3f38d6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 114
diff changeset
720
117
b91f2dd6f84d [PostDog] Fixed delete logic.
June Park <parkjune1995@gmail.com>
parents: 116
diff changeset
721 if (curr_history_items->deleted)
b91f2dd6f84d [PostDog] Fixed delete logic.
June Park <parkjune1995@gmail.com>
parents: 116
diff changeset
722 {
b91f2dd6f84d [PostDog] Fixed delete logic.
June Park <parkjune1995@gmail.com>
parents: 116
diff changeset
723 number_of_skipped_items++;
b91f2dd6f84d [PostDog] Fixed delete logic.
June Park <parkjune1995@gmail.com>
parents: 116
diff changeset
724 continue;
b91f2dd6f84d [PostDog] Fixed delete logic.
June Park <parkjune1995@gmail.com>
parents: 116
diff changeset
725 }
b91f2dd6f84d [PostDog] Fixed delete logic.
June Park <parkjune1995@gmail.com>
parents: 116
diff changeset
726
115
96db6c3f38d6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 114
diff changeset
727 curr_history_items->rect = (Rectangle){
155
3bb45eb67906 [Postdog] Updated variables names and padding sizes. Needs more work.
June Park <parkjune1995@gmail.com>
parents: 153
diff changeset
728 .x = history_list_area_rect.x,
3bb45eb67906 [Postdog] Updated variables names and padding sizes. Needs more work.
June Park <parkjune1995@gmail.com>
parents: 153
diff changeset
729 .y = history_list_area_rect.y + (padding + item_height) * (i - number_of_skipped_items) + history_scroll_offset,
3bb45eb67906 [Postdog] Updated variables names and padding sizes. Needs more work.
June Park <parkjune1995@gmail.com>
parents: 153
diff changeset
730 .width = history_list_area_rect.width,
115
96db6c3f38d6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 114
diff changeset
731 .height = item_height
96db6c3f38d6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 114
diff changeset
732 };
114
e2a73e64e8e6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 112
diff changeset
733 }
54
b3e82d22f961 [PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff changeset
734
116
7bd795bac997 [Postdog] Added scrollable area to inputs and history files, buttons to delete and view.
June Park <parkjune1995@gmail.com>
parents: 115
diff changeset
735 // --- URL --- //
155
3bb45eb67906 [Postdog] Updated variables names and padding sizes. Needs more work.
June Park <parkjune1995@gmail.com>
parents: 153
diff changeset
736 url_area_rect = (Rectangle){
3bb45eb67906 [Postdog] Updated variables names and padding sizes. Needs more work.
June Park <parkjune1995@gmail.com>
parents: 153
diff changeset
737 .x = content_area_rect.x,
3bb45eb67906 [Postdog] Updated variables names and padding sizes. Needs more work.
June Park <parkjune1995@gmail.com>
parents: 153
diff changeset
738 .y = content_area_rect.y,
3bb45eb67906 [Postdog] Updated variables names and padding sizes. Needs more work.
June Park <parkjune1995@gmail.com>
parents: 153
diff changeset
739 .width = content_area_rect.width,
3bb45eb67906 [Postdog] Updated variables names and padding sizes. Needs more work.
June Park <parkjune1995@gmail.com>
parents: 153
diff changeset
740 .height = content_area_rect.height * 0.1
115
96db6c3f38d6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 114
diff changeset
741 };
54
b3e82d22f961 [PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff changeset
742
155
3bb45eb67906 [Postdog] Updated variables names and padding sizes. Needs more work.
June Park <parkjune1995@gmail.com>
parents: 153
diff changeset
743 float url_control_y = url_area_rect.y + (url_area_rect.height - TEXT_SIZE * 2) / 2;
54
b3e82d22f961 [PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff changeset
744
155
3bb45eb67906 [Postdog] Updated variables names and padding sizes. Needs more work.
June Park <parkjune1995@gmail.com>
parents: 153
diff changeset
745 url_text_bounds_rect = (Rectangle){
3bb45eb67906 [Postdog] Updated variables names and padding sizes. Needs more work.
June Park <parkjune1995@gmail.com>
parents: 153
diff changeset
746 .x = url_area_rect.x + padding,
115
96db6c3f38d6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 114
diff changeset
747 .y = url_control_y,
96db6c3f38d6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 114
diff changeset
748 .width = 7 * (TEXT_SIZE / 2),
96db6c3f38d6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 114
diff changeset
749 .height = TEXT_SIZE * 2
96db6c3f38d6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 114
diff changeset
750 };
96db6c3f38d6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 114
diff changeset
751
155
3bb45eb67906 [Postdog] Updated variables names and padding sizes. Needs more work.
June Park <parkjune1995@gmail.com>
parents: 153
diff changeset
752 url_input_bounds_rect = RightOf(url_text_bounds_rect, padding);
3bb45eb67906 [Postdog] Updated variables names and padding sizes. Needs more work.
June Park <parkjune1995@gmail.com>
parents: 153
diff changeset
753 url_input_bounds_rect.width = url_area_rect.width * 0.7;
3bb45eb67906 [Postdog] Updated variables names and padding sizes. Needs more work.
June Park <parkjune1995@gmail.com>
parents: 153
diff changeset
754 url_input_bounds_rect.height = TEXT_SIZE * 2;
111
48f260576059 [PostDog] Rewriting it from scratch as it is unreadable for me.
June Park <parkjune1995@gmail.com>
parents: 63
diff changeset
755
155
3bb45eb67906 [Postdog] Updated variables names and padding sizes. Needs more work.
June Park <parkjune1995@gmail.com>
parents: 153
diff changeset
756 url_enter_button_rect = RightOf(url_input_bounds_rect, padding);
3bb45eb67906 [Postdog] Updated variables names and padding sizes. Needs more work.
June Park <parkjune1995@gmail.com>
parents: 153
diff changeset
757 url_enter_button_rect.width = url_area_rect.width * 0.1;
3bb45eb67906 [Postdog] Updated variables names and padding sizes. Needs more work.
June Park <parkjune1995@gmail.com>
parents: 153
diff changeset
758 url_enter_button_rect.height = TEXT_SIZE * 2;
54
b3e82d22f961 [PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff changeset
759
155
3bb45eb67906 [Postdog] Updated variables names and padding sizes. Needs more work.
June Park <parkjune1995@gmail.com>
parents: 153
diff changeset
760 method_dropdown_rect = RightOf(url_enter_button_rect, padding);
3bb45eb67906 [Postdog] Updated variables names and padding sizes. Needs more work.
June Park <parkjune1995@gmail.com>
parents: 153
diff changeset
761 method_dropdown_rect.width = url_area_rect.width * 0.1;
3bb45eb67906 [Postdog] Updated variables names and padding sizes. Needs more work.
June Park <parkjune1995@gmail.com>
parents: 153
diff changeset
762 method_dropdown_rect.height = TEXT_SIZE * 2;
112
d6d578b49a19 [PostDog] Got CRUD working.
June Park <parkjune1995@gmail.com>
parents: 111
diff changeset
763
116
7bd795bac997 [Postdog] Added scrollable area to inputs and history files, buttons to delete and view.
June Park <parkjune1995@gmail.com>
parents: 115
diff changeset
764 // -- Body -- //
155
3bb45eb67906 [Postdog] Updated variables names and padding sizes. Needs more work.
June Park <parkjune1995@gmail.com>
parents: 153
diff changeset
765 Rectangle body_area_rect = Below(url_area_rect, 0);
3bb45eb67906 [Postdog] Updated variables names and padding sizes. Needs more work.
June Park <parkjune1995@gmail.com>
parents: 153
diff changeset
766 body_area_rect.height = content_area_rect.height - url_area_rect.height;
115
96db6c3f38d6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 114
diff changeset
767
155
3bb45eb67906 [Postdog] Updated variables names and padding sizes. Needs more work.
June Park <parkjune1995@gmail.com>
parents: 153
diff changeset
768 input_area_rect = HorizontalSplit(body_area_rect, 0.5);
3bb45eb67906 [Postdog] Updated variables names and padding sizes. Needs more work.
June Park <parkjune1995@gmail.com>
parents: 153
diff changeset
769 result_area_rect = RightOf(input_area_rect, 0);
3bb45eb67906 [Postdog] Updated variables names and padding sizes. Needs more work.
June Park <parkjune1995@gmail.com>
parents: 153
diff changeset
770 result_area_rect.width = body_area_rect.width - input_area_rect.width;
54
b3e82d22f961 [PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff changeset
771
155
3bb45eb67906 [Postdog] Updated variables names and padding sizes. Needs more work.
June Park <parkjune1995@gmail.com>
parents: 153
diff changeset
772 input_tab_rect = (Rectangle){
3bb45eb67906 [Postdog] Updated variables names and padding sizes. Needs more work.
June Park <parkjune1995@gmail.com>
parents: 153
diff changeset
773 .x = input_area_rect.x + padding,
3bb45eb67906 [Postdog] Updated variables names and padding sizes. Needs more work.
June Park <parkjune1995@gmail.com>
parents: 153
diff changeset
774 .y = input_area_rect.y + padding,
3bb45eb67906 [Postdog] Updated variables names and padding sizes. Needs more work.
June Park <parkjune1995@gmail.com>
parents: 153
diff changeset
775 .width = input_area_rect.width - (2 * padding),
3bb45eb67906 [Postdog] Updated variables names and padding sizes. Needs more work.
June Park <parkjune1995@gmail.com>
parents: 153
diff changeset
776 .height = input_area_rect.height * 0.1
115
96db6c3f38d6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 114
diff changeset
777 };
96db6c3f38d6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 114
diff changeset
778
155
3bb45eb67906 [Postdog] Updated variables names and padding sizes. Needs more work.
June Park <parkjune1995@gmail.com>
parents: 153
diff changeset
779 input_tab_item_rect = input_tab_rect;
3bb45eb67906 [Postdog] Updated variables names and padding sizes. Needs more work.
June Park <parkjune1995@gmail.com>
parents: 153
diff changeset
780 input_tab_item_rect.width = input_tab_rect.width / 4;
54
b3e82d22f961 [PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff changeset
781
155
3bb45eb67906 [Postdog] Updated variables names and padding sizes. Needs more work.
June Park <parkjune1995@gmail.com>
parents: 153
diff changeset
782 input_body_rect = Below(input_tab_rect, 0);
3bb45eb67906 [Postdog] Updated variables names and padding sizes. Needs more work.
June Park <parkjune1995@gmail.com>
parents: 153
diff changeset
783 input_body_rect.width = input_tab_rect.width;
3bb45eb67906 [Postdog] Updated variables names and padding sizes. Needs more work.
June Park <parkjune1995@gmail.com>
parents: 153
diff changeset
784 input_body_rect.height = input_area_rect.height - input_tab_rect.height - (2 * padding);
54
b3e82d22f961 [PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff changeset
785
116
7bd795bac997 [Postdog] Added scrollable area to inputs and history files, buttons to delete and view.
June Park <parkjune1995@gmail.com>
parents: 115
diff changeset
786 // -- Result -- /
155
3bb45eb67906 [Postdog] Updated variables names and padding sizes. Needs more work.
June Park <parkjune1995@gmail.com>
parents: 153
diff changeset
787 result_body_rect = (Rectangle){
3bb45eb67906 [Postdog] Updated variables names and padding sizes. Needs more work.
June Park <parkjune1995@gmail.com>
parents: 153
diff changeset
788 .x = result_area_rect.x + padding,
3bb45eb67906 [Postdog] Updated variables names and padding sizes. Needs more work.
June Park <parkjune1995@gmail.com>
parents: 153
diff changeset
789 .y = input_body_rect.y,
3bb45eb67906 [Postdog] Updated variables names and padding sizes. Needs more work.
June Park <parkjune1995@gmail.com>
parents: 153
diff changeset
790 .width = result_area_rect.width - (2 * padding),
3bb45eb67906 [Postdog] Updated variables names and padding sizes. Needs more work.
June Park <parkjune1995@gmail.com>
parents: 153
diff changeset
791 .height = input_body_rect.height
115
96db6c3f38d6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 114
diff changeset
792 };
54
b3e82d22f961 [PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff changeset
793
114
e2a73e64e8e6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 112
diff changeset
794 Vector2 mouse_position = GetMousePosition();
116
7bd795bac997 [Postdog] Added scrollable area to inputs and history files, buttons to delete and view.
June Park <parkjune1995@gmail.com>
parents: 115
diff changeset
795 float mouse_wheel = GetMouseWheelMove();
7bd795bac997 [Postdog] Added scrollable area to inputs and history files, buttons to delete and view.
June Park <parkjune1995@gmail.com>
parents: 115
diff changeset
796
7bd795bac997 [Postdog] Added scrollable area to inputs and history files, buttons to delete and view.
June Park <parkjune1995@gmail.com>
parents: 115
diff changeset
797 // Reset input body scroll when tab changes
152
7387eec8e7f8 [Postdog] Updated to use Seobeo_Client instead of CURL. Updated to handle websocket connection.
June Park <parkjune1995@gmail.com>
parents: 118
diff changeset
798 if (prev_input_tab != active_input_tab)
7387eec8e7f8 [Postdog] Updated to use Seobeo_Client instead of CURL. Updated to handle websocket connection.
June Park <parkjune1995@gmail.com>
parents: 118
diff changeset
799 {
116
7bd795bac997 [Postdog] Added scrollable area to inputs and history files, buttons to delete and view.
June Park <parkjune1995@gmail.com>
parents: 115
diff changeset
800 input_body_scroll_offset = 0;
7bd795bac997 [Postdog] Added scrollable area to inputs and history files, buttons to delete and view.
June Park <parkjune1995@gmail.com>
parents: 115
diff changeset
801 prev_input_tab = active_input_tab;
7bd795bac997 [Postdog] Added scrollable area to inputs and history files, buttons to delete and view.
June Park <parkjune1995@gmail.com>
parents: 115
diff changeset
802 }
7bd795bac997 [Postdog] Added scrollable area to inputs and history files, buttons to delete and view.
June Park <parkjune1995@gmail.com>
parents: 115
diff changeset
803
7bd795bac997 [Postdog] Added scrollable area to inputs and history files, buttons to delete and view.
June Park <parkjune1995@gmail.com>
parents: 115
diff changeset
804 // Handle scroll wheel for history
155
3bb45eb67906 [Postdog] Updated variables names and padding sizes. Needs more work.
June Park <parkjune1995@gmail.com>
parents: 153
diff changeset
805 if (InArea(mouse_position, history_list_area_rect) && mouse_wheel != 0) {
116
7bd795bac997 [Postdog] Added scrollable area to inputs and history files, buttons to delete and view.
June Park <parkjune1995@gmail.com>
parents: 115
diff changeset
806 history_scroll_offset += mouse_wheel * 30; // 30 pixels per wheel tick
7bd795bac997 [Postdog] Added scrollable area to inputs and history files, buttons to delete and view.
June Park <parkjune1995@gmail.com>
parents: 115
diff changeset
807 // Clamp scroll offset
155
3bb45eb67906 [Postdog] Updated variables names and padding sizes. Needs more work.
June Park <parkjune1995@gmail.com>
parents: 153
diff changeset
808 float max_scroll = (total * (item_height + padding)) - history_list_area_rect.height;
116
7bd795bac997 [Postdog] Added scrollable area to inputs and history files, buttons to delete and view.
June Park <parkjune1995@gmail.com>
parents: 115
diff changeset
809 if (history_scroll_offset > 0) history_scroll_offset = 0;
7bd795bac997 [Postdog] Added scrollable area to inputs and history files, buttons to delete and view.
June Park <parkjune1995@gmail.com>
parents: 115
diff changeset
810 if (history_scroll_offset < -max_scroll && max_scroll > 0) history_scroll_offset = -max_scroll;
7bd795bac997 [Postdog] Added scrollable area to inputs and history files, buttons to delete and view.
June Park <parkjune1995@gmail.com>
parents: 115
diff changeset
811 }
7bd795bac997 [Postdog] Added scrollable area to inputs and history files, buttons to delete and view.
June Park <parkjune1995@gmail.com>
parents: 115
diff changeset
812
7bd795bac997 [Postdog] Added scrollable area to inputs and history files, buttons to delete and view.
June Park <parkjune1995@gmail.com>
parents: 115
diff changeset
813 // Handle scroll wheel for input body
155
3bb45eb67906 [Postdog] Updated variables names and padding sizes. Needs more work.
June Park <parkjune1995@gmail.com>
parents: 153
diff changeset
814 if (InArea(mouse_position, input_body_rect) && mouse_wheel != 0) {
116
7bd795bac997 [Postdog] Added scrollable area to inputs and history files, buttons to delete and view.
June Park <parkjune1995@gmail.com>
parents: 115
diff changeset
815 input_body_scroll_offset += mouse_wheel * 30;
7bd795bac997 [Postdog] Added scrollable area to inputs and history files, buttons to delete and view.
June Park <parkjune1995@gmail.com>
parents: 115
diff changeset
816 if (input_body_scroll_offset > 0) input_body_scroll_offset = 0;
7bd795bac997 [Postdog] Added scrollable area to inputs and history files, buttons to delete and view.
June Park <parkjune1995@gmail.com>
parents: 115
diff changeset
817 }
7bd795bac997 [Postdog] Added scrollable area to inputs and history files, buttons to delete and view.
June Park <parkjune1995@gmail.com>
parents: 115
diff changeset
818
7bd795bac997 [Postdog] Added scrollable area to inputs and history files, buttons to delete and view.
June Park <parkjune1995@gmail.com>
parents: 115
diff changeset
819 // Handle scroll wheel for result body
155
3bb45eb67906 [Postdog] Updated variables names and padding sizes. Needs more work.
June Park <parkjune1995@gmail.com>
parents: 153
diff changeset
820 if (InArea(mouse_position, result_body_rect) && mouse_wheel != 0) {
116
7bd795bac997 [Postdog] Added scrollable area to inputs and history files, buttons to delete and view.
June Park <parkjune1995@gmail.com>
parents: 115
diff changeset
821 result_body_scroll_offset += mouse_wheel * 30;
7bd795bac997 [Postdog] Added scrollable area to inputs and history files, buttons to delete and view.
June Park <parkjune1995@gmail.com>
parents: 115
diff changeset
822 if (result_body_scroll_offset > 0) result_body_scroll_offset = 0;
7bd795bac997 [Postdog] Added scrollable area to inputs and history files, buttons to delete and view.
June Park <parkjune1995@gmail.com>
parents: 115
diff changeset
823 }
114
e2a73e64e8e6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 112
diff changeset
824
54
b3e82d22f961 [PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff changeset
825 BeginDrawing();
b3e82d22f961 [PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff changeset
826 ClearBackground(GetColor(GuiGetStyle(DEFAULT, BACKGROUND_COLOR)));
b3e82d22f961 [PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff changeset
827
155
3bb45eb67906 [Postdog] Updated variables names and padding sizes. Needs more work.
June Park <parkjune1995@gmail.com>
parents: 153
diff changeset
828 // DrawRectangleRec(history_sidebar_rect, Fade(GRAY, 0.1f));
3bb45eb67906 [Postdog] Updated variables names and padding sizes. Needs more work.
June Park <parkjune1995@gmail.com>
parents: 153
diff changeset
829 DrawRectangleRounded(history_sidebar_rect, 0.5, 1, Fade(BLUE, 0.1f));
116
7bd795bac997 [Postdog] Added scrollable area to inputs and history files, buttons to delete and view.
June Park <parkjune1995@gmail.com>
parents: 115
diff changeset
830
155
3bb45eb67906 [Postdog] Updated variables names and padding sizes. Needs more work.
June Park <parkjune1995@gmail.com>
parents: 153
diff changeset
831 // DrawRectangleRec(logo_area_rect, Fade(BLUE, 0.2f));
3bb45eb67906 [Postdog] Updated variables names and padding sizes. Needs more work.
June Park <parkjune1995@gmail.com>
parents: 153
diff changeset
832 Rectangle logo_image_rect = AddPadding(logo_area_rect, padding);
116
7bd795bac997 [Postdog] Added scrollable area to inputs and history files, buttons to delete and view.
June Park <parkjune1995@gmail.com>
parents: 115
diff changeset
833 // Fit logo to area while maintaining aspect ratio
7bd795bac997 [Postdog] Added scrollable area to inputs and history files, buttons to delete and view.
June Park <parkjune1995@gmail.com>
parents: 115
diff changeset
834 float logo_size = logo_image_rect.height < logo_image_rect.width ? logo_image_rect.height : logo_image_rect.width;
155
3bb45eb67906 [Postdog] Updated variables names and padding sizes. Needs more work.
June Park <parkjune1995@gmail.com>
parents: 153
diff changeset
835 Rectangle dest_rect = {
116
7bd795bac997 [Postdog] Added scrollable area to inputs and history files, buttons to delete and view.
June Park <parkjune1995@gmail.com>
parents: 115
diff changeset
836 .x = logo_image_rect.x + (logo_image_rect.width - logo_size) / 2, // Center horizontally
7bd795bac997 [Postdog] Added scrollable area to inputs and history files, buttons to delete and view.
June Park <parkjune1995@gmail.com>
parents: 115
diff changeset
837 .y = logo_image_rect.y,
7bd795bac997 [Postdog] Added scrollable area to inputs and history files, buttons to delete and view.
June Park <parkjune1995@gmail.com>
parents: 115
diff changeset
838 .width = logo_size,
7bd795bac997 [Postdog] Added scrollable area to inputs and history files, buttons to delete and view.
June Park <parkjune1995@gmail.com>
parents: 115
diff changeset
839 .height = logo_size
7bd795bac997 [Postdog] Added scrollable area to inputs and history files, buttons to delete and view.
June Park <parkjune1995@gmail.com>
parents: 115
diff changeset
840 };
7bd795bac997 [Postdog] Added scrollable area to inputs and history files, buttons to delete and view.
June Park <parkjune1995@gmail.com>
parents: 115
diff changeset
841
155
3bb45eb67906 [Postdog] Updated variables names and padding sizes. Needs more work.
June Park <parkjune1995@gmail.com>
parents: 153
diff changeset
842 Rectangle source_rect = { 0, 0, logo_texture.width, logo_texture.height };
3bb45eb67906 [Postdog] Updated variables names and padding sizes. Needs more work.
June Park <parkjune1995@gmail.com>
parents: 153
diff changeset
843 DrawTexturePro(logo_texture, source_rect, dest_rect, (Vector2){0, 0}, 0.0f, WHITE);
116
7bd795bac997 [Postdog] Added scrollable area to inputs and history files, buttons to delete and view.
June Park <parkjune1995@gmail.com>
parents: 115
diff changeset
844
155
3bb45eb67906 [Postdog] Updated variables names and padding sizes. Needs more work.
June Park <parkjune1995@gmail.com>
parents: 153
diff changeset
845 BeginScissorMode(history_list_area_rect.x, history_list_area_rect.y, history_list_area_rect.width, history_list_area_rect.height);
116
7bd795bac997 [Postdog] Added scrollable area to inputs and history files, buttons to delete and view.
June Park <parkjune1995@gmail.com>
parents: 115
diff changeset
846 for (int i = 0; i < total; i++)
7bd795bac997 [Postdog] Added scrollable area to inputs and history files, buttons to delete and view.
June Park <parkjune1995@gmail.com>
parents: 115
diff changeset
847 {
117
b91f2dd6f84d [PostDog] Fixed delete logic.
June Park <parkjune1995@gmail.com>
parents: 116
diff changeset
848 HistoryItem *curr_history_items = i < new_history_items_length ?
118
249881ceff7b [PostDog] Updated some core logic. Will create a bookmark for postdog until the launch as this is annoying to deal with.
June Park <parkjune1995@gmail.com>
parents: 117
diff changeset
849 &new_history_items[i - new_history_items_length - 1] : &history_items[i - new_history_items_length];
117
b91f2dd6f84d [PostDog] Fixed delete logic.
June Park <parkjune1995@gmail.com>
parents: 116
diff changeset
850
b91f2dd6f84d [PostDog] Fixed delete logic.
June Park <parkjune1995@gmail.com>
parents: 116
diff changeset
851 if (curr_history_items->deleted)
116
7bd795bac997 [Postdog] Added scrollable area to inputs and history files, buttons to delete and view.
June Park <parkjune1995@gmail.com>
parents: 115
diff changeset
852 continue;
7bd795bac997 [Postdog] Added scrollable area to inputs and history files, buttons to delete and view.
June Park <parkjune1995@gmail.com>
parents: 115
diff changeset
853
155
3bb45eb67906 [Postdog] Updated variables names and padding sizes. Needs more work.
June Park <parkjune1995@gmail.com>
parents: 153
diff changeset
854 float diff = curr_history_items->rect.height*0.6;
3bb45eb67906 [Postdog] Updated variables names and padding sizes. Needs more work.
June Park <parkjune1995@gmail.com>
parents: 153
diff changeset
855 DrawRectangleRounded(curr_history_items->rect, 0.5, 1, Fade(BLACK, 0.1f));
3bb45eb67906 [Postdog] Updated variables names and padding sizes. Needs more work.
June Park <parkjune1995@gmail.com>
parents: 153
diff changeset
856 Rectangle filename_area_rect = curr_history_items->rect;
116
7bd795bac997 [Postdog] Added scrollable area to inputs and history files, buttons to delete and view.
June Park <parkjune1995@gmail.com>
parents: 115
diff changeset
857
155
3bb45eb67906 [Postdog] Updated variables names and padding sizes. Needs more work.
June Park <parkjune1995@gmail.com>
parents: 153
diff changeset
858 filename_area_rect.height -= diff;
3bb45eb67906 [Postdog] Updated variables names and padding sizes. Needs more work.
June Park <parkjune1995@gmail.com>
parents: 153
diff changeset
859 Rectangle icon_area = Below(filename_area_rect, 0);
116
7bd795bac997 [Postdog] Added scrollable area to inputs and history files, buttons to delete and view.
June Park <parkjune1995@gmail.com>
parents: 115
diff changeset
860 icon_area.height = diff;
7bd795bac997 [Postdog] Added scrollable area to inputs and history files, buttons to delete and view.
June Park <parkjune1995@gmail.com>
parents: 115
diff changeset
861
155
3bb45eb67906 [Postdog] Updated variables names and padding sizes. Needs more work.
June Park <parkjune1995@gmail.com>
parents: 153
diff changeset
862 // DrawRectangleRec(filename_area_rect, Fade(BLUE, 0.1f));
3bb45eb67906 [Postdog] Updated variables names and padding sizes. Needs more work.
June Park <parkjune1995@gmail.com>
parents: 153
diff changeset
863 // DrawRectangleRec(icon_area, Fade(YELLOW, 0.1f));
3bb45eb67906 [Postdog] Updated variables names and padding sizes. Needs more work.
June Park <parkjune1995@gmail.com>
parents: 153
diff changeset
864 // DrawRectangleRec(AddPadding(filename_area_rect, 5), Fade(BLUE, 0.1f));
116
7bd795bac997 [Postdog] Added scrollable area to inputs and history files, buttons to delete and view.
June Park <parkjune1995@gmail.com>
parents: 115
diff changeset
865
7bd795bac997 [Postdog] Added scrollable area to inputs and history files, buttons to delete and view.
June Park <parkjune1995@gmail.com>
parents: 115
diff changeset
866 Rectangle icon_area_left_column = LeftColumn(icon_area, 0.5, 0);
7bd795bac997 [Postdog] Added scrollable area to inputs and history files, buttons to delete and view.
June Park <parkjune1995@gmail.com>
parents: 115
diff changeset
867 Rectangle icon_area_right_column = RightColumn(icon_area, icon_area_left_column, 0);
7bd795bac997 [Postdog] Added scrollable area to inputs and history files, buttons to delete and view.
June Park <parkjune1995@gmail.com>
parents: 115
diff changeset
868
155
3bb45eb67906 [Postdog] Updated variables names and padding sizes. Needs more work.
June Park <parkjune1995@gmail.com>
parents: 153
diff changeset
869 GuiDrawText(curr_history_items->title, AddPaddingHorizontal(curr_history_items->rect, padding), TEXT_ALIGN_MIDDLE, BLACK);
3bb45eb67906 [Postdog] Updated variables names and padding sizes. Needs more work.
June Park <parkjune1995@gmail.com>
parents: 153
diff changeset
870 if (GuiButton(AddPadding(icon_area_left_column, padding), "view"))
118
249881ceff7b [PostDog] Updated some core logic. Will create a bookmark for postdog until the launch as this is annoying to deal with.
June Park <parkjune1995@gmail.com>
parents: 117
diff changeset
871 PostDog_Load_File(curr_history_items->filename);
155
3bb45eb67906 [Postdog] Updated variables names and padding sizes. Needs more work.
June Park <parkjune1995@gmail.com>
parents: 153
diff changeset
872 if (GuiButton(AddPadding(icon_area_right_column, padding), "delete"))
116
7bd795bac997 [Postdog] Added scrollable area to inputs and history files, buttons to delete and view.
June Park <parkjune1995@gmail.com>
parents: 115
diff changeset
873 {
7bd795bac997 [Postdog] Added scrollable area to inputs and history files, buttons to delete and view.
June Park <parkjune1995@gmail.com>
parents: 115
diff changeset
874 if (!remove(PostDog_Construct_URL(curr_history_items->filename)))
117
b91f2dd6f84d [PostDog] Fixed delete logic.
June Park <parkjune1995@gmail.com>
parents: 116
diff changeset
875 curr_history_items->deleted = TRUE;
116
7bd795bac997 [Postdog] Added scrollable area to inputs and history files, buttons to delete and view.
June Park <parkjune1995@gmail.com>
parents: 115
diff changeset
876 else
7bd795bac997 [Postdog] Added scrollable area to inputs and history files, buttons to delete and view.
June Park <parkjune1995@gmail.com>
parents: 115
diff changeset
877 fprintf(stderr, "Wasn't able to delete file: %s \n", curr_history_items->filename);
7bd795bac997 [Postdog] Added scrollable area to inputs and history files, buttons to delete and view.
June Park <parkjune1995@gmail.com>
parents: 115
diff changeset
878 }
7bd795bac997 [Postdog] Added scrollable area to inputs and history files, buttons to delete and view.
June Park <parkjune1995@gmail.com>
parents: 115
diff changeset
879 }
7bd795bac997 [Postdog] Added scrollable area to inputs and history files, buttons to delete and view.
June Park <parkjune1995@gmail.com>
parents: 115
diff changeset
880 EndScissorMode();
7bd795bac997 [Postdog] Added scrollable area to inputs and history files, buttons to delete and view.
June Park <parkjune1995@gmail.com>
parents: 115
diff changeset
881
7bd795bac997 [Postdog] Added scrollable area to inputs and history files, buttons to delete and view.
June Park <parkjune1995@gmail.com>
parents: 115
diff changeset
882 if (total > 0)
114
e2a73e64e8e6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 112
diff changeset
883 {
116
7bd795bac997 [Postdog] Added scrollable area to inputs and history files, buttons to delete and view.
June Park <parkjune1995@gmail.com>
parents: 115
diff changeset
884 float content_height = total * (item_height + padding);
155
3bb45eb67906 [Postdog] Updated variables names and padding sizes. Needs more work.
June Park <parkjune1995@gmail.com>
parents: 153
diff changeset
885 if (content_height > history_list_area_rect.height)
116
7bd795bac997 [Postdog] Added scrollable area to inputs and history files, buttons to delete and view.
June Park <parkjune1995@gmail.com>
parents: 115
diff changeset
886 {
155
3bb45eb67906 [Postdog] Updated variables names and padding sizes. Needs more work.
June Park <parkjune1995@gmail.com>
parents: 153
diff changeset
887 float scrollbar_height = (history_list_area_rect.height / content_height) * history_list_area_rect.height;
3bb45eb67906 [Postdog] Updated variables names and padding sizes. Needs more work.
June Park <parkjune1995@gmail.com>
parents: 153
diff changeset
888 float scrollbar_y = history_list_area_rect.y - (history_scroll_offset / content_height) * history_list_area_rect.height;
3bb45eb67906 [Postdog] Updated variables names and padding sizes. Needs more work.
June Park <parkjune1995@gmail.com>
parents: 153
diff changeset
889 Rectangle scrollbar_rect = {
3bb45eb67906 [Postdog] Updated variables names and padding sizes. Needs more work.
June Park <parkjune1995@gmail.com>
parents: 153
diff changeset
890 history_list_area_rect.x + history_list_area_rect.width - 5,
116
7bd795bac997 [Postdog] Added scrollable area to inputs and history files, buttons to delete and view.
June Park <parkjune1995@gmail.com>
parents: 115
diff changeset
891 scrollbar_y,
7bd795bac997 [Postdog] Added scrollable area to inputs and history files, buttons to delete and view.
June Park <parkjune1995@gmail.com>
parents: 115
diff changeset
892 5,
7bd795bac997 [Postdog] Added scrollable area to inputs and history files, buttons to delete and view.
June Park <parkjune1995@gmail.com>
parents: 115
diff changeset
893 scrollbar_height
7bd795bac997 [Postdog] Added scrollable area to inputs and history files, buttons to delete and view.
June Park <parkjune1995@gmail.com>
parents: 115
diff changeset
894 };
155
3bb45eb67906 [Postdog] Updated variables names and padding sizes. Needs more work.
June Park <parkjune1995@gmail.com>
parents: 153
diff changeset
895 DrawRectangleRec(scrollbar_rect, Fade(WHITE, 0.5f));
116
7bd795bac997 [Postdog] Added scrollable area to inputs and history files, buttons to delete and view.
June Park <parkjune1995@gmail.com>
parents: 115
diff changeset
896 }
114
e2a73e64e8e6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 112
diff changeset
897 }
54
b3e82d22f961 [PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff changeset
898
111
48f260576059 [PostDog] Rewriting it from scratch as it is unreadable for me.
June Park <parkjune1995@gmail.com>
parents: 63
diff changeset
899 // URL area Rect
155
3bb45eb67906 [Postdog] Updated variables names and padding sizes. Needs more work.
June Park <parkjune1995@gmail.com>
parents: 153
diff changeset
900 GuiDrawText("URL: ", url_text_bounds_rect, TEXT_ALIGN_CENTER, BLACK);
3bb45eb67906 [Postdog] Updated variables names and padding sizes. Needs more work.
June Park <parkjune1995@gmail.com>
parents: 153
diff changeset
901 DrawRectangleRec(url_area_rect, Fade(BLACK, 0.1f));
3bb45eb67906 [Postdog] Updated variables names and padding sizes. Needs more work.
June Park <parkjune1995@gmail.com>
parents: 153
diff changeset
902 if (GuiTextBox(url_input_bounds_rect, url_input_text, DEFAULT_TEXT_BUFFER_LENGTH, url_input_edit))
114
e2a73e64e8e6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 112
diff changeset
903 url_input_edit = !url_input_edit;
e2a73e64e8e6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 112
diff changeset
904
155
3bb45eb67906 [Postdog] Updated variables names and padding sizes. Needs more work.
June Park <parkjune1995@gmail.com>
parents: 153
diff changeset
905 sendRequest = GuiButton(url_enter_button_rect, "ENTER");
112
d6d578b49a19 [PostDog] Got CRUD working.
June Park <parkjune1995@gmail.com>
parents: 111
diff changeset
906 if (sendRequest)
118
249881ceff7b [PostDog] Updated some core logic. Will create a bookmark for postdog until the launch as this is annoying to deal with.
June Park <parkjune1995@gmail.com>
parents: 117
diff changeset
907 PostDog_Http_Request();
155
3bb45eb67906 [Postdog] Updated variables names and padding sizes. Needs more work.
June Park <parkjune1995@gmail.com>
parents: 153
diff changeset
908 if (GuiDropdownBox(method_dropdown_rect, "GET;POST;PUT;DELETE", &active_method_dropdown, method_edit))
112
d6d578b49a19 [PostDog] Got CRUD working.
June Park <parkjune1995@gmail.com>
parents: 111
diff changeset
909 method_edit = !method_edit;
54
b3e82d22f961 [PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff changeset
910
111
48f260576059 [PostDog] Rewriting it from scratch as it is unreadable for me.
June Park <parkjune1995@gmail.com>
parents: 63
diff changeset
911 // Input Tabs Rect
155
3bb45eb67906 [Postdog] Updated variables names and padding sizes. Needs more work.
June Park <parkjune1995@gmail.com>
parents: 153
diff changeset
912 DrawRectangleRec(input_area_rect, Fade(BLUE, 0.1f));
3bb45eb67906 [Postdog] Updated variables names and padding sizes. Needs more work.
June Park <parkjune1995@gmail.com>
parents: 153
diff changeset
913 DrawRectangleRec(input_tab_rect, Fade(DARKBLUE, 0.1f));
112
d6d578b49a19 [PostDog] Got CRUD working.
June Park <parkjune1995@gmail.com>
parents: 111
diff changeset
914 GuiSetStyle(TOGGLE, GROUP_PADDING, 0);
155
3bb45eb67906 [Postdog] Updated variables names and padding sizes. Needs more work.
June Park <parkjune1995@gmail.com>
parents: 153
diff changeset
915 GuiDrawRectangle(input_body_rect, 1, GetColor(GuiGetStyle(TEXTBOX, BORDER)), GetColor(GuiGetStyle(TEXTBOX, BASE_COLOR_PRESSED)));
116
7bd795bac997 [Postdog] Added scrollable area to inputs and history files, buttons to delete and view.
June Park <parkjune1995@gmail.com>
parents: 115
diff changeset
916
155
3bb45eb67906 [Postdog] Updated variables names and padding sizes. Needs more work.
June Park <parkjune1995@gmail.com>
parents: 153
diff changeset
917 BeginScissorMode(input_body_rect.x, input_body_rect.y, input_body_rect.width, input_body_rect.height);
3bb45eb67906 [Postdog] Updated variables names and padding sizes. Needs more work.
June Park <parkjune1995@gmail.com>
parents: 153
diff changeset
918 Rectangle scrolled_input_rect = AddPadding(input_body_rect, padding * 2);
3bb45eb67906 [Postdog] Updated variables names and padding sizes. Needs more work.
June Park <parkjune1995@gmail.com>
parents: 153
diff changeset
919 scrolled_input_rect.y += input_body_scroll_offset;
3bb45eb67906 [Postdog] Updated variables names and padding sizes. Needs more work.
June Park <parkjune1995@gmail.com>
parents: 153
diff changeset
920 scrolled_input_rect.height = MAX_SCROLL_HEIGHT;
152
7387eec8e7f8 [Postdog] Updated to use Seobeo_Client instead of CURL. Updated to handle websocket connection.
June Park <parkjune1995@gmail.com>
parents: 118
diff changeset
921 if (active_input_tab != TAB_WEBSOCKET)
7387eec8e7f8 [Postdog] Updated to use Seobeo_Client instead of CURL. Updated to handle websocket connection.
June Park <parkjune1995@gmail.com>
parents: 118
diff changeset
922 {
153
790930d9bb90 [PostDog] Adding websocket to be more usable.
June Park <parkjune1995@gmail.com>
parents: 152
diff changeset
923 WS_BREAK = TRUE;
155
3bb45eb67906 [Postdog] Updated variables names and padding sizes. Needs more work.
June Park <parkjune1995@gmail.com>
parents: 153
diff changeset
924 if (JUNE_GuiTextBox(scrolled_input_rect, input_body_array[active_input_tab], DEFAULT_TEXT_BUFFER_LENGTH, input_body_bool))
152
7387eec8e7f8 [Postdog] Updated to use Seobeo_Client instead of CURL. Updated to handle websocket connection.
June Park <parkjune1995@gmail.com>
parents: 118
diff changeset
925 input_body_bool = !input_body_bool;
7387eec8e7f8 [Postdog] Updated to use Seobeo_Client instead of CURL. Updated to handle websocket connection.
June Park <parkjune1995@gmail.com>
parents: 118
diff changeset
926 }
7387eec8e7f8 [Postdog] Updated to use Seobeo_Client instead of CURL. Updated to handle websocket connection.
June Park <parkjune1995@gmail.com>
parents: 118
diff changeset
927 else
7387eec8e7f8 [Postdog] Updated to use Seobeo_Client instead of CURL. Updated to handle websocket connection.
June Park <parkjune1995@gmail.com>
parents: 118
diff changeset
928 {
7387eec8e7f8 [Postdog] Updated to use Seobeo_Client instead of CURL. Updated to handle websocket connection.
June Park <parkjune1995@gmail.com>
parents: 118
diff changeset
929 boolean temp = true;
153
790930d9bb90 [PostDog] Adding websocket to be more usable.
June Park <parkjune1995@gmail.com>
parents: 152
diff changeset
930 WS_BREAK = FALSE;
790930d9bb90 [PostDog] Adding websocket to be more usable.
June Park <parkjune1995@gmail.com>
parents: 152
diff changeset
931 if (GuiTextInputBox(
155
3bb45eb67906 [Postdog] Updated variables names and padding sizes. Needs more work.
June Park <parkjune1995@gmail.com>
parents: 153
diff changeset
932 input_body_rect,
153
790930d9bb90 [PostDog] Adding websocket to be more usable.
June Park <parkjune1995@gmail.com>
parents: 152
diff changeset
933 "send message", ws != NULL ? "connected" : "start messaging",
155
3bb45eb67906 [Postdog] Updated variables names and padding sizes. Needs more work.
June Park <parkjune1995@gmail.com>
parents: 153
diff changeset
934 "send", input_body_array[active_input_tab], BODY_BUFFER_LENGTH, &temp) == 1)
153
790930d9bb90 [PostDog] Adding websocket to be more usable.
June Park <parkjune1995@gmail.com>
parents: 152
diff changeset
935 PostDog_Websocket_Thread_Send();
152
7387eec8e7f8 [Postdog] Updated to use Seobeo_Client instead of CURL. Updated to handle websocket connection.
June Park <parkjune1995@gmail.com>
parents: 118
diff changeset
936 }
116
7bd795bac997 [Postdog] Added scrollable area to inputs and history files, buttons to delete and view.
June Park <parkjune1995@gmail.com>
parents: 115
diff changeset
937 EndScissorMode();
7bd795bac997 [Postdog] Added scrollable area to inputs and history files, buttons to delete and view.
June Park <parkjune1995@gmail.com>
parents: 115
diff changeset
938
7bd795bac997 [Postdog] Added scrollable area to inputs and history files, buttons to delete and view.
June Park <parkjune1995@gmail.com>
parents: 115
diff changeset
939 if (input_body_scroll_offset < 0) {
118
249881ceff7b [PostDog] Updated some core logic. Will create a bookmark for postdog until the launch as this is annoying to deal with.
June Park <parkjune1995@gmail.com>
parents: 117
diff changeset
940 float scrollbar_height = 10;
155
3bb45eb67906 [Postdog] Updated variables names and padding sizes. Needs more work.
June Park <parkjune1995@gmail.com>
parents: 153
diff changeset
941 float scrollbar_y = input_body_rect.y - (input_body_scroll_offset / MAX_SCROLL_HEIGHT) * (input_body_rect.height - scrollbar_height);
3bb45eb67906 [Postdog] Updated variables names and padding sizes. Needs more work.
June Park <parkjune1995@gmail.com>
parents: 153
diff changeset
942 Rectangle scrollbar_rect = {
3bb45eb67906 [Postdog] Updated variables names and padding sizes. Needs more work.
June Park <parkjune1995@gmail.com>
parents: 153
diff changeset
943 input_body_rect.x + input_body_rect.width - 5,
116
7bd795bac997 [Postdog] Added scrollable area to inputs and history files, buttons to delete and view.
June Park <parkjune1995@gmail.com>
parents: 115
diff changeset
944 scrollbar_y,
7bd795bac997 [Postdog] Added scrollable area to inputs and history files, buttons to delete and view.
June Park <parkjune1995@gmail.com>
parents: 115
diff changeset
945 5,
7bd795bac997 [Postdog] Added scrollable area to inputs and history files, buttons to delete and view.
June Park <parkjune1995@gmail.com>
parents: 115
diff changeset
946 scrollbar_height
7bd795bac997 [Postdog] Added scrollable area to inputs and history files, buttons to delete and view.
June Park <parkjune1995@gmail.com>
parents: 115
diff changeset
947 };
155
3bb45eb67906 [Postdog] Updated variables names and padding sizes. Needs more work.
June Park <parkjune1995@gmail.com>
parents: 153
diff changeset
948 DrawRectangleRec(scrollbar_rect, Fade(BLUE, 0.5f));
116
7bd795bac997 [Postdog] Added scrollable area to inputs and history files, buttons to delete and view.
June Park <parkjune1995@gmail.com>
parents: 115
diff changeset
949 }
7bd795bac997 [Postdog] Added scrollable area to inputs and history files, buttons to delete and view.
June Park <parkjune1995@gmail.com>
parents: 115
diff changeset
950
155
3bb45eb67906 [Postdog] Updated variables names and padding sizes. Needs more work.
June Park <parkjune1995@gmail.com>
parents: 153
diff changeset
951 GuiToggleGroup(input_tab_item_rect, "Header;Body;Get Param;Websocket", &active_input_tab);
114
e2a73e64e8e6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 112
diff changeset
952
118
249881ceff7b [PostDog] Updated some core logic. Will create a bookmark for postdog until the launch as this is annoying to deal with.
June Park <parkjune1995@gmail.com>
parents: 117
diff changeset
953 PostDog_Update_URL();
54
b3e82d22f961 [PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff changeset
954
111
48f260576059 [PostDog] Rewriting it from scratch as it is unreadable for me.
June Park <parkjune1995@gmail.com>
parents: 63
diff changeset
955 // Result Rect
155
3bb45eb67906 [Postdog] Updated variables names and padding sizes. Needs more work.
June Park <parkjune1995@gmail.com>
parents: 153
diff changeset
956 DrawRectangleRec(result_area_rect, Fade(GREEN, 0.1f));
3bb45eb67906 [Postdog] Updated variables names and padding sizes. Needs more work.
June Park <parkjune1995@gmail.com>
parents: 153
diff changeset
957 DrawRectangleRec(result_body_rect, Fade(DARKGREEN, 0.1f));
116
7bd795bac997 [Postdog] Added scrollable area to inputs and history files, buttons to delete and view.
June Park <parkjune1995@gmail.com>
parents: 115
diff changeset
958
7bd795bac997 [Postdog] Added scrollable area to inputs and history files, buttons to delete and view.
June Park <parkjune1995@gmail.com>
parents: 115
diff changeset
959 // Create scrollable result body with offset
155
3bb45eb67906 [Postdog] Updated variables names and padding sizes. Needs more work.
June Park <parkjune1995@gmail.com>
parents: 153
diff changeset
960 BeginScissorMode(result_body_rect.x, result_body_rect.y, result_body_rect.width, result_body_rect.height);
3bb45eb67906 [Postdog] Updated variables names and padding sizes. Needs more work.
June Park <parkjune1995@gmail.com>
parents: 153
diff changeset
961 Rectangle scrolled_result = result_body_rect;
116
7bd795bac997 [Postdog] Added scrollable area to inputs and history files, buttons to delete and view.
June Park <parkjune1995@gmail.com>
parents: 115
diff changeset
962 scrolled_result.y += result_body_scroll_offset;
7bd795bac997 [Postdog] Added scrollable area to inputs and history files, buttons to delete and view.
June Park <parkjune1995@gmail.com>
parents: 115
diff changeset
963 scrolled_result.height = MAX_SCROLL_HEIGHT;
155
3bb45eb67906 [Postdog] Updated variables names and padding sizes. Needs more work.
June Park <parkjune1995@gmail.com>
parents: 153
diff changeset
964 GuiTextBoxMulti(scrolled_result, result_text, RESULT_BUFFER_LENGTH, false);
116
7bd795bac997 [Postdog] Added scrollable area to inputs and history files, buttons to delete and view.
June Park <parkjune1995@gmail.com>
parents: 115
diff changeset
965 EndScissorMode();
7bd795bac997 [Postdog] Added scrollable area to inputs and history files, buttons to delete and view.
June Park <parkjune1995@gmail.com>
parents: 115
diff changeset
966
152
7387eec8e7f8 [Postdog] Updated to use Seobeo_Client instead of CURL. Updated to handle websocket connection.
June Park <parkjune1995@gmail.com>
parents: 118
diff changeset
967 if (result_body_scroll_offset < 0)
7387eec8e7f8 [Postdog] Updated to use Seobeo_Client instead of CURL. Updated to handle websocket connection.
June Park <parkjune1995@gmail.com>
parents: 118
diff changeset
968 {
118
249881ceff7b [PostDog] Updated some core logic. Will create a bookmark for postdog until the launch as this is annoying to deal with.
June Park <parkjune1995@gmail.com>
parents: 117
diff changeset
969 float scrollbar_height = 10;
155
3bb45eb67906 [Postdog] Updated variables names and padding sizes. Needs more work.
June Park <parkjune1995@gmail.com>
parents: 153
diff changeset
970 float scrollbar_y = result_body_rect.y - (result_body_scroll_offset / MAX_SCROLL_HEIGHT) * (result_body_rect.height - scrollbar_height);
3bb45eb67906 [Postdog] Updated variables names and padding sizes. Needs more work.
June Park <parkjune1995@gmail.com>
parents: 153
diff changeset
971 Rectangle scrollbar_rect = {
3bb45eb67906 [Postdog] Updated variables names and padding sizes. Needs more work.
June Park <parkjune1995@gmail.com>
parents: 153
diff changeset
972 result_body_rect.x + result_body_rect.width - 5,
116
7bd795bac997 [Postdog] Added scrollable area to inputs and history files, buttons to delete and view.
June Park <parkjune1995@gmail.com>
parents: 115
diff changeset
973 scrollbar_y,
7bd795bac997 [Postdog] Added scrollable area to inputs and history files, buttons to delete and view.
June Park <parkjune1995@gmail.com>
parents: 115
diff changeset
974 5,
7bd795bac997 [Postdog] Added scrollable area to inputs and history files, buttons to delete and view.
June Park <parkjune1995@gmail.com>
parents: 115
diff changeset
975 scrollbar_height
7bd795bac997 [Postdog] Added scrollable area to inputs and history files, buttons to delete and view.
June Park <parkjune1995@gmail.com>
parents: 115
diff changeset
976 };
155
3bb45eb67906 [Postdog] Updated variables names and padding sizes. Needs more work.
June Park <parkjune1995@gmail.com>
parents: 153
diff changeset
977 DrawRectangleRec(scrollbar_rect, Fade(GREEN, 0.5f));
116
7bd795bac997 [Postdog] Added scrollable area to inputs and history files, buttons to delete and view.
June Park <parkjune1995@gmail.com>
parents: 115
diff changeset
978 }
114
e2a73e64e8e6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 112
diff changeset
979
e2a73e64e8e6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 112
diff changeset
980 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
981 {
e2a73e64e8e6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 112
diff changeset
982 SetClipboardText(url_input_text);
e2a73e64e8e6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 112
diff changeset
983 }
e2a73e64e8e6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 112
diff changeset
984 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
985 {
155
3bb45eb67906 [Postdog] Updated variables names and padding sizes. Needs more work.
June Park <parkjune1995@gmail.com>
parents: 153
diff changeset
986 SetClipboardText(input_body_array[active_input_tab]);
114
e2a73e64e8e6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 112
diff changeset
987 }
155
3bb45eb67906 [Postdog] Updated variables names and padding sizes. Needs more work.
June Park <parkjune1995@gmail.com>
parents: 153
diff changeset
988 else if (InArea(mouse_position, result_body_rect))
114
e2a73e64e8e6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 112
diff changeset
989 {
155
3bb45eb67906 [Postdog] Updated variables names and padding sizes. Needs more work.
June Park <parkjune1995@gmail.com>
parents: 153
diff changeset
990 DrawRectangleRec(result_body_rect, Fade(GREEN, 0.3f));
114
e2a73e64e8e6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 112
diff changeset
991 if ((IsKeyDown(KEY_LEFT_SUPER) || IsKeyDown(KEY_LEFT_CONTROL)) && IsKeyPressed(KEY_C))
155
3bb45eb67906 [Postdog] Updated variables names and padding sizes. Needs more work.
June Park <parkjune1995@gmail.com>
parents: 153
diff changeset
992 SetClipboardText(result_text);
114
e2a73e64e8e6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 112
diff changeset
993 }
54
b3e82d22f961 [PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff changeset
994 EndDrawing();
b3e82d22f961 [PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff changeset
995 }
b3e82d22f961 [PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff changeset
996 CloseWindow();
b3e82d22f961 [PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff changeset
997 return 0;
b3e82d22f961 [PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff changeset
998 }