#pragma once
#include "vg/submodules/stb/stb_image_write.h"
-#define STBI_ONLY_JPEG
+
+//#define STBI_ONLY_JPEG
#define STBI_NO_THREAD_LOCALS
#include "vg/submodules/stb/stb_image.h"
if( !vg_strgood(&q) )
return k_dir_open_path_too_long;
+ if( !(GetFileAttributes( q.buffer ) & FILE_ATTRIBUTE_DIRECTORY) )
+ return k_dir_open_is_file;
+
vg_info( "FindFirstFile( '%s' )\n", q.buffer );
dir->h = FindFirstFile( q.buffer, &dir->data );
if( dir->h == INVALID_HANDLE_VALUE )
#else
dir->h = opendir( name );
if( !dir->h )
- return k_dir_open_invalid_path;
+ {
+ if( errno == ENOTDIR )
+ return k_dir_open_is_file;
+ else
+ return k_dir_open_invalid_path;
+ }
#endif
dir->index = 1;
return k_dir_open_ok;
k_dir_open_none,
k_dir_open_ok,
k_dir_open_path_too_long,
- k_dir_open_invalid_path
+ k_dir_open_invalid_path,
+ k_dir_open_is_file
};
extern const char *dir_open_result_str[];
enum dir_open_result vg_dir_open( vg_dir *dir, const char *name );
a[2] = v;
}
+static inline void v4_fill( v4f a, f32 v )
+{
+ a[0] = v;
+ a[1] = v;
+ a[2] = v;
+ a[3] = v;
+}
+
static inline void v3_divs( v3f a, f32 s, v3f d )
{
if( s == 0.0f )
browser->filter = 0;
}
+void vg_filebrowser_set_path_to_home( struct vg_filebrowser *browser )
+{
+ // TODO
+ strcpy( browser->current_path, "/home/harry" );
+}
+
+static bool vg_filebrowser_up( struct vg_filebrowser *browser )
+{
+ vg_str str =
+ {
+ .buffer = browser->current_path,
+ .i = strlen( browser->current_path ),
+ .len = sizeof(browser->current_path)-1
+ };
+
+ char *sep = vg_strch( &str, '/' );
+ if( sep )
+ {
+ sep[0] = '\0';
+ return 1;
+ }
+ else return 0;
+}
+
void filebrowser_textbox_callback( ui_context *ctx, char *buffer, u32 len, void *userdata )
{
struct vg_filebrowser *browser = userdata;
if( ui_button_text( ctx, box_up, "\xb8", 1 ) == k_ui_button_click )
{
- vg_str str =
- {
- .buffer = browser->current_path,
- .i = strlen( browser->current_path ),
- .len = sizeof(browser->current_path)-1
- };
-
- char *sep = vg_strch( &str, '/' );
- if( sep )
+ if( vg_filebrowser_up( browser ) )
{
- sep[0] = '\0';
vg_filebrowser_free_entries( browser );
vg_filebrowser_populate( browser );
}
if( ui_button_text( ctx, cancel_box, "Cancel", 1 ) == k_ui_button_click )
{
+ vg_filebrowser_free_entries( browser );
result_action = k_filebrowser_action_escape;
}
{
if( ui_button_text( ctx, ok_box, "OK", 1 ) == k_ui_button_click )
{
+ u32 cur_len = strlen( browser->current_path );
+ if( (cur_len + strlen( browser->selected_entry->name ) + 2) > sizeof(browser->current_path) )
+ vg_fatal_error( "Max path size exceeded." );
+ else
+ {
+ strcat( browser->current_path, "/" );
+ strcat( browser->current_path, browser->selected_entry->name );
+ }
+
+ vg_filebrowser_free_entries( browser );
result_action = k_filebrowser_action_accept;
}
}
*folder_list_tail = NULL,
*file_list_head = NULL;
+ if( browser->open_result == k_dir_open_is_file )
+ {
+ if( vg_filebrowser_up( browser ) )
+ {
+ browser->open_result = vg_dir_open( &dir, browser->current_path );
+ }
+ }
+
if( browser->open_result != k_dir_open_ok )
+ {
return;
+ }
while( vg_dir_next_entry( &dir ) )
{
if( ext )
{
if( !strcmp( ext, "jpg" ) || !strcmp( ext, "jpeg" ) || !strcmp( ext, "png" ) || !strcmp( ext, "tga" ) ||
- !strcmp( ext, "bmp" ) )
+ !strcmp( ext, "bmp" ) || !strcmp( ext, "psd" ) )
{
media_type = k_media_type_image;
}
struct vg_filebrowser
{
char current_path[ 4096 ];
+
enum dir_open_result open_result;
struct vg_filebrowser_entry *whole_list, *view_top_entry, *selected_entry;
enum filebrowser_action vg_filebrowser_ui( ui_context *ctx, ui_rect root_rect, struct vg_filebrowser *browser );
void vg_filebrowser_populate( struct vg_filebrowser *browser );
void vg_filebrowser_free_entries( struct vg_filebrowser *browser );
+
+void vg_filebrowser_set_path_to_home( struct vg_filebrowser *browser );
void ui_panel( ui_context *ctx, ui_rect in_rect, ui_rect out_panel )
{
- ui_fill( ctx, in_rect, ui_colour(ctx, k_ui_bg+1 ) );
+ //ui_fill( ctx, in_rect, ui_colour(ctx, k_ui_bg+1 ) );
+ ui_fill( ctx, in_rect, ui_opacity( ui_colour( ctx, k_ui_bg+1 ), 0.7f ) );
ui_outline( ctx, in_rect, 1, ui_colour(ctx, k_ui_bg+7 ), 0 );
rect_copy( in_rect, out_panel );
- ui_rect_pad( out_panel, NULL );
+ ui_rect_pad( out_panel, (ui_px[2]){ 8, 8 } );
}
void ui_label( ui_context *ctx,
void ui_enum( ui_context *ctx, ui_rect inout_panel, const char *str_label,
struct ui_enum_opt *options, u32 len, i32 *value )
{
- ui_rect rect, label, box;
+ ui_rect rect, box;
ui_standard_widget( ctx, inout_panel, rect, 1 );
- ui_label( ctx, rect, str_label, ctx->scale, 0, box );
+
+ if( str_label )
+ ui_label( ctx, rect, str_label, ctx->scale, 0, box );
+ else
+ rect_copy( rect, box );
const char *display = "OUT OF RANGE";
int valid = 0;
return state;
}
-void ui_slider_text( ui_context *ctx,
- ui_rect box, const char *format, f32 value )
+void ui_slider_text( ui_context *ctx, ui_rect box, const char *format, f32 value )
{
/* TODO: replace this one day with our own function */
char buf[32];
ui_text( ctx, box, buf, 1, k_ui_align_middle_center, 0 );
}
-bool ui_slider_standard( ui_context *ctx,
- ui_rect box, f32 min, f32 max, f32 *value,
- const char *format )
+bool ui_slider_standard( ui_context *ctx, ui_rect box, f32 min, f32 max, f32 *value, const char *format )
{
f32 t;
ui_fill( ctx, line, ui_colour(ctx,state&mask_brighter? k_ui_bg+4: k_ui_bg+2) );
ui_fill( ctx, (ui_rect){ box[0]+line[2], box[1], box[2]-line[2], box[3] }, ui_colour(ctx, k_ui_bg ) );
ui_outline( ctx, box, 1, ui_colour(ctx,state? k_ui_fg+3: k_ui_bg+3), 0 );
- ui_slider_text( ctx, box, NULL, *value );
+ ui_slider_text( ctx, box, format, *value );
return (state & mask_using) && 1;
}
ui_px ui_standard_widget_height( ui_context *ctx, ui_px count );
void ui_standard_widget( ui_context *ctx, ui_rect inout_panel, ui_rect out_rect, ui_px count );
void ui_panel( ui_context *ctx, ui_rect in_rect, ui_rect out_panel );
-void ui_label( ui_context *ctx,
- ui_rect rect, const char *text, ui_px size,
- ui_px gap, ui_rect r );
+void ui_label( ui_context *ctx, ui_rect rect, const char *text, ui_px size, ui_px gap, ui_rect r );
void ui_info( ui_context *ctx, ui_rect inout_panel, const char *text );
void ui_image( ui_context *ctx, ui_rect rect, void *resource );