Blamite Game Engine - Blam (Core)
font_editor.hpp
Go to the documentation of this file.
1 #pragma once
2 
3 #include "../../debug_ui.h"
5 
6 using namespace Blam::Content::Fonts;
7 
9 {
16  {
17  private:
18  // nothing here atm
19  char current_font[1024] = "";
20  Font* font = NULL;
21  public:
25  FontEditor() {};
26 
31 
32  void Draw()
33  {
34  if (show)
35  {
36  ImGui::Begin("Font Editor", &show);
37 
38  if (ImGui::BeginCombo("font", current_font))
39  {
40  std::map<std::string, Font>::iterator it;
41 
42  for (it = GetFontList()->begin(); it != GetFontList()->end(); it++)
43  {
44  std::string font_id = it->first;
45 
46  if (ImGui::Selectable(font_id.c_str()))
47  {
48  SetActiveFont(font_id);
49  }
50  }
51 
52  ImGui::EndCombo();
53  }
54 
55  //make sure we only draw controls if font is not null
56  if (font)
57  {
58  ImGui::DragShort("char spacing", &(font->charspacing), 1.0f, 0, 32767);
59  ImGui::DragShort("size", &(font->size), 1.0f, 0, 32767);
60  ImGui::DragShort("char width", &(font->mono_width), 1.0f, 0, 32767);
61  ImGui::SameLine();
62  Widgets::ShowHelpMarker("controls width (in px) each character will be drawn with\r\n\r\nonly applies when monospaced is set to true");
63 
64  ImGui::Checkbox("monospaced", &font->monospaced);
65 
66  if (ImGui::Button("reload"))
67  {
68  std::string font_id = font->id;
69 
71  SetActiveFont(font_id);
72  }
73  }
74 
75  ImGui::End();
76  }
77  }
78 
79  void SetActiveFont(std::string font_id)
80  {
81  memcpy(&current_font, font_id.c_str(), IM_ARRAYSIZE(current_font));
82 
83  font = GetFont(font_id);
84  }
85  };
86 }
Blam::Content::Fonts::ReloadFont
BLAM HRESULT ReloadFont(std::string id)
Reloads all data for the specified font.
Definition: fonts.cpp:856
Blam::DebugUI::Windows::FontEditor::~FontEditor
~FontEditor()
Empty destructor.
Definition: font_editor.hpp:30
Blam::DebugUI::Widgets::ShowHelpMarker
BLAM void ShowHelpMarker(const char *desc)
Shows a help indicator.
Definition: widgets.cpp:5
Blam::DebugUI::Windows::FontEditor
Class for the Font Editor.
Definition: font_editor.hpp:15
Blam::Content::Fonts::GetFontList
BLAM std::map< std::string, Font > * GetFontList()
Retrieves the list of loaded fonts.
Definition: fonts.cpp:824
Blam::DebugUI::Windows::FontEditor::FontEditor
FontEditor()
Empty constructor.
Definition: font_editor.hpp:25
Blam::Content::Fonts::GetFont
BLAM Font * GetFont(std::string id)
Retrieves a font from the list of loaded fonts.
Definition: fonts.cpp:795
Blam::Content::Fonts::Font::charspacing
short charspacing
The amount of space, in pixels, between each character.
Definition: fonts.h:77
Blam::DebugUI::Windows::FontEditor::SetActiveFont
void SetActiveFont(std::string font_id)
Definition: font_editor.hpp:79
Blam::Content::Fonts::Font::size
short size
The size of the font.
Definition: fonts.h:76
Blam::DebugUI::ImGUIDrawingGroup
Class representing an ImGUI drawing group/draw list item.
Definition: debug_ui.h:408
Blam::Content::Fonts::Font::monospaced
bool monospaced
Whether or not to treat the font as a monospace font.
Definition: fonts.h:78
Blam::Content::Fonts::Font::mono_width
short mono_width
The width for each character to be. Extra space will be left as needed if the glyph width is too smal...
Definition: fonts.h:79
Blam::Content::Fonts::Font
Structure to contain data for a Font.
Definition: fonts.h:67
ImGui::DragShort
IMGUI_API bool DragShort(const char *label, short *v, float v_speed=1.0f, short v_min=0, short v_max=0, const char *format="%d")
Definition: imgui_extensions.cpp:3
Blam::DebugUI::Windows
Legacy namespace to contain data for the legacy ImGUI console.
Definition: debug_ui.h:493
Blam::Content::Fonts
Definition: fonts.h:32
Blam::Content::Fonts::Font::id
std::string id
The unique ID of the font.
Definition: fonts.h:75
Blam::DebugUI::Windows::FontEditor::Draw
void Draw()
Draws the contents of the group.
Definition: font_editor.hpp:32
imgui_extensions.h