Added IO.FontYOffset. Added asserts.

This commit is contained in:
ocornut 2014-08-30 20:02:10 +01:00
parent 8fc50f5ed3
commit 3b339efeb2
2 changed files with 9 additions and 2 deletions

View file

@ -279,6 +279,7 @@ ImGuiIO::ImGuiIO()
IniFilename = "imgui.ini";
LogFilename = "imgui_log.txt";
Font = NULL;
FontYOffset = 0.0f;
FontTexUvForWhite = ImVec2(0.0f,0.0f);
FontAllowScaling = false;
PixelCenterOffset = 0.0f;
@ -1199,6 +1200,7 @@ void NewFrame()
ImGui::GetDefaultFontData(&fnt_data, &fnt_size, NULL, NULL);
g.IO.Font = new ImBitmapFont();
g.IO.Font->LoadFromMemory(fnt_data, fnt_size);
g.IO.FontYOffset = +1;
}
g.Initialized = true;
}
@ -5093,6 +5095,8 @@ void ImBitmapFont::Clear()
bool ImBitmapFont::LoadFromFile(const char* filename)
{
IM_ASSERT(!IsLoaded()); // Call Clear()
// Load file
FILE* f;
if ((f = fopen(filename, "rb")) == NULL)
@ -5123,7 +5127,9 @@ bool ImBitmapFont::LoadFromFile(const char* filename)
bool ImBitmapFont::LoadFromMemory(const void* data, size_t data_size)
{
Data = (unsigned char*)data;
IM_ASSERT(!IsLoaded()); // Call Clear()
Data = (unsigned char*)data;
DataSize = data_size;
// Parse data
@ -5262,7 +5268,7 @@ void ImBitmapFont::RenderText(float size, ImVec2 pos, ImU32 col, const ImVec4& c
// Align to be pixel perfect
pos.x = (float)(int)pos.x;
pos.y = (float)(int)pos.y;
pos.y = (float)(int)pos.y + GImGui.IO.FontYOffset;
const ImVec4 clip_rect = clip_rect_ref;

View file

@ -391,6 +391,7 @@ struct ImGuiIO
float MouseDoubleClickMaxDist; // = 6.0f // Distance threshold to stay in to validate a double-click, in pixels.
int KeyMap[ImGuiKey_COUNT]; // <unset> // Map of indices into the KeysDown[512] entries array
ImFont Font; // <auto> // Gets passed to text functions. Typedef ImFont to the type you want (ImBitmapFont* or your own font).
float FontYOffset; // = 0.0f // Offset font rendering by xx pixels in Y axis.
ImVec2 FontTexUvForWhite; // = (0.0f,0.0f) // Font texture must have a white pixel at this UV coordinate. Adjust if you are using custom texture.
bool FontAllowScaling; // = false // Set to allow scaling text with CTRL+Wheel.
float PixelCenterOffset; // = 0.0f // Try to set to 0.5f or 0.375f if rendering is blurry