annotate postdog/main.c @ 160:948de3f54cea

[ThirdParty] Added libuv
author June Park <parkjune1995@gmail.com>
date Wed, 14 Jan 2026 19:39:52 -0800
parents 05cf9467a1c3
children 87d8d3eb3491
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
159
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
42 // ============================================================================
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
43 // TextArea Component
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
44 // ============================================================================
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
45
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
46 #define TEXT_SIZE_DEFAULT 10 // used to calcualte spacing
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
47 #define TEXT_AREA_FONT_SIZE 16
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
48 #define TEXT_AREA_LINE_HEIGHT 20
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
49 #define TEXT_AREA_PADDING 8
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
50 #define TEXT_AREA_CURSOR_WIDTH 2
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
51 #define TEXT_AREA_MAX_UNDO_STATES 64
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
52 #define TEXT_AREA_MAX_INSTANCES 8
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
53
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
54 typedef struct {
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
55 char *text;
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
56 int cursor_pos;
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
57 int selection_start;
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
58 int selection_end;
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
59 } TextAreaUndoEntry;
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
60
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
61 typedef struct {
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
62 int id; // Unique ID for this text area
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
63 int cursor_pos; // Current cursor position in text
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
64 int selection_start; // Selection start (-1 if no selection)
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
65 int selection_end; // Selection end (-1 if no selection)
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
66 float scroll_offset_y; // Vertical scroll offset
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
67 float scroll_offset_x; // Horizontal scroll offset (for non-wrap mode)
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
68 boolean is_selecting; // Currently dragging to select
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
69 boolean is_initialized; // State has been initialized
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
70
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
71 // Undo history
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
72 TextAreaUndoEntry *undo_stack; // Dowa array of undo entries
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
73 int undo_index; // Current position in undo stack
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
74
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
75 // Internal tracking
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
76 double last_blink_time;
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
77 boolean cursor_visible;
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
78 } TextAreaState;
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
79
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
80 static TextAreaState g_text_area_states[TEXT_AREA_MAX_INSTANCES] = {0};
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
81 static int g_text_area_state_count = 0;
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
82 static char *g_clipboard_text = NULL;
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
83 static Dowa_Arena *g_text_area_arena = NULL;
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
84
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
85 // Helper functions
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
86 static int TA_Min_Int(int a, int b) { return a < b ? a : b; }
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
87 static int TA_Max_Int(int a, int b) { return a > b ? a : b; }
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
88 static float TA_Min_Float(float a, float b) { return a < b ? a : b; }
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
89 static float TA_Max_Float(float a, float b) { return a > b ? a : b; }
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
90
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
91 static TextAreaState* GetTextAreaState(int id) {
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
92 for (int i = 0; i < g_text_area_state_count; i++) {
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
93 if (g_text_area_states[i].id == id && g_text_area_states[i].is_initialized) {
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
94 return &g_text_area_states[i];
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
95 }
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
96 }
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
97 return NULL;
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
98 }
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
99
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
100 static TextAreaState* CreateTextAreaState(int id) {
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
101 if (g_text_area_state_count >= TEXT_AREA_MAX_INSTANCES) {
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
102 return &g_text_area_states[0]; // Reuse first slot
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
103 }
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
104
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
105 TextAreaState *state = &g_text_area_states[g_text_area_state_count++];
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
106 memset(state, 0, sizeof(TextAreaState));
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
107 state->id = id;
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
108 state->selection_start = -1;
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
109 state->selection_end = -1;
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
110 state->undo_index = -1;
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
111 state->cursor_visible = TRUE;
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
112 state->is_initialized = TRUE;
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
113 return state;
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
114 }
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
115
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
116 static void GetLineAndColumn(const char *text, int pos, int *out_line, int *out_column) {
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
117 int line = 0;
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
118 int column = 0;
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
119 for (int i = 0; i < pos && text[i] != '\0'; i++) {
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
120 if (text[i] == '\n') {
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
121 line++;
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
122 column = 0;
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
123 } else {
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
124 column++;
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
125 }
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
126 }
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
127 *out_line = line;
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
128 *out_column = column;
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
129 }
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
130
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
131 static int GetPosFromLineColumn(const char *text, int line, int column) {
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
132 int current_line = 0;
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
133 int current_col = 0;
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
134 int i = 0;
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
135
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
136 while (text[i] != '\0') {
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
137 if (current_line == line && current_col == column) {
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
138 return i;
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
139 }
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
140 if (text[i] == '\n') {
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
141 if (current_line == line) {
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
142 return i;
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
143 }
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
144 current_line++;
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
145 current_col = 0;
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
146 } else {
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
147 current_col++;
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
148 }
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
149 i++;
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
150 }
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
151 return i;
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
152 }
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
153
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
154 static int GetLineStart(const char *text, int pos) {
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
155 int i = pos;
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
156 while (i > 0 && text[i - 1] != '\n') {
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
157 i--;
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
158 }
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
159 return i;
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
160 }
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
161
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
162 static int GetLineEnd(const char *text, int pos) {
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
163 int i = pos;
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
164 int len = strlen(text);
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
165 while (i < len && text[i] != '\n') {
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
166 i++;
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
167 }
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
168 return i;
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
169 }
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
170
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
171 static int CountLines(const char *text) {
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
172 int count = 1;
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
173 for (int i = 0; text[i] != '\0'; i++) {
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
174 if (text[i] == '\n') count++;
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
175 }
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
176 return count;
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
177 }
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
178
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
179 static int MeasureTextRange(const char *text, int start, int end, int font_size) {
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
180 if (start >= end) return 0;
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
181
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
182 char temp[1024];
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
183 int len = TA_Min_Int(end - start, 1023);
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
184 strncpy(temp, text + start, len);
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
185 temp[len] = '\0';
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
186
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
187 return MeasureTextEx(GuiGetFont(), temp, font_size, TEXT_SIZE_DEFAULT/TEXT_AREA_FONT_SIZE).x;
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
188 }
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
189
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
190 static int GetCharIndexFromPos(const char *text, Rectangle bounds, Vector2 pos,
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
191 boolean wrap, float scroll_y, int font_size, int line_height) {
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
192 if (!text || strlen(text) == 0) return 0;
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
193
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
194 float content_x = bounds.x + TEXT_AREA_PADDING;
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
195 float content_y = bounds.y + TEXT_AREA_PADDING - scroll_y;
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
196 float content_width = bounds.width - TEXT_AREA_PADDING * 2;
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
197
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
198 int text_len = strlen(text);
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
199
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
200 float click_line_y = (pos.y - content_y) / line_height;
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
201 int target_visual_line = (int)click_line_y;
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
202 if (target_visual_line < 0) target_visual_line = 0;
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
203
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
204 int current_visual_line = 0;
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
205 int i = 0;
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
206 int line_char_start = 0;
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
207
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
208 while (i <= text_len) {
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
209 boolean is_newline = (i < text_len && text[i] == '\n');
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
210
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
211 if (wrap && i > line_char_start) {
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
212 int line_width = MeasureTextRange(text, line_char_start, i, font_size);
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
213 if (line_width > content_width && i > line_char_start + 1) {
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
214 int wrap_pos = i - 1;
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
215 for (int j = i - 1; j > line_char_start; j--) {
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
216 if (text[j] == ' ') {
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
217 wrap_pos = j;
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
218 break;
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
219 }
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
220 }
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
221
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
222 if (current_visual_line == target_visual_line) {
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
223 float click_x = pos.x - content_x;
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
224 int best_pos = line_char_start;
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
225 float best_dist = 99999;
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
226
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
227 for (int k = line_char_start; k <= wrap_pos; k++) {
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
228 int char_x = MeasureTextRange(text, line_char_start, k, font_size);
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
229 float dist = (float)(click_x - char_x);
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
230 if (dist < 0) dist = -dist;
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
231 if (dist < best_dist) {
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
232 best_dist = dist;
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
233 best_pos = k;
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
234 }
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
235 }
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
236 return best_pos;
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
237 }
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
238
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
239 current_visual_line++;
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
240 line_char_start = (text[wrap_pos] == ' ') ? wrap_pos + 1 : wrap_pos;
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
241 i = line_char_start;
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
242 continue;
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
243 }
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
244 }
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
245
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
246 if (is_newline || i == text_len) {
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
247 if (current_visual_line == target_visual_line || i == text_len) {
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
248 float click_x = pos.x - content_x;
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
249 int line_end = i;
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
250 int best_pos = line_char_start;
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
251 float best_dist = 99999;
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
252
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
253 for (int k = line_char_start; k <= line_end; k++) {
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
254 int char_x = MeasureTextRange(text, line_char_start, k, font_size);
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
255 float dist = (float)(click_x - char_x);
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
256 if (dist < 0) dist = -dist;
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
257 if (dist < best_dist) {
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
258 best_dist = dist;
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
259 best_pos = k;
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
260 }
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
261 }
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
262 return TA_Min_Int(best_pos, text_len);
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
263 }
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
264
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
265 current_visual_line++;
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
266 line_char_start = i + 1;
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
267 }
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
268
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
269 i++;
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
270 }
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
271
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
272 return text_len;
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
273 }
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
274
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
275 static Vector2 GetCursorScreenPos(const char *text, int cursor_pos, Rectangle bounds,
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
276 boolean wrap, float scroll_y, int font_size, int line_height) {
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
277 float content_x = bounds.x + TEXT_AREA_PADDING;
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
278 float content_y = bounds.y + TEXT_AREA_PADDING - scroll_y;
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
279 float content_width = bounds.width - TEXT_AREA_PADDING * 2;
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
280
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
281 if (!text || cursor_pos == 0) {
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
282 return (Vector2){content_x, content_y};
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
283 }
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
284
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
285 int text_len = strlen(text);
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
286 cursor_pos = TA_Min_Int(cursor_pos, text_len);
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
287
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
288 int visual_line = 0;
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
289 int line_char_start = 0;
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
290
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
291 for (int i = 0; i <= cursor_pos; i++) {
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
292 if (i == cursor_pos) {
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
293 float x = content_x + MeasureTextRange(text, line_char_start, cursor_pos, font_size);
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
294 float y = content_y + visual_line * line_height;
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
295 return (Vector2){x, y};
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
296 }
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
297
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
298 if (text[i] == '\n') {
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
299 visual_line++;
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
300 line_char_start = i + 1;
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
301 } else if (wrap) {
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
302 int line_width = MeasureTextRange(text, line_char_start, i + 1, font_size);
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
303 if (line_width > content_width && i > line_char_start) {
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
304 int wrap_pos = i;
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
305 for (int j = i; j > line_char_start; j--) {
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
306 if (text[j] == ' ') {
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
307 wrap_pos = j;
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
308 break;
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
309 }
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
310 }
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
311
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
312 if (cursor_pos <= wrap_pos) {
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
313 float x = content_x + MeasureTextRange(text, line_char_start, cursor_pos, font_size);
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
314 float y = content_y + visual_line * line_height;
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
315 return (Vector2){x, y};
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
316 }
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
317
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
318 visual_line++;
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
319 line_char_start = (text[wrap_pos] == ' ') ? wrap_pos + 1 : wrap_pos;
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
320 }
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
321 }
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
322 }
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
323
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
324 float x = content_x + MeasureTextRange(text, line_char_start, cursor_pos, font_size);
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
325 float y = content_y + visual_line * line_height;
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
326 return (Vector2){x, y};
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
327 }
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
328
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
329 static float GetContentHeight(const char *text, Rectangle bounds, boolean wrap,
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
330 int font_size, int line_height) {
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
331 if (!text || strlen(text) == 0) return line_height;
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
332
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
333 float content_width = bounds.width - TEXT_AREA_PADDING * 2;
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
334 int visual_lines = 1;
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
335 int line_char_start = 0;
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
336 int text_len = strlen(text);
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
337
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
338 for (int i = 0; i <= text_len; i++) {
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
339 if (i == text_len || text[i] == '\n') {
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
340 visual_lines++;
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
341 line_char_start = i + 1;
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
342 } else if (wrap) {
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
343 int line_width = MeasureTextRange(text, line_char_start, i + 1, font_size);
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
344 if (line_width > content_width && i > line_char_start) {
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
345 int wrap_pos = i;
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
346 for (int j = i; j > line_char_start; j--) {
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
347 if (text[j] == ' ') {
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
348 wrap_pos = j;
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
349 break;
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
350 }
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
351 }
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
352 visual_lines++;
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
353 line_char_start = (text[wrap_pos] == ' ') ? wrap_pos + 1 : wrap_pos;
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
354 }
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
355 }
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
356 }
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
357
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
358 return visual_lines * line_height;
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
359 }
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
360
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
361 static void PushUndoState(TextAreaState *state, const char *text, Dowa_Arena *arena) {
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
362 TextAreaUndoEntry entry;
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
363 entry.text = Dowa_String_Copy_Arena((char*)text, arena);
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
364 entry.cursor_pos = state->cursor_pos;
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
365 entry.selection_start = state->selection_start;
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
366 entry.selection_end = state->selection_end;
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
367
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
368 if (state->undo_index < (int)Dowa_Array_Length(state->undo_stack) - 1) {
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
369 dowa__header(state->undo_stack)->length = state->undo_index + 1;
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
370 }
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
371
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
372 Dowa_Array_Push_Arena(state->undo_stack, entry, arena);
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
373 state->undo_index = Dowa_Array_Length(state->undo_stack) - 1;
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
374
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
375 if (Dowa_Array_Length(state->undo_stack) > TEXT_AREA_MAX_UNDO_STATES) {
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
376 for (int i = 0; i < (int)Dowa_Array_Length(state->undo_stack) - 1; i++) {
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
377 state->undo_stack[i] = state->undo_stack[i + 1];
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
378 }
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
379 dowa__header(state->undo_stack)->length--;
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
380 state->undo_index--;
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
381 }
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
382 }
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
383
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
384 static boolean PerformUndo(TextAreaState *state, char *text, int text_size) {
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
385 if (state->undo_index <= 0) return FALSE;
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
386
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
387 state->undo_index--;
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
388 TextAreaUndoEntry *entry = &state->undo_stack[state->undo_index];
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
389
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
390 strncpy(text, entry->text, text_size - 1);
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
391 text[text_size - 1] = '\0';
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
392 state->cursor_pos = entry->cursor_pos;
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
393 state->selection_start = entry->selection_start;
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
394 state->selection_end = entry->selection_end;
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
395
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
396 return TRUE;
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
397 }
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
398
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
399 static boolean PerformRedo(TextAreaState *state, char *text, int text_size) {
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
400 if (state->undo_index >= (int)Dowa_Array_Length(state->undo_stack) - 1) return FALSE;
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
401
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
402 state->undo_index++;
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
403 TextAreaUndoEntry *entry = &state->undo_stack[state->undo_index];
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
404
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
405 strncpy(text, entry->text, text_size - 1);
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
406 text[text_size - 1] = '\0';
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
407 state->cursor_pos = entry->cursor_pos;
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
408 state->selection_start = entry->selection_start;
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
409 state->selection_end = entry->selection_end;
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
410
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
411 return TRUE;
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
412 }
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
413
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
414 static void InsertTextAtCursor(char *text, int text_size, int cursor_pos,
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
415 const char *insert_text, int *new_cursor_pos) {
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
416 int text_len = strlen(text);
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
417 int insert_len = strlen(insert_text);
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
418
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
419 if (text_len + insert_len >= text_size - 1) {
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
420 insert_len = text_size - 1 - text_len;
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
421 if (insert_len <= 0) return;
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
422 }
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
423
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
424 memmove(text + cursor_pos + insert_len,
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
425 text + cursor_pos,
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
426 text_len - cursor_pos + 1);
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
427
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
428 memcpy(text + cursor_pos, insert_text, insert_len);
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
429
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
430 *new_cursor_pos = cursor_pos + insert_len;
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
431 }
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
432
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
433 static void DeleteTextRange(char *text, int start, int end) {
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
434 if (start >= end) return;
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
435 int text_len = strlen(text);
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
436 if (start < 0) start = 0;
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
437 if (end > text_len) end = text_len;
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
438
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
439 memmove(text + start, text + end, text_len - end + 1);
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
440 }
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
441
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
442 static char* GetSelectedText(const char *text, int sel_start, int sel_end, Dowa_Arena *arena) {
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
443 if (sel_start < 0 || sel_end < 0 || sel_start >= sel_end) return NULL;
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
444
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
445 int len = sel_end - sel_start;
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
446 char *result = Dowa_Arena_Allocate(arena, len + 1);
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
447 strncpy(result, text + sel_start, len);
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
448 result[len] = '\0';
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
449 return result;
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
450 }
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
451
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
452 boolean GuiTextArea(int id, Rectangle bounds, char *text, int text_size, boolean is_edit_mode,
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
453 boolean should_text_wrap, Dowa_Arena *arena) {
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
454 boolean should_toggle_edit_mode = FALSE;
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
455
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
456 // Get or create state for this text area
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
457 TextAreaState *state = GetTextAreaState(id);
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
458 if (!state) {
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
459 state = CreateTextAreaState(id);
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
460 state->cursor_pos = strlen(text);
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
461 state->last_blink_time = GetTime();
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
462 PushUndoState(state, text, arena);
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
463 }
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
464
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
465 int text_len = strlen(text);
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
466 Vector2 mouse_pos = GetMousePosition();
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
467 boolean mouse_in_bounds = CheckCollisionPointRec(mouse_pos, bounds);
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
468
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
469 // Handle click to enter/exit edit mode
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
470 if (IsMouseButtonPressed(MOUSE_BUTTON_LEFT)) {
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
471 if (mouse_in_bounds && !is_edit_mode) {
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
472 should_toggle_edit_mode = TRUE;
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
473 } else if (!mouse_in_bounds && is_edit_mode) {
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
474 should_toggle_edit_mode = TRUE;
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
475 }
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
476 }
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
477
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
478 // Content area
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
479 float content_height = GetContentHeight(text, bounds, should_text_wrap,
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
480 TEXT_AREA_FONT_SIZE, TEXT_AREA_LINE_HEIGHT);
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
481 float visible_height = bounds.height - TEXT_AREA_PADDING * 2;
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
482 float max_scroll = TA_Max_Float(0, content_height - visible_height);
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
483
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
484 // Handle scrolling
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
485 float wheel = GetMouseWheelMove();
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
486 if (mouse_in_bounds && wheel != 0) {
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
487 state->scroll_offset_y -= wheel * TEXT_AREA_LINE_HEIGHT * 3;
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
488 state->scroll_offset_y = TA_Max_Float(0, TA_Min_Float(state->scroll_offset_y, max_scroll));
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
489 }
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
490
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
491 if (is_edit_mode) {
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
492 boolean ctrl_pressed = IsKeyDown(KEY_LEFT_CONTROL) || IsKeyDown(KEY_RIGHT_CONTROL) ||
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
493 IsKeyDown(KEY_LEFT_SUPER) || IsKeyDown(KEY_RIGHT_SUPER);
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
494 boolean shift_pressed = IsKeyDown(KEY_LEFT_SHIFT) || IsKeyDown(KEY_RIGHT_SHIFT);
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
495 boolean text_changed = FALSE;
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
496
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
497 double current_time = GetTime();
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
498 if (current_time - state->last_blink_time > 0.5) {
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
499 state->cursor_visible = !state->cursor_visible;
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
500 state->last_blink_time = current_time;
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
501 }
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
502
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
503 // Mouse Selection
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
504 if (IsMouseButtonPressed(MOUSE_BUTTON_LEFT) && mouse_in_bounds) {
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
505 int click_pos = GetCharIndexFromPos(text, bounds, mouse_pos, should_text_wrap,
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
506 state->scroll_offset_y, TEXT_AREA_FONT_SIZE,
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
507 TEXT_AREA_LINE_HEIGHT);
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
508 state->cursor_pos = click_pos;
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
509 state->selection_start = -1;
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
510 state->selection_end = -1;
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
511 state->is_selecting = TRUE;
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
512 state->cursor_visible = TRUE;
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
513 state->last_blink_time = current_time;
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
514 }
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
515
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
516 if (state->is_selecting && IsMouseButtonDown(MOUSE_BUTTON_LEFT)) {
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
517 int drag_pos = GetCharIndexFromPos(text, bounds, mouse_pos, should_text_wrap,
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
518 state->scroll_offset_y, TEXT_AREA_FONT_SIZE,
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
519 TEXT_AREA_LINE_HEIGHT);
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
520 if (drag_pos != state->cursor_pos) {
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
521 if (state->selection_start < 0) {
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
522 state->selection_start = state->cursor_pos;
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
523 }
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
524 state->selection_end = drag_pos;
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
525 }
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
526 }
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
527
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
528 if (IsMouseButtonReleased(MOUSE_BUTTON_LEFT)) {
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
529 state->is_selecting = FALSE;
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
530 if (state->selection_start >= 0 && state->selection_end >= 0) {
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
531 if (state->selection_start > state->selection_end) {
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
532 int temp = state->selection_start;
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
533 state->selection_start = state->selection_end;
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
534 state->selection_end = temp;
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
535 }
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
536 if (state->selection_start == state->selection_end) {
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
537 state->selection_start = -1;
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
538 state->selection_end = -1;
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
539 }
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
540 }
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
541 }
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
542
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
543 // Ctrl+A: Select All
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
544 if (ctrl_pressed && IsKeyPressed(KEY_A)) {
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
545 state->selection_start = 0;
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
546 state->selection_end = text_len;
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
547 state->cursor_pos = text_len;
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
548 }
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
549
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
550 // Ctrl+C: Copy
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
551 if (ctrl_pressed && IsKeyPressed(KEY_C)) {
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
552 if (state->selection_start >= 0 && state->selection_end >= 0 &&
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
553 state->selection_start != state->selection_end) {
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
554 int sel_min = TA_Min_Int(state->selection_start, state->selection_end);
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
555 int sel_max = TA_Max_Int(state->selection_start, state->selection_end);
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
556 char *selected = GetSelectedText(text, sel_min, sel_max, arena);
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
557 if (selected) {
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
558 if (g_clipboard_text) free(g_clipboard_text);
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
559 g_clipboard_text = strdup(selected);
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
560 SetClipboardText(g_clipboard_text);
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
561 }
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
562 }
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
563 }
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
564
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
565 // Ctrl+X: Cut
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
566 if (ctrl_pressed && IsKeyPressed(KEY_X)) {
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
567 if (state->selection_start >= 0 && state->selection_end >= 0 &&
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
568 state->selection_start != state->selection_end) {
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
569 int sel_min = TA_Min_Int(state->selection_start, state->selection_end);
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
570 int sel_max = TA_Max_Int(state->selection_start, state->selection_end);
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
571 char *selected = GetSelectedText(text, sel_min, sel_max, arena);
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
572 if (selected) {
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
573 if (g_clipboard_text) free(g_clipboard_text);
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
574 g_clipboard_text = strdup(selected);
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
575 SetClipboardText(g_clipboard_text);
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
576 }
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
577
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
578 PushUndoState(state, text, arena);
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
579 DeleteTextRange(text, sel_min, sel_max);
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
580 state->cursor_pos = sel_min;
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
581 state->selection_start = -1;
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
582 state->selection_end = -1;
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
583 text_changed = TRUE;
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
584 }
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
585 }
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
586
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
587 // Ctrl+V: Paste
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
588 if (ctrl_pressed && IsKeyPressed(KEY_V)) {
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
589 const char *clipboard = GetClipboardText();
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
590 if (clipboard && strlen(clipboard) > 0) {
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
591 if (state->selection_start >= 0 && state->selection_end >= 0 &&
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
592 state->selection_start != state->selection_end) {
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
593 int sel_min = TA_Min_Int(state->selection_start, state->selection_end);
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
594 int sel_max = TA_Max_Int(state->selection_start, state->selection_end);
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
595 PushUndoState(state, text, arena);
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
596 DeleteTextRange(text, sel_min, sel_max);
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
597 state->cursor_pos = sel_min;
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
598 state->selection_start = -1;
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
599 state->selection_end = -1;
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
600 } else {
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
601 PushUndoState(state, text, arena);
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
602 }
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
603
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
604 int new_cursor;
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
605 InsertTextAtCursor(text, text_size, state->cursor_pos, clipboard, &new_cursor);
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
606 state->cursor_pos = new_cursor;
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
607 text_changed = TRUE;
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
608 }
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
609 }
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
610
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
611 // Ctrl+Z: Undo / Ctrl+Shift+Z: Redo
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
612 if (ctrl_pressed && IsKeyPressed(KEY_Z)) {
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
613 if (shift_pressed) {
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
614 PerformRedo(state, text, text_size);
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
615 } else {
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
616 PerformUndo(state, text, text_size);
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
617 }
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
618 }
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
619
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
620 // Arrow Keys Navigation
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
621 if (IsKeyPressed(KEY_LEFT) || IsKeyPressedRepeat(KEY_LEFT)) {
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
622 if (state->selection_start >= 0 && !shift_pressed) {
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
623 state->cursor_pos = TA_Min_Int(state->selection_start, state->selection_end);
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
624 state->selection_start = -1;
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
625 state->selection_end = -1;
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
626 } else if (state->cursor_pos > 0) {
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
627 if (shift_pressed) {
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
628 if (state->selection_start < 0) {
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
629 state->selection_start = state->cursor_pos;
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
630 state->selection_end = state->cursor_pos;
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
631 }
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
632 state->cursor_pos--;
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
633 state->selection_end = state->cursor_pos;
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
634 } else {
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
635 state->cursor_pos--;
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
636 }
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
637 }
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
638 state->cursor_visible = TRUE;
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
639 state->last_blink_time = current_time;
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
640 }
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
641
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
642 if (IsKeyPressed(KEY_RIGHT) || IsKeyPressedRepeat(KEY_RIGHT)) {
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
643 if (state->selection_start >= 0 && !shift_pressed) {
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
644 state->cursor_pos = TA_Max_Int(state->selection_start, state->selection_end);
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
645 state->selection_start = -1;
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
646 state->selection_end = -1;
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
647 } else if (state->cursor_pos < text_len) {
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
648 if (shift_pressed) {
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
649 if (state->selection_start < 0) {
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
650 state->selection_start = state->cursor_pos;
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
651 state->selection_end = state->cursor_pos;
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
652 }
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
653 state->cursor_pos++;
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
654 state->selection_end = state->cursor_pos;
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
655 } else {
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
656 state->cursor_pos++;
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
657 }
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
658 }
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
659 state->cursor_visible = TRUE;
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
660 state->last_blink_time = current_time;
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
661 }
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
662
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
663 if (IsKeyPressed(KEY_UP) || IsKeyPressedRepeat(KEY_UP)) {
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
664 int line, col;
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
665 GetLineAndColumn(text, state->cursor_pos, &line, &col);
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
666 if (line > 0) {
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
667 int new_pos = GetPosFromLineColumn(text, line - 1, col);
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
668 if (shift_pressed) {
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
669 if (state->selection_start < 0) {
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
670 state->selection_start = state->cursor_pos;
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
671 state->selection_end = state->cursor_pos;
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
672 }
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
673 state->selection_end = new_pos;
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
674 } else {
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
675 state->selection_start = -1;
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
676 state->selection_end = -1;
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
677 }
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
678 state->cursor_pos = new_pos;
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
679 }
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
680 state->cursor_visible = TRUE;
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
681 state->last_blink_time = current_time;
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
682 }
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
683
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
684 if (IsKeyPressed(KEY_DOWN) || IsKeyPressedRepeat(KEY_DOWN)) {
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
685 int line, col;
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
686 GetLineAndColumn(text, state->cursor_pos, &line, &col);
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
687 int total_lines = CountLines(text);
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
688 if (line < total_lines - 1) {
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
689 int new_pos = GetPosFromLineColumn(text, line + 1, col);
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
690 if (shift_pressed) {
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
691 if (state->selection_start < 0) {
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
692 state->selection_start = state->cursor_pos;
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
693 state->selection_end = state->cursor_pos;
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
694 }
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
695 state->selection_end = new_pos;
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
696 } else {
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
697 state->selection_start = -1;
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
698 state->selection_end = -1;
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
699 }
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
700 state->cursor_pos = new_pos;
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
701 }
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
702 state->cursor_visible = TRUE;
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
703 state->last_blink_time = current_time;
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
704 }
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
705
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
706 // Home/End keys
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
707 if (IsKeyPressed(KEY_HOME)) {
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
708 int line_start = GetLineStart(text, state->cursor_pos);
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
709 if (shift_pressed) {
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
710 if (state->selection_start < 0) {
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
711 state->selection_start = state->cursor_pos;
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
712 state->selection_end = state->cursor_pos;
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
713 }
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
714 state->selection_end = line_start;
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
715 } else {
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
716 state->selection_start = -1;
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
717 state->selection_end = -1;
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
718 }
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
719 state->cursor_pos = line_start;
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
720 }
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
721
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
722 if (IsKeyPressed(KEY_END)) {
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
723 int line_end = GetLineEnd(text, state->cursor_pos);
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
724 if (shift_pressed) {
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
725 if (state->selection_start < 0) {
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
726 state->selection_start = state->cursor_pos;
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
727 state->selection_end = state->cursor_pos;
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
728 }
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
729 state->selection_end = line_end;
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
730 } else {
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
731 state->selection_start = -1;
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
732 state->selection_end = -1;
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
733 }
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
734 state->cursor_pos = line_end;
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
735 }
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
736
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
737 // Text Input
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
738 if (!ctrl_pressed) {
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
739 int key = GetCharPressed();
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
740 while (key > 0) {
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
741 if (key >= 32 && key <= 126) {
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
742 if (state->selection_start >= 0 && state->selection_end >= 0 &&
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
743 state->selection_start != state->selection_end) {
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
744 int sel_min = TA_Min_Int(state->selection_start, state->selection_end);
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
745 int sel_max = TA_Max_Int(state->selection_start, state->selection_end);
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
746 PushUndoState(state, text, arena);
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
747 DeleteTextRange(text, sel_min, sel_max);
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
748 state->cursor_pos = sel_min;
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
749 state->selection_start = -1;
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
750 state->selection_end = -1;
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
751 text_changed = TRUE;
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
752 } else if (!text_changed) {
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
753 PushUndoState(state, text, arena);
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
754 }
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
755
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
756 char insert_str[2] = {(char)key, '\0'};
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
757 int new_cursor;
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
758 InsertTextAtCursor(text, text_size, state->cursor_pos, insert_str, &new_cursor);
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
759 state->cursor_pos = new_cursor;
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
760 text_changed = TRUE;
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
761 }
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
762 key = GetCharPressed();
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
763 }
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
764 }
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
765
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
766 // Enter key
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
767 if (IsKeyPressed(KEY_ENTER) || IsKeyPressed(KEY_KP_ENTER)) {
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
768 if (state->selection_start >= 0 && state->selection_end >= 0 &&
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
769 state->selection_start != state->selection_end) {
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
770 int sel_min = TA_Min_Int(state->selection_start, state->selection_end);
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
771 int sel_max = TA_Max_Int(state->selection_start, state->selection_end);
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
772 PushUndoState(state, text, arena);
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
773 DeleteTextRange(text, sel_min, sel_max);
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
774 state->cursor_pos = sel_min;
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
775 state->selection_start = -1;
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
776 state->selection_end = -1;
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
777 } else {
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
778 PushUndoState(state, text, arena);
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
779 }
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
780
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
781 int new_cursor;
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
782 InsertTextAtCursor(text, text_size, state->cursor_pos, "\n", &new_cursor);
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
783 state->cursor_pos = new_cursor;
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
784 text_changed = TRUE;
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
785 }
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
786
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
787 // Backspace
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
788 if (IsKeyPressed(KEY_BACKSPACE) || IsKeyPressedRepeat(KEY_BACKSPACE)) {
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
789 if (state->selection_start >= 0 && state->selection_end >= 0 &&
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
790 state->selection_start != state->selection_end) {
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
791 int sel_min = TA_Min_Int(state->selection_start, state->selection_end);
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
792 int sel_max = TA_Max_Int(state->selection_start, state->selection_end);
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
793 PushUndoState(state, text, arena);
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
794 DeleteTextRange(text, sel_min, sel_max);
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
795 state->cursor_pos = sel_min;
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
796 state->selection_start = -1;
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
797 state->selection_end = -1;
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
798 text_changed = TRUE;
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
799 } else if (state->cursor_pos > 0) {
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
800 PushUndoState(state, text, arena);
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
801 DeleteTextRange(text, state->cursor_pos - 1, state->cursor_pos);
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
802 state->cursor_pos--;
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
803 text_changed = TRUE;
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
804 }
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
805 }
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
806
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
807 // Delete key
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
808 if (IsKeyPressed(KEY_DELETE) || IsKeyPressedRepeat(KEY_DELETE)) {
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
809 text_len = strlen(text);
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
810 if (state->selection_start >= 0 && state->selection_end >= 0 &&
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
811 state->selection_start != state->selection_end) {
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
812 int sel_min = TA_Min_Int(state->selection_start, state->selection_end);
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
813 int sel_max = TA_Max_Int(state->selection_start, state->selection_end);
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
814 PushUndoState(state, text, arena);
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
815 DeleteTextRange(text, sel_min, sel_max);
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
816 state->cursor_pos = sel_min;
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
817 state->selection_start = -1;
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
818 state->selection_end = -1;
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
819 text_changed = TRUE;
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
820 } else if (state->cursor_pos < text_len) {
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
821 PushUndoState(state, text, arena);
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
822 DeleteTextRange(text, state->cursor_pos, state->cursor_pos + 1);
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
823 text_changed = TRUE;
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
824 }
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
825 }
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
826
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
827 // Tab key
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
828 if (IsKeyPressed(KEY_TAB)) {
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
829 if (state->selection_start >= 0 && state->selection_end >= 0 &&
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
830 state->selection_start != state->selection_end) {
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
831 int sel_min = TA_Min_Int(state->selection_start, state->selection_end);
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
832 int sel_max = TA_Max_Int(state->selection_start, state->selection_end);
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
833 PushUndoState(state, text, arena);
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
834 DeleteTextRange(text, sel_min, sel_max);
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
835 state->cursor_pos = sel_min;
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
836 state->selection_start = -1;
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
837 state->selection_end = -1;
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
838 } else {
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
839 PushUndoState(state, text, arena);
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
840 }
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
841
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
842 int new_cursor;
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
843 InsertTextAtCursor(text, text_size, state->cursor_pos, " ", &new_cursor);
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
844 state->cursor_pos = new_cursor;
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
845 text_changed = TRUE;
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
846 }
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
847
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
848 // Auto-scroll to keep cursor visible
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
849 Vector2 cursor_screen = GetCursorScreenPos(text, state->cursor_pos, bounds,
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
850 should_text_wrap, state->scroll_offset_y,
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
851 TEXT_AREA_FONT_SIZE, TEXT_AREA_LINE_HEIGHT);
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
852
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
853 float visible_top = bounds.y + TEXT_AREA_PADDING;
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
854 float visible_bottom = bounds.y + bounds.height - TEXT_AREA_PADDING - TEXT_AREA_LINE_HEIGHT;
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
855
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
856 if (cursor_screen.y < visible_top) {
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
857 state->scroll_offset_y -= visible_top - cursor_screen.y;
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
858 } else if (cursor_screen.y > visible_bottom) {
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
859 state->scroll_offset_y += cursor_screen.y - visible_bottom;
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
860 }
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
861
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
862 state->scroll_offset_y = TA_Max_Float(0, TA_Min_Float(state->scroll_offset_y, max_scroll));
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
863 }
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
864
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
865 // Drawing
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
866 DrawRectangleRec(bounds, is_edit_mode ? DARKGRAY : (Color){40, 40, 40, 255});
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
867 DrawRectangleLinesEx(bounds, 1, is_edit_mode ? WHITE : GRAY);
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
868
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
869 BeginScissorMode((int)bounds.x, (int)bounds.y, (int)bounds.width, (int)bounds.height);
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
870
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
871 float content_x = bounds.x + TEXT_AREA_PADDING;
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
872 float content_y = bounds.y + TEXT_AREA_PADDING - state->scroll_offset_y;
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
873 float content_width = bounds.width - TEXT_AREA_PADDING * 2;
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
874
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
875 text_len = strlen(text);
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
876
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
877 // Draw selection highlight
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
878 if (state->selection_start >= 0 && state->selection_end >= 0 &&
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
879 state->selection_start != state->selection_end) {
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
880 int sel_min = TA_Min_Int(state->selection_start, state->selection_end);
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
881 int sel_max = TA_Max_Int(state->selection_start, state->selection_end);
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
882
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
883 int line_char_start = 0;
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
884 int visual_line = 0;
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
885
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
886 for (int i = 0; i <= text_len; i++) {
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
887 boolean is_end = (i == text_len);
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
888 boolean is_newline = (!is_end && text[i] == '\n');
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
889 boolean should_draw_line = is_end || is_newline;
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
890
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
891 if (should_text_wrap && !is_end && !is_newline) {
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
892 int line_width = MeasureTextRange(text, line_char_start, i + 1, TEXT_AREA_FONT_SIZE);
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
893 if (line_width > content_width && i > line_char_start) {
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
894 should_draw_line = TRUE;
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
895 }
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
896 }
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
897
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
898 if (should_draw_line) {
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
899 int line_end = i;
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
900
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
901 if (sel_min < line_end && sel_max > line_char_start) {
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
902 int highlight_start = TA_Max_Int(sel_min, line_char_start);
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
903 int highlight_end = TA_Min_Int(sel_max, line_end);
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
904
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
905 float x1 = content_x + MeasureTextRange(text, line_char_start, highlight_start, TEXT_AREA_FONT_SIZE);
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
906 float x2 = content_x + MeasureTextRange(text, line_char_start, highlight_end, TEXT_AREA_FONT_SIZE);
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
907 float y = content_y + visual_line * TEXT_AREA_LINE_HEIGHT;
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
908
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
909 DrawRectangle((int)x1, (int)y, (int)(x2 - x1), TEXT_AREA_LINE_HEIGHT,
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
910 Fade(SKYBLUE, 0.5f));
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
911 }
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
912
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
913 visual_line++;
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
914 line_char_start = i + 1;
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
915 }
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
916 }
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
917 }
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
918
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
919 // Draw text with wrapping support
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
920 if (should_text_wrap) {
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
921 int line_char_start = 0;
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
922 int visual_line = 0;
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
923
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
924 for (int i = 0; i <= text_len; i++) {
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
925 boolean is_end = (i == text_len);
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
926 boolean is_newline = (!is_end && text[i] == '\n');
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
927 boolean should_draw_line = is_end || is_newline;
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
928
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
929 if (!is_end && !is_newline) {
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
930 int line_width = MeasureTextRange(text, line_char_start, i + 1, TEXT_AREA_FONT_SIZE);
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
931 if (line_width > content_width && i > line_char_start) {
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
932 should_draw_line = TRUE;
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
933 }
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
934 }
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
935
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
936 if (should_draw_line && i > line_char_start) {
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
937 char line_buffer[1024];
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
938 int line_len = TA_Min_Int(i - line_char_start, 1023);
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
939 strncpy(line_buffer, text + line_char_start, line_len);
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
940 line_buffer[line_len] = '\0';
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
941
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
942 Vector2 draw_text_vector = {
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
943 .x = content_x,
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
944 .y = content_y + visual_line * TEXT_AREA_LINE_HEIGHT
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
945 };
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
946 DrawTextEx(GuiGetFont(), line_buffer, draw_text_vector,
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
947 TEXT_AREA_FONT_SIZE, TEXT_SIZE_DEFAULT/TEXT_AREA_FONT_SIZE, WHITE);
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
948
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
949 visual_line++;
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
950 line_char_start = is_newline ? i + 1 : i;
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
951 } else if (is_newline) {
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
952 visual_line++;
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
953 line_char_start = i + 1;
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
954 }
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
955 }
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
956 } else {
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
957 int line_start = 0;
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
958 int visual_line = 0;
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
959
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
960 for (int i = 0; i <= text_len; i++) {
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
961 if (i == text_len || text[i] == '\n') {
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
962 if (i > line_start) {
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
963 char line_buffer[1024];
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
964 int line_len = TA_Min_Int(i - line_start, 1023);
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
965 strncpy(line_buffer, text + line_start, line_len);
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
966 line_buffer[line_len] = '\0';
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
967
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
968 Vector2 draw_text_vector = {
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
969 .x = content_x,
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
970 .y = content_y + visual_line * TEXT_AREA_LINE_HEIGHT
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
971 };
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
972 DrawTextEx(GuiGetFont(), line_buffer, draw_text_vector ,
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
973 TEXT_AREA_FONT_SIZE, TEXT_SIZE_DEFAULT/TEXT_AREA_FONT_SIZE, WHITE);
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
974 }
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
975 visual_line++;
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
976 line_start = i + 1;
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
977 }
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
978 }
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
979 }
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
980
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
981 // Draw cursor
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
982 if (is_edit_mode && state->cursor_visible) {
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
983 Vector2 cursor_pos = GetCursorScreenPos(text, state->cursor_pos, bounds,
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
984 should_text_wrap, state->scroll_offset_y,
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
985 TEXT_AREA_FONT_SIZE, TEXT_AREA_LINE_HEIGHT);
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
986
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
987 DrawRectangle((int)cursor_pos.x, (int)cursor_pos.y,
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
988 TEXT_AREA_CURSOR_WIDTH, TEXT_AREA_LINE_HEIGHT, WHITE);
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
989 }
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
990
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
991 EndScissorMode();
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
992
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
993 // Draw scrollbar if needed
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
994 if (max_scroll > 0) {
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
995 float scrollbar_height = (visible_height / content_height) * visible_height;
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
996 float scrollbar_y = bounds.y + TEXT_AREA_PADDING +
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
997 (state->scroll_offset_y / max_scroll) * (visible_height - scrollbar_height);
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
998
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
999 DrawRectangle((int)(bounds.x + bounds.width - 8), (int)scrollbar_y,
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
1000 6, (int)scrollbar_height, Fade(WHITE, 0.3f));
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
1001 }
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
1002
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
1003 return should_toggle_edit_mode;
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
1004 }
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
1005
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
1006 void GuiTextAreaResetState(int id) {
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
1007 TextAreaState *state = GetTextAreaState(id);
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
1008 if (state) {
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
1009 if (state->undo_stack) {
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
1010 Dowa_Array_Free(state->undo_stack);
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
1011 state->undo_stack = NULL;
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
1012 }
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
1013 state->is_initialized = FALSE;
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
1014 }
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
1015 }
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
1016
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
1017 void GuiTextAreaResetAllStates(void) {
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
1018 for (int i = 0; i < g_text_area_state_count; i++) {
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
1019 if (g_text_area_states[i].undo_stack) {
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
1020 Dowa_Array_Free(g_text_area_states[i].undo_stack);
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
1021 g_text_area_states[i].undo_stack = NULL;
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
1022 }
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
1023 g_text_area_states[i].is_initialized = FALSE;
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
1024 }
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
1025 g_text_area_state_count = 0;
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
1026 }
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
1027
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
1028 // ============================================================================
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
1029 // End TextArea Component
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
1030 // ============================================================================
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
1031
112
d6d578b49a19 [PostDog] Got CRUD working.
June Park <parkjune1995@gmail.com>
parents: 111
diff changeset
1032 typedef Dowa_KV(char*, char*) INPUT_HASHMAP;
d6d578b49a19 [PostDog] Got CRUD working.
June Park <parkjune1995@gmail.com>
parents: 111
diff changeset
1033
54
b3e82d22f961 [PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1034 typedef struct {
b3e82d22f961 [PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1035 char *data;
b3e82d22f961 [PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1036 size_t size;
b3e82d22f961 [PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1037 } ResponseBuffer;
b3e82d22f961 [PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1038
b3e82d22f961 [PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1039 typedef struct {
114
e2a73e64e8e6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 112
diff changeset
1040 char *filename;
159
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
1041 char *title;
114
e2a73e64e8e6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 112
diff changeset
1042 Rectangle rect;
e2a73e64e8e6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 112
diff changeset
1043 long time_modified;
117
b91f2dd6f84d [PostDog] Fixed delete logic.
June Park <parkjune1995@gmail.com>
parents: 116
diff changeset
1044 boolean deleted;
54
b3e82d22f961 [PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1045 } HistoryItem;
b3e82d22f961 [PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1046
114
e2a73e64e8e6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 112
diff changeset
1047 typedef struct {
e2a73e64e8e6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 112
diff changeset
1048 Rectangle rectangle;
e2a73e64e8e6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 112
diff changeset
1049 char *label;
e2a73e64e8e6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 112
diff changeset
1050 bool active;
e2a73e64e8e6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 112
diff changeset
1051 } TabItem;
e2a73e64e8e6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 112
diff changeset
1052
e2a73e64e8e6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 112
diff changeset
1053 typedef enum {
e2a73e64e8e6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 112
diff changeset
1054 TAB_HEADER = 0,
e2a73e64e8e6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 112
diff changeset
1055 TAB_BODY,
e2a73e64e8e6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 112
diff changeset
1056 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
1057 TAB_WEBSOCKET,
114
e2a73e64e8e6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 112
diff changeset
1058 TAB_LENGTH
e2a73e64e8e6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 112
diff changeset
1059 } PostDog_Tab_Enum;
e2a73e64e8e6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 112
diff changeset
1060
159
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
1061 // Text area IDs
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
1062 #define TEXT_AREA_ID_INPUT_HEADER 1
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
1063 #define TEXT_AREA_ID_INPUT_BODY 2
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
1064 #define TEXT_AREA_ID_INPUT_PARAMS 3
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
1065 #define TEXT_AREA_ID_INPUT_WS 4
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
1066 #define TEXT_AREA_ID_RESULT 5
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
1067
114
e2a73e64e8e6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 112
diff changeset
1068 static uint32 counter = 0;
e2a73e64e8e6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 112
diff changeset
1069 HistoryItem *history_items = NULL;
e2a73e64e8e6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 112
diff changeset
1070 HistoryItem *new_history_items = NULL;
e2a73e64e8e6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 112
diff changeset
1071
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
1072 // 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
1073 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
1074 char *result_text = NULL;
3bb45eb67906 [Postdog] Updated variables names and padding sizes. Needs more work.
June Park <parkjune1995@gmail.com>
parents: 153
diff changeset
1075 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
1076 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
1077 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
1078 Seobeo_WebSocket *ws = NULL;
153
790930d9bb90 [PostDog] Adding websocket to be more usable.
June Park <parkjune1995@gmail.com>
parents: 152
diff changeset
1079 boolean WS_BREAK = FALSE;
159
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
1080 pthread_t websocket_thread_id;
155
3bb45eb67906 [Postdog] Updated variables names and padding sizes. Needs more work.
June Park <parkjune1995@gmail.com>
parents: 153
diff changeset
1081 Color TEXT_COLOR = BLACK;
159
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
1082 boolean LOADING = FALSE;
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
1083
114
e2a73e64e8e6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 112
diff changeset
1084 int CompareHistoryItemsByDate(const void *a, const void *b) {
e2a73e64e8e6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 112
diff changeset
1085 HistoryItem *itemA = (HistoryItem *)a;
e2a73e64e8e6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 112
diff changeset
1086 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
1087 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
1088 }
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
1089
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
1090 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
1091 {
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
1092 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
1093 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
1094 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
1095 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
1096 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
1097
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
1098 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
1099 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
1100 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
1101 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
1102 }
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
1103
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
1104 return title;
114
e2a73e64e8e6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 112
diff changeset
1105 }
e2a73e64e8e6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 112
diff changeset
1106
e2a73e64e8e6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 112
diff changeset
1107 // 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
1108 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
1109 {
e2a73e64e8e6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 112
diff changeset
1110 HistoryItem *file_arr = *p_file_arr;
e2a73e64e8e6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 112
diff changeset
1111 #ifdef _WIN32
e2a73e64e8e6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 112
diff changeset
1112 struct _finddata_t fileinfo;
e2a73e64e8e6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 112
diff changeset
1113 intptr_t handle;
e2a73e64e8e6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 112
diff changeset
1114 char search_path[256];
e2a73e64e8e6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 112
diff changeset
1115 sprintf(search_path, "%s\\*", path);
e2a73e64e8e6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 112
diff changeset
1116
e2a73e64e8e6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 112
diff changeset
1117 if ((handle = _findfirst(search_path, &fileinfo)) == -1L) {
e2a73e64e8e6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 112
diff changeset
1118 printf("Directory is empty or cannot be read.\n");
e2a73e64e8e6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 112
diff changeset
1119 } else {
e2a73e64e8e6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 112
diff changeset
1120 do {
e2a73e64e8e6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 112
diff changeset
1121 HistoryItem item = {0};
e2a73e64e8e6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 112
diff changeset
1122 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
1123 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
1124 item.time_modified = fileinfo.time_write;
117
b91f2dd6f84d [PostDog] Fixed delete logic.
June Park <parkjune1995@gmail.com>
parents: 116
diff changeset
1125 item.deleted = FALSE;
114
e2a73e64e8e6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 112
diff changeset
1126 Dowa_Array_Push(file_arr, item);
e2a73e64e8e6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 112
diff changeset
1127 } while (_findnext(handle, &fileinfo) == 0);
e2a73e64e8e6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 112
diff changeset
1128 _findclose(handle);
e2a73e64e8e6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 112
diff changeset
1129 }
e2a73e64e8e6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 112
diff changeset
1130 #else
e2a73e64e8e6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 112
diff changeset
1131 struct dirent *entry;
e2a73e64e8e6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 112
diff changeset
1132 struct stat file_stat;
e2a73e64e8e6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 112
diff changeset
1133 DIR *dp = opendir(path);
e2a73e64e8e6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 112
diff changeset
1134 if (dp == NULL) return;
e2a73e64e8e6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 112
diff changeset
1135
e2a73e64e8e6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 112
diff changeset
1136 char full_path[256];
e2a73e64e8e6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 112
diff changeset
1137 while ((entry = readdir(dp)))
e2a73e64e8e6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 112
diff changeset
1138 {
e2a73e64e8e6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 112
diff changeset
1139 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
1140 continue;
e2a73e64e8e6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 112
diff changeset
1141 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
1142 if (stat(full_path, &file_stat) == 0)
e2a73e64e8e6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 112
diff changeset
1143 {
e2a73e64e8e6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 112
diff changeset
1144 HistoryItem item = {0};
e2a73e64e8e6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 112
diff changeset
1145 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
1146 item.title = PostDog_Extract_Title(entry->d_name);
114
e2a73e64e8e6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 112
diff changeset
1147 item.time_modified = file_stat.st_mtime;
117
b91f2dd6f84d [PostDog] Fixed delete logic.
June Park <parkjune1995@gmail.com>
parents: 116
diff changeset
1148 item.deleted = FALSE;
114
e2a73e64e8e6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 112
diff changeset
1149 Dowa_Array_Push(file_arr, item);
e2a73e64e8e6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 112
diff changeset
1150 }
e2a73e64e8e6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 112
diff changeset
1151 }
e2a73e64e8e6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 112
diff changeset
1152 closedir(dp);
e2a73e64e8e6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 112
diff changeset
1153 #endif
e2a73e64e8e6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 112
diff changeset
1154 int count = Dowa_Array_Length(file_arr);
e2a73e64e8e6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 112
diff changeset
1155 if (count > 1) {
e2a73e64e8e6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 112
diff changeset
1156 qsort(file_arr, count, sizeof(HistoryItem), CompareHistoryItemsByDate);
e2a73e64e8e6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 112
diff changeset
1157 }
e2a73e64e8e6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 112
diff changeset
1158 }
e2a73e64e8e6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 112
diff changeset
1159
e2a73e64e8e6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 112
diff changeset
1160 int PostDog_History_Load(HistoryItem **p_history_files)
e2a73e64e8e6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 112
diff changeset
1161 {
e2a73e64e8e6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 112
diff changeset
1162 if (access(POSTDOG_PATHS, F_OK) == -1)
e2a73e64e8e6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 112
diff changeset
1163 {
e2a73e64e8e6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 112
diff changeset
1164 printf("Directory '%s' not found. Creating it...\n", POSTDOG_PATHS);
e2a73e64e8e6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 112
diff changeset
1165 if (mkdir(POSTDOG_PATHS, 0777) != 0)
e2a73e64e8e6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 112
diff changeset
1166 return -1;
e2a73e64e8e6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 112
diff changeset
1167 return 0;
e2a73e64e8e6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 112
diff changeset
1168 }
e2a73e64e8e6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 112
diff changeset
1169 printf("Directory '%s' already exists.\n", POSTDOG_PATHS);
e2a73e64e8e6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 112
diff changeset
1170 PostDog_List_Directory(POSTDOG_PATHS, p_history_files);
e2a73e64e8e6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 112
diff changeset
1171 return 0;
e2a73e64e8e6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 112
diff changeset
1172 }
e2a73e64e8e6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 112
diff changeset
1173
e2a73e64e8e6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 112
diff changeset
1174 bool InArea(Vector2 mouse_position, Rectangle area)
e2a73e64e8e6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 112
diff changeset
1175 {
e2a73e64e8e6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 112
diff changeset
1176 return (
e2a73e64e8e6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 112
diff changeset
1177 mouse_position.x >= area.x &&
e2a73e64e8e6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 112
diff changeset
1178 mouse_position.x < area.x + area.width &&
e2a73e64e8e6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 112
diff changeset
1179 mouse_position.y >= area.y &&
e2a73e64e8e6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 112
diff changeset
1180 mouse_position.y < area.y + area.height
e2a73e64e8e6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 112
diff changeset
1181 );
e2a73e64e8e6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 112
diff changeset
1182 }
e2a73e64e8e6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 112
diff changeset
1183
e2a73e64e8e6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 112
diff changeset
1184 bool Clicked(Vector2 mouse_position, Rectangle area)
e2a73e64e8e6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 112
diff changeset
1185 {
e2a73e64e8e6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 112
diff changeset
1186 return (InArea(mouse_position, area) && IsMouseButtonPressed(MOUSE_BUTTON_LEFT));
e2a73e64e8e6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 112
diff changeset
1187 }
e2a73e64e8e6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 112
diff changeset
1188
159
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
1189 // -------- END of UI ---- //
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
1190
112
d6d578b49a19 [PostDog] Got CRUD working.
June Park <parkjune1995@gmail.com>
parents: 111
diff changeset
1191 char *PostDog_Enum_To_String(int active_enum)
d6d578b49a19 [PostDog] Got CRUD working.
June Park <parkjune1995@gmail.com>
parents: 111
diff changeset
1192 {
d6d578b49a19 [PostDog] Got CRUD working.
June Park <parkjune1995@gmail.com>
parents: 111
diff changeset
1193 switch(active_enum)
d6d578b49a19 [PostDog] Got CRUD working.
June Park <parkjune1995@gmail.com>
parents: 111
diff changeset
1194 {
d6d578b49a19 [PostDog] Got CRUD working.
June Park <parkjune1995@gmail.com>
parents: 111
diff changeset
1195 case 0: return "GET";
d6d578b49a19 [PostDog] Got CRUD working.
June Park <parkjune1995@gmail.com>
parents: 111
diff changeset
1196 case 1: return "POST";
d6d578b49a19 [PostDog] Got CRUD working.
June Park <parkjune1995@gmail.com>
parents: 111
diff changeset
1197 case 2: return "PUT";
d6d578b49a19 [PostDog] Got CRUD working.
June Park <parkjune1995@gmail.com>
parents: 111
diff changeset
1198 case 3: return "DELETE";
d6d578b49a19 [PostDog] Got CRUD working.
June Park <parkjune1995@gmail.com>
parents: 111
diff changeset
1199 }
114
e2a73e64e8e6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 112
diff changeset
1200 return 0;
e2a73e64e8e6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 112
diff changeset
1201 }
e2a73e64e8e6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 112
diff changeset
1202
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
1203 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
1204 {
7bd795bac997 [Postdog] Added scrollable area to inputs and history files, buttons to delete and view.
June Park <parkjune1995@gmail.com>
parents: 115
diff changeset
1205 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
1206 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
1207 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
1208 }
7bd795bac997 [Postdog] Added scrollable area to inputs and history files, buttons to delete and view.
June Park <parkjune1995@gmail.com>
parents: 115
diff changeset
1209
114
e2a73e64e8e6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 112
diff changeset
1210 void PostDog_History_CreateFile(char *filename, char* values)
e2a73e64e8e6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 112
diff changeset
1211 {
e2a73e64e8e6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 112
diff changeset
1212 char full_file_path[512] = {0};
e2a73e64e8e6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 112
diff changeset
1213 snprintf(full_file_path, 512, "%s/%s", POSTDOG_PATHS, filename);
e2a73e64e8e6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 112
diff changeset
1214 FILE *file = fopen(full_file_path, "w");
e2a73e64e8e6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 112
diff changeset
1215 if (!file)
e2a73e64e8e6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 112
diff changeset
1216 {
e2a73e64e8e6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 112
diff changeset
1217 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
1218 return;
e2a73e64e8e6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 112
diff changeset
1219 }
e2a73e64e8e6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 112
diff changeset
1220 fwrite(values, 1, strlen(values), file);
e2a73e64e8e6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 112
diff changeset
1221 fclose(file);
e2a73e64e8e6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 112
diff changeset
1222 }
e2a73e64e8e6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 112
diff changeset
1223
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
1224 void PostDog_Request_SaveFile(void)
114
e2a73e64e8e6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 112
diff changeset
1225 {
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
1226 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
1227 size_t new_file_size = 1024 * 1024;
e2a73e64e8e6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 112
diff changeset
1228 Dowa_Arena *arena = Dowa_Arena_Create(1024 * 1024 * 2);
e2a73e64e8e6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 112
diff changeset
1229 char *new_file = Dowa_Arena_Allocate(arena, 1024 * 1024);
159
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
1230 char *title = Dowa_Arena_Allocate(arena, strlen(method) + strlen(url_input_text) + 2);
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
1231 sprintf(title, "%s %s", method, url_input_text);
114
e2a73e64e8e6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 112
diff changeset
1232 snprintf(
e2a73e64e8e6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 112
diff changeset
1233 new_file,
e2a73e64e8e6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 112
diff changeset
1234 new_file_size,
e2a73e64e8e6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 112
diff changeset
1235 "%s\n"
e2a73e64e8e6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 112
diff changeset
1236 "---\n"
e2a73e64e8e6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 112
diff changeset
1237 "%s\n"
e2a73e64e8e6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 112
diff changeset
1238 "---\n"
e2a73e64e8e6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 112
diff changeset
1239 "%s\n"
e2a73e64e8e6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 112
diff changeset
1240 "---\n"
e2a73e64e8e6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 112
diff changeset
1241 "%s\n"
e2a73e64e8e6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 112
diff changeset
1242 "---\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
1243 "%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
1244 "---\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
1245 "%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
1246 "---\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
1247 "%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
1248 "---\n"
114
e2a73e64e8e6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 112
diff changeset
1249 "%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
1250 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
1251 url_input_text,
114
e2a73e64e8e6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 112
diff changeset
1252 method,
155
3bb45eb67906 [Postdog] Updated variables names and padding sizes. Needs more work.
June Park <parkjune1995@gmail.com>
parents: 153
diff changeset
1253 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
1254 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
1255 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
1256 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
1257 result_text
114
e2a73e64e8e6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 112
diff changeset
1258 );
e2a73e64e8e6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 112
diff changeset
1259 char *filename = Dowa_Arena_Allocate(arena, 1024);
e2a73e64e8e6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 112
diff changeset
1260 if (!filename)
e2a73e64e8e6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 112
diff changeset
1261 {
e2a73e64e8e6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 112
diff changeset
1262 perror("Error opening file");
159
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
1263 exit(EXIT_FAILURE);
114
e2a73e64e8e6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 112
diff changeset
1264 }
e2a73e64e8e6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 112
diff changeset
1265 char *uuid4 = (char *)Dowa_Arena_Allocate(arena, 37);
e2a73e64e8e6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 112
diff changeset
1266 if (!uuid4)
e2a73e64e8e6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 112
diff changeset
1267 {
e2a73e64e8e6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 112
diff changeset
1268 perror("Error uuid");
159
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
1269 exit(EXIT_FAILURE);
114
e2a73e64e8e6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 112
diff changeset
1270 }
159
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
1271
114
e2a73e64e8e6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 112
diff changeset
1272 int32 seed = (uint32)time(NULL) ^ counter++;
e2a73e64e8e6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 112
diff changeset
1273 Dowa_String_UUID(seed, uuid4);
e2a73e64e8e6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 112
diff changeset
1274 snprintf(filename, 1024, "%s.txt", uuid4);
e2a73e64e8e6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 112
diff changeset
1275 PostDog_History_CreateFile(filename, new_file);
e2a73e64e8e6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 112
diff changeset
1276
117
b91f2dd6f84d [PostDog] Fixed delete logic.
June Park <parkjune1995@gmail.com>
parents: 116
diff changeset
1277 HistoryItem item = {0};
b91f2dd6f84d [PostDog] Fixed delete logic.
June Park <parkjune1995@gmail.com>
parents: 116
diff changeset
1278 item.filename = strdup(filename);
159
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
1279 item.title = strdup(title);
117
b91f2dd6f84d [PostDog] Fixed delete logic.
June Park <parkjune1995@gmail.com>
parents: 116
diff changeset
1280 item.deleted = FALSE;
159
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
1281
114
e2a73e64e8e6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 112
diff changeset
1282 Dowa_Array_Push(new_history_items, item);
e2a73e64e8e6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 112
diff changeset
1283 Dowa_Arena_Free(arena);
112
d6d578b49a19 [PostDog] Got CRUD working.
June Park <parkjune1995@gmail.com>
parents: 111
diff changeset
1284 }
54
b3e82d22f961 [PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1285
159
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
1286 void PostDog_Websocket_Listen(void)
54
b3e82d22f961 [PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1287 {
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
1288 while (TRUE)
54
b3e82d22f961 [PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1289 {
153
790930d9bb90 [PostDog] Adding websocket to be more usable.
June Park <parkjune1995@gmail.com>
parents: 152
diff changeset
1290 if (WS_BREAK) break;
790930d9bb90 [PostDog] Adding websocket to be more usable.
June Park <parkjune1995@gmail.com>
parents: 152
diff changeset
1291
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
1292 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
1293 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
1294 {
7387eec8e7f8 [Postdog] Updated to use Seobeo_Client instead of CURL. Updated to handle websocket connection.
June Park <parkjune1995@gmail.com>
parents: 118
diff changeset
1295 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
1296 {
159
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
1297 printf("Response: %.*s\n", (int)p_msg->length, (char*)p_msg->data);
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
1298 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
1299 "\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
1300 }
7387eec8e7f8 [Postdog] Updated to use Seobeo_Client instead of CURL. Updated to handle websocket connection.
June Park <parkjune1995@gmail.com>
parents: 118
diff changeset
1301 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
1302 }
7387eec8e7f8 [Postdog] Updated to use Seobeo_Client instead of CURL. Updated to handle websocket connection.
June Park <parkjune1995@gmail.com>
parents: 118
diff changeset
1303 usleep(10000);
159
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
1304 printf("Listening\n");
54
b3e82d22f961 [PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1305 }
159
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
1306 return;
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
1307 }
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
1308
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
1309 void PostDog_Websocket_Connect(void)
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
1310 {
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
1311 ws = Seobeo_WebSocket_Connect(url_input_text);
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
1312 memset(result_text, 0, strlen(result_text));
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
1313 }
54
b3e82d22f961 [PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1314
159
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
1315 int PostDog_Websocket_Send(void)
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
1316 {
159
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
1317 if (Seobeo_WebSocket_Send_Text(ws, input_body_array[active_input_tab]) < 0)
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
1318 snprintf(result_text + strlen(result_text), RESULT_BUFFER_LENGTH - strlen(result_text),
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
1319 "Failed to send message\n");
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
1320 else
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
1321 snprintf(result_text + strlen(result_text), RESULT_BUFFER_LENGTH - strlen(result_text),
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
1322 "\n%s", input_body_array[active_input_tab]);
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
1323 }
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
1324
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
1325 void PostDog_Websocket_Destroy(pthread_t thread_id)
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
1326 {
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
1327 Seobeo_WebSocket_Destroy(ws);
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
1328 pthread_detach(thread_id);
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
1329 }
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
1330
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
1331 void *PostDog_Websocket_Start(void *arg)
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
1332 {
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
1333 PostDog_Websocket_Connect();
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
1334 PostDog_Websocket_Listen();
153
790930d9bb90 [PostDog] Adding websocket to be more usable.
June Park <parkjune1995@gmail.com>
parents: 152
diff changeset
1335 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
1336 }
54
b3e82d22f961 [PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1337
159
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
1338 pthread_t PostDog_Websocket_Start_Thread()
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
1339 {
7387eec8e7f8 [Postdog] Updated to use Seobeo_Client instead of CURL. Updated to handle websocket connection.
June Park <parkjune1995@gmail.com>
parents: 118
diff changeset
1340 pthread_t thread_id;
159
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
1341
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
1342 if (pthread_create(&thread_id, NULL, PostDog_Websocket_Start, NULL) != 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
1343 {
7387eec8e7f8 [Postdog] Updated to use Seobeo_Client instead of CURL. Updated to handle websocket connection.
June Park <parkjune1995@gmail.com>
parents: 118
diff changeset
1344 perror("Failed to create thread");
159
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
1345 return 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
1346 }
159
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
1347
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
1348 return thread_id;
54
b3e82d22f961 [PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1349 }
b3e82d22f961 [PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1350
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
1351 int PostDog_Http_Request(void)
54
b3e82d22f961 [PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1352 {
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
1353 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
1354 Seobeo_Client_Response *res;
159
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
1355 switch (active_method_dropdown)
54
b3e82d22f961 [PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1356 {
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
1357 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
1358 {
7387eec8e7f8 [Postdog] Updated to use Seobeo_Client instead of CURL. Updated to handle websocket connection.
June Park <parkjune1995@gmail.com>
parents: 118
diff changeset
1359 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
1360 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
1361 }
159
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
1362 case 1:
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
1363 {
7387eec8e7f8 [Postdog] Updated to use Seobeo_Client instead of CURL. Updated to handle websocket connection.
June Park <parkjune1995@gmail.com>
parents: 118
diff changeset
1364 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
1365 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
1366 }
7387eec8e7f8 [Postdog] Updated to use Seobeo_Client instead of CURL. Updated to handle websocket connection.
June Park <parkjune1995@gmail.com>
parents: 118
diff changeset
1367 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
1368 {
7387eec8e7f8 [Postdog] Updated to use Seobeo_Client instead of CURL. Updated to handle websocket connection.
June Park <parkjune1995@gmail.com>
parents: 118
diff changeset
1369 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
1370 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
1371 }
7387eec8e7f8 [Postdog] Updated to use Seobeo_Client instead of CURL. Updated to handle websocket connection.
June Park <parkjune1995@gmail.com>
parents: 118
diff changeset
1372 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
1373 {
7387eec8e7f8 [Postdog] Updated to use Seobeo_Client instead of CURL. Updated to handle websocket connection.
June Park <parkjune1995@gmail.com>
parents: 118
diff changeset
1374 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
1375 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
1376 }
54
b3e82d22f961 [PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1377 }
b3e82d22f961 [PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1378
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
1379 {
155
3bb45eb67906 [Postdog] Updated variables names and padding sizes. Needs more work.
June Park <parkjune1995@gmail.com>
parents: 153
diff changeset
1380 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
1381 {
155
3bb45eb67906 [Postdog] Updated variables names and padding sizes. Needs more work.
June Park <parkjune1995@gmail.com>
parents: 153
diff changeset
1382 char *headersCopy = strdup(input_body_array[TAB_HEADER]);
54
b3e82d22f961 [PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1383 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
1384 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
1385 {
54
b3e82d22f961 [PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1386 while (*line == ' ' || *line == '\t') line++;
114
e2a73e64e8e6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 112
diff changeset
1387 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
1388 Seobeo_Client_Request_Add_Header_Array(req, line);
54
b3e82d22f961 [PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1389 line = strtok(NULL, "\n");
b3e82d22f961 [PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1390 }
b3e82d22f961 [PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1391
159
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
1392 }
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
1393 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
1394 res = Seobeo_Client_Request_Execute(req);
54
b3e82d22f961 [PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1395
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
1396 if (res == NULL)
155
3bb45eb67906 [Postdog] Updated variables names and padding sizes. Needs more work.
June Park <parkjune1995@gmail.com>
parents: 153
diff changeset
1397 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
1398 else
155
3bb45eb67906 [Postdog] Updated variables names and padding sizes. Needs more work.
June Park <parkjune1995@gmail.com>
parents: 153
diff changeset
1399 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
1400 res->status_code, res->body ? res->body : "");
54
b3e82d22f961 [PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1401 }
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
1402 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
1403 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
1404 PostDog_Request_SaveFile();
54
b3e82d22f961 [PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1405 return 0;
b3e82d22f961 [PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1406 }
b3e82d22f961 [PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1407
159
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
1408 void *PostDog_Http_Thread(void *arg)
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
1409 {
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
1410 PostDog_Http_Request();
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
1411 printf("HTTP request finished.\n");
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
1412 LOADING = FALSE;
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
1413 return NULL;
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
1414 }
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
1415
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
1416 void PostDog_Http_Thread_Request()
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
1417 {
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
1418 pthread_t thread_id;
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
1419 LOADING = TRUE;
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
1420 if (pthread_create(&thread_id, NULL, PostDog_Http_Thread, NULL) != 0)
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
1421 {
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
1422 perror("Failed to create thread");
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
1423 return;
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
1424 }
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
1425 pthread_detach(thread_id);
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
1426 }
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
1427
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
1428 void PostDog_Update_URL(void)
112
d6d578b49a19 [PostDog] Got CRUD working.
June Park <parkjune1995@gmail.com>
parents: 111
diff changeset
1429 {
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
1430 // Save existing query string if present
112
d6d578b49a19 [PostDog] Got CRUD working.
June Park <parkjune1995@gmail.com>
parents: 111
diff changeset
1431 char *question_mark = strchr(url_input_text, '?');
d6d578b49a19 [PostDog] Got CRUD working.
June Park <parkjune1995@gmail.com>
parents: 111
diff changeset
1432 if (question_mark)
d6d578b49a19 [PostDog] Got CRUD working.
June Park <parkjune1995@gmail.com>
parents: 111
diff changeset
1433 *question_mark = '\0';
d6d578b49a19 [PostDog] Got CRUD working.
June Park <parkjune1995@gmail.com>
parents: 111
diff changeset
1434
155
3bb45eb67906 [Postdog] Updated variables names and padding sizes. Needs more work.
June Park <parkjune1995@gmail.com>
parents: 153
diff changeset
1435 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
1436 if (get_params_length == 0)
d6d578b49a19 [PostDog] Got CRUD working.
June Park <parkjune1995@gmail.com>
parents: 111
diff changeset
1437 return;
d6d578b49a19 [PostDog] Got CRUD working.
June Park <parkjune1995@gmail.com>
parents: 111
diff changeset
1438
d6d578b49a19 [PostDog] Got CRUD working.
June Park <parkjune1995@gmail.com>
parents: 111
diff changeset
1439 char *separator = "?";
d6d578b49a19 [PostDog] Got CRUD working.
June Park <parkjune1995@gmail.com>
parents: 111
diff changeset
1440
d6d578b49a19 [PostDog] Got CRUD working.
June Park <parkjune1995@gmail.com>
parents: 111
diff changeset
1441 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
1442 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
1443 for (int i = 0; i < Dowa_Array_Length(lines); i++)
d6d578b49a19 [PostDog] Got CRUD working.
June Park <parkjune1995@gmail.com>
parents: 111
diff changeset
1444 {
d6d578b49a19 [PostDog] Got CRUD working.
June Park <parkjune1995@gmail.com>
parents: 111
diff changeset
1445 char *line = lines[i];
d6d578b49a19 [PostDog] Got CRUD working.
June Park <parkjune1995@gmail.com>
parents: 111
diff changeset
1446 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
1447
d6d578b49a19 [PostDog] Got CRUD working.
June Park <parkjune1995@gmail.com>
parents: 111
diff changeset
1448 if (Dowa_Array_Length(key_value) < 2)
114
e2a73e64e8e6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 112
diff changeset
1449 break;
112
d6d578b49a19 [PostDog] Got CRUD working.
June Park <parkjune1995@gmail.com>
parents: 111
diff changeset
1450
d6d578b49a19 [PostDog] Got CRUD working.
June Park <parkjune1995@gmail.com>
parents: 111
diff changeset
1451 strcat(url_input_text, separator);
d6d578b49a19 [PostDog] Got CRUD working.
June Park <parkjune1995@gmail.com>
parents: 111
diff changeset
1452 strcat(url_input_text, key_value[0]);
d6d578b49a19 [PostDog] Got CRUD working.
June Park <parkjune1995@gmail.com>
parents: 111
diff changeset
1453 strcat(url_input_text, "=");
d6d578b49a19 [PostDog] Got CRUD working.
June Park <parkjune1995@gmail.com>
parents: 111
diff changeset
1454 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
1455 {
d6d578b49a19 [PostDog] Got CRUD working.
June Park <parkjune1995@gmail.com>
parents: 111
diff changeset
1456 if (!key_value[i] || key_value[i][0] == '\0')
d6d578b49a19 [PostDog] Got CRUD working.
June Park <parkjune1995@gmail.com>
parents: 111
diff changeset
1457 break;
d6d578b49a19 [PostDog] Got CRUD working.
June Park <parkjune1995@gmail.com>
parents: 111
diff changeset
1458 if (i > 1) strcat(url_input_text, "%20");
d6d578b49a19 [PostDog] Got CRUD working.
June Park <parkjune1995@gmail.com>
parents: 111
diff changeset
1459 strcat(url_input_text, key_value[i]);
d6d578b49a19 [PostDog] Got CRUD working.
June Park <parkjune1995@gmail.com>
parents: 111
diff changeset
1460 }
d6d578b49a19 [PostDog] Got CRUD working.
June Park <parkjune1995@gmail.com>
parents: 111
diff changeset
1461 separator = "&";
d6d578b49a19 [PostDog] Got CRUD working.
June Park <parkjune1995@gmail.com>
parents: 111
diff changeset
1462 }
d6d578b49a19 [PostDog] Got CRUD working.
June Park <parkjune1995@gmail.com>
parents: 111
diff changeset
1463
d6d578b49a19 [PostDog] Got CRUD working.
June Park <parkjune1995@gmail.com>
parents: 111
diff changeset
1464 Dowa_Arena_Free(arena);
d6d578b49a19 [PostDog] Got CRUD working.
June Park <parkjune1995@gmail.com>
parents: 111
diff changeset
1465 }
d6d578b49a19 [PostDog] Got CRUD working.
June Park <parkjune1995@gmail.com>
parents: 111
diff changeset
1466
114
e2a73e64e8e6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 112
diff changeset
1467 int PostDog_String_To_MethodEnum(char *value)
e2a73e64e8e6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 112
diff changeset
1468 {
e2a73e64e8e6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 112
diff changeset
1469 if (strstr(value, "GET"))
e2a73e64e8e6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 112
diff changeset
1470 return 0;
e2a73e64e8e6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 112
diff changeset
1471 if (strstr(value, "POST"))
e2a73e64e8e6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 112
diff changeset
1472 return 1;
e2a73e64e8e6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 112
diff changeset
1473 if (strstr(value, "PUT"))
e2a73e64e8e6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 112
diff changeset
1474 return 2;
e2a73e64e8e6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 112
diff changeset
1475 if (strstr(value, "DELETE"))
e2a73e64e8e6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 112
diff changeset
1476 return 3;
e2a73e64e8e6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 112
diff changeset
1477 return 0;
e2a73e64e8e6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 112
diff changeset
1478 }
e2a73e64e8e6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 112
diff changeset
1479
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
1480 void PostDog_Params_Reset(void)
114
e2a73e64e8e6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 112
diff changeset
1481 {
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
1482 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
1483 result_text[0] = '\0';
114
e2a73e64e8e6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 112
diff changeset
1484 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
1485 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
1486 input_body_array[i][0] = '\0';
159
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
1487
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
1488 // Reset text area states when clearing
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
1489 GuiTextAreaResetAllStates();
114
e2a73e64e8e6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 112
diff changeset
1490 }
e2a73e64e8e6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 112
diff changeset
1491
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
1492 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
1493 {
114
e2a73e64e8e6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 112
diff changeset
1494 char full_file_path[512] = {0};
e2a73e64e8e6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 112
diff changeset
1495 snprintf(full_file_path, 512, "%s/%s", POSTDOG_PATHS, filename);
e2a73e64e8e6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 112
diff changeset
1496 FILE *file = fopen(full_file_path, "r");
e2a73e64e8e6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 112
diff changeset
1497 if (!file)
e2a73e64e8e6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 112
diff changeset
1498 return;
e2a73e64e8e6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 112
diff changeset
1499
e2a73e64e8e6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 112
diff changeset
1500 fseek(file, 0, SEEK_END);
e2a73e64e8e6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 112
diff changeset
1501 size_t file_size = ftell(file);
e2a73e64e8e6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 112
diff changeset
1502 fseek(file, 0, SEEK_SET);
e2a73e64e8e6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 112
diff changeset
1503
e2a73e64e8e6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 112
diff changeset
1504 Dowa_Arena *init_arena = Dowa_Arena_Create(file_size + 2);
e2a73e64e8e6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 112
diff changeset
1505 Dowa_Arena *split_arena = Dowa_Arena_Create(file_size * 2);
e2a73e64e8e6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 112
diff changeset
1506 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
1507 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
1508 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
1509
114
e2a73e64e8e6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 112
diff changeset
1510 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
1511
114
e2a73e64e8e6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 112
diff changeset
1512 for (int i = 0; i < Dowa_Array_Length(values); i++)
e2a73e64e8e6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 112
diff changeset
1513 {
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
1514 switch (i)
114
e2a73e64e8e6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 112
diff changeset
1515 {
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
1516 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
1517 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
1518
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
1519 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
1520 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
1521 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
1522 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
1523
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
1524 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
1525 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
1526 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
1527
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
1528 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
1529 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
1530 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
1531 case 6: // Websocket (TAB_WEBSOCKET)
114
e2a73e64e8e6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 112
diff changeset
1532 {
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
1533 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
1534 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
1535 // 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
1536 for (int j = strlen(values[i]); j > 0; j--)
114
e2a73e64e8e6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 112
diff changeset
1537 {
155
3bb45eb67906 [Postdog] Updated variables names and padding sizes. Needs more work.
June Park <parkjune1995@gmail.com>
parents: 153
diff changeset
1538 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
1539 {
155
3bb45eb67906 [Postdog] Updated variables names and padding sizes. Needs more work.
June Park <parkjune1995@gmail.com>
parents: 153
diff changeset
1540 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
1541 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
1542 }
114
e2a73e64e8e6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 112
diff changeset
1543 }
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
1544 break;
114
e2a73e64e8e6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 112
diff changeset
1545 }
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
1546
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
1547 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
1548 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
1549 break;
114
e2a73e64e8e6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 112
diff changeset
1550 }
e2a73e64e8e6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 112
diff changeset
1551 }
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
1552
159
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
1553 // Reset text area states when loading new file
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
1554 GuiTextAreaResetAllStates();
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
1555
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
1556 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
1557 Dowa_Arena_Free(split_arena);
114
e2a73e64e8e6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 112
diff changeset
1558 }
e2a73e64e8e6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 112
diff changeset
1559
e2a73e64e8e6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 112
diff changeset
1560 Rectangle AddPadding(Rectangle rect, float padding)
e2a73e64e8e6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 112
diff changeset
1561 {
115
96db6c3f38d6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 114
diff changeset
1562 return (Rectangle){
114
e2a73e64e8e6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 112
diff changeset
1563 rect.x + padding,
e2a73e64e8e6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 112
diff changeset
1564 rect.y + padding,
e2a73e64e8e6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 112
diff changeset
1565 rect.width - (2 * padding),
e2a73e64e8e6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 112
diff changeset
1566 rect.height - (2 * padding)
e2a73e64e8e6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 112
diff changeset
1567 };
e2a73e64e8e6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 112
diff changeset
1568 }
e2a73e64e8e6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 112
diff changeset
1569
155
3bb45eb67906 [Postdog] Updated variables names and padding sizes. Needs more work.
June Park <parkjune1995@gmail.com>
parents: 153
diff changeset
1570 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
1571 {
3bb45eb67906 [Postdog] Updated variables names and padding sizes. Needs more work.
June Park <parkjune1995@gmail.com>
parents: 153
diff changeset
1572 return (Rectangle){
3bb45eb67906 [Postdog] Updated variables names and padding sizes. Needs more work.
June Park <parkjune1995@gmail.com>
parents: 153
diff changeset
1573 rect.x + left,
3bb45eb67906 [Postdog] Updated variables names and padding sizes. Needs more work.
June Park <parkjune1995@gmail.com>
parents: 153
diff changeset
1574 rect.y + top,
3bb45eb67906 [Postdog] Updated variables names and padding sizes. Needs more work.
June Park <parkjune1995@gmail.com>
parents: 153
diff changeset
1575 rect.width - (right + left),
3bb45eb67906 [Postdog] Updated variables names and padding sizes. Needs more work.
June Park <parkjune1995@gmail.com>
parents: 153
diff changeset
1576 rect.height - (top + down),
3bb45eb67906 [Postdog] Updated variables names and padding sizes. Needs more work.
June Park <parkjune1995@gmail.com>
parents: 153
diff changeset
1577 };
3bb45eb67906 [Postdog] Updated variables names and padding sizes. Needs more work.
June Park <parkjune1995@gmail.com>
parents: 153
diff changeset
1578 }
3bb45eb67906 [Postdog] Updated variables names and padding sizes. Needs more work.
June Park <parkjune1995@gmail.com>
parents: 153
diff changeset
1579
3bb45eb67906 [Postdog] Updated variables names and padding sizes. Needs more work.
June Park <parkjune1995@gmail.com>
parents: 153
diff changeset
1580
3bb45eb67906 [Postdog] Updated variables names and padding sizes. Needs more work.
June Park <parkjune1995@gmail.com>
parents: 153
diff changeset
1581
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
1582 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
1583 {
7bd795bac997 [Postdog] Added scrollable area to inputs and history files, buttons to delete and view.
June Park <parkjune1995@gmail.com>
parents: 115
diff changeset
1584 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
1585 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
1586 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
1587 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
1588 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
1589 };
7bd795bac997 [Postdog] Added scrollable area to inputs and history files, buttons to delete and view.
June Park <parkjune1995@gmail.com>
parents: 115
diff changeset
1590 }
7bd795bac997 [Postdog] Added scrollable area to inputs and history files, buttons to delete and view.
June Park <parkjune1995@gmail.com>
parents: 115
diff changeset
1591
7bd795bac997 [Postdog] Added scrollable area to inputs and history files, buttons to delete and view.
June Park <parkjune1995@gmail.com>
parents: 115
diff changeset
1592 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
1593 {
7bd795bac997 [Postdog] Added scrollable area to inputs and history files, buttons to delete and view.
June Park <parkjune1995@gmail.com>
parents: 115
diff changeset
1594 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
1595 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
1596 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
1597 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
1598 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
1599 };
7bd795bac997 [Postdog] Added scrollable area to inputs and history files, buttons to delete and view.
June Park <parkjune1995@gmail.com>
parents: 115
diff changeset
1600 }
7bd795bac997 [Postdog] Added scrollable area to inputs and history files, buttons to delete and view.
June Park <parkjune1995@gmail.com>
parents: 115
diff changeset
1601
115
96db6c3f38d6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 114
diff changeset
1602 // Layout helper functions
96db6c3f38d6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 114
diff changeset
1603 Rectangle RightOf(Rectangle ref, float padding)
96db6c3f38d6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 114
diff changeset
1604 {
96db6c3f38d6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 114
diff changeset
1605 return (Rectangle){
96db6c3f38d6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 114
diff changeset
1606 .x = ref.x + ref.width + padding,
96db6c3f38d6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 114
diff changeset
1607 .y = ref.y,
96db6c3f38d6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 114
diff changeset
1608 .width = 0,
96db6c3f38d6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 114
diff changeset
1609 .height = ref.height
96db6c3f38d6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 114
diff changeset
1610 };
96db6c3f38d6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 114
diff changeset
1611 }
96db6c3f38d6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 114
diff changeset
1612
96db6c3f38d6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 114
diff changeset
1613 Rectangle Below(Rectangle ref, float padding)
96db6c3f38d6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 114
diff changeset
1614 {
96db6c3f38d6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 114
diff changeset
1615 return (Rectangle){
96db6c3f38d6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 114
diff changeset
1616 .x = ref.x,
96db6c3f38d6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 114
diff changeset
1617 .y = ref.y + ref.height + padding,
96db6c3f38d6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 114
diff changeset
1618 .width = ref.width,
96db6c3f38d6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 114
diff changeset
1619 .height = 0
96db6c3f38d6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 114
diff changeset
1620 };
96db6c3f38d6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 114
diff changeset
1621 }
96db6c3f38d6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 114
diff changeset
1622
96db6c3f38d6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 114
diff changeset
1623 Rectangle LeftColumn(Rectangle container, float ratio, float padding)
96db6c3f38d6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 114
diff changeset
1624 {
96db6c3f38d6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 114
diff changeset
1625 return (Rectangle){
96db6c3f38d6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 114
diff changeset
1626 .x = container.x + padding,
96db6c3f38d6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 114
diff changeset
1627 .y = container.y + padding,
96db6c3f38d6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 114
diff changeset
1628 .width = (container.width * ratio) - padding,
96db6c3f38d6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 114
diff changeset
1629 .height = container.height - (2 * padding)
96db6c3f38d6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 114
diff changeset
1630 };
96db6c3f38d6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 114
diff changeset
1631 }
96db6c3f38d6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 114
diff changeset
1632
96db6c3f38d6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 114
diff changeset
1633 Rectangle RightColumn(Rectangle container, Rectangle leftCol, float padding)
96db6c3f38d6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 114
diff changeset
1634 {
96db6c3f38d6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 114
diff changeset
1635 return (Rectangle){
96db6c3f38d6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 114
diff changeset
1636 .x = leftCol.x + leftCol.width + padding,
96db6c3f38d6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 114
diff changeset
1637 .y = container.y + padding,
96db6c3f38d6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 114
diff changeset
1638 .width = container.width - leftCol.width - (3 * padding),
96db6c3f38d6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 114
diff changeset
1639 .height = container.height - (2 * padding)
96db6c3f38d6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 114
diff changeset
1640 };
96db6c3f38d6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 114
diff changeset
1641 }
96db6c3f38d6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 114
diff changeset
1642
96db6c3f38d6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 114
diff changeset
1643 Rectangle HorizontalSplit(Rectangle container, float ratio)
96db6c3f38d6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 114
diff changeset
1644 {
96db6c3f38d6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 114
diff changeset
1645 return (Rectangle){
96db6c3f38d6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 114
diff changeset
1646 .x = container.x,
96db6c3f38d6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 114
diff changeset
1647 .y = container.y,
96db6c3f38d6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 114
diff changeset
1648 .width = container.width * ratio,
96db6c3f38d6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 114
diff changeset
1649 .height = container.height
96db6c3f38d6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 114
diff changeset
1650 };
96db6c3f38d6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 114
diff changeset
1651 }
96db6c3f38d6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 114
diff changeset
1652
54
b3e82d22f961 [PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1653 int main()
b3e82d22f961 [PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1654 {
111
48f260576059 [PostDog] Rewriting it from scratch as it is unreadable for me.
June Park <parkjune1995@gmail.com>
parents: 63
diff changeset
1655 // -- initizlied --//
48f260576059 [PostDog] Rewriting it from scratch as it is unreadable for me.
June Park <parkjune1995@gmail.com>
parents: 63
diff changeset
1656 InitWindow(SCREEN_WIDTH, SCREEN_HEIGHT, "PostDog");
54
b3e82d22f961 [PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1657 SetWindowState(FLAG_WINDOW_RESIZABLE);
b3e82d22f961 [PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1658 SetTargetFPS(60);
b3e82d22f961 [PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1659
114
e2a73e64e8e6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 112
diff changeset
1660 Font customFont = LoadFontEx("postdog/Roboto-Regular.ttf", 20, 0, 0);
e2a73e64e8e6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 112
diff changeset
1661 GuiSetFont(customFont);
153
790930d9bb90 [PostDog] Adding websocket to be more usable.
June Park <parkjune1995@gmail.com>
parents: 152
diff changeset
1662 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
1663 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
1664 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
1665 SetWindowIcon(logo_original);
159
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
1666 Texture2D logo_texture = LoadTextureFromImage(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
1667 UnloadImage(logo_original);
114
e2a73e64e8e6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 112
diff changeset
1668
159
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
1669 // Arena for text area undo states
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
1670 g_text_area_arena = Dowa_Arena_Create(1024 * 1024 * 8); // 8MB for undo states
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
1671
111
48f260576059 [PostDog] Rewriting it from scratch as it is unreadable for me.
June Park <parkjune1995@gmail.com>
parents: 63
diff changeset
1672 // -- Starting pos ---//
155
3bb45eb67906 [Postdog] Updated variables names and padding sizes. Needs more work.
June Park <parkjune1995@gmail.com>
parents: 153
diff changeset
1673 Rectangle history_sidebar_rect = { 0 };
114
e2a73e64e8e6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 112
diff changeset
1674 Dowa_Array_Reserve(history_items, 10);
e2a73e64e8e6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 112
diff changeset
1675 Dowa_Array_Reserve(new_history_items, 10);
e2a73e64e8e6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 112
diff changeset
1676 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
1677 int32 *history_deleted_items = NULL;
54
b3e82d22f961 [PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1678
155
3bb45eb67906 [Postdog] Updated variables names and padding sizes. Needs more work.
June Park <parkjune1995@gmail.com>
parents: 153
diff changeset
1679 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
1680 Rectangle url_input_bounds_rect = { 0 };
114
e2a73e64e8e6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 112
diff changeset
1681 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
1682 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
1683 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
1684 Rectangle method_dropdown_rect = { 0 };
54
b3e82d22f961 [PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1685
114
e2a73e64e8e6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 112
diff changeset
1686
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
1687 // 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
1688 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
1689 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
1690
155
3bb45eb67906 [Postdog] Updated variables names and padding sizes. Needs more work.
June Park <parkjune1995@gmail.com>
parents: 153
diff changeset
1691 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
1692 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
1693 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
1694 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
1695
155
3bb45eb67906 [Postdog] Updated variables names and padding sizes. Needs more work.
June Park <parkjune1995@gmail.com>
parents: 153
diff changeset
1696 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
1697 snprintf(input_body_array[TAB_BODY], HEADER_BUFFER_LENGTH, "");
112
d6d578b49a19 [PostDog] Got CRUD working.
June Park <parkjune1995@gmail.com>
parents: 111
diff changeset
1698
155
3bb45eb67906 [Postdog] Updated variables names and padding sizes. Needs more work.
June Park <parkjune1995@gmail.com>
parents: 153
diff changeset
1699 result_text = (char *)malloc(sizeof(char) * RESULT_BUFFER_LENGTH);
159
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
1700 result_text[0] = '\0';
112
d6d578b49a19 [PostDog] Got CRUD working.
June Park <parkjune1995@gmail.com>
parents: 111
diff changeset
1701
d6d578b49a19 [PostDog] Got CRUD working.
June Park <parkjune1995@gmail.com>
parents: 111
diff changeset
1702 bool method_edit = false;
d6d578b49a19 [PostDog] Got CRUD working.
June Park <parkjune1995@gmail.com>
parents: 111
diff changeset
1703
111
48f260576059 [PostDog] Rewriting it from scratch as it is unreadable for me.
June Park <parkjune1995@gmail.com>
parents: 63
diff changeset
1704 int sendRequest;
54
b3e82d22f961 [PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1705
112
d6d578b49a19 [PostDog] Got CRUD working.
June Park <parkjune1995@gmail.com>
parents: 111
diff changeset
1706 // -- input --//
155
3bb45eb67906 [Postdog] Updated variables names and padding sizes. Needs more work.
June Park <parkjune1995@gmail.com>
parents: 153
diff changeset
1707 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
1708 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
1709 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
1710 Rectangle input_body_rect = { 0 };
159
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
1711 bool input_body_edit_mode = false;
54
b3e82d22f961 [PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1712
112
d6d578b49a19 [PostDog] Got CRUD working.
June Park <parkjune1995@gmail.com>
parents: 111
diff changeset
1713 // -- result --//
155
3bb45eb67906 [Postdog] Updated variables names and padding sizes. Needs more work.
June Park <parkjune1995@gmail.com>
parents: 153
diff changeset
1714 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
1715 Rectangle result_body_rect = { 0 };
159
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
1716 bool result_body_edit_mode = false;
54
b3e82d22f961 [PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1717
111
48f260576059 [PostDog] Rewriting it from scratch as it is unreadable for me.
June Park <parkjune1995@gmail.com>
parents: 63
diff changeset
1718 // General styling.
114
e2a73e64e8e6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 112
diff changeset
1719 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
1720 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
1721
7bd795bac997 [Postdog] Added scrollable area to inputs and history files, buttons to delete and view.
June Park <parkjune1995@gmail.com>
parents: 115
diff changeset
1722 // 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
1723 float history_scroll_offset = 0;
54
b3e82d22f961 [PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1724
b3e82d22f961 [PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1725 while (!WindowShouldClose())
b3e82d22f961 [PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1726 {
111
48f260576059 [PostDog] Rewriting it from scratch as it is unreadable for me.
June Park <parkjune1995@gmail.com>
parents: 63
diff changeset
1727 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
1728 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
1729
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
1730 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
1731 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
1732
7bd795bac997 [Postdog] Added scrollable area to inputs and history files, buttons to delete and view.
June Park <parkjune1995@gmail.com>
parents: 115
diff changeset
1733 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
1734 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
1735
155
3bb45eb67906 [Postdog] Updated variables names and padding sizes. Needs more work.
June Park <parkjune1995@gmail.com>
parents: 153
diff changeset
1736 Rectangle screen_rect = { 0, 0, screen_width, screen_height };
114
e2a73e64e8e6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 112
diff changeset
1737
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
1738 // -- Side bar --//
155
3bb45eb67906 [Postdog] Updated variables names and padding sizes. Needs more work.
June Park <parkjune1995@gmail.com>
parents: 153
diff changeset
1739 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
1740 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
1741 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
1742 .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
1743 .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
1744 .width = history_sidebar_rect.width,
159
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
1745 .height = 80
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
1746 };
115
96db6c3f38d6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 114
diff changeset
1747
155
3bb45eb67906 [Postdog] Updated variables names and padding sizes. Needs more work.
June Park <parkjune1995@gmail.com>
parents: 153
diff changeset
1748 Rectangle history_list_area_rect = Below(logo_area_rect, padding);
159
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
1749 history_list_area_rect.x += padding;
155
3bb45eb67906 [Postdog] Updated variables names and padding sizes. Needs more work.
June Park <parkjune1995@gmail.com>
parents: 153
diff changeset
1750 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
1751 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
1752
114
e2a73e64e8e6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 112
diff changeset
1753 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
1754 int32 history_item_length = Dowa_Array_Length(history_items);
115
96db6c3f38d6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 114
diff changeset
1755 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
1756 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
1757
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
1758 int32 number_of_skipped_items = 0;
114
e2a73e64e8e6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 112
diff changeset
1759 for (int i = 0; i < total; i++)
e2a73e64e8e6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 112
diff changeset
1760 {
115
96db6c3f38d6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 114
diff changeset
1761 HistoryItem *curr_history_items = i < new_history_items_length ?
159
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
1762 &new_history_items[new_history_items_length - i - 1] : &history_items[i - new_history_items_length];
115
96db6c3f38d6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 114
diff changeset
1763
117
b91f2dd6f84d [PostDog] Fixed delete logic.
June Park <parkjune1995@gmail.com>
parents: 116
diff changeset
1764 if (curr_history_items->deleted)
b91f2dd6f84d [PostDog] Fixed delete logic.
June Park <parkjune1995@gmail.com>
parents: 116
diff changeset
1765 {
b91f2dd6f84d [PostDog] Fixed delete logic.
June Park <parkjune1995@gmail.com>
parents: 116
diff changeset
1766 number_of_skipped_items++;
b91f2dd6f84d [PostDog] Fixed delete logic.
June Park <parkjune1995@gmail.com>
parents: 116
diff changeset
1767 continue;
b91f2dd6f84d [PostDog] Fixed delete logic.
June Park <parkjune1995@gmail.com>
parents: 116
diff changeset
1768 }
b91f2dd6f84d [PostDog] Fixed delete logic.
June Park <parkjune1995@gmail.com>
parents: 116
diff changeset
1769
115
96db6c3f38d6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 114
diff changeset
1770 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
1771 .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
1772 .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
1773 .width = history_list_area_rect.width,
115
96db6c3f38d6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 114
diff changeset
1774 .height = item_height
96db6c3f38d6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 114
diff changeset
1775 };
114
e2a73e64e8e6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 112
diff changeset
1776 }
54
b3e82d22f961 [PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1777
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
1778 // --- URL --- //
155
3bb45eb67906 [Postdog] Updated variables names and padding sizes. Needs more work.
June Park <parkjune1995@gmail.com>
parents: 153
diff changeset
1779 url_area_rect = (Rectangle){
3bb45eb67906 [Postdog] Updated variables names and padding sizes. Needs more work.
June Park <parkjune1995@gmail.com>
parents: 153
diff changeset
1780 .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
1781 .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
1782 .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
1783 .height = content_area_rect.height * 0.1
115
96db6c3f38d6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 114
diff changeset
1784 };
54
b3e82d22f961 [PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1785
155
3bb45eb67906 [Postdog] Updated variables names and padding sizes. Needs more work.
June Park <parkjune1995@gmail.com>
parents: 153
diff changeset
1786 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
1787
155
3bb45eb67906 [Postdog] Updated variables names and padding sizes. Needs more work.
June Park <parkjune1995@gmail.com>
parents: 153
diff changeset
1788 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
1789 .x = url_area_rect.x + padding,
115
96db6c3f38d6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 114
diff changeset
1790 .y = url_control_y,
96db6c3f38d6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 114
diff changeset
1791 .width = 7 * (TEXT_SIZE / 2),
96db6c3f38d6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 114
diff changeset
1792 .height = TEXT_SIZE * 2
96db6c3f38d6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 114
diff changeset
1793 };
96db6c3f38d6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 114
diff changeset
1794
155
3bb45eb67906 [Postdog] Updated variables names and padding sizes. Needs more work.
June Park <parkjune1995@gmail.com>
parents: 153
diff changeset
1795 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
1796 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
1797 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
1798
155
3bb45eb67906 [Postdog] Updated variables names and padding sizes. Needs more work.
June Park <parkjune1995@gmail.com>
parents: 153
diff changeset
1799 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
1800 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
1801 url_enter_button_rect.height = TEXT_SIZE * 2;
54
b3e82d22f961 [PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1802
155
3bb45eb67906 [Postdog] Updated variables names and padding sizes. Needs more work.
June Park <parkjune1995@gmail.com>
parents: 153
diff changeset
1803 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
1804 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
1805 method_dropdown_rect.height = TEXT_SIZE * 2;
112
d6d578b49a19 [PostDog] Got CRUD working.
June Park <parkjune1995@gmail.com>
parents: 111
diff changeset
1806
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
1807 // -- Body -- //
155
3bb45eb67906 [Postdog] Updated variables names and padding sizes. Needs more work.
June Park <parkjune1995@gmail.com>
parents: 153
diff changeset
1808 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
1809 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
1810
155
3bb45eb67906 [Postdog] Updated variables names and padding sizes. Needs more work.
June Park <parkjune1995@gmail.com>
parents: 153
diff changeset
1811 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
1812 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
1813 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
1814
155
3bb45eb67906 [Postdog] Updated variables names and padding sizes. Needs more work.
June Park <parkjune1995@gmail.com>
parents: 153
diff changeset
1815 input_tab_rect = (Rectangle){
3bb45eb67906 [Postdog] Updated variables names and padding sizes. Needs more work.
June Park <parkjune1995@gmail.com>
parents: 153
diff changeset
1816 .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
1817 .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
1818 .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
1819 .height = input_area_rect.height * 0.1
115
96db6c3f38d6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 114
diff changeset
1820 };
96db6c3f38d6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 114
diff changeset
1821
155
3bb45eb67906 [Postdog] Updated variables names and padding sizes. Needs more work.
June Park <parkjune1995@gmail.com>
parents: 153
diff changeset
1822 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
1823 input_tab_item_rect.width = input_tab_rect.width / 4;
54
b3e82d22f961 [PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1824
155
3bb45eb67906 [Postdog] Updated variables names and padding sizes. Needs more work.
June Park <parkjune1995@gmail.com>
parents: 153
diff changeset
1825 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
1826 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
1827 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
1828
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
1829 // -- Result -- /
155
3bb45eb67906 [Postdog] Updated variables names and padding sizes. Needs more work.
June Park <parkjune1995@gmail.com>
parents: 153
diff changeset
1830 result_body_rect = (Rectangle){
3bb45eb67906 [Postdog] Updated variables names and padding sizes. Needs more work.
June Park <parkjune1995@gmail.com>
parents: 153
diff changeset
1831 .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
1832 .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
1833 .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
1834 .height = input_body_rect.height
115
96db6c3f38d6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 114
diff changeset
1835 };
54
b3e82d22f961 [PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1836
114
e2a73e64e8e6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 112
diff changeset
1837 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
1838 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
1839
159
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
1840 // Reset text area state 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
1841 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
1842 {
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
1843 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
1844 }
7bd795bac997 [Postdog] Added scrollable area to inputs and history files, buttons to delete and view.
June Park <parkjune1995@gmail.com>
parents: 115
diff changeset
1845
7bd795bac997 [Postdog] Added scrollable area to inputs and history files, buttons to delete and view.
June Park <parkjune1995@gmail.com>
parents: 115
diff changeset
1846 // 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
1847 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
1848 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
1849 // Clamp scroll offset
155
3bb45eb67906 [Postdog] Updated variables names and padding sizes. Needs more work.
June Park <parkjune1995@gmail.com>
parents: 153
diff changeset
1850 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
1851 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
1852 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
1853 }
7bd795bac997 [Postdog] Added scrollable area to inputs and history files, buttons to delete and view.
June Park <parkjune1995@gmail.com>
parents: 115
diff changeset
1854
159
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
1855 // Reset
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
1856 SetMouseCursor(MOUSE_CURSOR_DEFAULT);
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
1857
159
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
1858 // TODO: Move all for loop rect up here so it does not flicker.
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
1859 if (
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
1860 InArea(mouse_position, result_area_rect) ||
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
1861 InArea(mouse_position, input_tab_rect) ||
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
1862 InArea(mouse_position, url_input_bounds_rect) ||
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
1863 InArea(mouse_position, url_enter_button_rect) ||
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
1864 InArea(mouse_position, method_dropdown_rect) ||
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
1865 InArea(mouse_position, logo_area_rect)
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
1866 )
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
1867 SetMouseCursor(MOUSE_CURSOR_POINTING_HAND);
114
e2a73e64e8e6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 112
diff changeset
1868
159
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
1869 if (Clicked(mouse_position, logo_area_rect))
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
1870 PostDog_Params_Reset();
54
b3e82d22f961 [PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1871 BeginDrawing();
b3e82d22f961 [PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1872 ClearBackground(GetColor(GuiGetStyle(DEFAULT, BACKGROUND_COLOR)));
b3e82d22f961 [PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1873
155
3bb45eb67906 [Postdog] Updated variables names and padding sizes. Needs more work.
June Park <parkjune1995@gmail.com>
parents: 153
diff changeset
1874 // 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
1875 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
1876
155
3bb45eb67906 [Postdog] Updated variables names and padding sizes. Needs more work.
June Park <parkjune1995@gmail.com>
parents: 153
diff changeset
1877 // 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
1878 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
1879 // 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
1880 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
1881 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
1882 .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
1883 .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
1884 .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
1885 .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
1886 };
7bd795bac997 [Postdog] Added scrollable area to inputs and history files, buttons to delete and view.
June Park <parkjune1995@gmail.com>
parents: 115
diff changeset
1887
155
3bb45eb67906 [Postdog] Updated variables names and padding sizes. Needs more work.
June Park <parkjune1995@gmail.com>
parents: 153
diff changeset
1888 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
1889 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
1890
155
3bb45eb67906 [Postdog] Updated variables names and padding sizes. Needs more work.
June Park <parkjune1995@gmail.com>
parents: 153
diff changeset
1891 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
1892 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
1893 {
159
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
1894 HistoryItem *curr_history_items = i < new_history_items_length ?
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
1895 &new_history_items[new_history_items_length - i - 1] : &history_items[i - new_history_items_length];
117
b91f2dd6f84d [PostDog] Fixed delete logic.
June Park <parkjune1995@gmail.com>
parents: 116
diff changeset
1896
b91f2dd6f84d [PostDog] Fixed delete logic.
June Park <parkjune1995@gmail.com>
parents: 116
diff changeset
1897 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
1898 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
1899
155
3bb45eb67906 [Postdog] Updated variables names and padding sizes. Needs more work.
June Park <parkjune1995@gmail.com>
parents: 153
diff changeset
1900 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
1901 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
1902 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
1903
159
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
1904 filename_area_rect.height -= diff;
155
3bb45eb67906 [Postdog] Updated variables names and padding sizes. Needs more work.
June Park <parkjune1995@gmail.com>
parents: 153
diff changeset
1905 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
1906 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
1907
155
3bb45eb67906 [Postdog] Updated variables names and padding sizes. Needs more work.
June Park <parkjune1995@gmail.com>
parents: 153
diff changeset
1908 // 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
1909 // 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
1910 // 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
1911
7bd795bac997 [Postdog] Added scrollable area to inputs and history files, buttons to delete and view.
June Park <parkjune1995@gmail.com>
parents: 115
diff changeset
1912 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
1913 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
1914
159
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
1915 filename_area_rect.y += 2*padding;
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
1916 GuiDrawText(curr_history_items->title, AddPadding(filename_area_rect, padding), TEXT_ALIGN_CENTER, BLACK);
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
1917 if (
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
1918 InArea(mouse_position, icon_area_left_column) ||
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
1919 InArea(mouse_position, icon_area_right_column)
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
1920 )
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
1921 SetMouseCursor(MOUSE_CURSOR_POINTING_HAND);
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
1922
155
3bb45eb67906 [Postdog] Updated variables names and padding sizes. Needs more work.
June Park <parkjune1995@gmail.com>
parents: 153
diff changeset
1923 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
1924 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
1925 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
1926 {
7bd795bac997 [Postdog] Added scrollable area to inputs and history files, buttons to delete and view.
June Park <parkjune1995@gmail.com>
parents: 115
diff changeset
1927 if (!remove(PostDog_Construct_URL(curr_history_items->filename)))
117
b91f2dd6f84d [PostDog] Fixed delete logic.
June Park <parkjune1995@gmail.com>
parents: 116
diff changeset
1928 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
1929 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
1930 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
1931 }
7bd795bac997 [Postdog] Added scrollable area to inputs and history files, buttons to delete and view.
June Park <parkjune1995@gmail.com>
parents: 115
diff changeset
1932 }
7bd795bac997 [Postdog] Added scrollable area to inputs and history files, buttons to delete and view.
June Park <parkjune1995@gmail.com>
parents: 115
diff changeset
1933 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
1934
7bd795bac997 [Postdog] Added scrollable area to inputs and history files, buttons to delete and view.
June Park <parkjune1995@gmail.com>
parents: 115
diff changeset
1935 if (total > 0)
114
e2a73e64e8e6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 112
diff changeset
1936 {
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
1937 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
1938 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
1939 {
155
3bb45eb67906 [Postdog] Updated variables names and padding sizes. Needs more work.
June Park <parkjune1995@gmail.com>
parents: 153
diff changeset
1940 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
1941 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
1942 Rectangle scrollbar_rect = {
3bb45eb67906 [Postdog] Updated variables names and padding sizes. Needs more work.
June Park <parkjune1995@gmail.com>
parents: 153
diff changeset
1943 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
1944 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
1945 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
1946 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
1947 };
155
3bb45eb67906 [Postdog] Updated variables names and padding sizes. Needs more work.
June Park <parkjune1995@gmail.com>
parents: 153
diff changeset
1948 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
1949 }
114
e2a73e64e8e6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 112
diff changeset
1950 }
54
b3e82d22f961 [PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1951
111
48f260576059 [PostDog] Rewriting it from scratch as it is unreadable for me.
June Park <parkjune1995@gmail.com>
parents: 63
diff changeset
1952 // URL area Rect
159
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
1953 GuiDrawText("URL: ", url_text_bounds_rect, TEXT_ALIGN_CENTER, BLACK);
155
3bb45eb67906 [Postdog] Updated variables names and padding sizes. Needs more work.
June Park <parkjune1995@gmail.com>
parents: 153
diff changeset
1954 DrawRectangleRec(url_area_rect, Fade(BLACK, 0.1f));
159
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
1955
155
3bb45eb67906 [Postdog] Updated variables names and padding sizes. Needs more work.
June Park <parkjune1995@gmail.com>
parents: 153
diff changeset
1956 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
1957 url_input_edit = !url_input_edit;
e2a73e64e8e6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 112
diff changeset
1958
159
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
1959 if (url_input_edit)
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
1960 {
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
1961 if (IsKeyPressed(KEY_ENTER))
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
1962 {
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
1963 PostDog_Http_Thread_Request();
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
1964 url_input_edit = !url_input_edit;
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
1965 }
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
1966 }
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
1967
155
3bb45eb67906 [Postdog] Updated variables names and padding sizes. Needs more work.
June Park <parkjune1995@gmail.com>
parents: 153
diff changeset
1968 sendRequest = GuiButton(url_enter_button_rect, "ENTER");
112
d6d578b49a19 [PostDog] Got CRUD working.
June Park <parkjune1995@gmail.com>
parents: 111
diff changeset
1969 if (sendRequest)
159
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
1970 PostDog_Http_Thread_Request();
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
1971
155
3bb45eb67906 [Postdog] Updated variables names and padding sizes. Needs more work.
June Park <parkjune1995@gmail.com>
parents: 153
diff changeset
1972 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
1973 method_edit = !method_edit;
54
b3e82d22f961 [PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1974
111
48f260576059 [PostDog] Rewriting it from scratch as it is unreadable for me.
June Park <parkjune1995@gmail.com>
parents: 63
diff changeset
1975 // Input Tabs Rect
155
3bb45eb67906 [Postdog] Updated variables names and padding sizes. Needs more work.
June Park <parkjune1995@gmail.com>
parents: 153
diff changeset
1976 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
1977 DrawRectangleRec(input_tab_rect, Fade(DARKBLUE, 0.1f));
112
d6d578b49a19 [PostDog] Got CRUD working.
June Park <parkjune1995@gmail.com>
parents: 111
diff changeset
1978 GuiSetStyle(TOGGLE, GROUP_PADDING, 0);
159
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
1979
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
1980 int text_area_id = TEXT_AREA_ID_INPUT_HEADER + active_input_tab;
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
1981 if (GuiTextArea(text_area_id, input_body_rect, input_body_array[active_input_tab],
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
1982 BODY_BUFFER_LENGTH, input_body_edit_mode, TRUE, g_text_area_arena))
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
1983 input_body_edit_mode = !input_body_edit_mode;
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
1984
159
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
1985 if (active_input_tab != TAB_WEBSOCKET)
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
1986 {
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
1987 WS_BREAK = TRUE;
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
1988 if (websocket_thread_id)
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
1989 PostDog_Websocket_Destroy(websocket_thread_id);
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
1990 }
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
1991 else
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
1992 {
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
1993 WS_BREAK = FALSE;
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
1994 Rectangle temp = {
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
1995 .x = input_body_rect.x + input_body_rect.width - (3 * padding) - 100,
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
1996 .y = input_body_rect.y + input_body_rect.height - (3 * padding) - 20,
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
1997 .width = 100,
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
1998 .height = 40
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
1999 };
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
2000 if (GuiButton(temp, "Send") || (input_body_edit_mode && IsKeyDown(KEY_LEFT_SHIFT) && IsKeyDown(KEY_ENTER)))
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
2001 {
159
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
2002 if (!ws)
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
2003 websocket_thread_id = PostDog_Websocket_Start_Thread();
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
2004 usleep(10000);
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
2005 PostDog_Websocket_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
2006 }
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
2007 }
7bd795bac997 [Postdog] Added scrollable area to inputs and history files, buttons to delete and view.
June Park <parkjune1995@gmail.com>
parents: 115
diff changeset
2008
159
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
2009
155
3bb45eb67906 [Postdog] Updated variables names and padding sizes. Needs more work.
June Park <parkjune1995@gmail.com>
parents: 153
diff changeset
2010 GuiToggleGroup(input_tab_item_rect, "Header;Body;Get Param;Websocket", &active_input_tab);
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
2011 PostDog_Update_URL();
54
b3e82d22f961 [PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff changeset
2012
159
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
2013 // TODO: Add animations.
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
2014 DrawRectangleRec(result_area_rect, LOADING ? Fade(RED, 0.1f) : Fade(GREEN, 0.1f));
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
2015 boolean result_toggle = GuiTextArea(TEXT_AREA_ID_RESULT, result_body_rect, result_text,
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
2016 RESULT_BUFFER_LENGTH, result_body_edit_mode, TRUE, g_text_area_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
2017
159
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
2018 GuiToggleGroup(input_tab_item_rect, "Header;Body;Get Param;Websocket", &active_input_tab);
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
2019 if (result_toggle)
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
2020 result_body_edit_mode = !result_body_edit_mode;
114
e2a73e64e8e6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 112
diff changeset
2021
54
b3e82d22f961 [PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff changeset
2022 EndDrawing();
b3e82d22f961 [PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff changeset
2023 }
159
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
2024
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
2025 GuiTextAreaResetAllStates();
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
2026 Dowa_Arena_Free(g_text_area_arena);
54
b3e82d22f961 [PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff changeset
2027 CloseWindow();
b3e82d22f961 [PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff changeset
2028 return 0;
b3e82d22f961 [PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff changeset
2029 }