Navigation Menu

Skip to content

Commit

Permalink
FontAwesome icons (#119)
Browse files Browse the repository at this point in the history
* Add FontAwesome fonts

* Support copying .ttf files

Also ignore .txt files (we want to keep licenses near assets)

* Support loading FontAwesome into dear imgui

* Load and use FontAwesome in shell

* Add some more icons

Using a lemon since we don't have a potato icon
  • Loading branch information
seanmiddleditch committed Aug 17, 2019
1 parent 3814d2b commit 9f3601e
Show file tree
Hide file tree
Showing 7 changed files with 81 additions and 4 deletions.
34 changes: 34 additions & 0 deletions resources/fonts/fontawesome5/LICENSE.txt
@@ -0,0 +1,34 @@
Font Awesome Free License
-------------------------

Font Awesome Free is free, open source, and GPL friendly. You can use it for
commercial projects, open source projects, or really almost whatever you want.
Full Font Awesome Free license: https://fontawesome.com/license/free.

# Icons: CC BY 4.0 License (https://creativecommons.org/licenses/by/4.0/)
In the Font Awesome Free download, the CC BY 4.0 license applies to all icons
packaged as SVG and JS file types.

# Fonts: SIL OFL 1.1 License (https://scripts.sil.org/OFL)
In the Font Awesome Free download, the SIL OFL license applies to all icons
packaged as web and desktop font files.

# Code: MIT License (https://opensource.org/licenses/MIT)
In the Font Awesome Free download, the MIT license applies to all non-font and
non-icon files.

# Attribution
Attribution is required by MIT, SIL OFL, and CC BY licenses. Downloaded Font
Awesome Free files already contain embedded comments with sufficient
attribution, so you shouldn't need to do anything additional when using these
files normally.

We've kept attribution comments terse, so we ask that you do not actively work
to remove them from files, especially code. They're a great way for folks to
learn about Font Awesome.

# Brand Icons
All brand icons are trademarks of their respective owners. The use of these
trademarks does not indicate endorsement of the trademark holder by Font
Awesome, nor vice versa. **Please do not use brand logos for any purpose except
to represent the company, product, or service to which they refer.**
Binary file added resources/fonts/fontawesome5/fa-regular-400.ttf
Binary file not shown.
Binary file added resources/fonts/fontawesome5/fa-solid-900.ttf
Binary file not shown.
4 changes: 4 additions & 0 deletions source/app/recon/private/converter_app.cpp
Expand Up @@ -134,12 +134,16 @@ void up::recon::ConverterApp::registerConverters() {
#endif
_converters.push_back({[](string_view path) { return path::extension(path) == ".hlsli"; },
new_box<IgnoreConverter>()});
_converters.push_back({[](string_view path) { return path::extension(path) == ".txt"; },
new_box<IgnoreConverter>()});
_converters.push_back({[](string_view path) { return path::extension(path) == ".json"; },
new_box<JsonConverter>()});
_converters.push_back({[](string_view path) { return path::extension(path) == ".png"; },
new_box<CopyConverter>()});
_converters.push_back({[](string_view path) { return path::extension(path) == ".jpg"; },
new_box<CopyConverter>()});
_converters.push_back({[](string_view path) { return path::extension(path) == ".ttf"; },
new_box<CopyConverter>()});
_converters.push_back({[](string_view path) { return path::extension(path) == ".obj"; },
new_box<ModelConverter>()});
}
Expand Down
17 changes: 13 additions & 4 deletions source/app/shell/private/shell_app.cpp
Expand Up @@ -137,6 +137,15 @@ int up::ShellApp::initialize() {
}

_drawImgui.bindShaders(std::move(imguiVertShader), std::move(imguiPixelShader));
auto fontStream = _fileSystem.openRead("resources/fonts/fontawesome5/fa-solid-900.ttf");
if (!fontStream) {
_errorDialog("Failed to open FontAwesome font");
return 1;
}
if (!_drawImgui.loadFontAwesome5(std::move(fontStream))) {
_errorDialog("Failed to load FontAwesome font");
return 1;
}
_drawImgui.createResources(*_device);

_camera.lookAt({0, 10, 15}, {0, 0, 0}, {0, 1, 0});
Expand Down Expand Up @@ -286,14 +295,14 @@ void up::ShellApp::_drawUI() {
if (ImGui::BeginMainMenuBar()) {
menuSize = ImGui::GetWindowSize();

if (ImGui::BeginMenu("Potato")) {
if (ImGui::MenuItem("Quit", "ESC")) {
if (ImGui::BeginMenu(u8"\uf094 Potato")) {
if (ImGui::MenuItem(u8"\uf52b Quit", "ESC")) {
_running = false;
}
ImGui::EndMenu();
}

if (ImGui::BeginMenu("View")) {
if (ImGui::BeginMenu(u8"\uf06e View")) {
if (ImGui::BeginMenu("Camera")) {
if (ImGui::MenuItem("Fly", "ctrl-f")) {
_cameraController = new_box<FlyCameraController>(_camera);
Expand All @@ -316,7 +325,7 @@ void up::ShellApp::_drawUI() {
ImGui::Spacing();
ImGui::Spacing();

if (ImGui::MenuItem(!_paused ? "Pause" : "Play", "F5")) {
if (ImGui::MenuItem(!_paused ? u8"\uf04c Pause" : u8"\uf04b Play", "F5")) {
_paused = !_paused;
}

Expand Down
27 changes: 27 additions & 0 deletions source/library/render/private/draw_imgui.cpp
Expand Up @@ -66,6 +66,31 @@ bool up::DrawImgui::createResources(GpuDevice& device) {
return true;
}

auto up::DrawImgui::loadFontAwesome5(Stream fontFile) -> bool {
static constexpr auto s_minGlyph = 0xf000;
static constexpr auto s_maxGlyph = 0xf897;
static constexpr ImWchar s_ranges[] = {s_minGlyph, s_maxGlyph, 0};

_ensureContext();

ImGui::SetCurrentContext(_context.get());
auto& io = ImGui::GetIO();

vector<byte> fontData;
if (readBinary(fontFile, fontData) != IOResult::Success) {
return false;
}


ImFontConfig config; // = {.MergeMode = true, .PixelSnapH = true};
config.MergeMode = true;
config.PixelSnapH = true;
config.FontDataOwnedByAtlas = false;

auto font = io.Fonts->AddFontFromMemoryTTF(fontData.data(), static_cast<int>(fontData.size()), 13.0f, &config, s_ranges);
return font != nullptr;
}

void up::DrawImgui::releaseResources() {
_indexBuffer.reset();
_vertexBuffer.reset();
Expand Down Expand Up @@ -264,6 +289,8 @@ void up::DrawImgui::_ensureContext() {
ImGui::SetCurrentContext(_context.get());
auto& io = ImGui::GetIO();

io.Fonts->AddFontDefault();

io.BackendPlatformName = "potato::grui";
io.IniFilename = nullptr;

Expand Down
3 changes: 3 additions & 0 deletions source/library/render/public/potato/render/draw_imgui.h
Expand Up @@ -7,6 +7,7 @@
#include "potato/foundation/rc.h"
#include "potato/foundation/unique_resource.h"
#include "potato/foundation/string.h"
#include "potato/filesystem/stream.h"

namespace up {
class GpuBuffer;
Expand Down Expand Up @@ -37,6 +38,8 @@ namespace up {
UP_RENDER_API bool createResources(GpuDevice& device);
UP_RENDER_API void releaseResources();

UP_RENDER_API bool loadFontAwesome5(Stream fontFile);

UP_RENDER_API bool handleEvent(SDL_Event const& ev);

UP_RENDER_API void beginFrame();
Expand Down

0 comments on commit 9f3601e

Please sign in to comment.