[k_dir_open_invalid_path] = "Invalid path"
};
+bool vg_path_exists( const char *path )
+{
+#ifdef _WIN32
+ DWORD attributes = GetFileAttributes( path );
+ if( attributes == INVALID_FILE_ATTRIBUTES )
+ return 0;
+ return 1;
+#else
+ return access(path, F_OK) != -1;
+#endif
+}
+
+bool vg_make_directory( const char *path )
+{
+#ifdef _WIN32
+ return CreateDirectory( path, NULL )? 1:0;
+#else
+ return mkdir( path, S_IRWXU|S_IRWXG|S_IRWXO ) == 0;
+#endif
+}
+
enum dir_open_result vg_dir_open( vg_dir *dir, const char *name )
{
#ifdef _WIN32
if( !vg_strgood(&q) )
return k_dir_open_path_too_long;
- if( !(GetFileAttributes( q.buffer ) & FILE_ATTRIBUTE_DIRECTORY) )
+ DWORD attributes = GetFileAttributes( q.buffer );
+ if( attributes == INVALID_FILE_ATTRIBUTES )
+ return k_dir_open_invalid_path;
+
+ if( !(attributes & FILE_ATTRIBUTE_DIRECTORY) )
return k_dir_open_is_file;
vg_info( "FindFirstFile( '%s' )\n", q.buffer );
{
ui_rect screen = { 0,0, ctx->area[0], ctx->area[1] };
ui_fill( ctx, screen, 0xa0000000 );
- ui_rect box = {0,0,400,200};
+ ui_rect box = {0,0,416,216};
u32 colour = ui_colour(ctx,k_ui_fg),
type = ctx->modal.options & UI_MODAL_TYPE_BITS;
ui_rect_center( screen, box );
ui_fill( ctx, box, ui_colour(ctx,k_ui_bg) );
ui_outline( ctx, box, -1, colour, 0 );
+ ui_rect_pad( box, (ui_px[]){8,8} );
ui_rect message;
rect_copy( box, message );
- message[3] = 100;
+ message[3] = 150;
ui_rect_center( box, message );
- ui_rect row0, row1, btn;
- ui_split_ratio( message, k_ui_axis_h, 0.76f, 0, row0, row1 );
+ ui_rect row0, row1;
+ ui_split( message, k_ui_axis_h, -28, 0, row0, row1 );
row0[0] += ctx->font->sx;
- ui_ntext( ctx, row0, ctx->modal.message, (box[2]/ctx->font->sx)-2, 1,
- k_ui_align_left, colour );
+ ui_ntext( ctx, row0, ctx->modal.message, (box[2]/ctx->font->sx)-2, 1, k_ui_align_left, colour );
+
+ ui_rect btn_ok;
+ ui_split( row1, k_ui_axis_v, -120, 8, row1, btn_ok );
- rect_copy( row1, btn );
- btn[2] = 86;
- btn[3] = 28;
- ui_rect_center( row1, btn );
-
ctx->focused_control_type = k_ui_control_none; /* HACK */
- if( ui_button_text( ctx, btn, "OK", 1 ) != 1 )
+
+ bool close_modal = 0;
+ if( ctx->modal.options & UI_MODAL_CANCEL )
+ {
+ ui_rect btn_cancel;
+ ui_split( row1, k_ui_axis_v, -120, 8, row1, btn_cancel );
+ if( ui_button_text( ctx, btn_cancel, "Cancel", 1 ) == k_ui_button_click )
+ {
+ if( ctx->modal.callbacks.close )
+ ctx->modal.callbacks.close( UI_MODAL_CANCEL );
+
+ close_modal = 1;
+ }
+ }
+
+ if( ui_button_text( ctx, btn_ok, ctx->modal.ok_text, 1 ) == k_ui_button_click )
+ {
+ if( ctx->modal.callbacks.close )
+ ctx->modal.callbacks.close( 0 );
+
+ close_modal = 1;
+ }
+
+ if( !close_modal )
ctx->focused_control_hit = 1;
+
ctx->focused_control_type = k_ui_control_modal; /* HACK */
ctx->wants_mouse = 1;
}
}
}
-void ui_start_modal( ui_context *ctx, const char *message, u32 options );
void _ui_textbox_clipboard_paste( ui_context *ctx )
{
if( !ctx->have_clipboard_text() )
int datastart = _ui_textbox_delete_char( ctx, 0 );
int length = strlen( text );
- if( (ctx->textbox.len - strlen(ctx->textbuf)) < length ){
- ui_start_modal( ctx,
- "Clipboard content exceeds buffer size.", UI_MODAL_BAD );
+ if( (ctx->textbox.len - strlen(ctx->textbuf)) < length )
+ {
+ ui_start_modal( ctx, "Clipboard content exceeds buffer size.", NULL, UI_MODAL_BAD, NULL );
return;
}
* Modal UI
* -----------------------------------------------------------------------------
*/
-void ui_start_modal( ui_context *ctx, const char *message, u32 options )
+void ui_start_modal( ui_context *ctx, const char *message, const char *ok_text,
+ u32 options, const struct ui_modal_callbacks *callbacks )
{
ctx->focused_control_type = k_ui_control_modal;
ctx->modal.message = message;
- ctx->modal.callbacks.close = NULL;
+ ctx->modal.ok_text = ok_text? ok_text: "OK";
+ if( callbacks )
+ ctx->modal.callbacks = *callbacks;
+ else
+ ctx->modal.callbacks.close = NULL;
+
ctx->modal.options = options;
-
u32 type = options & UI_MODAL_TYPE_BITS;
if( type == UI_MODAL_OK ) vg_info( message );
else if( type == UI_MODAL_WARN ) vg_warn( message );
#define UI_MODAL_BAD 0x2
#define UI_MODAL_WARN 0x3
#define UI_MODAL_TYPE_BITS 0x3
+#define UI_MODAL_CANCEL 0x8
#define UI_MOUSE_LEFT 1
#define UI_MOUSE_MIDDLE 2
struct ui_modal
{
- const char *message;
+ const char *message, *ok_text;
u32 options;
struct ui_modal_callbacks
bool ui_colourpicker( ui_context *ctx, ui_rect inout_panel, const char *str_label, v4f value, enum ui_colour_type type );
void _ui_textbox_move_cursor( ui_context *ctx, int *cursor0, int *cursor1, int dir, int snap_together );
int _ui_textbox_delete_char( ui_context *ctx, int direction );
-void ui_start_modal( ui_context *ctx, const char *message, u32 options );
+void ui_start_modal( ui_context *ctx, const char *message, const char *ok_text,
+ u32 options, const struct ui_modal_callbacks *callbacks );
void _ui_textbox_put_char( ui_context *ctx, char c );
void _ui_textbox_left_select( ui_context *ctx );
const char **titles, u32 count, i32 *page );
void ui_defocus_all( ui_context *ctx );
-void ui_start_modal( ui_context *ctx, const char *message, u32 options );
-
void ui_proc_utf8( ui_context *ctx, const char *text );
void ui_dev_colourview( ui_context *ctx );