annotate postdog/main.c @ 161:87d8d3eb3491

[PostDog] WIP to make it more mordern looking
author June Park <parkjune1995@gmail.com>
date Thu, 15 Jan 2026 08:29:26 -0800
parents 05cf9467a1c3
children 058de208e640
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>
161
87d8d3eb3491 [PostDog] WIP to make it more mordern looking
June Park <parkjune1995@gmail.com>
parents: 159
diff changeset
6 #include <uv.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
7387eec8e7f8 [Postdog] Updated to use Seobeo_Client instead of CURL. Updated to handle websocket connection.
June Park <parkjune1995@gmail.com>
parents: 118
diff changeset
21 #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
22 #include "seobeo/seobeo.h"
161
87d8d3eb3491 [PostDog] WIP to make it more mordern looking
June Park <parkjune1995@gmail.com>
parents: 159
diff changeset
23 #include "third_party/raylib/include/raylib.h"
87d8d3eb3491 [PostDog] WIP to make it more mordern looking
June Park <parkjune1995@gmail.com>
parents: 159
diff changeset
24 #include "third_party/raylib/include/raygui.h"
87d8d3eb3491 [PostDog] WIP to make it more mordern looking
June Park <parkjune1995@gmail.com>
parents: 159
diff changeset
25 #include "third_party/raylib/custom.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
26
114
e2a73e64e8e6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 112
diff changeset
27 #ifndef POSTDOG_PATHS
e2a73e64e8e6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 112
diff changeset
28 #define POSTDOG_PATHS "/Users/mrjunejune/zenbu/postdog/history"
e2a73e64e8e6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 112
diff changeset
29 #endif
e2a73e64e8e6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 112
diff changeset
30
54
b3e82d22f961 [PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff changeset
31 #define SCREEN_WIDTH 1280
b3e82d22f961 [PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff changeset
32 #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
33 #define MAX_SCROLL_HEIGHT 10000
54
b3e82d22f961 [PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff changeset
34
112
d6d578b49a19 [PostDog] Got CRUD working.
June Park <parkjune1995@gmail.com>
parents: 111
diff changeset
35 #define HEADER_BUFFER_LENGTH 1024 * 4
d6d578b49a19 [PostDog] Got CRUD working.
June Park <parkjune1995@gmail.com>
parents: 111
diff changeset
36 #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
37 #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
38 #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
39 #define RESULT_BUFFER_LENGTH 1024 * 1024 * 5
112
d6d578b49a19 [PostDog] Got CRUD working.
June Park <parkjune1995@gmail.com>
parents: 111
diff changeset
40
161
87d8d3eb3491 [PostDog] WIP to make it more mordern looking
June Park <parkjune1995@gmail.com>
parents: 159
diff changeset
41 #define URL_TEXT_DEFAULT "https://httpbin.org/get"
87d8d3eb3491 [PostDog] WIP to make it more mordern looking
June Park <parkjune1995@gmail.com>
parents: 159
diff changeset
42 #define HEADER_TEXT_DEFAULT "Content-Type: application/json"
87d8d3eb3491 [PostDog] WIP to make it more mordern looking
June Park <parkjune1995@gmail.com>
parents: 159
diff changeset
43 #define BODY_TEXT_DEFAULT ""
87d8d3eb3491 [PostDog] WIP to make it more mordern looking
June Park <parkjune1995@gmail.com>
parents: 159
diff changeset
44 #define GET_PARAM_TEXT_DEFAULT "foo bar"
87d8d3eb3491 [PostDog] WIP to make it more mordern looking
June Park <parkjune1995@gmail.com>
parents: 159
diff changeset
45
159
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
46 // ============================================================================
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
47 // 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
48 // ============================================================================
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
49
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_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
51 #define TEXT_AREA_LINE_HEIGHT 20
161
87d8d3eb3491 [PostDog] WIP to make it more mordern looking
June Park <parkjune1995@gmail.com>
parents: 159
diff changeset
52 #define TEXT_AREA_PADDING 30
159
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
53 #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
54 #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
55 #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
56
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
57 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
58 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
59 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
60 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
61 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
62 } TextAreaUndoEntry;
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
63
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
64 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
65 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
66 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
67 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
68 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
69 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
70 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
71 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
72 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
73
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
74 // 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
75 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
76 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
77
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
78 // 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
79 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
80 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
81 } TextAreaState;
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
82
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 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
84 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
85 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
86 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
87
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
88 // 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
89 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
90 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
91 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
92 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
93
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
94 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
95 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
96 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
97 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
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 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
101 }
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
102
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
103 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
104 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
105 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
106 }
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
107
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
108 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
109 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
110 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
111 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
112 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
113 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
114 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
115 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
116 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
117 }
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
118
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
119 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
120 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
121 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
122 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
123 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
124 line++;
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
125 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
126 } else {
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
127 column++;
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
128 }
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 *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
131 *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
132 }
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
133
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
134 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
135 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
136 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
137 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
138
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
139 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
140 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
141 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
142 }
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
143 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
144 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
145 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
146 }
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_line++;
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
148 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
149 } else {
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
150 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
151 }
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
152 i++;
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 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
155 }
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
156
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
157 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
158 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
159 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
160 i--;
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 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
163 }
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
164
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
165 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
166 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
167 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
168 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
169 i++;
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 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
172 }
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
173
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
174 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
175 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
176 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
177 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
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 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
180 }
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 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
183 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
184
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
185 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
186 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
187 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
188 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
189
161
87d8d3eb3491 [PostDog] WIP to make it more mordern looking
June Park <parkjune1995@gmail.com>
parents: 159
diff changeset
190 return MeasureTextEx(GuiGetFont(), temp, font_size, TEXT_SIZE_DEFAULT/GuiGetStyle(DEFAULT, TEXT_SIZE)).x;
159
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
191 }
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
192
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
193 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
194 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
195 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
196
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
197 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
198 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
199 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
200
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 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
202
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
203 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
204 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
205 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
206
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
207 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
208 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
209 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
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 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
212 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
213
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
214 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
215 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
216 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
217 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
218 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
219 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
220 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
221 break;
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
222 }
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
223 }
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
224
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
225 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
226 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
227 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
228 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
229
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
230 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
231 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
232 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
233 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
234 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
235 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
236 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
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 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
240 }
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
241
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
242 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
243 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
244 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
245 continue;
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
246 }
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
247 }
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
248
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
249 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
250 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
251 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
252 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
253 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
254 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
255
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
256 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
257 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
258 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
259 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
260 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
261 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
262 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
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 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
266 }
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 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
269 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
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 i++;
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 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
276 }
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
277
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
278 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
279 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
280 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
281 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
282 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
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 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
285 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
286 }
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 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
289 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
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 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
292 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
293
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
294 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
295 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
296 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
297 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
298 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
299 }
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
300
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
301 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
302 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
303 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
304 } 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
305 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
306 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
307 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
308 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
309 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
310 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
311 break;
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
312 }
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
313 }
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
314
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
315 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
316 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
317 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
318 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
319 }
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 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
322 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
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 }
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
325 }
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
326
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
327 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
328 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
329 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
330 }
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
331
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
332 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
333 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
334 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
335
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
336 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
337 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
338 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
339 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
340
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
341 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
342 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
343 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
344 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
345 } 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
346 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
347 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
348 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
349 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
350 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
351 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
352 break;
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
353 }
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 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
356 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
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 }
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 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
362 }
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
363
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
364 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
365 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
366 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
367 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
368 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
369 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
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 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
372 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
373 }
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 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
376 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
377
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
378 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
379 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
380 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
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 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
383 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
384 }
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
385 }
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 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
388 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
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 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
391 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
392
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
393 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
394 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
395 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
396 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
397 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
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 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
400 }
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 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
403 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
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 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
406 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
407
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
408 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
409 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
410 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
411 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
412 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
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 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
415 }
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
416
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
417 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
418 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
419 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
420 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
421
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
422 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
423 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
424 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
425 }
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
426
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
427 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
428 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
429 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
430
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
431 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
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 *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
434 }
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
435
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
436 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
437 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
438 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
439 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
440 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
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 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
443 }
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 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
446 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
447
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
448 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
449 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
450 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
451 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
452 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
453 }
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
454
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
455 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
456 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
457 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
458
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
459 // 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
460 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
461 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
462 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
463 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
464 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
465 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
466 }
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
467
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
468 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
469 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
470 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
471
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
472 // 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
473 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
474 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
475 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
476 } 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
477 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
478 }
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
479 }
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
480
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
481 // 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
482 float content_height = GetContentHeight(text, bounds, should_text_wrap,
161
87d8d3eb3491 [PostDog] WIP to make it more mordern looking
June Park <parkjune1995@gmail.com>
parents: 159
diff changeset
483 GuiGetStyle(DEFAULT, TEXT_SIZE), TEXT_AREA_LINE_HEIGHT);
159
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
484 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
485 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
486
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
487 // 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
488 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
489 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
490 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
491 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
492 }
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
493
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
494 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
495 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
496 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
497 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
498 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
499
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
500 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
501 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
502 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
503 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
504 }
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
505
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
506 // 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
507 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
508 int click_pos = GetCharIndexFromPos(text, bounds, mouse_pos, should_text_wrap,
161
87d8d3eb3491 [PostDog] WIP to make it more mordern looking
June Park <parkjune1995@gmail.com>
parents: 159
diff changeset
509 state->scroll_offset_y, GuiGetStyle(DEFAULT, TEXT_SIZE),
159
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
510 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
511 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
512 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
513 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
514 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
515 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
516 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
517 }
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
518
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
519 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
520 int drag_pos = GetCharIndexFromPos(text, bounds, mouse_pos, should_text_wrap,
161
87d8d3eb3491 [PostDog] WIP to make it more mordern looking
June Park <parkjune1995@gmail.com>
parents: 159
diff changeset
521 state->scroll_offset_y, GuiGetStyle(DEFAULT, TEXT_SIZE),
159
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
522 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
523 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
524 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
525 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
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 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
528 }
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
529 }
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
530
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 (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
532 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
533 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
534 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
535 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
536 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_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
538 }
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
539 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
540 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
541 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
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 }
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
544 }
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
545
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
546 // 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
547 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
548 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
549 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
550 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
551 }
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
552
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
553 // 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
554 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
555 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
556 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
557 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
558 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
559 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
560 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
561 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
562 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
563 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
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 }
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
566 }
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
567
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
568 // 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
569 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
570 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
571 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
572 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
573 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
574 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
575 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
576 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
577 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
578 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
579 }
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
580
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
581 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
582 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
583 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
584 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
585 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
586 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
587 }
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
588 }
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
589
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
590 // 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
591 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
592 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
593 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
594 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
595 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
596 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
597 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
598 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
599 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
600 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
601 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
602 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
603 } else {
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
604 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
605 }
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
606
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
607 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
608 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
609 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
610 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
611 }
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
612 }
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
613
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
614 // 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
615 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
616 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
617 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
618 } else {
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
619 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
620 }
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
621 }
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
622
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
623 // 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
624 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
625 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
626 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
627 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
628 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
629 } 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
630 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
631 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
632 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
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 }
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 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
637 } else {
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_pos--;
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
639 }
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 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
642 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
643 }
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
644
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
645 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
646 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
647 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
648 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
649 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
650 } 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
651 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
652 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
653 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
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 }
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 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
658 } else {
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_pos++;
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
660 }
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 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
663 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
664 }
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
665
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 (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
667 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
668 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
669 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
670 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
671 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
672 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
673 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
674 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
675 }
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 = 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
677 } else {
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->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
679 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
680 }
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->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
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 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
684 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
685 }
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
686
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
687 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
688 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
689 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
690 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
691 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
692 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
693 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
694 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
695 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
696 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
697 }
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 = 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
699 } else {
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->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
701 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
702 }
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->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
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 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
706 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
707 }
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
708
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
709 // 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
710 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
711 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
712 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
713 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
714 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
715 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
716 }
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 = 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
718 } else {
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->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
720 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
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 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
723 }
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
724
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 (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
726 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
727 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
728 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
729 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
730 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
731 }
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 = 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
733 } else {
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->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
735 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
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 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
738 }
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
739
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
740 // 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
741 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
742 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
743 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
744 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
745 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
746 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
747 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
748 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
749 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
750 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
751 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
752 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
753 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
754 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
755 } 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
756 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
757 }
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
758
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
759 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
760 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
761 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
762 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
763 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
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 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
766 }
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
767 }
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
768
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
769 // 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
770 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
771 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
772 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
773 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
774 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
775 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
776 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
777 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
778 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
779 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
780 } else {
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
781 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
782 }
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
783
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
784 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
785 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
786 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
787 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
788 }
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
789
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
790 // Backspace
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
791 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
792 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
793 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
794 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
795 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
796 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
797 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
798 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
799 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
800 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
801 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
802 } 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
803 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
804 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
805 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
806 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
807 }
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
808 }
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
809
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
810 // 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
811 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
812 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
813 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
814 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
815 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
816 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
817 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
818 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
819 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
820 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
821 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
822 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
823 } 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
824 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
825 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
826 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
827 }
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
828 }
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
829
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
830 // 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
831 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
832 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
833 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
834 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
835 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
836 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
837 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
838 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
839 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
840 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
841 } else {
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
842 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
843 }
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
844
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
845 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
846 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
847 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
848 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
849 }
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
850
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
851 // 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
852 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
853 should_text_wrap, state->scroll_offset_y,
161
87d8d3eb3491 [PostDog] WIP to make it more mordern looking
June Park <parkjune1995@gmail.com>
parents: 159
diff changeset
854 GuiGetStyle(DEFAULT, TEXT_SIZE), TEXT_AREA_LINE_HEIGHT);
159
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 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
857 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
858
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
859 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
860 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
861 } 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
862 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
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 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
866 }
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
867
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
868 // Drawing
161
87d8d3eb3491 [PostDog] WIP to make it more mordern looking
June Park <parkjune1995@gmail.com>
parents: 159
diff changeset
869 DrawRectangleRounded(bounds, 0.2, 1, is_edit_mode ? DARKGRAY : (Color){40, 40, 40, 255});
87d8d3eb3491 [PostDog] WIP to make it more mordern looking
June Park <parkjune1995@gmail.com>
parents: 159
diff changeset
870 // DrawRectangleRec(bounds, is_edit_mode ? DARKGRAY : (Color){40, 40, 40, 255});
87d8d3eb3491 [PostDog] WIP to make it more mordern looking
June Park <parkjune1995@gmail.com>
parents: 159
diff changeset
871 // DrawRectangleLinesEx(bounds, 1, is_edit_mode ? WHITE : GRAY);
87d8d3eb3491 [PostDog] WIP to make it more mordern looking
June Park <parkjune1995@gmail.com>
parents: 159
diff changeset
872 DrawRectangleRoundedLines(bounds, 0.2, 1, is_edit_mode ? WHITE : GRAY);
159
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
873
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
874 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
875
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
876 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
877 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
878 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
879
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
880 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
881
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
882 // 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
883 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
884 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
885 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
886 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
887
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
888 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
889 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
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 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
892 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
893 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
894 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
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 if (should_text_wrap && !is_end && !is_newline) {
161
87d8d3eb3491 [PostDog] WIP to make it more mordern looking
June Park <parkjune1995@gmail.com>
parents: 159
diff changeset
897 int line_width = MeasureTextRange(text, line_char_start, i + 1, GuiGetStyle(DEFAULT, TEXT_SIZE));
159
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 (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
899 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
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 }
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
902
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
903 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
904 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
905
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
906 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
907 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
908 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
909
161
87d8d3eb3491 [PostDog] WIP to make it more mordern looking
June Park <parkjune1995@gmail.com>
parents: 159
diff changeset
910 float x1 = content_x + MeasureTextRange(text, line_char_start, highlight_start, GuiGetStyle(DEFAULT, TEXT_SIZE));
87d8d3eb3491 [PostDog] WIP to make it more mordern looking
June Park <parkjune1995@gmail.com>
parents: 159
diff changeset
911 float x2 = content_x + MeasureTextRange(text, line_char_start, highlight_end, GuiGetStyle(DEFAULT, TEXT_SIZE));
159
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
912 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
913
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
914 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
915 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
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 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
919 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
920 }
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
921 }
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
922 }
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 // 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
925 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
926 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
927 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
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 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
930 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
931 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
932 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
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 if (!is_end && !is_newline) {
161
87d8d3eb3491 [PostDog] WIP to make it more mordern looking
June Park <parkjune1995@gmail.com>
parents: 159
diff changeset
935 int line_width = MeasureTextRange(text, line_char_start, i + 1, GuiGetStyle(DEFAULT, TEXT_SIZE));
159
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 (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
937 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
938 }
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
939 }
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
940
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
941 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
942 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
943 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
944 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
945 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
946
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
947 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
948 .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
949 .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
950 };
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
951 DrawTextEx(GuiGetFont(), line_buffer, draw_text_vector,
161
87d8d3eb3491 [PostDog] WIP to make it more mordern looking
June Park <parkjune1995@gmail.com>
parents: 159
diff changeset
952 GuiGetStyle(DEFAULT, TEXT_SIZE), TEXT_SIZE_DEFAULT/GuiGetStyle(DEFAULT, TEXT_SIZE), WHITE);
159
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
953
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
954 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
955 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
956 } 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
957 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
958 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
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 }
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
961 } else {
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
962 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
963 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
964
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
965 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
966 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
967 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
968 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
969 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
970 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
971 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
972
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
973 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
974 .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
975 .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
976 };
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
977 DrawTextEx(GuiGetFont(), line_buffer, draw_text_vector ,
161
87d8d3eb3491 [PostDog] WIP to make it more mordern looking
June Park <parkjune1995@gmail.com>
parents: 159
diff changeset
978 GuiGetStyle(DEFAULT, TEXT_SIZE), TEXT_SIZE_DEFAULT/GuiGetStyle(DEFAULT, TEXT_SIZE), WHITE);
159
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 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
981 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
982 }
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
983 }
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
984 }
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
985
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
986 // 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
987 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
988 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
989 should_text_wrap, state->scroll_offset_y,
161
87d8d3eb3491 [PostDog] WIP to make it more mordern looking
June Park <parkjune1995@gmail.com>
parents: 159
diff changeset
990 GuiGetStyle(DEFAULT, TEXT_SIZE), TEXT_AREA_LINE_HEIGHT);
159
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
991
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
992 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
993 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
994 }
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
995
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
996 EndScissorMode();
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
997
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
998 // 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
999 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
1000 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
1001 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
1002 (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
1003
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
1004 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
1005 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
1006 }
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
1007
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
1008 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
1009 }
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
1010
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
1011 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
1012 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
1013 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
1014 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
1015 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
1016 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
1017 }
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
1018 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
1019 }
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
1020 }
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
1021
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
1022 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
1023 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
1024 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
1025 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
1026 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
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 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
1029 }
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
1030 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
1031 }
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
1032
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
1033 // ============================================================================
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
1034 // 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
1035 // ============================================================================
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
1036
112
d6d578b49a19 [PostDog] Got CRUD working.
June Park <parkjune1995@gmail.com>
parents: 111
diff changeset
1037 typedef Dowa_KV(char*, char*) INPUT_HASHMAP;
d6d578b49a19 [PostDog] Got CRUD working.
June Park <parkjune1995@gmail.com>
parents: 111
diff changeset
1038
54
b3e82d22f961 [PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1039 typedef struct {
b3e82d22f961 [PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1040 char *data;
b3e82d22f961 [PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1041 size_t size;
b3e82d22f961 [PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1042 } ResponseBuffer;
b3e82d22f961 [PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1043
b3e82d22f961 [PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1044 typedef struct {
114
e2a73e64e8e6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 112
diff changeset
1045 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
1046 char *title;
114
e2a73e64e8e6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 112
diff changeset
1047 Rectangle rect;
e2a73e64e8e6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 112
diff changeset
1048 long time_modified;
117
b91f2dd6f84d [PostDog] Fixed delete logic.
June Park <parkjune1995@gmail.com>
parents: 116
diff changeset
1049 boolean deleted;
54
b3e82d22f961 [PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1050 } HistoryItem;
b3e82d22f961 [PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1051
114
e2a73e64e8e6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 112
diff changeset
1052 typedef struct {
e2a73e64e8e6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 112
diff changeset
1053 Rectangle rectangle;
e2a73e64e8e6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 112
diff changeset
1054 char *label;
e2a73e64e8e6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 112
diff changeset
1055 bool active;
e2a73e64e8e6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 112
diff changeset
1056 } TabItem;
e2a73e64e8e6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 112
diff changeset
1057
e2a73e64e8e6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 112
diff changeset
1058 typedef enum {
e2a73e64e8e6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 112
diff changeset
1059 TAB_HEADER = 0,
e2a73e64e8e6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 112
diff changeset
1060 TAB_BODY,
e2a73e64e8e6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 112
diff changeset
1061 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
1062 TAB_WEBSOCKET,
114
e2a73e64e8e6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 112
diff changeset
1063 TAB_LENGTH
e2a73e64e8e6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 112
diff changeset
1064 } PostDog_Tab_Enum;
e2a73e64e8e6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 112
diff changeset
1065
159
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
1066 // 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
1067 #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
1068 #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
1069 #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
1070 #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
1071 #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
1072
114
e2a73e64e8e6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 112
diff changeset
1073 static uint32 counter = 0;
161
87d8d3eb3491 [PostDog] WIP to make it more mordern looking
June Park <parkjune1995@gmail.com>
parents: 159
diff changeset
1074 static uv_mutex_t history_mutex;
87d8d3eb3491 [PostDog] WIP to make it more mordern looking
June Park <parkjune1995@gmail.com>
parents: 159
diff changeset
1075 static uv_loop_t *main_loop = NULL;
114
e2a73e64e8e6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 112
diff changeset
1076 HistoryItem *history_items = NULL;
e2a73e64e8e6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 112
diff changeset
1077 HistoryItem *new_history_items = NULL;
e2a73e64e8e6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 112
diff changeset
1078
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
1079 // 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
1080 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
1081 char *result_text = NULL;
3bb45eb67906 [Postdog] Updated variables names and padding sizes. Needs more work.
June Park <parkjune1995@gmail.com>
parents: 153
diff changeset
1082 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
1083 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
1084 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
1085 Seobeo_WebSocket *ws = NULL;
153
790930d9bb90 [PostDog] Adding websocket to be more usable.
June Park <parkjune1995@gmail.com>
parents: 152
diff changeset
1086 boolean WS_BREAK = FALSE;
161
87d8d3eb3491 [PostDog] WIP to make it more mordern looking
June Park <parkjune1995@gmail.com>
parents: 159
diff changeset
1087 uv_thread_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
1088 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
1089 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
1090
114
e2a73e64e8e6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 112
diff changeset
1091 int CompareHistoryItemsByDate(const void *a, const void *b) {
e2a73e64e8e6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 112
diff changeset
1092 HistoryItem *itemA = (HistoryItem *)a;
e2a73e64e8e6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 112
diff changeset
1093 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
1094 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
1095 }
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
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 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
1098 {
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 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
1100 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
1101 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
1102 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
1103 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
1104
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
1105 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
1106 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
1107 fclose(file);
161
87d8d3eb3491 [PostDog] WIP to make it more mordern looking
June Park <parkjune1995@gmail.com>
parents: 159
diff changeset
1108 free(title);
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
1109 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
1110 }
161
87d8d3eb3491 [PostDog] WIP to make it more mordern looking
June Park <parkjune1995@gmail.com>
parents: 159
diff changeset
1111 fclose(file);
87d8d3eb3491 [PostDog] WIP to make it more mordern looking
June Park <parkjune1995@gmail.com>
parents: 159
diff changeset
1112
87d8d3eb3491 [PostDog] WIP to make it more mordern looking
June Park <parkjune1995@gmail.com>
parents: 159
diff changeset
1113 // Strip trailing newline
87d8d3eb3491 [PostDog] WIP to make it more mordern looking
June Park <parkjune1995@gmail.com>
parents: 159
diff changeset
1114 title[strcspn(title, "\n")] = '\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
1115
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
1116 return title;
114
e2a73e64e8e6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 112
diff changeset
1117 }
e2a73e64e8e6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 112
diff changeset
1118
e2a73e64e8e6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 112
diff changeset
1119 // 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
1120 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
1121 {
e2a73e64e8e6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 112
diff changeset
1122 HistoryItem *file_arr = *p_file_arr;
e2a73e64e8e6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 112
diff changeset
1123 #ifdef _WIN32
e2a73e64e8e6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 112
diff changeset
1124 struct _finddata_t fileinfo;
e2a73e64e8e6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 112
diff changeset
1125 intptr_t handle;
e2a73e64e8e6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 112
diff changeset
1126 char search_path[256];
e2a73e64e8e6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 112
diff changeset
1127 sprintf(search_path, "%s\\*", path);
e2a73e64e8e6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 112
diff changeset
1128
e2a73e64e8e6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 112
diff changeset
1129 if ((handle = _findfirst(search_path, &fileinfo)) == -1L) {
e2a73e64e8e6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 112
diff changeset
1130 printf("Directory is empty or cannot be read.\n");
e2a73e64e8e6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 112
diff changeset
1131 } else {
e2a73e64e8e6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 112
diff changeset
1132 do {
e2a73e64e8e6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 112
diff changeset
1133 HistoryItem item = {0};
e2a73e64e8e6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 112
diff changeset
1134 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
1135 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
1136 item.time_modified = fileinfo.time_write;
117
b91f2dd6f84d [PostDog] Fixed delete logic.
June Park <parkjune1995@gmail.com>
parents: 116
diff changeset
1137 item.deleted = FALSE;
114
e2a73e64e8e6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 112
diff changeset
1138 Dowa_Array_Push(file_arr, item);
e2a73e64e8e6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 112
diff changeset
1139 } while (_findnext(handle, &fileinfo) == 0);
e2a73e64e8e6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 112
diff changeset
1140 _findclose(handle);
e2a73e64e8e6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 112
diff changeset
1141 }
e2a73e64e8e6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 112
diff changeset
1142 #else
e2a73e64e8e6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 112
diff changeset
1143 struct dirent *entry;
e2a73e64e8e6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 112
diff changeset
1144 struct stat file_stat;
e2a73e64e8e6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 112
diff changeset
1145 DIR *dp = opendir(path);
e2a73e64e8e6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 112
diff changeset
1146 if (dp == NULL) return;
e2a73e64e8e6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 112
diff changeset
1147
e2a73e64e8e6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 112
diff changeset
1148 char full_path[256];
e2a73e64e8e6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 112
diff changeset
1149 while ((entry = readdir(dp)))
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 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
1152 continue;
e2a73e64e8e6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 112
diff changeset
1153 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
1154 if (stat(full_path, &file_stat) == 0)
e2a73e64e8e6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 112
diff changeset
1155 {
e2a73e64e8e6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 112
diff changeset
1156 HistoryItem item = {0};
e2a73e64e8e6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 112
diff changeset
1157 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
1158 item.title = PostDog_Extract_Title(entry->d_name);
114
e2a73e64e8e6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 112
diff changeset
1159 item.time_modified = file_stat.st_mtime;
117
b91f2dd6f84d [PostDog] Fixed delete logic.
June Park <parkjune1995@gmail.com>
parents: 116
diff changeset
1160 item.deleted = FALSE;
114
e2a73e64e8e6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 112
diff changeset
1161 Dowa_Array_Push(file_arr, item);
e2a73e64e8e6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 112
diff changeset
1162 }
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 closedir(dp);
e2a73e64e8e6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 112
diff changeset
1165 #endif
161
87d8d3eb3491 [PostDog] WIP to make it more mordern looking
June Park <parkjune1995@gmail.com>
parents: 159
diff changeset
1166
87d8d3eb3491 [PostDog] WIP to make it more mordern looking
June Park <parkjune1995@gmail.com>
parents: 159
diff changeset
1167 // Update the caller's pointer in case array was reallocated
87d8d3eb3491 [PostDog] WIP to make it more mordern looking
June Park <parkjune1995@gmail.com>
parents: 159
diff changeset
1168 *p_file_arr = file_arr;
87d8d3eb3491 [PostDog] WIP to make it more mordern looking
June Park <parkjune1995@gmail.com>
parents: 159
diff changeset
1169
114
e2a73e64e8e6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 112
diff changeset
1170 int count = Dowa_Array_Length(file_arr);
e2a73e64e8e6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 112
diff changeset
1171 if (count > 1) {
e2a73e64e8e6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 112
diff changeset
1172 qsort(file_arr, count, sizeof(HistoryItem), CompareHistoryItemsByDate);
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 }
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 int PostDog_History_Load(HistoryItem **p_history_files)
e2a73e64e8e6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 112
diff changeset
1177 {
e2a73e64e8e6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 112
diff changeset
1178 if (access(POSTDOG_PATHS, F_OK) == -1)
e2a73e64e8e6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 112
diff changeset
1179 {
e2a73e64e8e6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 112
diff changeset
1180 printf("Directory '%s' not found. Creating it...\n", POSTDOG_PATHS);
e2a73e64e8e6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 112
diff changeset
1181 if (mkdir(POSTDOG_PATHS, 0777) != 0)
e2a73e64e8e6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 112
diff changeset
1182 return -1;
e2a73e64e8e6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 112
diff changeset
1183 return 0;
e2a73e64e8e6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 112
diff changeset
1184 }
e2a73e64e8e6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 112
diff changeset
1185 printf("Directory '%s' already exists.\n", POSTDOG_PATHS);
e2a73e64e8e6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 112
diff changeset
1186 PostDog_List_Directory(POSTDOG_PATHS, p_history_files);
e2a73e64e8e6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 112
diff changeset
1187 return 0;
e2a73e64e8e6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 112
diff changeset
1188 }
e2a73e64e8e6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 112
diff changeset
1189
e2a73e64e8e6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 112
diff changeset
1190 bool InArea(Vector2 mouse_position, Rectangle area)
e2a73e64e8e6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 112
diff changeset
1191 {
e2a73e64e8e6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 112
diff changeset
1192 return (
e2a73e64e8e6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 112
diff changeset
1193 mouse_position.x >= area.x &&
e2a73e64e8e6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 112
diff changeset
1194 mouse_position.x < area.x + area.width &&
e2a73e64e8e6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 112
diff changeset
1195 mouse_position.y >= area.y &&
e2a73e64e8e6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 112
diff changeset
1196 mouse_position.y < area.y + area.height
e2a73e64e8e6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 112
diff changeset
1197 );
e2a73e64e8e6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 112
diff changeset
1198 }
e2a73e64e8e6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 112
diff changeset
1199
e2a73e64e8e6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 112
diff changeset
1200 bool Clicked(Vector2 mouse_position, Rectangle area)
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 return (InArea(mouse_position, area) && IsMouseButtonPressed(MOUSE_BUTTON_LEFT));
e2a73e64e8e6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 112
diff changeset
1203 }
e2a73e64e8e6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 112
diff changeset
1204
159
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
1205 // -------- 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
1206
112
d6d578b49a19 [PostDog] Got CRUD working.
June Park <parkjune1995@gmail.com>
parents: 111
diff changeset
1207 char *PostDog_Enum_To_String(int active_enum)
d6d578b49a19 [PostDog] Got CRUD working.
June Park <parkjune1995@gmail.com>
parents: 111
diff changeset
1208 {
d6d578b49a19 [PostDog] Got CRUD working.
June Park <parkjune1995@gmail.com>
parents: 111
diff changeset
1209 switch(active_enum)
d6d578b49a19 [PostDog] Got CRUD working.
June Park <parkjune1995@gmail.com>
parents: 111
diff changeset
1210 {
d6d578b49a19 [PostDog] Got CRUD working.
June Park <parkjune1995@gmail.com>
parents: 111
diff changeset
1211 case 0: return "GET";
d6d578b49a19 [PostDog] Got CRUD working.
June Park <parkjune1995@gmail.com>
parents: 111
diff changeset
1212 case 1: return "POST";
d6d578b49a19 [PostDog] Got CRUD working.
June Park <parkjune1995@gmail.com>
parents: 111
diff changeset
1213 case 2: return "PUT";
d6d578b49a19 [PostDog] Got CRUD working.
June Park <parkjune1995@gmail.com>
parents: 111
diff changeset
1214 case 3: return "DELETE";
d6d578b49a19 [PostDog] Got CRUD working.
June Park <parkjune1995@gmail.com>
parents: 111
diff changeset
1215 }
114
e2a73e64e8e6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 112
diff changeset
1216 return 0;
e2a73e64e8e6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 112
diff changeset
1217 }
e2a73e64e8e6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 112
diff changeset
1218
161
87d8d3eb3491 [PostDog] WIP to make it more mordern looking
June Park <parkjune1995@gmail.com>
parents: 159
diff changeset
1219 char *PostDog_Construct_URL(char *filename, char *out_buffer, size_t buffer_size)
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
1220 {
161
87d8d3eb3491 [PostDog] WIP to make it more mordern looking
June Park <parkjune1995@gmail.com>
parents: 159
diff changeset
1221 snprintf(out_buffer, buffer_size, "%s/%s", POSTDOG_PATHS, filename);
87d8d3eb3491 [PostDog] WIP to make it more mordern looking
June Park <parkjune1995@gmail.com>
parents: 159
diff changeset
1222 return out_buffer;
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
1223 }
7bd795bac997 [Postdog] Added scrollable area to inputs and history files, buttons to delete and view.
June Park <parkjune1995@gmail.com>
parents: 115
diff changeset
1224
161
87d8d3eb3491 [PostDog] WIP to make it more mordern looking
June Park <parkjune1995@gmail.com>
parents: 159
diff changeset
1225 boolean PostDog_History_CreateFile(char *filename, char* values)
114
e2a73e64e8e6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 112
diff changeset
1226 {
e2a73e64e8e6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 112
diff changeset
1227 char full_file_path[512] = {0};
e2a73e64e8e6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 112
diff changeset
1228 snprintf(full_file_path, 512, "%s/%s", POSTDOG_PATHS, filename);
e2a73e64e8e6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 112
diff changeset
1229 FILE *file = fopen(full_file_path, "w");
e2a73e64e8e6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 112
diff changeset
1230 if (!file)
e2a73e64e8e6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 112
diff changeset
1231 {
161
87d8d3eb3491 [PostDog] WIP to make it more mordern looking
June Park <parkjune1995@gmail.com>
parents: 159
diff changeset
1232 fprintf(stderr, "Failed to create a file: %s\n", full_file_path);
87d8d3eb3491 [PostDog] WIP to make it more mordern looking
June Park <parkjune1995@gmail.com>
parents: 159
diff changeset
1233 return FALSE;
114
e2a73e64e8e6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 112
diff changeset
1234 }
e2a73e64e8e6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 112
diff changeset
1235 fwrite(values, 1, strlen(values), file);
e2a73e64e8e6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 112
diff changeset
1236 fclose(file);
161
87d8d3eb3491 [PostDog] WIP to make it more mordern looking
June Park <parkjune1995@gmail.com>
parents: 159
diff changeset
1237 return TRUE;
114
e2a73e64e8e6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 112
diff changeset
1238 }
e2a73e64e8e6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 112
diff changeset
1239
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
1240 void PostDog_Request_SaveFile(void)
114
e2a73e64e8e6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 112
diff changeset
1241 {
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
1242 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
1243 size_t new_file_size = 1024 * 1024;
e2a73e64e8e6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 112
diff changeset
1244 Dowa_Arena *arena = Dowa_Arena_Create(1024 * 1024 * 2);
e2a73e64e8e6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 112
diff changeset
1245 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
1246 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
1247 sprintf(title, "%s %s", method, url_input_text);
114
e2a73e64e8e6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 112
diff changeset
1248 snprintf(
e2a73e64e8e6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 112
diff changeset
1249 new_file,
e2a73e64e8e6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 112
diff changeset
1250 new_file_size,
e2a73e64e8e6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 112
diff changeset
1251 "%s\n"
e2a73e64e8e6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 112
diff changeset
1252 "---\n"
e2a73e64e8e6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 112
diff changeset
1253 "%s\n"
e2a73e64e8e6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 112
diff changeset
1254 "---\n"
e2a73e64e8e6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 112
diff changeset
1255 "%s\n"
e2a73e64e8e6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 112
diff changeset
1256 "---\n"
e2a73e64e8e6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 112
diff changeset
1257 "%s\n"
e2a73e64e8e6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 112
diff changeset
1258 "---\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
1259 "%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
1260 "---\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
1261 "%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
1262 "---\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
1263 "%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
1264 "---\n"
114
e2a73e64e8e6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 112
diff changeset
1265 "%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
1266 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
1267 url_input_text,
114
e2a73e64e8e6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 112
diff changeset
1268 method,
155
3bb45eb67906 [Postdog] Updated variables names and padding sizes. Needs more work.
June Park <parkjune1995@gmail.com>
parents: 153
diff changeset
1269 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
1270 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
1271 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
1272 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
1273 result_text
114
e2a73e64e8e6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 112
diff changeset
1274 );
e2a73e64e8e6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 112
diff changeset
1275 char *filename = Dowa_Arena_Allocate(arena, 1024);
e2a73e64e8e6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 112
diff changeset
1276 if (!filename)
e2a73e64e8e6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 112
diff changeset
1277 {
e2a73e64e8e6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 112
diff changeset
1278 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
1279 exit(EXIT_FAILURE);
114
e2a73e64e8e6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 112
diff changeset
1280 }
e2a73e64e8e6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 112
diff changeset
1281 char *uuid4 = (char *)Dowa_Arena_Allocate(arena, 37);
e2a73e64e8e6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 112
diff changeset
1282 if (!uuid4)
e2a73e64e8e6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 112
diff changeset
1283 {
e2a73e64e8e6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 112
diff changeset
1284 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
1285 exit(EXIT_FAILURE);
114
e2a73e64e8e6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 112
diff changeset
1286 }
159
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
1287
161
87d8d3eb3491 [PostDog] WIP to make it more mordern looking
June Park <parkjune1995@gmail.com>
parents: 159
diff changeset
1288 uv_mutex_lock(&history_mutex);
87d8d3eb3491 [PostDog] WIP to make it more mordern looking
June Park <parkjune1995@gmail.com>
parents: 159
diff changeset
1289
114
e2a73e64e8e6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 112
diff changeset
1290 int32 seed = (uint32)time(NULL) ^ counter++;
e2a73e64e8e6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 112
diff changeset
1291 Dowa_String_UUID(seed, uuid4);
e2a73e64e8e6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 112
diff changeset
1292 snprintf(filename, 1024, "%s.txt", uuid4);
e2a73e64e8e6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 112
diff changeset
1293
161
87d8d3eb3491 [PostDog] WIP to make it more mordern looking
June Park <parkjune1995@gmail.com>
parents: 159
diff changeset
1294 if (PostDog_History_CreateFile(filename, new_file))
87d8d3eb3491 [PostDog] WIP to make it more mordern looking
June Park <parkjune1995@gmail.com>
parents: 159
diff changeset
1295 {
87d8d3eb3491 [PostDog] WIP to make it more mordern looking
June Park <parkjune1995@gmail.com>
parents: 159
diff changeset
1296 HistoryItem item = {0};
87d8d3eb3491 [PostDog] WIP to make it more mordern looking
June Park <parkjune1995@gmail.com>
parents: 159
diff changeset
1297 item.filename = strdup(filename);
87d8d3eb3491 [PostDog] WIP to make it more mordern looking
June Park <parkjune1995@gmail.com>
parents: 159
diff changeset
1298 item.title = strdup(title);
87d8d3eb3491 [PostDog] WIP to make it more mordern looking
June Park <parkjune1995@gmail.com>
parents: 159
diff changeset
1299 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
1300
161
87d8d3eb3491 [PostDog] WIP to make it more mordern looking
June Park <parkjune1995@gmail.com>
parents: 159
diff changeset
1301 Dowa_Array_Push(new_history_items, item);
87d8d3eb3491 [PostDog] WIP to make it more mordern looking
June Park <parkjune1995@gmail.com>
parents: 159
diff changeset
1302 }
87d8d3eb3491 [PostDog] WIP to make it more mordern looking
June Park <parkjune1995@gmail.com>
parents: 159
diff changeset
1303
87d8d3eb3491 [PostDog] WIP to make it more mordern looking
June Park <parkjune1995@gmail.com>
parents: 159
diff changeset
1304 uv_mutex_unlock(&history_mutex);
114
e2a73e64e8e6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 112
diff changeset
1305 Dowa_Arena_Free(arena);
112
d6d578b49a19 [PostDog] Got CRUD working.
June Park <parkjune1995@gmail.com>
parents: 111
diff changeset
1306 }
54
b3e82d22f961 [PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1307
159
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
1308 void PostDog_Websocket_Listen(void)
54
b3e82d22f961 [PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1309 {
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
1310 while (TRUE)
54
b3e82d22f961 [PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1311 {
153
790930d9bb90 [PostDog] Adding websocket to be more usable.
June Park <parkjune1995@gmail.com>
parents: 152
diff changeset
1312 if (WS_BREAK) break;
790930d9bb90 [PostDog] Adding websocket to be more usable.
June Park <parkjune1995@gmail.com>
parents: 152
diff changeset
1313
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
1314 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
1315 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
1316 {
7387eec8e7f8 [Postdog] Updated to use Seobeo_Client instead of CURL. Updated to handle websocket connection.
June Park <parkjune1995@gmail.com>
parents: 118
diff changeset
1317 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
1318 {
159
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
1319 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
1320 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
1321 "\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
1322 }
7387eec8e7f8 [Postdog] Updated to use Seobeo_Client instead of CURL. Updated to handle websocket connection.
June Park <parkjune1995@gmail.com>
parents: 118
diff changeset
1323 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
1324 }
7387eec8e7f8 [Postdog] Updated to use Seobeo_Client instead of CURL. Updated to handle websocket connection.
June Park <parkjune1995@gmail.com>
parents: 118
diff changeset
1325 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
1326 printf("Listening\n");
54
b3e82d22f961 [PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1327 }
159
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
1328 return;
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_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
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 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
1334 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
1335 }
54
b3e82d22f961 [PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1336
159
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
1337 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
1338 {
159
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
1339 if (Seobeo_WebSocket_Send_Text(ws, input_body_array[active_input_tab]) < 0)
161
87d8d3eb3491 [PostDog] WIP to make it more mordern looking
June Park <parkjune1995@gmail.com>
parents: 159
diff changeset
1340 {
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 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
1342 "Failed to send message\n");
161
87d8d3eb3491 [PostDog] WIP to make it more mordern looking
June Park <parkjune1995@gmail.com>
parents: 159
diff changeset
1343 return -1;
87d8d3eb3491 [PostDog] WIP to make it more mordern looking
June Park <parkjune1995@gmail.com>
parents: 159
diff changeset
1344 }
87d8d3eb3491 [PostDog] WIP to make it more mordern looking
June Park <parkjune1995@gmail.com>
parents: 159
diff changeset
1345 snprintf(result_text + strlen(result_text), RESULT_BUFFER_LENGTH - strlen(result_text),
87d8d3eb3491 [PostDog] WIP to make it more mordern looking
June Park <parkjune1995@gmail.com>
parents: 159
diff changeset
1346 "\n%s", input_body_array[active_input_tab]);
87d8d3eb3491 [PostDog] WIP to make it more mordern looking
June Park <parkjune1995@gmail.com>
parents: 159
diff changeset
1347 return 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
1348 }
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
1349
161
87d8d3eb3491 [PostDog] WIP to make it more mordern looking
June Park <parkjune1995@gmail.com>
parents: 159
diff changeset
1350 void PostDog_Websocket_Destroy(uv_thread_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
1351 {
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
1352 Seobeo_WebSocket_Destroy(ws);
161
87d8d3eb3491 [PostDog] WIP to make it more mordern looking
June Park <parkjune1995@gmail.com>
parents: 159
diff changeset
1353 uv_thread_join(&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
1354 }
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
1355
161
87d8d3eb3491 [PostDog] WIP to make it more mordern looking
June Park <parkjune1995@gmail.com>
parents: 159
diff changeset
1356 void PostDog_Websocket_Start(void *arg)
159
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
1357 {
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
1358 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
1359 PostDog_Websocket_Listen();
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
1360 }
54
b3e82d22f961 [PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1361
161
87d8d3eb3491 [PostDog] WIP to make it more mordern looking
June Park <parkjune1995@gmail.com>
parents: 159
diff changeset
1362 uv_thread_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
1363 {
161
87d8d3eb3491 [PostDog] WIP to make it more mordern looking
June Park <parkjune1995@gmail.com>
parents: 159
diff changeset
1364 uv_thread_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
1365
161
87d8d3eb3491 [PostDog] WIP to make it more mordern looking
June Park <parkjune1995@gmail.com>
parents: 159
diff changeset
1366 if (uv_thread_create(&thread_id, 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
1367 {
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 perror("Failed to create thread");
161
87d8d3eb3491 [PostDog] WIP to make it more mordern looking
June Park <parkjune1995@gmail.com>
parents: 159
diff changeset
1369 memset(&thread_id, 0, sizeof(thread_id));
87d8d3eb3491 [PostDog] WIP to make it more mordern looking
June Park <parkjune1995@gmail.com>
parents: 159
diff changeset
1370 return thread_id;
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
1371 }
159
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
1372
161
87d8d3eb3491 [PostDog] WIP to make it more mordern looking
June Park <parkjune1995@gmail.com>
parents: 159
diff changeset
1373 return thread_id;
54
b3e82d22f961 [PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1374 }
b3e82d22f961 [PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1375
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
1376 int PostDog_Http_Request(void)
54
b3e82d22f961 [PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1377 {
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
1378 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
1379 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
1380 switch (active_method_dropdown)
54
b3e82d22f961 [PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1381 {
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
1382 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
1383 {
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 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
1385 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
1386 }
159
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
1387 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
1388 {
7387eec8e7f8 [Postdog] Updated to use Seobeo_Client instead of CURL. Updated to handle websocket connection.
June Park <parkjune1995@gmail.com>
parents: 118
diff changeset
1389 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
1390 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
1391 }
7387eec8e7f8 [Postdog] Updated to use Seobeo_Client instead of CURL. Updated to handle websocket connection.
June Park <parkjune1995@gmail.com>
parents: 118
diff changeset
1392 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
1393 {
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 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
1395 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
1396 }
7387eec8e7f8 [Postdog] Updated to use Seobeo_Client instead of CURL. Updated to handle websocket connection.
June Park <parkjune1995@gmail.com>
parents: 118
diff changeset
1397 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
1398 {
7387eec8e7f8 [Postdog] Updated to use Seobeo_Client instead of CURL. Updated to handle websocket connection.
June Park <parkjune1995@gmail.com>
parents: 118
diff changeset
1399 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
1400 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
1401 }
54
b3e82d22f961 [PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1402 }
b3e82d22f961 [PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1403
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
1404 {
155
3bb45eb67906 [Postdog] Updated variables names and padding sizes. Needs more work.
June Park <parkjune1995@gmail.com>
parents: 153
diff changeset
1405 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
1406 {
155
3bb45eb67906 [Postdog] Updated variables names and padding sizes. Needs more work.
June Park <parkjune1995@gmail.com>
parents: 153
diff changeset
1407 char *headersCopy = strdup(input_body_array[TAB_HEADER]);
54
b3e82d22f961 [PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1408 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
1409 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
1410 {
54
b3e82d22f961 [PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1411 while (*line == ' ' || *line == '\t') line++;
114
e2a73e64e8e6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 112
diff changeset
1412 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
1413 Seobeo_Client_Request_Add_Header_Array(req, line);
54
b3e82d22f961 [PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1414 line = strtok(NULL, "\n");
b3e82d22f961 [PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1415 }
b3e82d22f961 [PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1416
159
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
1417 }
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
1418 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
1419 res = Seobeo_Client_Request_Execute(req);
54
b3e82d22f961 [PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1420
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
1421 if (res == NULL)
155
3bb45eb67906 [Postdog] Updated variables names and padding sizes. Needs more work.
June Park <parkjune1995@gmail.com>
parents: 153
diff changeset
1422 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
1423 else
155
3bb45eb67906 [Postdog] Updated variables names and padding sizes. Needs more work.
June Park <parkjune1995@gmail.com>
parents: 153
diff changeset
1424 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
1425 res->status_code, res->body ? res->body : "");
54
b3e82d22f961 [PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1426 }
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
1427 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
1428 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
1429 PostDog_Request_SaveFile();
54
b3e82d22f961 [PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1430 return 0;
b3e82d22f961 [PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1431 }
b3e82d22f961 [PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1432
161
87d8d3eb3491 [PostDog] WIP to make it more mordern looking
June Park <parkjune1995@gmail.com>
parents: 159
diff changeset
1433 void PostDog_Http_Work(uv_work_t *req)
159
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
1434 {
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
1435 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
1436 printf("HTTP request finished.\n");
161
87d8d3eb3491 [PostDog] WIP to make it more mordern looking
June Park <parkjune1995@gmail.com>
parents: 159
diff changeset
1437 }
87d8d3eb3491 [PostDog] WIP to make it more mordern looking
June Park <parkjune1995@gmail.com>
parents: 159
diff changeset
1438
87d8d3eb3491 [PostDog] WIP to make it more mordern looking
June Park <parkjune1995@gmail.com>
parents: 159
diff changeset
1439 void PostDog_Http_Work_Done(uv_work_t *req, int status)
87d8d3eb3491 [PostDog] WIP to make it more mordern looking
June Park <parkjune1995@gmail.com>
parents: 159
diff changeset
1440 {
159
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
1441 LOADING = FALSE;
161
87d8d3eb3491 [PostDog] WIP to make it more mordern looking
June Park <parkjune1995@gmail.com>
parents: 159
diff changeset
1442 free(req);
159
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
1443 }
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
1444
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
1445 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
1446 {
161
87d8d3eb3491 [PostDog] WIP to make it more mordern looking
June Park <parkjune1995@gmail.com>
parents: 159
diff changeset
1447 uv_work_t *work_req = malloc(sizeof(uv_work_t));
87d8d3eb3491 [PostDog] WIP to make it more mordern looking
June Park <parkjune1995@gmail.com>
parents: 159
diff changeset
1448 if (!work_req)
159
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
1449 {
161
87d8d3eb3491 [PostDog] WIP to make it more mordern looking
June Park <parkjune1995@gmail.com>
parents: 159
diff changeset
1450 perror("Failed to allocate work request");
159
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
1451 return;
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
1452 }
161
87d8d3eb3491 [PostDog] WIP to make it more mordern looking
June Park <parkjune1995@gmail.com>
parents: 159
diff changeset
1453 LOADING = TRUE;
87d8d3eb3491 [PostDog] WIP to make it more mordern looking
June Park <parkjune1995@gmail.com>
parents: 159
diff changeset
1454 if (uv_queue_work(main_loop, work_req, PostDog_Http_Work, PostDog_Http_Work_Done) != 0)
87d8d3eb3491 [PostDog] WIP to make it more mordern looking
June Park <parkjune1995@gmail.com>
parents: 159
diff changeset
1455 {
87d8d3eb3491 [PostDog] WIP to make it more mordern looking
June Park <parkjune1995@gmail.com>
parents: 159
diff changeset
1456 perror("Failed to queue work");
87d8d3eb3491 [PostDog] WIP to make it more mordern looking
June Park <parkjune1995@gmail.com>
parents: 159
diff changeset
1457 free(work_req);
87d8d3eb3491 [PostDog] WIP to make it more mordern looking
June Park <parkjune1995@gmail.com>
parents: 159
diff changeset
1458 LOADING = FALSE;
87d8d3eb3491 [PostDog] WIP to make it more mordern looking
June Park <parkjune1995@gmail.com>
parents: 159
diff changeset
1459 }
159
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
1460 }
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
1461
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
1462 void PostDog_Update_URL(void)
112
d6d578b49a19 [PostDog] Got CRUD working.
June Park <parkjune1995@gmail.com>
parents: 111
diff changeset
1463 {
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
1464 // Save existing query string if present
112
d6d578b49a19 [PostDog] Got CRUD working.
June Park <parkjune1995@gmail.com>
parents: 111
diff changeset
1465 char *question_mark = strchr(url_input_text, '?');
d6d578b49a19 [PostDog] Got CRUD working.
June Park <parkjune1995@gmail.com>
parents: 111
diff changeset
1466 if (question_mark)
d6d578b49a19 [PostDog] Got CRUD working.
June Park <parkjune1995@gmail.com>
parents: 111
diff changeset
1467 *question_mark = '\0';
d6d578b49a19 [PostDog] Got CRUD working.
June Park <parkjune1995@gmail.com>
parents: 111
diff changeset
1468
155
3bb45eb67906 [Postdog] Updated variables names and padding sizes. Needs more work.
June Park <parkjune1995@gmail.com>
parents: 153
diff changeset
1469 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
1470 if (get_params_length == 0)
d6d578b49a19 [PostDog] Got CRUD working.
June Park <parkjune1995@gmail.com>
parents: 111
diff changeset
1471 return;
d6d578b49a19 [PostDog] Got CRUD working.
June Park <parkjune1995@gmail.com>
parents: 111
diff changeset
1472
d6d578b49a19 [PostDog] Got CRUD working.
June Park <parkjune1995@gmail.com>
parents: 111
diff changeset
1473 char *separator = "?";
d6d578b49a19 [PostDog] Got CRUD working.
June Park <parkjune1995@gmail.com>
parents: 111
diff changeset
1474
d6d578b49a19 [PostDog] Got CRUD working.
June Park <parkjune1995@gmail.com>
parents: 111
diff changeset
1475 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
1476 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
1477 for (int i = 0; i < Dowa_Array_Length(lines); i++)
d6d578b49a19 [PostDog] Got CRUD working.
June Park <parkjune1995@gmail.com>
parents: 111
diff changeset
1478 {
d6d578b49a19 [PostDog] Got CRUD working.
June Park <parkjune1995@gmail.com>
parents: 111
diff changeset
1479 char *line = lines[i];
d6d578b49a19 [PostDog] Got CRUD working.
June Park <parkjune1995@gmail.com>
parents: 111
diff changeset
1480 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
1481
d6d578b49a19 [PostDog] Got CRUD working.
June Park <parkjune1995@gmail.com>
parents: 111
diff changeset
1482 if (Dowa_Array_Length(key_value) < 2)
114
e2a73e64e8e6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 112
diff changeset
1483 break;
112
d6d578b49a19 [PostDog] Got CRUD working.
June Park <parkjune1995@gmail.com>
parents: 111
diff changeset
1484
d6d578b49a19 [PostDog] Got CRUD working.
June Park <parkjune1995@gmail.com>
parents: 111
diff changeset
1485 strcat(url_input_text, separator);
d6d578b49a19 [PostDog] Got CRUD working.
June Park <parkjune1995@gmail.com>
parents: 111
diff changeset
1486 strcat(url_input_text, key_value[0]);
d6d578b49a19 [PostDog] Got CRUD working.
June Park <parkjune1995@gmail.com>
parents: 111
diff changeset
1487 strcat(url_input_text, "=");
d6d578b49a19 [PostDog] Got CRUD working.
June Park <parkjune1995@gmail.com>
parents: 111
diff changeset
1488 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
1489 {
d6d578b49a19 [PostDog] Got CRUD working.
June Park <parkjune1995@gmail.com>
parents: 111
diff changeset
1490 if (!key_value[i] || key_value[i][0] == '\0')
d6d578b49a19 [PostDog] Got CRUD working.
June Park <parkjune1995@gmail.com>
parents: 111
diff changeset
1491 break;
d6d578b49a19 [PostDog] Got CRUD working.
June Park <parkjune1995@gmail.com>
parents: 111
diff changeset
1492 if (i > 1) strcat(url_input_text, "%20");
d6d578b49a19 [PostDog] Got CRUD working.
June Park <parkjune1995@gmail.com>
parents: 111
diff changeset
1493 strcat(url_input_text, key_value[i]);
d6d578b49a19 [PostDog] Got CRUD working.
June Park <parkjune1995@gmail.com>
parents: 111
diff changeset
1494 }
d6d578b49a19 [PostDog] Got CRUD working.
June Park <parkjune1995@gmail.com>
parents: 111
diff changeset
1495 separator = "&";
d6d578b49a19 [PostDog] Got CRUD working.
June Park <parkjune1995@gmail.com>
parents: 111
diff changeset
1496 }
d6d578b49a19 [PostDog] Got CRUD working.
June Park <parkjune1995@gmail.com>
parents: 111
diff changeset
1497
d6d578b49a19 [PostDog] Got CRUD working.
June Park <parkjune1995@gmail.com>
parents: 111
diff changeset
1498 Dowa_Arena_Free(arena);
d6d578b49a19 [PostDog] Got CRUD working.
June Park <parkjune1995@gmail.com>
parents: 111
diff changeset
1499 }
d6d578b49a19 [PostDog] Got CRUD working.
June Park <parkjune1995@gmail.com>
parents: 111
diff changeset
1500
114
e2a73e64e8e6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 112
diff changeset
1501 int PostDog_String_To_MethodEnum(char *value)
e2a73e64e8e6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 112
diff changeset
1502 {
e2a73e64e8e6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 112
diff changeset
1503 if (strstr(value, "GET"))
e2a73e64e8e6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 112
diff changeset
1504 return 0;
e2a73e64e8e6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 112
diff changeset
1505 if (strstr(value, "POST"))
e2a73e64e8e6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 112
diff changeset
1506 return 1;
e2a73e64e8e6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 112
diff changeset
1507 if (strstr(value, "PUT"))
e2a73e64e8e6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 112
diff changeset
1508 return 2;
e2a73e64e8e6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 112
diff changeset
1509 if (strstr(value, "DELETE"))
e2a73e64e8e6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 112
diff changeset
1510 return 3;
e2a73e64e8e6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 112
diff changeset
1511 return 0;
e2a73e64e8e6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 112
diff changeset
1512 }
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 void PostDog_Params_Reset(void)
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 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
1517 result_text[0] = '\0';
114
e2a73e64e8e6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 112
diff changeset
1518 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
1519 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
1520 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
1521
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
1522 // 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
1523 GuiTextAreaResetAllStates();
114
e2a73e64e8e6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 112
diff changeset
1524 }
e2a73e64e8e6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 112
diff changeset
1525
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
1526 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
1527 {
114
e2a73e64e8e6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 112
diff changeset
1528 char full_file_path[512] = {0};
e2a73e64e8e6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 112
diff changeset
1529 snprintf(full_file_path, 512, "%s/%s", POSTDOG_PATHS, filename);
e2a73e64e8e6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 112
diff changeset
1530 FILE *file = fopen(full_file_path, "r");
e2a73e64e8e6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 112
diff changeset
1531 if (!file)
e2a73e64e8e6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 112
diff changeset
1532 return;
e2a73e64e8e6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 112
diff changeset
1533
e2a73e64e8e6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 112
diff changeset
1534 fseek(file, 0, SEEK_END);
e2a73e64e8e6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 112
diff changeset
1535 size_t file_size = ftell(file);
e2a73e64e8e6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 112
diff changeset
1536 fseek(file, 0, SEEK_SET);
e2a73e64e8e6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 112
diff changeset
1537
e2a73e64e8e6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 112
diff changeset
1538 Dowa_Arena *init_arena = Dowa_Arena_Create(file_size + 2);
e2a73e64e8e6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 112
diff changeset
1539 Dowa_Arena *split_arena = Dowa_Arena_Create(file_size * 2);
e2a73e64e8e6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 112
diff changeset
1540 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
1541 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
1542 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
1543
114
e2a73e64e8e6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 112
diff changeset
1544 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
1545
114
e2a73e64e8e6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 112
diff changeset
1546 for (int i = 0; i < Dowa_Array_Length(values); i++)
e2a73e64e8e6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 112
diff changeset
1547 {
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
1548 switch (i)
114
e2a73e64e8e6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 112
diff changeset
1549 {
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
1550 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
1551 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
1552
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
1553 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
1554 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
1555 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
1556 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
1557
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
1558 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
1559 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
1560 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
1561
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
1562 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
1563 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
1564 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
1565 case 6: // Websocket (TAB_WEBSOCKET)
114
e2a73e64e8e6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 112
diff changeset
1566 {
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
1567 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
1568 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
1569 // 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
1570 for (int j = strlen(values[i]); j > 0; j--)
114
e2a73e64e8e6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 112
diff changeset
1571 {
155
3bb45eb67906 [Postdog] Updated variables names and padding sizes. Needs more work.
June Park <parkjune1995@gmail.com>
parents: 153
diff changeset
1572 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
1573 {
155
3bb45eb67906 [Postdog] Updated variables names and padding sizes. Needs more work.
June Park <parkjune1995@gmail.com>
parents: 153
diff changeset
1574 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
1575 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
1576 }
114
e2a73e64e8e6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 112
diff changeset
1577 }
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
1578 break;
114
e2a73e64e8e6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 112
diff changeset
1579 }
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
1580
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
1581 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
1582 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
1583 break;
114
e2a73e64e8e6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 112
diff changeset
1584 }
e2a73e64e8e6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 112
diff changeset
1585 }
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
1586
159
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
1587 // 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
1588 GuiTextAreaResetAllStates();
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
1589
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
1590 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
1591 Dowa_Arena_Free(split_arena);
114
e2a73e64e8e6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 112
diff changeset
1592 }
e2a73e64e8e6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 112
diff changeset
1593
54
b3e82d22f961 [PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1594 int main()
b3e82d22f961 [PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1595 {
161
87d8d3eb3491 [PostDog] WIP to make it more mordern looking
June Park <parkjune1995@gmail.com>
parents: 159
diff changeset
1596 // -- initialize libuv --//
87d8d3eb3491 [PostDog] WIP to make it more mordern looking
June Park <parkjune1995@gmail.com>
parents: 159
diff changeset
1597 main_loop = uv_default_loop();
87d8d3eb3491 [PostDog] WIP to make it more mordern looking
June Park <parkjune1995@gmail.com>
parents: 159
diff changeset
1598 uv_mutex_init(&history_mutex);
87d8d3eb3491 [PostDog] WIP to make it more mordern looking
June Park <parkjune1995@gmail.com>
parents: 159
diff changeset
1599
111
48f260576059 [PostDog] Rewriting it from scratch as it is unreadable for me.
June Park <parkjune1995@gmail.com>
parents: 63
diff changeset
1600 // -- initizlied --//
48f260576059 [PostDog] Rewriting it from scratch as it is unreadable for me.
June Park <parkjune1995@gmail.com>
parents: 63
diff changeset
1601 InitWindow(SCREEN_WIDTH, SCREEN_HEIGHT, "PostDog");
54
b3e82d22f961 [PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1602 SetWindowState(FLAG_WINDOW_RESIZABLE);
b3e82d22f961 [PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1603 SetTargetFPS(60);
b3e82d22f961 [PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1604
114
e2a73e64e8e6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 112
diff changeset
1605 Font customFont = LoadFontEx("postdog/Roboto-Regular.ttf", 20, 0, 0);
e2a73e64e8e6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 112
diff changeset
1606 GuiSetFont(customFont);
153
790930d9bb90 [PostDog] Adding websocket to be more usable.
June Park <parkjune1995@gmail.com>
parents: 152
diff changeset
1607 GuiSetStyle(DEFAULT, TEXT_SIZE, 15);
161
87d8d3eb3491 [PostDog] WIP to make it more mordern looking
June Park <parkjune1995@gmail.com>
parents: 159
diff changeset
1608 Image logo_original = LoadImage("postdog/logo_bigger.png");
87d8d3eb3491 [PostDog] WIP to make it more mordern looking
June Park <parkjune1995@gmail.com>
parents: 159
diff changeset
1609 ImageResize(&logo_original, 200, 600);
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
1610 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
1611 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
1612 UnloadImage(logo_original);
114
e2a73e64e8e6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 112
diff changeset
1613
159
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
1614 // Arena for text area undo states
161
87d8d3eb3491 [PostDog] WIP to make it more mordern looking
June Park <parkjune1995@gmail.com>
parents: 159
diff changeset
1615 g_text_area_arena = Dowa_Arena_Create(1024 * 1024 * 4);
159
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
1616
111
48f260576059 [PostDog] Rewriting it from scratch as it is unreadable for me.
June Park <parkjune1995@gmail.com>
parents: 63
diff changeset
1617 // -- Starting pos ---//
161
87d8d3eb3491 [PostDog] WIP to make it more mordern looking
June Park <parkjune1995@gmail.com>
parents: 159
diff changeset
1618 Rectangle full_screen = { 0 };
155
3bb45eb67906 [Postdog] Updated variables names and padding sizes. Needs more work.
June Park <parkjune1995@gmail.com>
parents: 153
diff changeset
1619 Rectangle history_sidebar_rect = { 0 };
114
e2a73e64e8e6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 112
diff changeset
1620 Dowa_Array_Reserve(history_items, 10);
e2a73e64e8e6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 112
diff changeset
1621 Dowa_Array_Reserve(new_history_items, 10);
e2a73e64e8e6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 112
diff changeset
1622 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
1623 int32 *history_deleted_items = NULL;
54
b3e82d22f961 [PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1624
155
3bb45eb67906 [Postdog] Updated variables names and padding sizes. Needs more work.
June Park <parkjune1995@gmail.com>
parents: 153
diff changeset
1625 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
1626 Rectangle url_input_bounds_rect = { 0 };
114
e2a73e64e8e6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 112
diff changeset
1627 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
1628 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
1629 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
1630 Rectangle method_dropdown_rect = { 0 };
54
b3e82d22f961 [PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1631
114
e2a73e64e8e6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 112
diff changeset
1632
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
1633 // 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
1634 url_input_text = (char *)malloc(sizeof(char) * URL_TEXT_BUFFER_LENGTH);
161
87d8d3eb3491 [PostDog] WIP to make it more mordern looking
June Park <parkjune1995@gmail.com>
parents: 159
diff changeset
1635 snprintf(url_input_text, URL_TEXT_BUFFER_LENGTH, URL_TEXT_DEFAULT);
112
d6d578b49a19 [PostDog] Got CRUD working.
June Park <parkjune1995@gmail.com>
parents: 111
diff changeset
1636
155
3bb45eb67906 [Postdog] Updated variables names and padding sizes. Needs more work.
June Park <parkjune1995@gmail.com>
parents: 153
diff changeset
1637 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
1638 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
1639 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
1640 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
1641
161
87d8d3eb3491 [PostDog] WIP to make it more mordern looking
June Park <parkjune1995@gmail.com>
parents: 159
diff changeset
1642 snprintf(input_body_array[TAB_HEADER], HEADER_BUFFER_LENGTH, HEADER_TEXT_DEFAULT);
87d8d3eb3491 [PostDog] WIP to make it more mordern looking
June Park <parkjune1995@gmail.com>
parents: 159
diff changeset
1643 snprintf(input_body_array[TAB_BODY], HEADER_BUFFER_LENGTH, BODY_TEXT_DEFAULT);
87d8d3eb3491 [PostDog] WIP to make it more mordern looking
June Park <parkjune1995@gmail.com>
parents: 159
diff changeset
1644 snprintf(input_body_array[TAB_GET_PARAMS], HEADER_BUFFER_LENGTH, GET_PARAM_TEXT_DEFAULT);
112
d6d578b49a19 [PostDog] Got CRUD working.
June Park <parkjune1995@gmail.com>
parents: 111
diff changeset
1645
155
3bb45eb67906 [Postdog] Updated variables names and padding sizes. Needs more work.
June Park <parkjune1995@gmail.com>
parents: 153
diff changeset
1646 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
1647 result_text[0] = '\0';
112
d6d578b49a19 [PostDog] Got CRUD working.
June Park <parkjune1995@gmail.com>
parents: 111
diff changeset
1648
d6d578b49a19 [PostDog] Got CRUD working.
June Park <parkjune1995@gmail.com>
parents: 111
diff changeset
1649 bool method_edit = false;
d6d578b49a19 [PostDog] Got CRUD working.
June Park <parkjune1995@gmail.com>
parents: 111
diff changeset
1650
111
48f260576059 [PostDog] Rewriting it from scratch as it is unreadable for me.
June Park <parkjune1995@gmail.com>
parents: 63
diff changeset
1651 int sendRequest;
54
b3e82d22f961 [PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1652
112
d6d578b49a19 [PostDog] Got CRUD working.
June Park <parkjune1995@gmail.com>
parents: 111
diff changeset
1653 // -- input --//
155
3bb45eb67906 [Postdog] Updated variables names and padding sizes. Needs more work.
June Park <parkjune1995@gmail.com>
parents: 153
diff changeset
1654 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
1655 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
1656 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
1657 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
1658 bool input_body_edit_mode = false;
54
b3e82d22f961 [PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1659
112
d6d578b49a19 [PostDog] Got CRUD working.
June Park <parkjune1995@gmail.com>
parents: 111
diff changeset
1660 // -- result --//
155
3bb45eb67906 [Postdog] Updated variables names and padding sizes. Needs more work.
June Park <parkjune1995@gmail.com>
parents: 153
diff changeset
1661 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
1662 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
1663 bool result_body_edit_mode = false;
54
b3e82d22f961 [PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1664
111
48f260576059 [PostDog] Rewriting it from scratch as it is unreadable for me.
June Park <parkjune1995@gmail.com>
parents: 63
diff changeset
1665 // General styling.
114
e2a73e64e8e6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 112
diff changeset
1666 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
1667 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
1668
7bd795bac997 [Postdog] Added scrollable area to inputs and history files, buttons to delete and view.
June Park <parkjune1995@gmail.com>
parents: 115
diff changeset
1669 // 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
1670 float history_scroll_offset = 0;
54
b3e82d22f961 [PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1671
b3e82d22f961 [PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1672 while (!WindowShouldClose())
b3e82d22f961 [PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1673 {
161
87d8d3eb3491 [PostDog] WIP to make it more mordern looking
June Park <parkjune1995@gmail.com>
parents: 159
diff changeset
1674 // Process libuv events (non-blocking)
87d8d3eb3491 [PostDog] WIP to make it more mordern looking
June Park <parkjune1995@gmail.com>
parents: 159
diff changeset
1675 uv_run(main_loop, UV_RUN_NOWAIT);
87d8d3eb3491 [PostDog] WIP to make it more mordern looking
June Park <parkjune1995@gmail.com>
parents: 159
diff changeset
1676
111
48f260576059 [PostDog] Rewriting it from scratch as it is unreadable for me.
June Park <parkjune1995@gmail.com>
parents: 63
diff changeset
1677 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
1678 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
1679
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
1680 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
1681 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
1682
7bd795bac997 [Postdog] Added scrollable area to inputs and history files, buttons to delete and view.
June Park <parkjune1995@gmail.com>
parents: 115
diff changeset
1683 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
1684 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
1685
155
3bb45eb67906 [Postdog] Updated variables names and padding sizes. Needs more work.
June Park <parkjune1995@gmail.com>
parents: 153
diff changeset
1686 Rectangle screen_rect = { 0, 0, screen_width, screen_height };
114
e2a73e64e8e6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 112
diff changeset
1687
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
1688 // -- Side bar --//
161
87d8d3eb3491 [PostDog] WIP to make it more mordern looking
June Park <parkjune1995@gmail.com>
parents: 159
diff changeset
1689 history_sidebar_rect = LeftColumn(screen_rect, 0.20, padding);
155
3bb45eb67906 [Postdog] Updated variables names and padding sizes. Needs more work.
June Park <parkjune1995@gmail.com>
parents: 153
diff changeset
1690 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
1691 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
1692 .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
1693 .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
1694 .width = history_sidebar_rect.width,
161
87d8d3eb3491 [PostDog] WIP to make it more mordern looking
June Park <parkjune1995@gmail.com>
parents: 159
diff changeset
1695 .height = 300
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
1696 };
115
96db6c3f38d6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 114
diff changeset
1697
161
87d8d3eb3491 [PostDog] WIP to make it more mordern looking
June Park <parkjune1995@gmail.com>
parents: 159
diff changeset
1698
87d8d3eb3491 [PostDog] WIP to make it more mordern looking
June Park <parkjune1995@gmail.com>
parents: 159
diff changeset
1699 DrawRectangleSelectiveRounded(history_sidebar_rect, 10, 10, ORANGE, TRUE, FALSE, FALSE, TRUE);
87d8d3eb3491 [PostDog] WIP to make it more mordern looking
June Park <parkjune1995@gmail.com>
parents: 159
diff changeset
1700 DrawRectangleSelectiveRounded(content_area_rect, 10, 10, WHITE, FALSE, TRUE, TRUE, FALSE);
87d8d3eb3491 [PostDog] WIP to make it more mordern looking
June Park <parkjune1995@gmail.com>
parents: 159
diff changeset
1701
155
3bb45eb67906 [Postdog] Updated variables names and padding sizes. Needs more work.
June Park <parkjune1995@gmail.com>
parents: 153
diff changeset
1702 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
1703 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
1704 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
1705 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
1706
114
e2a73e64e8e6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 112
diff changeset
1707 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
1708 int32 history_item_length = Dowa_Array_Length(history_items);
115
96db6c3f38d6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 114
diff changeset
1709 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
1710 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
1711
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
1712 int32 number_of_skipped_items = 0;
114
e2a73e64e8e6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 112
diff changeset
1713 for (int i = 0; i < total; i++)
e2a73e64e8e6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 112
diff changeset
1714 {
115
96db6c3f38d6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 114
diff changeset
1715 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
1716 &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
1717
117
b91f2dd6f84d [PostDog] Fixed delete logic.
June Park <parkjune1995@gmail.com>
parents: 116
diff changeset
1718 if (curr_history_items->deleted)
b91f2dd6f84d [PostDog] Fixed delete logic.
June Park <parkjune1995@gmail.com>
parents: 116
diff changeset
1719 {
b91f2dd6f84d [PostDog] Fixed delete logic.
June Park <parkjune1995@gmail.com>
parents: 116
diff changeset
1720 number_of_skipped_items++;
b91f2dd6f84d [PostDog] Fixed delete logic.
June Park <parkjune1995@gmail.com>
parents: 116
diff changeset
1721 continue;
b91f2dd6f84d [PostDog] Fixed delete logic.
June Park <parkjune1995@gmail.com>
parents: 116
diff changeset
1722 }
b91f2dd6f84d [PostDog] Fixed delete logic.
June Park <parkjune1995@gmail.com>
parents: 116
diff changeset
1723
115
96db6c3f38d6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 114
diff changeset
1724 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
1725 .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
1726 .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
1727 .width = history_list_area_rect.width,
115
96db6c3f38d6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 114
diff changeset
1728 .height = item_height
96db6c3f38d6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 114
diff changeset
1729 };
114
e2a73e64e8e6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 112
diff changeset
1730 }
54
b3e82d22f961 [PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1731
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
1732 // --- URL --- //
155
3bb45eb67906 [Postdog] Updated variables names and padding sizes. Needs more work.
June Park <parkjune1995@gmail.com>
parents: 153
diff changeset
1733 url_area_rect = (Rectangle){
3bb45eb67906 [Postdog] Updated variables names and padding sizes. Needs more work.
June Park <parkjune1995@gmail.com>
parents: 153
diff changeset
1734 .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
1735 .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
1736 .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
1737 .height = content_area_rect.height * 0.1
115
96db6c3f38d6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 114
diff changeset
1738 };
54
b3e82d22f961 [PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1739
155
3bb45eb67906 [Postdog] Updated variables names and padding sizes. Needs more work.
June Park <parkjune1995@gmail.com>
parents: 153
diff changeset
1740 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
1741
155
3bb45eb67906 [Postdog] Updated variables names and padding sizes. Needs more work.
June Park <parkjune1995@gmail.com>
parents: 153
diff changeset
1742 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
1743 .x = url_area_rect.x + padding,
115
96db6c3f38d6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 114
diff changeset
1744 .y = url_control_y,
161
87d8d3eb3491 [PostDog] WIP to make it more mordern looking
June Park <parkjune1995@gmail.com>
parents: 159
diff changeset
1745 .width = 10 * (TEXT_SIZE / 2),
115
96db6c3f38d6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 114
diff changeset
1746 .height = TEXT_SIZE * 2
96db6c3f38d6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 114
diff changeset
1747 };
96db6c3f38d6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 114
diff changeset
1748
155
3bb45eb67906 [Postdog] Updated variables names and padding sizes. Needs more work.
June Park <parkjune1995@gmail.com>
parents: 153
diff changeset
1749 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
1750 url_input_bounds_rect.width = url_area_rect.width * 0.7;
161
87d8d3eb3491 [PostDog] WIP to make it more mordern looking
June Park <parkjune1995@gmail.com>
parents: 159
diff changeset
1751 url_input_bounds_rect.height = TEXT_SIZE * 2.5;
111
48f260576059 [PostDog] Rewriting it from scratch as it is unreadable for me.
June Park <parkjune1995@gmail.com>
parents: 63
diff changeset
1752
155
3bb45eb67906 [Postdog] Updated variables names and padding sizes. Needs more work.
June Park <parkjune1995@gmail.com>
parents: 153
diff changeset
1753 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
1754 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
1755 url_enter_button_rect.height = TEXT_SIZE * 2;
54
b3e82d22f961 [PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1756
155
3bb45eb67906 [Postdog] Updated variables names and padding sizes. Needs more work.
June Park <parkjune1995@gmail.com>
parents: 153
diff changeset
1757 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
1758 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
1759 method_dropdown_rect.height = TEXT_SIZE * 2;
112
d6d578b49a19 [PostDog] Got CRUD working.
June Park <parkjune1995@gmail.com>
parents: 111
diff changeset
1760
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
1761 // -- Body -- //
155
3bb45eb67906 [Postdog] Updated variables names and padding sizes. Needs more work.
June Park <parkjune1995@gmail.com>
parents: 153
diff changeset
1762 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
1763 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
1764
155
3bb45eb67906 [Postdog] Updated variables names and padding sizes. Needs more work.
June Park <parkjune1995@gmail.com>
parents: 153
diff changeset
1765 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
1766 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
1767 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
1768
155
3bb45eb67906 [Postdog] Updated variables names and padding sizes. Needs more work.
June Park <parkjune1995@gmail.com>
parents: 153
diff changeset
1769 input_tab_rect = (Rectangle){
3bb45eb67906 [Postdog] Updated variables names and padding sizes. Needs more work.
June Park <parkjune1995@gmail.com>
parents: 153
diff changeset
1770 .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
1771 .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
1772 .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
1773 .height = input_area_rect.height * 0.1
115
96db6c3f38d6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 114
diff changeset
1774 };
96db6c3f38d6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 114
diff changeset
1775
155
3bb45eb67906 [Postdog] Updated variables names and padding sizes. Needs more work.
June Park <parkjune1995@gmail.com>
parents: 153
diff changeset
1776 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
1777 input_tab_item_rect.width = input_tab_rect.width / 4;
54
b3e82d22f961 [PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1778
155
3bb45eb67906 [Postdog] Updated variables names and padding sizes. Needs more work.
June Park <parkjune1995@gmail.com>
parents: 153
diff changeset
1779 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
1780 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
1781 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
1782
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
1783 // -- Result -- /
155
3bb45eb67906 [Postdog] Updated variables names and padding sizes. Needs more work.
June Park <parkjune1995@gmail.com>
parents: 153
diff changeset
1784 result_body_rect = (Rectangle){
3bb45eb67906 [Postdog] Updated variables names and padding sizes. Needs more work.
June Park <parkjune1995@gmail.com>
parents: 153
diff changeset
1785 .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
1786 .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
1787 .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
1788 .height = input_body_rect.height
115
96db6c3f38d6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 114
diff changeset
1789 };
54
b3e82d22f961 [PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1790
114
e2a73e64e8e6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 112
diff changeset
1791 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
1792 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
1793
159
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
1794 // 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
1795 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
1796 {
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
1797 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
1798 }
7bd795bac997 [Postdog] Added scrollable area to inputs and history files, buttons to delete and view.
June Park <parkjune1995@gmail.com>
parents: 115
diff changeset
1799
7bd795bac997 [Postdog] Added scrollable area to inputs and history files, buttons to delete and view.
June Park <parkjune1995@gmail.com>
parents: 115
diff changeset
1800 // 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
1801 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
1802 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
1803 // Clamp scroll offset
155
3bb45eb67906 [Postdog] Updated variables names and padding sizes. Needs more work.
June Park <parkjune1995@gmail.com>
parents: 153
diff changeset
1804 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
1805 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
1806 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
1807 }
7bd795bac997 [Postdog] Added scrollable area to inputs and history files, buttons to delete and view.
June Park <parkjune1995@gmail.com>
parents: 115
diff changeset
1808
159
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
1809 // Reset
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
1810 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
1811
159
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
1812 // 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
1813 if (
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
1814 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
1815 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
1816 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
1817 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
1818 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
1819 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
1820 )
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
1821 SetMouseCursor(MOUSE_CURSOR_POINTING_HAND);
114
e2a73e64e8e6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 112
diff changeset
1822
159
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
1823 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
1824 PostDog_Params_Reset();
161
87d8d3eb3491 [PostDog] WIP to make it more mordern looking
June Park <parkjune1995@gmail.com>
parents: 159
diff changeset
1825
87d8d3eb3491 [PostDog] WIP to make it more mordern looking
June Park <parkjune1995@gmail.com>
parents: 159
diff changeset
1826 // --- Begin Drawing --- //
54
b3e82d22f961 [PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1827 BeginDrawing();
b3e82d22f961 [PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1828 ClearBackground(GetColor(GuiGetStyle(DEFAULT, BACKGROUND_COLOR)));
b3e82d22f961 [PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1829
155
3bb45eb67906 [Postdog] Updated variables names and padding sizes. Needs more work.
June Park <parkjune1995@gmail.com>
parents: 153
diff changeset
1830 // 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
1831 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
1832
155
3bb45eb67906 [Postdog] Updated variables names and padding sizes. Needs more work.
June Park <parkjune1995@gmail.com>
parents: 153
diff changeset
1833 // 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
1834 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
1835 // 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
1836 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
1837 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
1838 .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
1839 .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
1840 .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
1841 .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
1842 };
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
155
3bb45eb67906 [Postdog] Updated variables names and padding sizes. Needs more work.
June Park <parkjune1995@gmail.com>
parents: 153
diff changeset
1844 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
1845 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
1846
155
3bb45eb67906 [Postdog] Updated variables names and padding sizes. Needs more work.
June Park <parkjune1995@gmail.com>
parents: 153
diff changeset
1847 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
1848 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
1849 {
159
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
1850 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
1851 &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
1852
b91f2dd6f84d [PostDog] Fixed delete logic.
June Park <parkjune1995@gmail.com>
parents: 116
diff changeset
1853 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
1854 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
1855
155
3bb45eb67906 [Postdog] Updated variables names and padding sizes. Needs more work.
June Park <parkjune1995@gmail.com>
parents: 153
diff changeset
1856 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
1857 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
1858 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
1859
159
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
1860 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
1861 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
1862 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
1863
155
3bb45eb67906 [Postdog] Updated variables names and padding sizes. Needs more work.
June Park <parkjune1995@gmail.com>
parents: 153
diff changeset
1864 // 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
1865 // 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
1866 // 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
1867
7bd795bac997 [Postdog] Added scrollable area to inputs and history files, buttons to delete and view.
June Park <parkjune1995@gmail.com>
parents: 115
diff changeset
1868 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
1869 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
1870
161
87d8d3eb3491 [PostDog] WIP to make it more mordern looking
June Park <parkjune1995@gmail.com>
parents: 159
diff changeset
1871 Rectangle temp = AddPadding(filename_area_rect, padding);
87d8d3eb3491 [PostDog] WIP to make it more mordern looking
June Park <parkjune1995@gmail.com>
parents: 159
diff changeset
1872
87d8d3eb3491 [PostDog] WIP to make it more mordern looking
June Park <parkjune1995@gmail.com>
parents: 159
diff changeset
1873 // ADD this back
87d8d3eb3491 [PostDog] WIP to make it more mordern looking
June Park <parkjune1995@gmail.com>
parents: 159
diff changeset
1874 // GuiDrawText(curr_history_items->title, temp, TEXT_ALIGN_CENTER, 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
1875 if (
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
1876 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
1877 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
1878 )
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
1879 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
1880
155
3bb45eb67906 [Postdog] Updated variables names and padding sizes. Needs more work.
June Park <parkjune1995@gmail.com>
parents: 153
diff changeset
1881 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
1882 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
1883 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
1884 {
161
87d8d3eb3491 [PostDog] WIP to make it more mordern looking
June Park <parkjune1995@gmail.com>
parents: 159
diff changeset
1885 char delete_path[512];
87d8d3eb3491 [PostDog] WIP to make it more mordern looking
June Park <parkjune1995@gmail.com>
parents: 159
diff changeset
1886 if (!remove(PostDog_Construct_URL(curr_history_items->filename, delete_path, sizeof(delete_path))))
117
b91f2dd6f84d [PostDog] Fixed delete logic.
June Park <parkjune1995@gmail.com>
parents: 116
diff changeset
1887 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
1888 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
1889 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
1890 }
7bd795bac997 [Postdog] Added scrollable area to inputs and history files, buttons to delete and view.
June Park <parkjune1995@gmail.com>
parents: 115
diff changeset
1891 }
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 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
1893
7bd795bac997 [Postdog] Added scrollable area to inputs and history files, buttons to delete and view.
June Park <parkjune1995@gmail.com>
parents: 115
diff changeset
1894 if (total > 0)
114
e2a73e64e8e6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 112
diff changeset
1895 {
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
1896 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
1897 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
1898 {
155
3bb45eb67906 [Postdog] Updated variables names and padding sizes. Needs more work.
June Park <parkjune1995@gmail.com>
parents: 153
diff changeset
1899 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
1900 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
1901 Rectangle scrollbar_rect = {
3bb45eb67906 [Postdog] Updated variables names and padding sizes. Needs more work.
June Park <parkjune1995@gmail.com>
parents: 153
diff changeset
1902 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
1903 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
1904 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
1905 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
1906 };
155
3bb45eb67906 [Postdog] Updated variables names and padding sizes. Needs more work.
June Park <parkjune1995@gmail.com>
parents: 153
diff changeset
1907 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
1908 }
114
e2a73e64e8e6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 112
diff changeset
1909 }
54
b3e82d22f961 [PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1910
111
48f260576059 [PostDog] Rewriting it from scratch as it is unreadable for me.
June Park <parkjune1995@gmail.com>
parents: 63
diff changeset
1911 // URL area Rect
155
3bb45eb67906 [Postdog] Updated variables names and padding sizes. Needs more work.
June Park <parkjune1995@gmail.com>
parents: 153
diff changeset
1912 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
1913
161
87d8d3eb3491 [PostDog] WIP to make it more mordern looking
June Park <parkjune1995@gmail.com>
parents: 159
diff changeset
1914 if (GuiTextArea(21, url_input_bounds_rect, url_input_text, DEFAULT_TEXT_BUFFER_LENGTH, url_input_edit, FALSE, g_text_area_arena))
114
e2a73e64e8e6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 112
diff changeset
1915 url_input_edit = !url_input_edit;
e2a73e64e8e6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 112
diff changeset
1916
159
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 (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
1918 {
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
1919 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
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 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
1922 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
1923 }
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
1924 }
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
1925
161
87d8d3eb3491 [PostDog] WIP to make it more mordern looking
June Park <parkjune1995@gmail.com>
parents: 159
diff changeset
1926 if (GuiButtonRounded(url_enter_button_rect, "New Request", 0.2, 1))
159
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
1927 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
1928
161
87d8d3eb3491 [PostDog] WIP to make it more mordern looking
June Park <parkjune1995@gmail.com>
parents: 159
diff changeset
1929 DrawRectangleSelectiveRounded(body_area_rect, 10, 10, ORANGE, TRUE, FALSE, FALSE, TRUE);
87d8d3eb3491 [PostDog] WIP to make it more mordern looking
June Park <parkjune1995@gmail.com>
parents: 159
diff changeset
1930 DrawRectangleSelectiveRounded(result_area_rect, 10, 10, WHITE, FALSE, TRUE, TRUE, FALSE);
54
b3e82d22f961 [PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1931
111
48f260576059 [PostDog] Rewriting it from scratch as it is unreadable for me.
June Park <parkjune1995@gmail.com>
parents: 63
diff changeset
1932 // Input Tabs Rect
155
3bb45eb67906 [Postdog] Updated variables names and padding sizes. Needs more work.
June Park <parkjune1995@gmail.com>
parents: 153
diff changeset
1933 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
1934 DrawRectangleRec(input_tab_rect, Fade(DARKBLUE, 0.1f));
112
d6d578b49a19 [PostDog] Got CRUD working.
June Park <parkjune1995@gmail.com>
parents: 111
diff changeset
1935 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
1936
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
1937 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
1938 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
1939 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
1940 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
1941
159
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
1942 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
1943 {
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
1944 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
1945 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
1946 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
1947 }
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
1948 else
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
1949 {
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
1950 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
1951 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
1952 .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
1953 .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
1954 .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
1955 .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
1956 };
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
1957 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
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 (!ws)
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
1960 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
1961 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
1962 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
1963 }
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
1964 }
7bd795bac997 [Postdog] Added scrollable area to inputs and history files, buttons to delete and view.
June Park <parkjune1995@gmail.com>
parents: 115
diff changeset
1965
159
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
1966
155
3bb45eb67906 [Postdog] Updated variables names and padding sizes. Needs more work.
June Park <parkjune1995@gmail.com>
parents: 153
diff changeset
1967 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
1968 PostDog_Update_URL();
54
b3e82d22f961 [PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1969
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 // 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
1971 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
1972 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
1973 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
1974
159
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
1975 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
1976 result_body_edit_mode = !result_body_edit_mode;
114
e2a73e64e8e6 [Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents: 112
diff changeset
1977
161
87d8d3eb3491 [PostDog] WIP to make it more mordern looking
June Park <parkjune1995@gmail.com>
parents: 159
diff changeset
1978 if (GuiDropdownBoxRounded(url_text_bounds_rect, "GET;POST;PUT;DELETE", &active_method_dropdown, method_edit, 0.2, 1))
87d8d3eb3491 [PostDog] WIP to make it more mordern looking
June Park <parkjune1995@gmail.com>
parents: 159
diff changeset
1979 method_edit = !method_edit;
54
b3e82d22f961 [PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1980 EndDrawing();
b3e82d22f961 [PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1981 }
159
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
1982
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
1983 GuiTextAreaResetAllStates();
05cf9467a1c3 [Postdog] Updated to use text area that can handle like html text area.
June Park <parkjune1995@gmail.com>
parents: 155
diff changeset
1984 Dowa_Arena_Free(g_text_area_arena);
161
87d8d3eb3491 [PostDog] WIP to make it more mordern looking
June Park <parkjune1995@gmail.com>
parents: 159
diff changeset
1985
87d8d3eb3491 [PostDog] WIP to make it more mordern looking
June Park <parkjune1995@gmail.com>
parents: 159
diff changeset
1986 // Cleanup libuv
87d8d3eb3491 [PostDog] WIP to make it more mordern looking
June Park <parkjune1995@gmail.com>
parents: 159
diff changeset
1987 uv_mutex_destroy(&history_mutex);
87d8d3eb3491 [PostDog] WIP to make it more mordern looking
June Park <parkjune1995@gmail.com>
parents: 159
diff changeset
1988 uv_loop_close(main_loop);
87d8d3eb3491 [PostDog] WIP to make it more mordern looking
June Park <parkjune1995@gmail.com>
parents: 159
diff changeset
1989
54
b3e82d22f961 [PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1990 CloseWindow();
b3e82d22f961 [PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1991 return 0;
b3e82d22f961 [PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1992 }