11#include "edit.h"
22
3- font_t * new_font (char * name , float size ) {
4- font_t * font = malloc (sizeof (font_t ));
5- font -> name = name ;
6- font -> size = size ;
7- font -> stash = sth_create (512 , 512 );
8- font -> id = sth_add_font (font -> stash , name );
9- // sth_add_font_from_memory(self->stash, self->data);
10- return font ;
11- }
12-
13- void destroy_font (font_t * font ) {
14- if (font == NULL ) return ;
15- sth_delete (font -> stash );
16- free (font );
17- font = NULL ;
18- }
19-
203buffer_t * new_buffer () {
214 buffer_t * buffer = malloc (sizeof (buffer_t ));
225 buffer -> lines = new_lines (LINE_SIZE );
@@ -527,12 +510,6 @@ void gl_render_edit(edit_t *self, float x, float y) {
527510 }
528511}
529512
530- float measure_text (font_t * font , char * text , int count ) {
531- float dx , dy ;
532- sth_measure (font -> stash , font -> id , font -> size , -1 , text , count , & dx , & dy );
533- return dx ;
534- }
535-
536513void update_cursor_pos (buffer_t * self ) {
537514 int cur_row = self -> cursor_row ;
538515 if (cur_row < 0 || self -> line_count <= 0 ) {
@@ -549,6 +526,15 @@ void update_cursor_pos(buffer_t *self) {
549526 measure_text (self -> font , self -> lines [cur_row ]-> texts , self -> cursor_col );
550527}
551528
529+ float gl_edit_get_cursor_x (edit_t * self ) {
530+ return self -> buffer -> cursor_x / self -> scale +
531+ self -> lineno_width / self -> scale ;
532+ }
533+
534+ float gl_edit_get_cursor_y (edit_t * self ) {
535+ return self -> buffer -> cursor_y /self -> scale + self -> scroll_y ;
536+ }
537+
552538int gl_edit_get_line_count (edit_t * self ) { return self -> buffer -> line_count ; }
553539
554540int gl_edit_get_row_count (edit_t * self , int row ) {
@@ -1037,6 +1023,9 @@ edit_t *gl_new_edit(int shader, float w, float h, float width, float height) {
10371023 return self ;
10381024}
10391025
1026+ font_t * gl_edit_get_font (edit_t * self ){
1027+ return self -> font ;
1028+ }
10401029void gl_resize_edit_window (edit_t * self , float width , float height ) {
10411030 glUseProgram (self -> mvp .shader );
10421031 mat4_set_orthographic (& self -> mvp .projection , 0 , width * self -> scale ,
@@ -1106,6 +1095,13 @@ char *gl_get_edit_text(edit_t *self) {
11061095 return self -> texts ;
11071096}
11081097
1098+ float gl_edit_measure_text (edit_t * self ){
1099+ if (self -> texts == NULL ){
1100+ gl_get_edit_text (self );
1101+ }
1102+ return measure_text (self -> buffer -> font , self -> texts , strlen (self -> texts ));
1103+ }
1104+
11091105void buffer_color (buffer_t * buffer , void * colors ) {
11101106 int * text_colors = colors ;
11111107 int count = 0 ;
0 commit comments