new textedit widget and text editor
This commit is contained in:
parent
0a423f01e4
commit
5023c24047
@ -75,9 +75,9 @@ cd ..
|
|||||||
cd frotz
|
cd frotz
|
||||||
./make.sh
|
./make.sh
|
||||||
cd ..
|
cd ..
|
||||||
cd text
|
#cd text
|
||||||
./make.sh
|
#./make.sh
|
||||||
cd ..
|
#cd ..
|
||||||
cd my_basic
|
cd my_basic
|
||||||
./make.sh
|
./make.sh
|
||||||
cd ..
|
cd ..
|
||||||
|
@ -96,6 +96,13 @@ i686-quinn-strip filemanager.exe
|
|||||||
mv filemanager.exe $HOME/Quinn/fsroot/gui
|
mv filemanager.exe $HOME/Quinn/fsroot/gui
|
||||||
rm filemanager.o
|
rm filemanager.o
|
||||||
|
|
||||||
|
cd $HOME/Quinn/src/quinn-os/programs/gui/edit/
|
||||||
|
i686-quinn-gcc $CFLAGS -I$HOME/Quinn/sysroot/usr/include -c edit.c
|
||||||
|
i686-quinn-gcc $CFLAGS edit.o $HOME/Quinn/sysroot/usr/lib/libquinn.a $HOME/Quinn/sysroot/usr/lib/libfreetype.a $HOME/Quinn/sysroot/usr/lib/libpng.a $HOME/Quinn/sysroot/usr/lib/libz.a -o edit.exe
|
||||||
|
i686-quinn-strip edit.exe
|
||||||
|
mv edit.exe $HOME/Quinn/fsroot/gui
|
||||||
|
rm edit.o
|
||||||
|
|
||||||
cd $HOME/Quinn/src/quinn-os/programs/gui/meminfo/
|
cd $HOME/Quinn/src/quinn-os/programs/gui/meminfo/
|
||||||
i686-quinn-gcc $CFLAGS -I$HOME/Quinn/sysroot/usr/include -c meminfo.c
|
i686-quinn-gcc $CFLAGS -I$HOME/Quinn/sysroot/usr/include -c meminfo.c
|
||||||
i686-quinn-gcc $CFLAGS meminfo.o $HOME/Quinn/sysroot/usr/lib/libquinn.a $HOME/Quinn/sysroot/usr/lib/libfreetype.a $HOME/Quinn/sysroot/usr/lib/libpng.a $HOME/Quinn/sysroot/usr/lib/libz.a -o meminfo.exe
|
i686-quinn-gcc $CFLAGS meminfo.o $HOME/Quinn/sysroot/usr/lib/libquinn.a $HOME/Quinn/sysroot/usr/lib/libfreetype.a $HOME/Quinn/sysroot/usr/lib/libpng.a $HOME/Quinn/sysroot/usr/lib/libz.a -o meminfo.exe
|
||||||
|
15
minix.c
15
minix.c
@ -844,7 +844,20 @@ int minix_clear_zones(struct vfs_device_t *device, int ino, unsigned long long s
|
|||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
void minix_trunc_file(struct vfs_device_t *device, struct minix_file_info *finfo) { minix_clear_zones(device, finfo->inode, 0, finfo->file_size); }
|
void minix_wipe_inode(struct vfs_device_t *device, struct minix_file_info *finfo) {
|
||||||
|
struct minix_inode *inode = minix_get_inode(device, finfo->inode);
|
||||||
|
|
||||||
|
inode->i_size = 0;
|
||||||
|
for (int i = 0; i < 10; i++) {
|
||||||
|
inode->i_zone[i] = NO_ZONE;
|
||||||
|
}
|
||||||
|
|
||||||
|
minix_write_inode(device, finfo->inode, inode);
|
||||||
|
}
|
||||||
|
|
||||||
|
void minix_trunc_file(struct vfs_device_t *device, struct minix_file_info *finfo) {
|
||||||
|
minix_clear_zones(device, finfo->inode, 0, finfo->file_size);
|
||||||
|
}
|
||||||
|
|
||||||
void minix_free_inode(struct vfs_device_t *device, unsigned int ino) { minix_free_bit(device, 0, ino); }
|
void minix_free_inode(struct vfs_device_t *device, unsigned int ino) { minix_free_bit(device, 0, ino); }
|
||||||
|
|
||||||
|
1
minix.h
1
minix.h
@ -68,4 +68,5 @@ extern int minix_read_data(struct vfs_device_t *device, struct minix_file_info *
|
|||||||
extern int minix_change_directory(struct vfs_device_t *device, char *path);
|
extern int minix_change_directory(struct vfs_device_t *device, char *path);
|
||||||
extern int minix_unlink_file(struct vfs_device_t *device, const char *path);
|
extern int minix_unlink_file(struct vfs_device_t *device, const char *path);
|
||||||
extern int minix_load_superblock(struct vfs_device_t *device);
|
extern int minix_load_superblock(struct vfs_device_t *device);
|
||||||
|
extern void minix_wipe_inode(struct vfs_device_t *device, struct minix_file_info *finfo);
|
||||||
#endif
|
#endif
|
||||||
|
@ -16,7 +16,7 @@ WORK=disk0:/gui/
|
|||||||
EXEC=disk0:/games/qdoom.exe
|
EXEC=disk0:/games/qdoom.exe
|
||||||
ICON=disk0:/system/icons/qdoom.png
|
ICON=disk0:/system/icons/qdoom.png
|
||||||
WORK=disk0:/games/
|
WORK=disk0:/games/
|
||||||
EXEC=disk0:/gui/text.exe
|
EXEC=disk0:/gui/edit.exe
|
||||||
ICON=disk0:/system/icons/text.png
|
ICON=disk0:/system/icons/text.png
|
||||||
WORK=disk0:/gui/
|
WORK=disk0:/gui/
|
||||||
|
|
||||||
|
@ -30,13 +30,13 @@
|
|||||||
<p>
|
<p>
|
||||||
Quinn is a hobby operating system for 32-bit x86 computers.
|
Quinn is a hobby operating system for 32-bit x86 computers.
|
||||||
If you would like to learn more about Quinn, see:
|
If you would like to learn more about Quinn, see:
|
||||||
<a href="https://quinn.positronicbrain.net/">https://quinn.positronicbrain.net/</a>
|
<a href="https://quinn.pamment.id.au/">https://quinn.pamment.id.au/</a>
|
||||||
</p>
|
</p>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
</div>
|
</div>
|
||||||
<div id="footer">
|
<div id="footer">
|
||||||
Quinn © 2016-2021 Andrew Pamment
|
Quinn © 2016-2022 Andrew Pamment
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</body>
|
</body>
|
||||||
|
217
programs/gui/edit/edit.c
Normal file
217
programs/gui/edit/edit.c
Normal file
@ -0,0 +1,217 @@
|
|||||||
|
#include <stdlib.h>
|
||||||
|
#include <string.h>
|
||||||
|
#include <stdio.h>
|
||||||
|
#include "quinn.h"
|
||||||
|
#include "convertxpm.h"
|
||||||
|
#include "edit.xpm"
|
||||||
|
|
||||||
|
char filename[1024];
|
||||||
|
struct widget_t *textbox;
|
||||||
|
struct widget_t *poslabel;
|
||||||
|
char tmp_buffer[100];
|
||||||
|
int window_handle;
|
||||||
|
|
||||||
|
char *basename(char *path) {
|
||||||
|
char *ptr = path;
|
||||||
|
for (int i = strlen(path); i >= 0; i--) {
|
||||||
|
if (path[i] == '/') {
|
||||||
|
ptr = &path[i+1];
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return ptr;
|
||||||
|
}
|
||||||
|
|
||||||
|
void exit_callback(int wh) {
|
||||||
|
quinn_exit();
|
||||||
|
exit(0);
|
||||||
|
}
|
||||||
|
|
||||||
|
int open_dialog_wh;
|
||||||
|
struct widget_t *open_txtbox;
|
||||||
|
|
||||||
|
int open_document() {
|
||||||
|
int ret = 0;
|
||||||
|
FILE *fptr = fopen(filename, "r");
|
||||||
|
if (fptr) {
|
||||||
|
fseek(fptr, 0, SEEK_END);
|
||||||
|
int size = ftell(fptr);
|
||||||
|
char *buffer = (char *)malloc(size + 1);
|
||||||
|
if (buffer) {
|
||||||
|
fseek(fptr, 0, SEEK_SET);
|
||||||
|
memset(buffer, 0, size + 1);
|
||||||
|
fread(buffer, size, 1, fptr);
|
||||||
|
quinn_textedit_set_text(textbox, buffer);
|
||||||
|
free(buffer);
|
||||||
|
ret = 1;
|
||||||
|
snprintf(tmp_buffer, 100, "Edit: %s", basename(filename));
|
||||||
|
quinn_set_win_caption(window_handle, tmp_buffer);
|
||||||
|
}
|
||||||
|
fclose(fptr);
|
||||||
|
}
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
void open_dialog_close(int wh) {
|
||||||
|
quinn_flag_remove_window(open_dialog_wh);
|
||||||
|
}
|
||||||
|
|
||||||
|
void opendialogbtnopen_cb(void *data) {
|
||||||
|
if (strlen(quinn_textbox_get_text(open_txtbox)) > 0) {
|
||||||
|
strlcpy(filename, quinn_textbox_get_text(open_txtbox), 1024);
|
||||||
|
if (!open_document()) {
|
||||||
|
quinn_show_message_box(window_handle, "Open Failed!", "There was an error reading the file.", 0, NULL);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
quinn_flag_remove_window(open_dialog_wh);
|
||||||
|
}
|
||||||
|
|
||||||
|
void opendialogbtncancel_cb(void *data) {
|
||||||
|
quinn_flag_remove_window(open_dialog_wh);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void openbtn_cb(void *data) {
|
||||||
|
struct window_req_t *req;
|
||||||
|
req = (struct window_req_t *)malloc(sizeof(struct window_req_t));
|
||||||
|
|
||||||
|
req->x = 150;
|
||||||
|
req->y = 150;
|
||||||
|
req->width = 300;
|
||||||
|
req->height = 80;
|
||||||
|
req->icon = NULL;
|
||||||
|
req->flags = 0;
|
||||||
|
strcpy(req->name, "Open");
|
||||||
|
|
||||||
|
open_dialog_wh = quinn_req_window(req, open_dialog_close);
|
||||||
|
free(req);
|
||||||
|
open_txtbox = quinn_add_textbox(open_dialog_wh, 10, 10, 280, 30, "", NULL);
|
||||||
|
quinn_add_button(open_dialog_wh, 60, 50, 75, 20, "Open", NULL, opendialogbtnopen_cb);
|
||||||
|
quinn_add_button(open_dialog_wh, 155, 50, 75, 20, "Cancel", NULL, opendialogbtncancel_cb);
|
||||||
|
quinn_update_window();
|
||||||
|
}
|
||||||
|
|
||||||
|
int save_document() {
|
||||||
|
char *text = quinn_textedit_get_text(textbox);
|
||||||
|
FILE *fptr = fopen(filename, "w");
|
||||||
|
int ret = 0;
|
||||||
|
if (fptr) {
|
||||||
|
fputs(text, fptr);
|
||||||
|
fclose(fptr);
|
||||||
|
snprintf(tmp_buffer, 100, "Saved!");
|
||||||
|
quinn_label_settext(poslabel, tmp_buffer);
|
||||||
|
ret = 1;
|
||||||
|
snprintf(tmp_buffer, 100, "Edit: %s", basename(filename));
|
||||||
|
quinn_set_win_caption(window_handle, tmp_buffer);
|
||||||
|
}
|
||||||
|
free(text);
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
int save_dialog_wh;
|
||||||
|
struct widget_t *save_txtbox;
|
||||||
|
|
||||||
|
void save_dialog_close(int wh) {
|
||||||
|
quinn_flag_remove_window(save_dialog_wh);
|
||||||
|
}
|
||||||
|
|
||||||
|
void savedialogbtnsave_cb(void *data) {
|
||||||
|
if (strlen(quinn_textbox_get_text(save_txtbox)) > 0) {
|
||||||
|
strlcpy(filename, quinn_textbox_get_text(save_txtbox), 1024);
|
||||||
|
if (!save_document()) {
|
||||||
|
quinn_show_message_box(window_handle, "Save Failed!", "There was an error writing the file.", 0, NULL);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
quinn_flag_remove_window(save_dialog_wh);
|
||||||
|
}
|
||||||
|
|
||||||
|
void savedialogbtncancel_cb(void *data) {
|
||||||
|
quinn_flag_remove_window(save_dialog_wh);
|
||||||
|
}
|
||||||
|
|
||||||
|
void saveasbtn_cb(void *data) {
|
||||||
|
struct window_req_t *req;
|
||||||
|
req = (struct window_req_t *)malloc(sizeof(struct window_req_t));
|
||||||
|
|
||||||
|
req->x = 150;
|
||||||
|
req->y = 150;
|
||||||
|
req->width = 300;
|
||||||
|
req->height = 80;
|
||||||
|
req->icon = NULL;
|
||||||
|
req->flags = 0;
|
||||||
|
strcpy(req->name, "Save As");
|
||||||
|
|
||||||
|
save_dialog_wh = quinn_req_window(req, save_dialog_close);
|
||||||
|
free(req);
|
||||||
|
save_txtbox = quinn_add_textbox(save_dialog_wh, 10, 10, 280, 30, "", NULL);
|
||||||
|
quinn_add_button(save_dialog_wh, 60, 50, 75, 20, "Save", NULL, savedialogbtnsave_cb);
|
||||||
|
quinn_add_button(save_dialog_wh, 155, 50, 75, 20, "Cancel", NULL, savedialogbtncancel_cb);
|
||||||
|
quinn_update_window();
|
||||||
|
}
|
||||||
|
|
||||||
|
void savebtn_cb(void *data) {
|
||||||
|
if (strlen(filename) == 0) {
|
||||||
|
saveasbtn_cb(data);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (!save_document()) {
|
||||||
|
quinn_show_message_box(window_handle, "Save Failed!", "There was an error writing the file.", 0, NULL);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void newbtn_cb(void *data) {
|
||||||
|
quinn_textedit_set_text(textbox, "");
|
||||||
|
memset(filename, 0, 1024);
|
||||||
|
quinn_set_win_caption(window_handle, "Edit");
|
||||||
|
}
|
||||||
|
|
||||||
|
int main(int argc, char **argv) {
|
||||||
|
struct window_req_t *req;
|
||||||
|
|
||||||
|
char buff[10];
|
||||||
|
|
||||||
|
|
||||||
|
quinn_init();
|
||||||
|
|
||||||
|
unsigned char *icon;
|
||||||
|
|
||||||
|
convert_xpm(edit_xpm, &icon);
|
||||||
|
|
||||||
|
req = (struct window_req_t *)malloc(sizeof(struct window_req_t));
|
||||||
|
|
||||||
|
req->x = 100;
|
||||||
|
req->y = 100;
|
||||||
|
req->width = 520;
|
||||||
|
req->height = 520;
|
||||||
|
req->icon = icon;
|
||||||
|
req->flags = 0;
|
||||||
|
strcpy(req->name, "Edit");
|
||||||
|
|
||||||
|
window_handle = quinn_req_window(req, exit_callback);
|
||||||
|
free(req);
|
||||||
|
free(icon);
|
||||||
|
poslabel = quinn_add_label(window_handle, 0, 500, 520, 20, 2, 0xff000000, "Welcome to Edit!", NULL);
|
||||||
|
textbox = quinn_add_textedit(window_handle, 0, 20, 520, 480, NULL);
|
||||||
|
quinn_add_button(window_handle, 0, 0, 75, 20, "New", NULL, newbtn_cb);
|
||||||
|
quinn_add_button(window_handle, 75, 0, 75, 20, "Open", NULL, openbtn_cb);
|
||||||
|
quinn_add_button(window_handle, 150, 0, 75, 20, "Save", NULL, savebtn_cb);
|
||||||
|
quinn_add_button(window_handle, 225, 0, 75, 20, "Save as", NULL, saveasbtn_cb);
|
||||||
|
quinn_set_font(textbox, "disk0:/fonts/DejaVuSansMono.ttf");
|
||||||
|
|
||||||
|
if (argc == 2) {
|
||||||
|
strlcpy(filename, argv[1], 1024);
|
||||||
|
if (open_document()) {
|
||||||
|
snprintf(tmp_buffer, 100, "Loaded \"%s\".", basename(filename));
|
||||||
|
quinn_label_settext(poslabel, tmp_buffer);
|
||||||
|
} else {
|
||||||
|
memset(filename, 0, 1024);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
while (1) {
|
||||||
|
quinn_process(1);
|
||||||
|
snprintf(tmp_buffer, 100, "Line %d, Col %d.", quinn_textedit_get_y(textbox), quinn_textedit_get_x(textbox));
|
||||||
|
quinn_label_settext(poslabel, tmp_buffer);
|
||||||
|
}
|
||||||
|
quinn_exit();
|
||||||
|
}
|
351
programs/gui/edit/edit.xpm
Normal file
351
programs/gui/edit/edit.xpm
Normal file
@ -0,0 +1,351 @@
|
|||||||
|
/* XPM */
|
||||||
|
static char * edit_xpm[] = {
|
||||||
|
"64 64 284 2",
|
||||||
|
" c None",
|
||||||
|
". c #1C0F16",
|
||||||
|
"+ c #1F1118",
|
||||||
|
"@ c #180D13",
|
||||||
|
"# c #4A293B",
|
||||||
|
"$ c #B1618B",
|
||||||
|
"% c #AB5E87",
|
||||||
|
"& c #402332",
|
||||||
|
"* c #1C0F17",
|
||||||
|
"= c #A75C83",
|
||||||
|
"- c #AD5F88",
|
||||||
|
"; c #1C1016",
|
||||||
|
"> c #120C0E",
|
||||||
|
", c #130F11",
|
||||||
|
"' c #73415C",
|
||||||
|
") c #24141C",
|
||||||
|
"! c #1F1D1E",
|
||||||
|
"~ c #848484",
|
||||||
|
"{ c #3E393C",
|
||||||
|
"] c #442A38",
|
||||||
|
"^ c #74405B",
|
||||||
|
"/ c #0B0B07",
|
||||||
|
"( c #050505",
|
||||||
|
"_ c #1B1B1B",
|
||||||
|
": c #161615",
|
||||||
|
"< c #0F0F0F",
|
||||||
|
"[ c #0C0C0C",
|
||||||
|
"} c #0B0B0B",
|
||||||
|
"| c #0E0E0C",
|
||||||
|
"1 c #090908",
|
||||||
|
"2 c #060606",
|
||||||
|
"3 c #141012",
|
||||||
|
"4 c #646364",
|
||||||
|
"5 c #898989",
|
||||||
|
"6 c #585556",
|
||||||
|
"7 c #2A1D24",
|
||||||
|
"8 c #1D1016",
|
||||||
|
"9 c #12110C",
|
||||||
|
"0 c #564E39",
|
||||||
|
"a c #756A4D",
|
||||||
|
"b c #22211E",
|
||||||
|
"c c #707070",
|
||||||
|
"d c #22201D",
|
||||||
|
"e c #524A36",
|
||||||
|
"f c #1B1B07",
|
||||||
|
"g c #1A1919",
|
||||||
|
"h c #7B7B7B",
|
||||||
|
"i c #302D2E",
|
||||||
|
"j c #181610",
|
||||||
|
"k c #C3B080",
|
||||||
|
"l c #9A8B65",
|
||||||
|
"m c #8F815E",
|
||||||
|
"n c #8E805D",
|
||||||
|
"o c #252420",
|
||||||
|
"p c #25231F",
|
||||||
|
"q c #A19169",
|
||||||
|
"r c #504D24",
|
||||||
|
"s c #D8E511",
|
||||||
|
"t c #868E0C",
|
||||||
|
"u c #111010",
|
||||||
|
"v c #6D6D6D",
|
||||||
|
"w c #6F6E6E",
|
||||||
|
"x c #161315",
|
||||||
|
"y c #191711",
|
||||||
|
"z c #645C47",
|
||||||
|
"A c #575552",
|
||||||
|
"B c #73726F",
|
||||||
|
"C c #72716E",
|
||||||
|
"D c #232322",
|
||||||
|
"E c #222121",
|
||||||
|
"F c #484642",
|
||||||
|
"G c #5D563D",
|
||||||
|
"H c #858B13",
|
||||||
|
"I c #F0FF13",
|
||||||
|
"J c #B4C00E",
|
||||||
|
"K c #100F0E",
|
||||||
|
"L c #171616",
|
||||||
|
"M c #413E37",
|
||||||
|
"N c #FFFFFF",
|
||||||
|
"O c #FCFCFC",
|
||||||
|
"P c #323232",
|
||||||
|
"Q c #343434",
|
||||||
|
"R c #F4F4F4",
|
||||||
|
"S c #35370C",
|
||||||
|
"T c #ECFB13",
|
||||||
|
"U c #8C930B",
|
||||||
|
"V c #0E0F02",
|
||||||
|
"W c #44413A",
|
||||||
|
"X c #848573",
|
||||||
|
"Y c #B1BC0E",
|
||||||
|
"Z c #E4F212",
|
||||||
|
"` c #292C04",
|
||||||
|
" . c #FBFBFB",
|
||||||
|
".. c #141414",
|
||||||
|
"+. c #313131",
|
||||||
|
"@. c #353535",
|
||||||
|
"#. c #383838",
|
||||||
|
"$. c #373737",
|
||||||
|
"%. c #3D3D3D",
|
||||||
|
"&. c #3C3C3C",
|
||||||
|
"*. c #3E3E3E",
|
||||||
|
"=. c #242424",
|
||||||
|
"-. c #E2E2E2",
|
||||||
|
";. c #676C25",
|
||||||
|
">. c #636908",
|
||||||
|
",. c #FEFEFE",
|
||||||
|
"'. c #DDDDDD",
|
||||||
|
"). c #D2D2D2",
|
||||||
|
"!. c #CCCCCC",
|
||||||
|
"~. c #C8C8C8",
|
||||||
|
"{. c #BBBBBB",
|
||||||
|
"]. c #AEAEAE",
|
||||||
|
"^. c #AAAAAA",
|
||||||
|
"/. c #B2B2B2",
|
||||||
|
"(. c #5D5F42",
|
||||||
|
"_. c #D8E611",
|
||||||
|
":. c #C9D510",
|
||||||
|
"<. c #272903",
|
||||||
|
"[. c #B8B9B2",
|
||||||
|
"}. c #8E961C",
|
||||||
|
"|. c #3B3E05",
|
||||||
|
"1. c #F8F8F8",
|
||||||
|
"2. c #55582C",
|
||||||
|
"3. c #EDFC13",
|
||||||
|
"4. c #969F0D",
|
||||||
|
"5. c #ECECEC",
|
||||||
|
"6. c #C0C0C0",
|
||||||
|
"7. c #666753",
|
||||||
|
"8. c #BAC613",
|
||||||
|
"9. c #E7F512",
|
||||||
|
"0. c #2A2C07",
|
||||||
|
"a. c #C4C4C4",
|
||||||
|
"b. c #444444",
|
||||||
|
"c. c #555A0E",
|
||||||
|
"d. c #6E7213",
|
||||||
|
"e. c #1C1A10",
|
||||||
|
"f. c #5C5E40",
|
||||||
|
"g. c #DCEA11",
|
||||||
|
"h. c #CCD910",
|
||||||
|
"i. c #5E592F",
|
||||||
|
"j. c #201E15",
|
||||||
|
"k. c #B0B1A9",
|
||||||
|
"l. c #91991A",
|
||||||
|
"m. c #41440C",
|
||||||
|
"n. c #B7A578",
|
||||||
|
"o. c #F6F6F6",
|
||||||
|
"p. c #52552A",
|
||||||
|
"q. c #EEFD13",
|
||||||
|
"r. c #A2AB15",
|
||||||
|
"s. c #343320",
|
||||||
|
"t. c #F7F7F7",
|
||||||
|
"u. c #D5D5D5",
|
||||||
|
"v. c #6B6D59",
|
||||||
|
"w. c #BBC712",
|
||||||
|
"x. c #575936",
|
||||||
|
"y. c #413E36",
|
||||||
|
"z. c #D6D6D6",
|
||||||
|
"A. c #2F2F2F",
|
||||||
|
"B. c #292929",
|
||||||
|
"C. c #555A0C",
|
||||||
|
"D. c #767C1D",
|
||||||
|
"E. c #CECECB",
|
||||||
|
"F. c #5B5D3E",
|
||||||
|
"G. c #DDEB12",
|
||||||
|
"H. c #CEDB11",
|
||||||
|
"I. c #717359",
|
||||||
|
"J. c #ACADA4",
|
||||||
|
"K. c #959D1A",
|
||||||
|
"L. c #5A5D27",
|
||||||
|
"M. c #525528",
|
||||||
|
"N. c #A4AE16",
|
||||||
|
"O. c #9D9E90",
|
||||||
|
"P. c #EBEBEB",
|
||||||
|
"Q. c #8F8F8F",
|
||||||
|
"R. c #4E4F3B",
|
||||||
|
"S. c #C0CC11",
|
||||||
|
"T. c #E8F612",
|
||||||
|
"U. c #3E401E",
|
||||||
|
"V. c #C6C6C6",
|
||||||
|
"W. c #E7E7E7",
|
||||||
|
"X. c #757575",
|
||||||
|
"Y. c #656564",
|
||||||
|
"Z. c #606513",
|
||||||
|
"`. c #6D7312",
|
||||||
|
" + c #5F5F5B",
|
||||||
|
".+ c #BCBCBC",
|
||||||
|
"++ c #5D5F3D",
|
||||||
|
"@+ c #E1EF12",
|
||||||
|
"#+ c #CFDC11",
|
||||||
|
"$+ c #6F7157",
|
||||||
|
"%+ c #A8A99E",
|
||||||
|
"&+ c #98A119",
|
||||||
|
"*+ c #5A5E26",
|
||||||
|
"=+ c #F5F5F5",
|
||||||
|
"-+ c #575A29",
|
||||||
|
";+ c #EFFE13",
|
||||||
|
">+ c #A7B116",
|
||||||
|
",+ c #9A9B8C",
|
||||||
|
"'+ c #CECECE",
|
||||||
|
")+ c #1E1F09",
|
||||||
|
"!+ c #C1CE0F",
|
||||||
|
"~+ c #272906",
|
||||||
|
"{+ c #939393",
|
||||||
|
"]+ c #F0F0F0",
|
||||||
|
"^+ c #C8C8C7",
|
||||||
|
"/+ c #6E741F",
|
||||||
|
"(+ c #787F1C",
|
||||||
|
"_+ c #BCBCB8",
|
||||||
|
":+ c #F9F9F9",
|
||||||
|
"<+ c #575939",
|
||||||
|
"[+ c #E2F012",
|
||||||
|
"}+ c #D0DD10",
|
||||||
|
"|+ c #6C6E54",
|
||||||
|
"1+ c #A4A59A",
|
||||||
|
"2+ c #9CA519",
|
||||||
|
"3+ c #5A5E25",
|
||||||
|
"4+ c #F2F2F2",
|
||||||
|
"5+ c #545727",
|
||||||
|
"6+ c #AEB816",
|
||||||
|
"7+ c #979889",
|
||||||
|
"8+ c #252711",
|
||||||
|
"9+ c #C3CF10",
|
||||||
|
"0+ c #E9F812",
|
||||||
|
"a+ c #2D300B",
|
||||||
|
"b+ c #DBDBDB",
|
||||||
|
"c+ c #A9A9A7",
|
||||||
|
"d+ c #70751D",
|
||||||
|
"e+ c #7A8019",
|
||||||
|
"f+ c #ACACA7",
|
||||||
|
"g+ c #37332D",
|
||||||
|
"h+ c #2A280E",
|
||||||
|
"i+ c #DCE911",
|
||||||
|
"j+ c #D2DF11",
|
||||||
|
"k+ c #6A6C52",
|
||||||
|
"l+ c #4E433D",
|
||||||
|
"m+ c #805D47",
|
||||||
|
"n+ c #1A150E",
|
||||||
|
"o+ c #90990D",
|
||||||
|
"p+ c #5C6025",
|
||||||
|
"q+ c #EAEAEA",
|
||||||
|
"r+ c #E3E3E3",
|
||||||
|
"s+ c #C1C1C1",
|
||||||
|
"t+ c #5F4A3D",
|
||||||
|
"u+ c #B18061",
|
||||||
|
"v+ c #A07357",
|
||||||
|
"w+ c #2C2219",
|
||||||
|
"x+ c #36350E",
|
||||||
|
"y+ c #848575",
|
||||||
|
"z+ c #EFEFEF",
|
||||||
|
"A+ c #212121",
|
||||||
|
"B+ c #1B1917",
|
||||||
|
"C+ c #87614A",
|
||||||
|
"D+ c #644938",
|
||||||
|
"E+ c #16120E",
|
||||||
|
"F+ c #59534E",
|
||||||
|
"G+ c #AC7C5E",
|
||||||
|
"H+ c #A8795C",
|
||||||
|
"I+ c #4C3F36",
|
||||||
|
"J+ c #8B8987",
|
||||||
|
"K+ c #4C423C",
|
||||||
|
"L+ c #8E684F",
|
||||||
|
"M+ c #423A36",
|
||||||
|
"N+ c #D1D1D1",
|
||||||
|
"O+ c #070605",
|
||||||
|
"P+ c #65605D",
|
||||||
|
"Q+ c #5E5C5C",
|
||||||
|
"R+ c #413E35",
|
||||||
|
"S+ c #423E35",
|
||||||
|
"T+ c #EEEEEE",
|
||||||
|
"U+ c #C3C3C3",
|
||||||
|
"V+ c #514B3D",
|
||||||
|
"W+ c #A2926A",
|
||||||
|
"X+ c #3D392F",
|
||||||
|
"Y+ c #2C2A24",
|
||||||
|
"Z+ c #454034",
|
||||||
|
"`+ c #AE9D72",
|
||||||
|
" @ c #201C15",
|
||||||
|
".@ c #14110D",
|
||||||
|
"+@ c #A4946C",
|
||||||
|
"@@ c #AB9A70",
|
||||||
|
"#@ c #13110C",
|
||||||
|
"$@ c #0C0B09",
|
||||||
|
"%@ c #060504",
|
||||||
|
"&@ c #0C0B08",
|
||||||
|
" ",
|
||||||
|
" . + @ ",
|
||||||
|
" # $ % & ",
|
||||||
|
" * = $ $ - ; ",
|
||||||
|
" > , ' $ $ $ ) ",
|
||||||
|
" ! ~ { ] - ^ ",
|
||||||
|
" / / / / / / / / / / / ( _ : : < < [ } | 1 [ 2 / / / / / / / / / / 3 4 5 5 6 7 8 ",
|
||||||
|
" 9 0 a a a a a a a a a a a b c c c c c c c c c c d a a a a a a a a a a e f g h 5 5 i ",
|
||||||
|
" j k k l m m m m m m m m n o c c c c c c c c c c p m m m m m m m m q k r s t u v w x ",
|
||||||
|
" y k z A B B B B B B B B C D c c c c c c c c c c E B B B B B B B B F G H I I J K L ",
|
||||||
|
" y k M N N N N N N N N N O P c c c c c c c c c c Q N N N N N N N N R S T I I I U V ",
|
||||||
|
" y k W N N N N N N N N N O P c c c c c c c c c c Q N N N N N N N N X Y I I I Z ` ",
|
||||||
|
" y k W N N N N N N N N N ...P +.@.#.#.$.%.%.&.*.=.N N N N N N N -.;.I I I I >. ",
|
||||||
|
" y k W N N N N N N N N N ,.'.'.).!.!.~.{.{.{.].^./.N N N N N N N (._.I I I :.<. ",
|
||||||
|
" y k W N N N N N N N N N N N N N N N N N N N N N N N N N N N N [.}.I I I I |. ",
|
||||||
|
" y k W N N N N N N N N N N N N N N N N N N N N N N N N N N N 1.2.3.I I I 4. ",
|
||||||
|
" y k W N 5.6.6.6.6.6.6.6.6.6.6.6.6.6.6.6.6.6.6.6.6.6.6.6.6.6.7.8.I I I 9.0. ",
|
||||||
|
" y k W N a.b.b.b.b.b.b.b.b.b.b.b.b.b.b.b.b.b.b.b.b.b.b.b.b.&.c.I I I I d.e. ",
|
||||||
|
" y k W N N N N N N N N N N N N N N N N N N N N N N N N N N f.g.I I I h.i.j. ",
|
||||||
|
" y k W N N N N N N N N N N N N N N N N N N N N N N N N N k.l.I I I I m.n.j. ",
|
||||||
|
" y k W N N N N N N N N N N N N N N N N N N N N N N N N o.p.q.I I I r.s.k j. ",
|
||||||
|
" y k W N t.u.u.u.u.u.u.u.u.u.u.u.u.u.u.u.u.u.u.u.u.u.u.v.w.I I I 9.x.y.k j. ",
|
||||||
|
" y k W N z.A.A.A.A.A.A.A.A.A.A.A.A.A.A.A.A.A.A.A.A.A.B.C.I I I I D.E.y.k j. ",
|
||||||
|
" y k W N N N N N N N N N N N N N N N N N N N N N N N F.G.I I I H.I.N y.k j. ",
|
||||||
|
" y k W N N N N N N N N N N N N N N N N N N N N N N J.K.I I I I L.5.N y.k j. ",
|
||||||
|
" y k W N N N N N N N N N N N N N N N N N N N N N o.M.q.I I I N.O.N N y.k j. ",
|
||||||
|
" y k W N P.Q.Q.Q.Q.Q.Q.Q.Q.Q.Q.Q.Q.Q.Q.Q.Q.Q.Q.Q.R.S.I I I T.U.V.N N y.k j. ",
|
||||||
|
" y k W N W.X.X.X.X.X.X.X.X.X.X.X.X.X.X.X.X.X.X.Y.Z.I I I I `. +.+N N y.k j. ",
|
||||||
|
" y k W N N N N N N N N N N N N N N N N N N N N ++@+I I I #+$+N N N N y.k j. ",
|
||||||
|
" y k W N N N N N N N N N N N N N N N N N N N %+&+I I I I *+P.N N N N y.k j. ",
|
||||||
|
" y k W N N N N N N N N N N N N N N N N N N =+-+;+I I I >+,+N N N N N y.k j. ",
|
||||||
|
" y k W N '+................................)+!+I I I T.~+......{+N N y.k j. ",
|
||||||
|
" y k W N O ]+]+]+]+]+]+]+]+]+]+]+]+]+]+]+^+/+I I I I (+_+]+]+]+:+N N y.k j. ",
|
||||||
|
" y k W N N N N N N N N N N N N N N N N N <+[+I I I }+|+N N N N N N N y.k j. ",
|
||||||
|
" y k W N N N N N N N N N N N N N N N N 1+2+I I I I 3+P.N N N N N N N y.k j. ",
|
||||||
|
" y k W N N N N N N N N N N N N N N N 4+5+;+I I I 6+7+N N N N N N N N y.k j. ",
|
||||||
|
" y k W N P.B.B.B.B.B.B.B.B.B.B.B.B.B.8+9+I I I 0+a+B.B.B.B.B.B.~ N N y.k j. ",
|
||||||
|
" y k W N O b+b+b+b+b+b+b+b+b+b+b+b+c+d+I I I I e+f+b+b+b+b+b+b+P.N N y.k j. ",
|
||||||
|
" y k W N N N N N N N N N N N N N N g+h+i+I I j+k+N N N N N N N N N N y.k j. ",
|
||||||
|
" y k W N N N N N N N N N N N N N N l+m+n+o+I p+q+N N N N N N N N N N y.k j. ",
|
||||||
|
" y k W N ,.r+r+r+r+r+r+r+r+r+r+r+s+t+u+v+w+x+y+r+r+r+r+r+r+r+r+z+N N y.k j. ",
|
||||||
|
" y k W N ]+A+A+A+A+A+A+A+A+A+A+A+B+C+u+u+D+E+A+A+A+A+A+A+A+A+A+h N N y.k j. ",
|
||||||
|
" y k W N N N N N N N N N N N N N F+G+H+I+J+N N N N N N N N N N N N N y.k j. ",
|
||||||
|
" y k W N N N N N N N N N N N N N K+L+M+N+N N N N N N N N N N N N N N y.k j. ",
|
||||||
|
" y k W N N N N N N N N N N N N ^.O+P+o.N N N N N N N N N N N N N N N y.k j. ",
|
||||||
|
" y k W N N N N N N N N N N N N A.Q+N N N N N N N N N N N N N N N N N y.k j. ",
|
||||||
|
" y k W N N N N N N N N N N N N b+N N N N N N N N N N N N N N N N N N y.k j. ",
|
||||||
|
" y k W N N N N N N N N N N N N N N N N N N N N N N N N N N N N N N N y.k j. ",
|
||||||
|
" y k W N N N N N N N N N N N N N N N N N N N N N N N N N N N N N N N y.k j. ",
|
||||||
|
" y k W N N N N N N N N N N N N N N N N N N N N N N N N N N N N N N N R+k j. ",
|
||||||
|
" y k S+z.T+T+T+T+T+T+T+T+T+T+T+T+T+T+T+T+T+T+T+T+T+T+T+T+T+T+T+T+T+U+V+k j. ",
|
||||||
|
" y k W+X+Y+Y+Y+Y+Y+Y+Y+Y+Y+Y+Y+Y+Y+Y+Y+Y+Y+Y+Y+Y+Y+Y+Y+Y+Y+Y+Y+Y+Y+Z+`+k j. ",
|
||||||
|
" y k k k k k k k k k k k k k k k k k k k k k k k k k k k k k k k k k k k @ ",
|
||||||
|
" .@+@k k k k k k k k k k k k k k k k k k k k k k k k k k k k k k k k k @@#@ ",
|
||||||
|
" $@%@%@%@%@%@%@%@%@%@%@%@%@%@%@%@%@%@%@%@%@%@%@%@%@%@%@%@%@%@%@%@%@%@&@ ",
|
||||||
|
" ",
|
||||||
|
" ",
|
||||||
|
" ",
|
||||||
|
" ",
|
||||||
|
" ",
|
||||||
|
" ",
|
||||||
|
" ",
|
||||||
|
" ",
|
||||||
|
" "};
|
@ -164,6 +164,42 @@ void run_callback(void *data) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void edit_callback(void *data) {
|
||||||
|
char *filepath;
|
||||||
|
int ret;
|
||||||
|
|
||||||
|
if (active_list == 1) {
|
||||||
|
filepath = (char *)malloc(strlen(cwd) + strlen(filename) + 1);
|
||||||
|
sprintf(filepath, "%s%s", cwd, filename);
|
||||||
|
__asm__ volatile ("int $0x30" : "=a" (ret) : "0" (19), "b" (cwd));
|
||||||
|
} else {
|
||||||
|
filepath = (char *)malloc(strlen(cwd2) + strlen(filename) + 1);
|
||||||
|
sprintf(filepath, "%s%s", cwd2, filename);
|
||||||
|
__asm__ volatile ("int $0x30" : "=a" (ret) : "0" (19), "b" (cwd2));
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
char *argv_s[3];
|
||||||
|
argv_s[0] = "disk0:/gui/edit.exe";
|
||||||
|
argv_s[1] = filepath;
|
||||||
|
argv_s[2] = NULL;
|
||||||
|
|
||||||
|
pid_t pid = fork();
|
||||||
|
|
||||||
|
switch (pid) {
|
||||||
|
case 0:
|
||||||
|
execve("disk0:/gui/edit.exe", argv_s, environ);
|
||||||
|
exit(-1);
|
||||||
|
break;
|
||||||
|
case -1:
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
free(filepath);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void copy_callback(void *data) {
|
void copy_callback(void *data) {
|
||||||
char *source, *destination;
|
char *source, *destination;
|
||||||
FILE *sptr, *dptr;
|
FILE *sptr, *dptr;
|
||||||
@ -342,6 +378,7 @@ int main(int argc, char **argv) {
|
|||||||
quinn_add_button(window_handle, 3, 306, 60,25, "Copy", NULL, copy_callback);
|
quinn_add_button(window_handle, 3, 306, 60,25, "Copy", NULL, copy_callback);
|
||||||
quinn_add_button(window_handle, 63, 306, 60, 25, "Delete", NULL, delete_callback);
|
quinn_add_button(window_handle, 63, 306, 60, 25, "Delete", NULL, delete_callback);
|
||||||
quinn_add_button(window_handle, 123, 306, 60, 25, "Run", NULL, run_callback);
|
quinn_add_button(window_handle, 123, 306, 60, 25, "Run", NULL, run_callback);
|
||||||
|
quinn_add_button(window_handle, 183, 306, 60, 25, "Edit", NULL, edit_callback);
|
||||||
|
|
||||||
disk0_callback(NULL);
|
disk0_callback(NULL);
|
||||||
disk0_callback2(NULL);
|
disk0_callback2(NULL);
|
||||||
|
@ -123,11 +123,9 @@ struct memory_font_t {
|
|||||||
};
|
};
|
||||||
|
|
||||||
struct memory_font_t *default_font;
|
struct memory_font_t *default_font;
|
||||||
struct memory_font_t *mono_font;
|
|
||||||
|
|
||||||
FT_Library library;
|
FT_Library library;
|
||||||
FT_Face ftface;
|
FT_Face ftface;
|
||||||
FT_Face ftface_mono;
|
|
||||||
|
|
||||||
|
|
||||||
unsigned char _quinn_keycodes[256];
|
unsigned char _quinn_keycodes[256];
|
||||||
@ -220,6 +218,16 @@ struct textbox_t {
|
|||||||
void (*callback)();
|
void (*callback)();
|
||||||
};
|
};
|
||||||
|
|
||||||
|
struct textedit_t {
|
||||||
|
char *surf;
|
||||||
|
char **lines;
|
||||||
|
int line_count;
|
||||||
|
int x;
|
||||||
|
int y;
|
||||||
|
int x_offset;
|
||||||
|
int y_offset;
|
||||||
|
void (*callback)();
|
||||||
|
};
|
||||||
|
|
||||||
int read_font(char *name, struct memory_font_t *font)
|
int read_font(char *name, struct memory_font_t *font)
|
||||||
{
|
{
|
||||||
@ -739,8 +747,6 @@ void quinn_init() {
|
|||||||
|
|
||||||
default_font = (struct memory_font_t *)malloc(sizeof(struct memory_font_t));
|
default_font = (struct memory_font_t *)malloc(sizeof(struct memory_font_t));
|
||||||
read_font("disk0:/fonts/DejaVuSans.ttf", default_font);
|
read_font("disk0:/fonts/DejaVuSans.ttf", default_font);
|
||||||
mono_font = (struct memory_font_t *)malloc(sizeof(struct memory_font_t));
|
|
||||||
read_font("disk0:/fonts/DejaVuSansMono.ttf", mono_font);
|
|
||||||
|
|
||||||
|
|
||||||
FT_Error error;
|
FT_Error error;
|
||||||
@ -748,11 +754,6 @@ void quinn_init() {
|
|||||||
error = FT_Init_FreeType(&library);
|
error = FT_Init_FreeType(&library);
|
||||||
error = FT_New_Memory_Face(library, default_font->buffer, default_font->len, 0, &ftface);
|
error = FT_New_Memory_Face(library, default_font->buffer, default_font->len, 0, &ftface);
|
||||||
error = FT_Set_Char_Size(ftface, 8 * 64, 0, 100, 0);
|
error = FT_Set_Char_Size(ftface, 8 * 64, 0, 100, 0);
|
||||||
|
|
||||||
|
|
||||||
error = FT_New_Memory_Face(library, mono_font->buffer, mono_font->len, 0, &ftface_mono);
|
|
||||||
error = FT_Set_Char_Size(ftface_mono, 8 * 64, 0, 100, 0);
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void quinn_draw_listbox(struct window_t *win, char *surface, struct widget_t *widget, int surf_w, int surf_h) {
|
void quinn_draw_listbox(struct window_t *win, char *surface, struct widget_t *widget, int surf_w, int surf_h) {
|
||||||
@ -783,6 +784,100 @@ void quinn_draw_listbox(struct window_t *win, char *surface, struct widget_t *wi
|
|||||||
quinn_render_int(win, surface, listbox->surface, widget->w, widget->h, widget->x, widget->y, surf_w, surf_h);
|
quinn_render_int(win, surface, listbox->surface, widget->w, widget->h, widget->x, widget->y, surf_w, surf_h);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void quinn_textedit_up(struct widget_t *widget) {
|
||||||
|
struct textedit_t *txtedit = (struct textedit_t *)widget->widget;
|
||||||
|
|
||||||
|
if (txtedit->y > 0) {
|
||||||
|
txtedit->y--;
|
||||||
|
|
||||||
|
if (strlen(txtedit->lines[txtedit->y]) < txtedit->x) {
|
||||||
|
txtedit->x = strlen(txtedit->lines[txtedit->y]);
|
||||||
|
}
|
||||||
|
if (txtedit->y < txtedit->y_offset) {
|
||||||
|
txtedit->y_offset--;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void quinn_textedit_down(struct widget_t *widget) {
|
||||||
|
struct textedit_t *txtedit = (struct textedit_t *)widget->widget;
|
||||||
|
|
||||||
|
if (txtedit->y < txtedit->line_count -1) {
|
||||||
|
txtedit->y++;
|
||||||
|
|
||||||
|
if (strlen(txtedit->lines[txtedit->y]) < txtedit->x) {
|
||||||
|
txtedit->x = strlen(txtedit->lines[txtedit->y]);
|
||||||
|
}
|
||||||
|
int lines_per_widget = widget->h / 10;
|
||||||
|
|
||||||
|
if (txtedit->y >= lines_per_widget) {
|
||||||
|
txtedit->y_offset++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void quinn_textedit_left(struct widget_t *widget) {
|
||||||
|
struct textedit_t *txtedit = (struct textedit_t *)widget->widget;
|
||||||
|
|
||||||
|
if (txtedit->x > 0) {
|
||||||
|
txtedit->x--;
|
||||||
|
if (txtedit->x_offset > 0) {
|
||||||
|
txtedit->x_offset--;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void quinn_textedit_right(struct widget_t *widget) {
|
||||||
|
struct textedit_t *txtedit = (struct textedit_t *)widget->widget;
|
||||||
|
|
||||||
|
if (txtedit->x < strlen(txtedit->lines[txtedit->y])) {
|
||||||
|
txtedit->x++;
|
||||||
|
while (quinn_draw_text_width(&txtedit->lines[txtedit->y][txtedit->x_offset], txtedit->x - txtedit->x_offset, widget->font_face) >= widget->w) {
|
||||||
|
txtedit->x_offset++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void quinn_draw_textedit(struct window_t *win, char *surface, struct widget_t *widget, int surf_w, int surf_h) {
|
||||||
|
struct textedit_t *txtedit = (struct textedit_t *)widget->widget;
|
||||||
|
|
||||||
|
quinn_fill_rect_int(win, txtedit->surf, widget->w, widget->h, 0, 0, widget->w, widget->h, 0xff000000);
|
||||||
|
quinn_fill_rect_int(win, txtedit->surf, widget->w, widget->h, 1, 1, widget->w - 2, widget->h - 2, 0xffffffff);
|
||||||
|
|
||||||
|
for (int j = txtedit->y_offset; j < txtedit->line_count; j++) {
|
||||||
|
int i;
|
||||||
|
int size = 0;
|
||||||
|
for (i = txtedit->x_offset; i < strlen(txtedit->lines[j]); i++) {
|
||||||
|
char c[2];
|
||||||
|
|
||||||
|
c[0] = txtedit->lines[j][i];
|
||||||
|
c[1] = '\0';
|
||||||
|
|
||||||
|
int w = quinn_draw_text_width(&c, 1, widget->font_face);
|
||||||
|
if (size + w < widget->w) {
|
||||||
|
quinn_draw_text_int(win, txtedit->surf, widget->w, widget->h, size + w / 2, (j - txtedit->y_offset) * 10 + 10, 0xff000000, c, widget->font_face);
|
||||||
|
if (j == txtedit->y) {
|
||||||
|
if (i == txtedit->x) {
|
||||||
|
// draw cursor
|
||||||
|
quinn_draw_line_int(win, txtedit->surf, quinn_draw_text_width(&txtedit->lines[j][txtedit->x_offset], txtedit->x - txtedit->x_offset, widget->font_face) + 1, (j - txtedit->y_offset) * 10, quinn_draw_text_width(&txtedit->lines[j][txtedit->x_offset], txtedit->x - txtedit->x_offset, widget->font_face) + 1, (j - txtedit->y_offset) * 10 + 10, widget->w, widget->h, 0xffff0000);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
size += w;
|
||||||
|
}
|
||||||
|
if (j == txtedit->y && txtedit->x == strlen(txtedit->lines[j])) {
|
||||||
|
quinn_draw_line_int(win, txtedit->surf, quinn_draw_text_width(&txtedit->lines[j][txtedit->x_offset], txtedit->x - txtedit->x_offset, widget->font_face) + 1, (j - txtedit->y_offset) * 10, quinn_draw_text_width(&txtedit->lines[j][txtedit->x_offset], txtedit->x - txtedit->x_offset, widget->font_face) + 1, (j - txtedit->y_offset) * 10 + 10, widget->w, widget->h, 0xffff0000);
|
||||||
|
}
|
||||||
|
if (((j - txtedit->y_offset) + 1) * 10 > widget->h) break;
|
||||||
|
}
|
||||||
|
|
||||||
|
quinn_render_int(win, surface, txtedit->surf, widget->w, widget->h, widget->x, widget->y, surf_w, surf_h);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
void quinn_draw_textbox(struct window_t *win, char *surface, struct widget_t *widget, int surf_w, int surf_h) {
|
void quinn_draw_textbox(struct window_t *win, char *surface, struct widget_t *widget, int surf_w, int surf_h) {
|
||||||
struct textbox_t *txtbox = (struct textbox_t *)widget->widget;
|
struct textbox_t *txtbox = (struct textbox_t *)widget->widget;
|
||||||
int i;
|
int i;
|
||||||
@ -960,6 +1055,8 @@ void quinn_update_window() {
|
|||||||
quinn_render_sdl(windows[i], windows[i]->surface, sdl_surf->surf, windows[i]->widgets[j]->w, windows[i]->widgets[j]->h, windows[i]->widgets[j]->x, windows[i]->widgets[j]->y, windows[i]->w, windows[i]->h);
|
quinn_render_sdl(windows[i], windows[i]->surface, sdl_surf->surf, windows[i]->widgets[j]->w, windows[i]->widgets[j]->h, windows[i]->widgets[j]->x, windows[i]->widgets[j]->y, windows[i]->w, windows[i]->h);
|
||||||
} else if (windows[i]->widgets[j]->type == 7) {
|
} else if (windows[i]->widgets[j]->type == 7) {
|
||||||
quinn_draw_colour_picker(windows[i], windows[i]->surface, windows[i]->widgets[j], windows[i]->w, windows[i]->h);
|
quinn_draw_colour_picker(windows[i], windows[i]->surface, windows[i]->widgets[j], windows[i]->w, windows[i]->h);
|
||||||
|
} else if (windows[i]->widgets[j]->type == 8) {
|
||||||
|
quinn_draw_textedit(windows[i], windows[i]->surface, windows[i]->widgets[j], windows[i]->w, windows[i]->h);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1063,6 +1160,8 @@ int quinn_process_input(int blocking) {
|
|||||||
if (surf->char_callback != NULL) {
|
if (surf->char_callback != NULL) {
|
||||||
surf->char_callback(keyChars_set1_s[req.event_msgs[l].code]);
|
surf->char_callback(keyChars_set1_s[req.event_msgs[l].code]);
|
||||||
}
|
}
|
||||||
|
} else if (key_receiver->type == 8) {
|
||||||
|
quinn_textedit_insert_char(key_receiver, keyChars_set1_s[req.event_msgs[l].code]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
@ -1074,10 +1173,31 @@ int quinn_process_input(int blocking) {
|
|||||||
if (surf->char_callback != NULL) {
|
if (surf->char_callback != NULL) {
|
||||||
surf->char_callback(keyChars_set1[req.event_msgs[l].code]);
|
surf->char_callback(keyChars_set1[req.event_msgs[l].code]);
|
||||||
}
|
}
|
||||||
|
} else if (key_receiver->type == 8) {
|
||||||
|
quinn_textedit_insert_char(key_receiver, keyChars_set1[req.event_msgs[l].code]);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
if (key_receiver->type == 8) {
|
||||||
|
switch(req.event_msgs[l].code) {
|
||||||
|
case KEYBOARD_KEY_ARROW_UP:
|
||||||
|
quinn_textedit_up(key_receiver);
|
||||||
|
break;
|
||||||
|
case KEYBOARD_KEY_ARROW_DOWN:
|
||||||
|
quinn_textedit_down(key_receiver);
|
||||||
|
break;
|
||||||
|
case KEYBOARD_KEY_ARROW_LEFT:
|
||||||
|
quinn_textedit_left(key_receiver);
|
||||||
|
break;
|
||||||
|
case KEYBOARD_KEY_ARROW_RIGHT:
|
||||||
|
quinn_textedit_right(key_receiver);
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
break;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -1606,6 +1726,443 @@ void quinn_free_button(struct widget_t *w) {
|
|||||||
free(w);
|
free(w);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
struct widget_t *quinn_add_textedit(int wh, int x, int y, int w, int h, void (*callback)()) {
|
||||||
|
struct window_t *window;
|
||||||
|
struct widget_t *newwidget = (struct widget_t *)malloc(sizeof(struct widget_t));
|
||||||
|
if (!newwidget) {
|
||||||
|
printf("Out of memory\n");
|
||||||
|
exit(-1);
|
||||||
|
}
|
||||||
|
struct textedit_t *txtedit = (struct textedit_t *)malloc(sizeof(struct textedit_t));
|
||||||
|
|
||||||
|
if (!txtedit) {
|
||||||
|
free(newwidget);
|
||||||
|
printf("Out of memory\n");
|
||||||
|
exit(-1);
|
||||||
|
}
|
||||||
|
|
||||||
|
txtedit->surf = (void *)malloc(w * h * 4);
|
||||||
|
if (!txtedit->surf) {
|
||||||
|
printf("Out of memory\n");
|
||||||
|
exit(-1);
|
||||||
|
}
|
||||||
|
|
||||||
|
txtedit->callback = callback;
|
||||||
|
txtedit->line_count = 0;
|
||||||
|
txtedit->lines = NULL;
|
||||||
|
txtedit->x = 0;
|
||||||
|
txtedit->y = 0;
|
||||||
|
|
||||||
|
newwidget->widget = txtedit;
|
||||||
|
newwidget->type = 8;
|
||||||
|
newwidget->w = w;
|
||||||
|
newwidget->h = h;
|
||||||
|
newwidget->x = x;
|
||||||
|
newwidget->y = y;
|
||||||
|
newwidget->font_data = NULL;
|
||||||
|
newwidget->font_face = NULL;
|
||||||
|
window = quinn_find_window(wh);
|
||||||
|
if (window == NULL) {
|
||||||
|
free(txtedit);
|
||||||
|
free(newwidget);
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!quinn_add_widget(window, newwidget)) {
|
||||||
|
free(txtedit);
|
||||||
|
free(newwidget);
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
return newwidget;
|
||||||
|
}
|
||||||
|
|
||||||
|
void quinn_textedit_set_text(struct widget_t *w, const char * text) {
|
||||||
|
struct textedit_t *txtedit;
|
||||||
|
if (w->type != 8) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
txtedit = (struct textedit_t *)w->widget;
|
||||||
|
|
||||||
|
for (int i = 0; i < txtedit->line_count;i++) {
|
||||||
|
free(txtedit->lines[i]);
|
||||||
|
}
|
||||||
|
|
||||||
|
free(txtedit->lines);
|
||||||
|
txtedit->line_count = 0;
|
||||||
|
txtedit->x = 0;
|
||||||
|
txtedit->y = 0;
|
||||||
|
txtedit->x_offset = 0;
|
||||||
|
txtedit->y_offset = 0;
|
||||||
|
|
||||||
|
char *startptr = text;
|
||||||
|
char *endptr = text;
|
||||||
|
|
||||||
|
for (int i = 0; i < strlen(text); i++) {
|
||||||
|
if (text[i] == '\n') {
|
||||||
|
endptr = &text[i];
|
||||||
|
|
||||||
|
char *newline = (char *)malloc(endptr - startptr + 1);
|
||||||
|
if (!newline) {
|
||||||
|
// error
|
||||||
|
if (txtedit->line_count > 0) {
|
||||||
|
for (int j = 0; j < txtedit->line_count;j++) {
|
||||||
|
free(txtedit->lines[j]);
|
||||||
|
}
|
||||||
|
free(txtedit->lines);
|
||||||
|
txtedit->line_count = 0;
|
||||||
|
}
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
memset(newline, 0, endptr - startptr + 1);
|
||||||
|
memcpy(newline, startptr, endptr - startptr);
|
||||||
|
|
||||||
|
endptr++;
|
||||||
|
startptr = endptr;
|
||||||
|
|
||||||
|
char **tmp;
|
||||||
|
|
||||||
|
if (txtedit->line_count == 0) {
|
||||||
|
tmp = (char **)malloc(sizeof(char *));
|
||||||
|
} else {
|
||||||
|
tmp = (char **)realloc(txtedit->lines, sizeof(char *) * (txtedit->line_count + 1));
|
||||||
|
}
|
||||||
|
|
||||||
|
if (tmp == NULL) {
|
||||||
|
if (txtedit->line_count > 0) {
|
||||||
|
for (int j = 0; j < txtedit->line_count;j++) {
|
||||||
|
free(txtedit->lines[j]);
|
||||||
|
}
|
||||||
|
free(txtedit->lines);
|
||||||
|
txtedit->line_count = 0;
|
||||||
|
}
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
txtedit->lines = tmp;
|
||||||
|
txtedit->lines[txtedit->line_count] = newline;
|
||||||
|
txtedit->line_count++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (startptr != endptr) {
|
||||||
|
char *newline = (char *)malloc(endptr - startptr + 1);
|
||||||
|
if (!newline) {
|
||||||
|
// error
|
||||||
|
if (txtedit->line_count > 0) {
|
||||||
|
for (int j = 0; j < txtedit->line_count;j++) {
|
||||||
|
free(txtedit->lines[j]);
|
||||||
|
}
|
||||||
|
free(txtedit->lines);
|
||||||
|
txtedit->line_count = 0;
|
||||||
|
}
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
memset(newline, 0, endptr - startptr + 1);
|
||||||
|
memcpy(newline, startptr, endptr - startptr);
|
||||||
|
|
||||||
|
endptr++;
|
||||||
|
startptr = endptr;
|
||||||
|
|
||||||
|
char **tmp;
|
||||||
|
|
||||||
|
if (txtedit->line_count == 0) {
|
||||||
|
tmp = (char **)malloc(sizeof(char *));
|
||||||
|
} else {
|
||||||
|
tmp = (char **)realloc(txtedit->lines, sizeof(char *) * (txtedit->line_count + 1));
|
||||||
|
}
|
||||||
|
|
||||||
|
if (tmp == NULL) {
|
||||||
|
if (txtedit->line_count > 0) {
|
||||||
|
for (int j = 0; j < txtedit->line_count;j++) {
|
||||||
|
free(txtedit->lines[j]);
|
||||||
|
}
|
||||||
|
free(txtedit->lines);
|
||||||
|
txtedit->line_count = 0;
|
||||||
|
}
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
txtedit->lines = tmp;
|
||||||
|
txtedit->lines[txtedit->line_count] = newline;
|
||||||
|
txtedit->line_count++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
char *quinn_textedit_get_text(struct widget_t *w) {
|
||||||
|
struct textedit_t *txtedit;
|
||||||
|
|
||||||
|
if (w->type != 8) {
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
txtedit = (struct textbox_t *)w->widget;
|
||||||
|
|
||||||
|
int buffer_size = 0;
|
||||||
|
|
||||||
|
for (int i = 0; i < txtedit->line_count;i++) {
|
||||||
|
buffer_size += strlen(txtedit->lines[i]) + 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
char *buffer = (char *)malloc(buffer_size + 1);
|
||||||
|
if (!buffer) {
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
memset(buffer, 0, buffer_size + 1);
|
||||||
|
|
||||||
|
int buffer_at = 0;
|
||||||
|
|
||||||
|
for (int i = 0; i < txtedit->line_count;i++) {
|
||||||
|
memcpy(&buffer[buffer_at], txtedit->lines[i], strlen(txtedit->lines[i]));
|
||||||
|
buffer_at += strlen(txtedit->lines[i]);
|
||||||
|
buffer[buffer_at] = '\n';
|
||||||
|
buffer_at++;
|
||||||
|
}
|
||||||
|
return buffer;
|
||||||
|
}
|
||||||
|
|
||||||
|
void quinn_free_textedit(struct widget_t *w) {
|
||||||
|
struct textedit_t *txtedit;
|
||||||
|
if (w->font_face) {
|
||||||
|
FT_Done_Face(*(FT_Face *)w->font_face);
|
||||||
|
free(w->font_face);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (w->font_data) {
|
||||||
|
free(w->font_data);
|
||||||
|
}
|
||||||
|
txtedit = (struct textedit_t *)w->widget;
|
||||||
|
free(txtedit->surf);
|
||||||
|
for (int i = 0; i < txtedit->line_count;i++) {
|
||||||
|
free(txtedit->lines[i]);
|
||||||
|
}
|
||||||
|
|
||||||
|
free(txtedit->lines);
|
||||||
|
free(txtedit);
|
||||||
|
free(w);
|
||||||
|
}
|
||||||
|
|
||||||
|
int quinn_textedit_get_x(struct widget_t *w) {
|
||||||
|
if (w->type != 8) {
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
struct textedit_t *txtedit = (struct textedit_t *)w->widget;
|
||||||
|
return txtedit->x;
|
||||||
|
}
|
||||||
|
|
||||||
|
int quinn_textedit_get_y(struct widget_t *w) {
|
||||||
|
if (w->type != 8) {
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
struct textedit_t *txtedit = (struct textedit_t *)w->widget;
|
||||||
|
return txtedit->y;
|
||||||
|
}
|
||||||
|
|
||||||
|
void quinn_textedit_insert_char(struct widget_t *w, char c) {
|
||||||
|
int i;
|
||||||
|
if (w->type != 8) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
struct textedit_t *txtedit = (struct textedit_t *)w->widget;
|
||||||
|
|
||||||
|
if (txtedit->y >= txtedit->line_count) {
|
||||||
|
if (txtedit->line_count == 0) {
|
||||||
|
txtedit->lines = (char **)malloc(sizeof(char *));
|
||||||
|
if (!txtedit->lines) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
txtedit->lines[0] = (char *)malloc(1);
|
||||||
|
if (!txtedit->lines[0]) {
|
||||||
|
free(txtedit->lines);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
txtedit->line_count++;
|
||||||
|
txtedit->lines[txtedit->y][0] = '\0';
|
||||||
|
} else {
|
||||||
|
char **tmp = (char **)realloc(txtedit->lines, sizeof(char *) * (txtedit->line_count + 1));
|
||||||
|
if (!tmp) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
txtedit->lines = tmp;
|
||||||
|
txtedit->lines[txtedit->line_count] = (char *)malloc(1);
|
||||||
|
if (!txtedit->lines[txtedit->line_count]) {
|
||||||
|
exit(-1);
|
||||||
|
}
|
||||||
|
txtedit->line_count++;
|
||||||
|
txtedit->lines[txtedit->y][0] = '\0';
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
switch (c) {
|
||||||
|
case '\b':
|
||||||
|
if (txtedit->x > 0) {
|
||||||
|
char *text_cpy = (char *)malloc(strlen(txtedit->lines[txtedit->y]));
|
||||||
|
memset(text_cpy, 0, strlen(txtedit->lines[txtedit->y]));
|
||||||
|
for (int i=0;i<txtedit->x - 1;i++) {
|
||||||
|
text_cpy[i] = txtedit->lines[txtedit->y][i];
|
||||||
|
}
|
||||||
|
for (int i=txtedit->x;i<strlen(txtedit->lines[txtedit->y]);i++) {
|
||||||
|
text_cpy[i-1] = txtedit->lines[txtedit->y][i];
|
||||||
|
}
|
||||||
|
free(txtedit->lines[txtedit->y]);
|
||||||
|
txtedit->lines[txtedit->y] = text_cpy;
|
||||||
|
txtedit->x--;
|
||||||
|
if (txtedit->x_offset > 0) {
|
||||||
|
txtedit->x_offset--;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
// delete line break
|
||||||
|
if (txtedit->y > 0) {
|
||||||
|
char *newline = (char *)malloc(strlen(txtedit->lines[txtedit->y]) + strlen(txtedit->lines[txtedit->y - 1]) + 1);
|
||||||
|
if (!newline) {
|
||||||
|
exit(-1);
|
||||||
|
}
|
||||||
|
|
||||||
|
int new_x = strlen(txtedit->lines[txtedit->y - 1]);
|
||||||
|
|
||||||
|
sprintf(newline, "%s%s", txtedit->lines[txtedit->y - 1], txtedit->lines[txtedit->y]);
|
||||||
|
|
||||||
|
free(txtedit->lines[txtedit->y - 1]);
|
||||||
|
txtedit->lines[txtedit->y - 1] = newline;
|
||||||
|
free(txtedit->lines[txtedit->y]);
|
||||||
|
for (int i = txtedit->y; i < txtedit->line_count - 1;i++) {
|
||||||
|
txtedit->lines[i] = txtedit->lines[i + 1];
|
||||||
|
}
|
||||||
|
char **tmp = (char **)realloc(txtedit->lines, sizeof(char *) * (txtedit->line_count - 1));
|
||||||
|
if (!tmp) {
|
||||||
|
exit(-1);
|
||||||
|
}
|
||||||
|
txtedit->lines = tmp;
|
||||||
|
txtedit->line_count--;
|
||||||
|
txtedit->y--;
|
||||||
|
txtedit->x = new_x;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case '\t':
|
||||||
|
// TODO:
|
||||||
|
break;
|
||||||
|
case '\n':
|
||||||
|
if (txtedit->y == txtedit->line_count - 1 && txtedit->x == strlen(txtedit->lines[txtedit->y])) {
|
||||||
|
// append a new line
|
||||||
|
txtedit->y++;
|
||||||
|
txtedit->x = 0;
|
||||||
|
} else {
|
||||||
|
// insert a new line
|
||||||
|
if (txtedit->x == 0) {
|
||||||
|
// move current line down
|
||||||
|
char **tmp = (char **)realloc(txtedit->lines, sizeof(char *) * (txtedit->line_count + 1));
|
||||||
|
if (!tmp) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
txtedit->lines = tmp;
|
||||||
|
for (int i = txtedit->line_count; i > txtedit->y; i--) {
|
||||||
|
txtedit->lines[i] = txtedit->lines[i-1];
|
||||||
|
}
|
||||||
|
txtedit->lines[txtedit->y] = (char *)malloc(1);
|
||||||
|
if (!txtedit->lines[txtedit->y]) {
|
||||||
|
exit(-1);
|
||||||
|
}
|
||||||
|
txtedit->lines[txtedit->y][0] = '\0';
|
||||||
|
txtedit->line_count++;
|
||||||
|
txtedit->y++;
|
||||||
|
int lines_per_widget = w->h / 10;
|
||||||
|
|
||||||
|
if (txtedit->y >= lines_per_widget) {
|
||||||
|
txtedit->y_offset++;
|
||||||
|
}
|
||||||
|
txtedit->x = 0;
|
||||||
|
txtedit->x_offset = 0;
|
||||||
|
return;
|
||||||
|
} else if (txtedit->x == strlen(txtedit->lines[txtedit->y]) - 1) {
|
||||||
|
// leave current line
|
||||||
|
char **tmp = (char **)realloc(txtedit->lines, sizeof(char *) * (txtedit->line_count + 1));
|
||||||
|
if (!tmp) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
txtedit->lines = tmp;
|
||||||
|
for (int i = txtedit->line_count; i > txtedit->y - 1; i--) {
|
||||||
|
txtedit->lines[i] = txtedit->lines[i-1];
|
||||||
|
}
|
||||||
|
txtedit->lines[txtedit->y] = (char *)malloc(1);
|
||||||
|
if (!txtedit->lines[txtedit->y]) {
|
||||||
|
exit(-1);
|
||||||
|
}
|
||||||
|
txtedit->lines[txtedit->y][0] = '\0';
|
||||||
|
txtedit->line_count++;
|
||||||
|
txtedit->y++;
|
||||||
|
int lines_per_widget = w->h / 10;
|
||||||
|
|
||||||
|
if (txtedit->y >= lines_per_widget) {
|
||||||
|
txtedit->y_offset++;
|
||||||
|
}
|
||||||
|
txtedit->x = 0;
|
||||||
|
txtedit->x_offset = 0;
|
||||||
|
} else {
|
||||||
|
// split line
|
||||||
|
// leave current line
|
||||||
|
char **tmp = (char **)realloc(txtedit->lines, sizeof(char *) * (txtedit->line_count + 1));
|
||||||
|
if (!tmp) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
txtedit->lines = tmp;
|
||||||
|
for (int i = txtedit->line_count; i > txtedit->y; i--) {
|
||||||
|
txtedit->lines[i] = txtedit->lines[i-1];
|
||||||
|
}
|
||||||
|
|
||||||
|
txtedit->lines[txtedit->y] = (char *)malloc(txtedit->x + 1);
|
||||||
|
if (!txtedit->lines[txtedit->y]) {
|
||||||
|
exit(-1);
|
||||||
|
}
|
||||||
|
|
||||||
|
memset(txtedit->lines[txtedit->y], 0, txtedit->x + 1);
|
||||||
|
|
||||||
|
memcpy(txtedit->lines[txtedit->y], txtedit->lines[txtedit->y + 1], txtedit->x);
|
||||||
|
|
||||||
|
int tocopy = strlen(txtedit->lines[txtedit->y + 1]) - txtedit->x;
|
||||||
|
|
||||||
|
memmove(txtedit->lines[txtedit->y + 1], &txtedit->lines[txtedit->y + 1][txtedit->x], tocopy);
|
||||||
|
txtedit->lines[txtedit->y + 1][tocopy] = '\0';
|
||||||
|
txtedit->lines[txtedit->y + 1] = realloc(txtedit->lines[txtedit->y + 1], tocopy + 1);
|
||||||
|
|
||||||
|
txtedit->line_count++;
|
||||||
|
txtedit->y++;
|
||||||
|
int lines_per_widget = w->h / 10;
|
||||||
|
|
||||||
|
if (txtedit->y >= lines_per_widget) {
|
||||||
|
txtedit->y_offset++;
|
||||||
|
}
|
||||||
|
txtedit->x = 0;
|
||||||
|
txtedit->x_offset = 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
{
|
||||||
|
char *text_cpy = (char *)malloc(strlen(txtedit->lines[txtedit->y]) + 2);
|
||||||
|
memset(text_cpy, 0, strlen(txtedit->lines[txtedit->y]) + 2);
|
||||||
|
for (i=0;i<txtedit->x;i++) {
|
||||||
|
text_cpy[i] = txtedit->lines[txtedit->y][i];
|
||||||
|
}
|
||||||
|
text_cpy[txtedit->x] = c;
|
||||||
|
for (i=txtedit->x;i<strlen(txtedit->lines[txtedit->y]);i++) {
|
||||||
|
text_cpy[i+1] = txtedit->lines[txtedit->y][i];
|
||||||
|
}
|
||||||
|
free(txtedit->lines[txtedit->y]);
|
||||||
|
txtedit->lines[txtedit->y] = text_cpy;
|
||||||
|
txtedit->x++;
|
||||||
|
|
||||||
|
while (quinn_draw_text_width(&txtedit->lines[txtedit->y][txtedit->x_offset], txtedit->x - txtedit->x_offset, w->font_face) >= w->w) {
|
||||||
|
txtedit->x_offset++;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
struct widget_t *quinn_add_textbox(int wh, int x, int y, int w, int h, char *text, void (*callback)()) {
|
struct widget_t *quinn_add_textbox(int wh, int x, int y, int w, int h, char *text, void (*callback)()) {
|
||||||
struct window_t *window;
|
struct window_t *window;
|
||||||
struct widget_t *newwidget = (struct widget_t *)malloc(sizeof(struct widget_t));
|
struct widget_t *newwidget = (struct widget_t *)malloc(sizeof(struct widget_t));
|
||||||
@ -1616,6 +2173,7 @@ struct widget_t *quinn_add_textbox(int wh, int x, int y, int w, int h, char *tex
|
|||||||
struct textbox_t *txtbox = (struct textbox_t *)malloc(sizeof(struct textbox_t));
|
struct textbox_t *txtbox = (struct textbox_t *)malloc(sizeof(struct textbox_t));
|
||||||
|
|
||||||
if (!txtbox) {
|
if (!txtbox) {
|
||||||
|
free(newwidget);
|
||||||
printf("Out of memory\n");
|
printf("Out of memory\n");
|
||||||
exit(-1);
|
exit(-1);
|
||||||
}
|
}
|
||||||
|
@ -80,13 +80,22 @@ extern void quinn_free_colourpicker(struct widget_t *w);
|
|||||||
extern void quinn_remove_window(int wh);
|
extern void quinn_remove_window(int wh);
|
||||||
extern void quinn_show_message_box(int wh, char *title, char *message, unsigned char show_cancel, void (*callback)());
|
extern void quinn_show_message_box(int wh, char *title, char *message, unsigned char show_cancel, void (*callback)());
|
||||||
extern struct widget_t *quinn_add_textbox(int wh, int x, int y, int w, int h, char *text, void (*callback)());
|
extern struct widget_t *quinn_add_textbox(int wh, int x, int y, int w, int h, char *text, void (*callback)());
|
||||||
|
extern struct widget_t *quinn_add_textedit(int wh, int x, int y, int w, int h, void (*callback)());
|
||||||
|
extern char *quinn_textedit_get_text(struct widget_t *w);
|
||||||
|
extern void quinn_textedit_set_text(struct widget_t *w, const char * text);
|
||||||
|
extern void quinn_textedit_insert_char(struct widget_t *w, char c);
|
||||||
extern void quinn_textbox_insert_char(struct widget_t *w, char c);
|
extern void quinn_textbox_insert_char(struct widget_t *w, char c);
|
||||||
extern const char *quinn_textbox_get_text(struct widget_t *w);
|
extern const char *quinn_textbox_get_text(struct widget_t *w);
|
||||||
extern void quinn_textbox_set_text(struct widget_t *w, const char * text);
|
extern void quinn_textbox_set_text(struct widget_t *w, const char * text);
|
||||||
extern void quinn_free_textbox(struct widget_t *w);
|
extern void quinn_free_textbox(struct widget_t *w);
|
||||||
|
extern void quinn_free_textedit(struct widget_t *w);
|
||||||
extern void quinn_surface_set_cooked(struct widget_t *w, int cooked);
|
extern void quinn_surface_set_cooked(struct widget_t *w, int cooked);
|
||||||
extern char *quinn_surface_get_surface(struct widget_t *w);
|
extern char *quinn_surface_get_surface(struct widget_t *w);
|
||||||
extern void quinn_show_message_box_xy(int wh, char *title, char *message, unsigned char show_cancel, void (*callback)(), int x, int y);
|
extern void quinn_show_message_box_xy(int wh, char *title, char *message, unsigned char show_cancel, void (*callback)(), int x, int y);
|
||||||
extern int quinn_add_colourpicker(int wh, int x, int y, void (*callback)(unsigned long colour));
|
extern int quinn_add_colourpicker(int wh, int x, int y, void (*callback)(unsigned long colour));
|
||||||
extern int quinn_set_font(struct widget_t *w, char *font);
|
extern int quinn_set_font(struct widget_t *w, char *font);
|
||||||
|
extern void quinn_label_settext(struct widget_t *w, char *text);
|
||||||
|
extern int quinn_textedit_get_x(struct widget_t *w);
|
||||||
|
extern int quinn_textedit_get_y(struct widget_t *w);
|
||||||
|
extern void quinn_flag_remove_window(int wh);
|
||||||
#endif
|
#endif
|
||||||
|
22
socket.c
22
socket.c
@ -237,16 +237,20 @@ int socket_read(unsigned int serial, char *buffer, int len) {
|
|||||||
data = (struct tcp_data_t *)socket_get_packet(sock);
|
data = (struct tcp_data_t *)socket_get_packet(sock);
|
||||||
} else {
|
} else {
|
||||||
if (sock->status == SOCKET_STATUS_CLOSEWAIT) {
|
if (sock->status == SOCKET_STATUS_CLOSEWAIT) {
|
||||||
sock->status = 1;
|
sock->status = SOCKET_STATUS_CLOSE;
|
||||||
socket_doclose(sock);
|
socket_doclose(sock);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
} else if (sock->status == SOCKET_STATUS_CONNECTED || sock->status == SOCKET_STATUS_OPENED) {
|
||||||
if (sock->flags & SOCKET_FLAG_NOBLOCK) {
|
if (sock->flags & SOCKET_FLAG_NOBLOCK) {
|
||||||
return -2;
|
return -2;
|
||||||
|
} else {
|
||||||
|
current_task->sleep_reason = SLEEP_TCP_READ;
|
||||||
|
current_task->state = TASK_SLEEPING;
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
current_task->sleep_reason = SLEEP_TCP_READ;
|
kprintf("SOCKET READ, STATUS %d!\n", sock->status);
|
||||||
current_task->state = TASK_SLEEPING;
|
return 0;
|
||||||
return -1;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -499,7 +503,9 @@ void socket_close(unsigned int serial) {
|
|||||||
|
|
||||||
if (sock->ref == 0) {
|
if (sock->ref == 0) {
|
||||||
if (sock->socket_type == 1 && sock->ether != (void *)0) {
|
if (sock->socket_type == 1 && sock->ether != (void *)0) {
|
||||||
socket_queue(sock, (void *)0, 0, TCP_FLAGS_FIN | TCP_FLAGS_ACK);
|
if (sock->status == SOCKET_STATUS_CONNECTED) {
|
||||||
|
socket_queue(sock, (void *)0, 0, TCP_FLAGS_FIN | TCP_FLAGS_ACK);
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
sock->status = SOCKET_STATUS_CLOSE;
|
sock->status = SOCKET_STATUS_CLOSE;
|
||||||
socket_doclose(sock);
|
socket_doclose(sock);
|
||||||
|
4
tcp.c
4
tcp.c
@ -185,7 +185,9 @@ void tcp_process_packet(struct ether_t *ether, unsigned int dest, unsigned int s
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
sock->send_payload = 1;
|
sock->send_payload = 1;
|
||||||
tcp_process_socket(sock);
|
if (sock->status != SOCKET_STATUS_FINACK) {
|
||||||
|
tcp_process_socket(sock);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
1
vfs.c
1
vfs.c
@ -829,6 +829,7 @@ int vfs_open_file_dev(struct vfs_device_t *device, char *path, int flags, int mo
|
|||||||
if (flags & O_TRUNC) {
|
if (flags & O_TRUNC) {
|
||||||
if (info->file_size > 0) {
|
if (info->file_size > 0) {
|
||||||
minix_trunc_file(device, info);
|
minix_trunc_file(device, info);
|
||||||
|
minix_wipe_inode(device, info);
|
||||||
info->file_size = 0;
|
info->file_size = 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user