Skip to content

Commit

Permalink
- add posix api to get file size, add support to supply font size dur…
Browse files Browse the repository at this point in the history
…ing dev ui init
  • Loading branch information
polymonster committed Dec 20, 2023
1 parent b4949f6 commit 1295426
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 13 deletions.
1 change: 1 addition & 0 deletions core/pen/include/file_system.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ namespace pen
bool filesystem_file_exists(const c8* filename);
pen_error filesystem_read_file_to_buffer(const c8* filename, void** p_buffer, u32& buffer_size);
pen_error filesystem_getmtime(const c8* filename, u32& mtime_out);
size_t filesystem_getsize(const c8* filename);
void filesystem_toggle_hidden_files();
pen_error filesystem_enum_volumes(fs_tree_node& results);
pen_error filesystem_enum_directory(const c8* directory, fs_tree_node& results, s32 num_wildcards = 0, ...);
Expand Down
5 changes: 5 additions & 0 deletions core/pen/source/osx/os.mm
Original file line number Diff line number Diff line change
Expand Up @@ -853,6 +853,11 @@ void os_ignore_slient()
{
// stub
}

f32 os_get_status_bar_portrait_height()
{
return 0.0f;
}
}

//
Expand Down
9 changes: 8 additions & 1 deletion core/pen/source/posix/file_system.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -222,7 +222,6 @@ namespace pen

if (num_items == 0)
{

return PEN_ERR_FILE_NOT_FOUND;
}

Expand Down Expand Up @@ -300,6 +299,14 @@ namespace pen
return PEN_ERR_OK;
}

size_t filesystem_getsize(const c8* filename)
{
struct stat stat_res;
memset(&stat_res, 0x0, sizeof(stat_res));
stat(filename, &stat_res);
return stat_res.st_size;
}

const c8* filesystem_get_user_directory()
{
static c8 default_dir[1024];
Expand Down
16 changes: 5 additions & 11 deletions core/put/source/dev_ui.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,6 @@

#include <fstream>

#if PEN_PLATFORM_IOS
#define DEV_UI_SCALE 3
#else
#define DEV_UI_SCALE 1
#endif

using namespace pen;
using namespace put;

Expand Down Expand Up @@ -63,17 +57,17 @@ namespace
bool s_initialised = false;
bool s_enable_main_menu_bar = true;

void create_texture_atlas()
void create_texture_atlas(float pixel_size)
{
ImGuiIO& io = ImGui::GetIO();
const Str cousine_reg = pen::os_path_for_resource("data/fonts/cousine-regular.ttf");
io.Fonts->AddFontFromFileTTF(cousine_reg.c_str(), 14 * DEV_UI_SCALE);
io.Fonts->AddFontFromFileTTF(cousine_reg.c_str(), pixel_size);

ImFontConfig config;
config.MergeMode = true;
static const ImWchar icon_ranges[] = {ICON_MIN_FA, ICON_MAX_FA, 0};
const Str font_awesome = pen::os_path_for_resource("data/fonts/fontawesome-webfont.ttf");
io.Fonts->AddFontFromFileTTF(font_awesome.c_str(), 14 * DEV_UI_SCALE, &config, icon_ranges);
io.Fonts->AddFontFromFileTTF(font_awesome.c_str(), pixel_size, &config, icon_ranges);

// Build texture atlas
unsigned char* pixels;
Expand Down Expand Up @@ -313,7 +307,7 @@ namespace put
}
}

bool init(ImGuiStyle& style)
bool init(ImGuiStyle& style, float font_pixel_size)
{
create_context();

Expand Down Expand Up @@ -346,7 +340,7 @@ namespace put
s_imgui_rs.imgui_shader = pmfx::load_shader("imgui");
s_imgui_rs.imgui_ex_shader = pmfx::load_shader("imgui_ex");

create_texture_atlas();
create_texture_atlas(font_pixel_size);

create_render_states();

Expand Down
9 changes: 8 additions & 1 deletion core/put/source/dev_ui.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,13 @@

#define IMG(I) (void*)(intptr_t) I

#if PEN_PLATFORM_IOS
#define DEV_UI_SCALE 3
#else
#define DEV_UI_SCALE 1
#endif


namespace put
{
namespace dev_ui
Expand Down Expand Up @@ -67,7 +74,7 @@ namespace put

void create_context();
ImGuiStyle& default_pmtech_style();
bool init(ImGuiStyle& style = default_pmtech_style());
bool init(ImGuiStyle& style = default_pmtech_style(), f32 font_pixel_size = 14.0f * DEV_UI_SCALE);
void shutdown();
void render();
void update();
Expand Down

0 comments on commit 1295426

Please sign in to comment.