Merge remote-tracking branch 'origin' into 2015-03-antialiased-primitives

This commit is contained in:
ocornut 2015-05-31 16:57:43 +01:00
commit ade7661b3f
7 changed files with 1312 additions and 524 deletions

View File

@ -32,7 +32,7 @@ Demo
---- ----
You should be able to build the examples from sources (tested on Windows/Mac/Linux). If you don't, let me know! If you want to have a quick look at the features of ImGui, you can download binaries of the demo app here. You should be able to build the examples from sources (tested on Windows/Mac/Linux). If you don't, let me know! If you want to have a quick look at the features of ImGui, you can download binaries of the demo app here.
- [imgui-demo-binaries-20150321.zip](http://www.miracleworld.net/imgui/binaries/imgui-demo-binaries-20150321.zip) (Windows binaries, ImGui 1.37 WIP 2015/03/31, 4 executables, 391 KB) - [imgui-demo-binaries-20150531.zip](http://www.miracleworld.net/imgui/binaries/imgui-demo-binaries-20150531.zip) (Windows binaries, ImGui 1.40 WIP 2015/05/31, 4 executables, 432 KB)
Gallery Gallery
@ -42,7 +42,9 @@ Gallery
![screenshot 2](/web/test_window_02.png?raw=true) ![screenshot 2](/web/test_window_02.png?raw=true)
![screenshot 3](/web/test_window_03.png?raw=true) ![screenshot 3](/web/test_window_03.png?raw=true)
![screenshot 4](/web/test_window_04.png?raw=true) ![screenshot 4](/web/test_window_04.png?raw=true)
![screenshot 4](/web/examples_02.png?raw=true) ![screenshot 5](/web/test_window_05_menus.png?raw=true)
![screenshot 6](/web/examples_03.png?raw=true)
![screenshot 7](/web/examples_02.png?raw=true)
ImGui can load TTF fonts. UTF-8 is supported for text display and input. Here using Arial Unicode font to display Japanese. Initialize custom font with: ImGui can load TTF fonts. UTF-8 is supported for text display and input. Here using Arial Unicode font to display Japanese. Initialize custom font with:
``` ```
@ -127,13 +129,13 @@ Embeds [stb_textedit.h, stb_truetype.h, stb_rectpack.h](https://github.com/nothi
Inspiration, feedback, and testing for early versions: Casey Muratori, Atman Binstock, Mikko Mononen, Emmanuel Briney, Stefan Kamoda, Anton Mikhailov, Matt Willis. And everybody posting feedback, questions and patches on the GitHub. Inspiration, feedback, and testing for early versions: Casey Muratori, Atman Binstock, Mikko Mononen, Emmanuel Briney, Stefan Kamoda, Anton Mikhailov, Matt Willis. And everybody posting feedback, questions and patches on the GitHub.
ImGui is financially supported on [**Patreon**](http://www.patreon.com/imgui). ImGui development is financially supported on [**Patreon**](http://www.patreon.com/imgui).
Special supporters Special supporters:
- Jetha Chan, Mārtiņš Možeiko, Alex Evans, Pastagames, Wild Sheep Studio - Jetha Chan, Wild Sheep Studio, Pastagames, Mārtiņš Možeiko, Daniel Collin, Stefano Cristiano.
And And:
- Dale Kim, Michel Courtine, Paul Patrashcu, Rui Figueira - Michel Courtine, César Leblic, Dale Kim, Alex Evans, Rui Figueira, Paul Patrashcu, Jerome Lanquetot, Ctrl Alt Ninja, Paul Fleming, Neil Henning, Stephan Dilly.
And other supporters; thanks! And other supporters; thanks!

View File

@ -31,6 +31,9 @@
//---- Don't implement help and test window functionality (ShowUserGuide()/ShowStyleEditor()/ShowTestWindow() methods will be empty) //---- Don't implement help and test window functionality (ShowUserGuide()/ShowStyleEditor()/ShowTestWindow() methods will be empty)
//#define IMGUI_DISABLE_TEST_WINDOWS //#define IMGUI_DISABLE_TEST_WINDOWS
//---- Don't define obsolete functions names
//#define IMGUI_DISABLE_OBSOLETE_FUNCTIONS
//---- Implement STB libraries in a namespace to avoid conflicts //---- Implement STB libraries in a namespace to avoid conflicts
//#define IMGUI_STB_NAMESPACE ImStb //#define IMGUI_STB_NAMESPACE ImStb

1571
imgui.cpp

File diff suppressed because it is too large Load Diff

168
imgui.h
View File

@ -1,4 +1,4 @@
// ImGui library v1.39 WIP // ImGui library v1.40 WIP
// See .cpp file for documentation. // See .cpp file for documentation.
// See ImGui::ShowTestWindow() for sample code. // See ImGui::ShowTestWindow() for sample code.
// Read 'Programmer guide' in .cpp for notes on how to setup ImGui in your codebase. // Read 'Programmer guide' in .cpp for notes on how to setup ImGui in your codebase.
@ -13,7 +13,7 @@
#include <stdlib.h> // NULL, malloc, free, qsort, atoi #include <stdlib.h> // NULL, malloc, free, qsort, atoi
#include <string.h> // memset, memmove, memcpy, strlen, strchr, strcpy, strcmp #include <string.h> // memset, memmove, memcpy, strlen, strchr, strcpy, strcmp
#define IMGUI_VERSION "1.39 WIP" #define IMGUI_VERSION "1.40 WIP"
// Define assertion handler. // Define assertion handler.
#ifndef IM_ASSERT #ifndef IM_ASSERT
@ -80,6 +80,7 @@ struct ImVec4
// - struct ImGuiTextBuffer // Text buffer for logging/accumulating text // - struct ImGuiTextBuffer // Text buffer for logging/accumulating text
// - struct ImGuiStorage // Custom key value storage (if you need to alter open/close states manually) // - struct ImGuiStorage // Custom key value storage (if you need to alter open/close states manually)
// - struct ImGuiTextEditCallbackData // Shared state of ImGui::InputText() when using custom callbacks // - struct ImGuiTextEditCallbackData // Shared state of ImGui::InputText() when using custom callbacks
// - struct ImGuiListClipper // Helper to manually clip large list of items.
// - struct ImColor // Helper functions to created packed 32-bit RGBA color values // - struct ImColor // Helper functions to created packed 32-bit RGBA color values
// - struct ImDrawList // Draw command list // - struct ImDrawList // Draw command list
// - struct ImFontAtlas // Bake multiple fonts into a single texture, TTF font loader, bake glyphs into bitmap // - struct ImFontAtlas // Bake multiple fonts into a single texture, TTF font loader, bake glyphs into bitmap
@ -115,10 +116,10 @@ namespace ImGui
IMGUI_API ImFont* GetWindowFont(); IMGUI_API ImFont* GetWindowFont();
IMGUI_API float GetWindowFontSize(); // size (also height in pixels) of current font with current scale applied IMGUI_API float GetWindowFontSize(); // size (also height in pixels) of current font with current scale applied
IMGUI_API void SetWindowFontScale(float scale); // per-window font scale. Adjust IO.FontGlobalScale if you want to scale all windows IMGUI_API void SetWindowFontScale(float scale); // per-window font scale. Adjust IO.FontGlobalScale if you want to scale all windows
IMGUI_API ImVec2 GetWindowPos(); // you should rarely need/care about the window position, but it can be useful if you want to do your own drawing IMGUI_API ImVec2 GetWindowPos(); // get current window position in screen space (useful if you want to do your own drawing via the DrawList api)
IMGUI_API ImVec2 GetWindowSize(); // get current window position IMGUI_API ImVec2 GetWindowSize(); // get current window size
IMGUI_API float GetWindowWidth(); IMGUI_API float GetWindowWidth();
IMGUI_API bool GetWindowCollapsed(); IMGUI_API bool IsWindowCollapsed();
IMGUI_API void SetNextWindowPos(const ImVec2& pos, ImGuiSetCond cond = 0); // set next window position - call before Begin() IMGUI_API void SetNextWindowPos(const ImVec2& pos, ImGuiSetCond cond = 0); // set next window position - call before Begin()
IMGUI_API void SetNextWindowSize(const ImVec2& size, ImGuiSetCond cond = 0); // set next window size. set to ImVec2(0,0) to force an auto-fit IMGUI_API void SetNextWindowSize(const ImVec2& size, ImGuiSetCond cond = 0); // set next window size. set to ImVec2(0,0) to force an auto-fit
@ -157,6 +158,8 @@ namespace ImGui
IMGUI_API void PopAllowKeyboardFocus(); IMGUI_API void PopAllowKeyboardFocus();
IMGUI_API void PushTextWrapPos(float wrap_pos_x = 0.0f); // word-wrapping for Text*() commands. < 0.0f: no wrapping; 0.0f: wrap to end of window (or column); > 0.0f: wrap at 'wrap_pos_x' position in window local space IMGUI_API void PushTextWrapPos(float wrap_pos_x = 0.0f); // word-wrapping for Text*() commands. < 0.0f: no wrapping; 0.0f: wrap to end of window (or column); > 0.0f: wrap at 'wrap_pos_x' position in window local space
IMGUI_API void PopTextWrapPos(); IMGUI_API void PopTextWrapPos();
IMGUI_API void PushButtonRepeat(bool repeat); // in 'repeat' mode, Button*() functions return true multiple times as you hold them (uses io.KeyRepeatDelay/io.KeyRepeatRate for now)
IMGUI_API void PopButtonRepeat();
// Tooltip // Tooltip
IMGUI_API void SetTooltip(const char* fmt, ...); // set tooltip under mouse-cursor, typically use with ImGui::IsHovered(). last call wins IMGUI_API void SetTooltip(const char* fmt, ...); // set tooltip under mouse-cursor, typically use with ImGui::IsHovered(). last call wins
@ -165,15 +168,21 @@ namespace ImGui
IMGUI_API void EndTooltip(); IMGUI_API void EndTooltip();
// Popup // Popup
IMGUI_API void BeginPopup(bool* p_opened); IMGUI_API void OpenPopup(const char* str_id); // mark popup as open. popup identifiers are relative to the current ID-stack (so OpenPopup and BeginPopup needs to be at the same level). close childs popups if any. will close popup when user click outside, or activate a pressable item, or CloseCurrentPopup() is called within a BeginPopup()/EndPopup() block.
IMGUI_API bool BeginPopup(const char* str_id); // return true if popup if opened and start outputting to it. only call EndPopup() if BeginPopup() returned true!
IMGUI_API bool BeginPopupContextItem(const char* str_id, int mouse_button = 1); // open and begin popup when clicked on last item
IMGUI_API bool BeginPopupContextWindow(bool also_over_items = true, const char* str_id = NULL, int mouse_button = 1); // open and begin popup when clicked on current window
IMGUI_API bool BeginPopupContextVoid(const char* str_id = NULL, int mouse_button = 1); // open and begin popup when clicked in void (no window)
IMGUI_API void EndPopup(); IMGUI_API void EndPopup();
IMGUI_API void CloseCurrentPopup(); // close the popup we have begin-ed into. clicking on a MenuItem or Selectable automatically close the current popup.
// Layout // Cursor / Layout
IMGUI_API void BeginGroup(); IMGUI_API void BeginGroup(); // once closing a group it is seen as a single item (so you can use IsItemHovered() on a group, SameLine() between groups, etc.
IMGUI_API void EndGroup(); IMGUI_API void EndGroup();
IMGUI_API void Separator(); // horizontal line IMGUI_API void Separator(); // horizontal line
IMGUI_API void SameLine(int column_x = 0, int spacing_w = -1); // call between widgets or groups to layout them horizontally IMGUI_API void SameLine(int column_x = 0, int spacing_w = -1); // call between widgets or groups to layout them horizontally
IMGUI_API void Spacing(); // add vertical spacing IMGUI_API void Spacing(); // add spacing
IMGUI_API void Dummy(const ImVec2& size); // add a dummy item of given size
IMGUI_API void Indent(); // move content position toward the right by style.IndentSpacing pixels IMGUI_API void Indent(); // move content position toward the right by style.IndentSpacing pixels
IMGUI_API void Unindent(); // move content position back to the left (cancel Indent) IMGUI_API void Unindent(); // move content position back to the left (cancel Indent)
IMGUI_API void Columns(int count = 1, const char* id = NULL, bool border=true); // setup number of columns. use an identifier to distinguish multiple column sets. close with Columns(1). IMGUI_API void Columns(int count = 1, const char* id = NULL, bool border=true); // setup number of columns. use an identifier to distinguish multiple column sets. close with Columns(1).
@ -193,7 +202,8 @@ namespace ImGui
IMGUI_API void SetCursorScreenPos(const ImVec2& pos); // cursor position in absolute screen coordinates [0..io.DisplaySize] IMGUI_API void SetCursorScreenPos(const ImVec2& pos); // cursor position in absolute screen coordinates [0..io.DisplaySize]
IMGUI_API void AlignFirstTextHeightToWidgets(); // call once if the first item on the line is a Text() item and you want to vertically lower it to match subsequent (bigger) widgets IMGUI_API void AlignFirstTextHeightToWidgets(); // call once if the first item on the line is a Text() item and you want to vertically lower it to match subsequent (bigger) widgets
IMGUI_API float GetTextLineHeight(); // height of font == GetWindowFontSize() IMGUI_API float GetTextLineHeight(); // height of font == GetWindowFontSize()
IMGUI_API float GetTextLineHeightWithSpacing(); // spacing (in pixels) between 2 consecutive lines of text == GetWindowFontSize() + GetStyle().ItemSpacing.y IMGUI_API float GetTextLineHeightWithSpacing(); // distance (in pixels) between 2 consecutive lines of text == GetWindowFontSize() + GetStyle().ItemSpacing.y
IMGUI_API float GetItemsLineHeightWithSpacing(); // distance (in pixels) between 2 consecutive lines of standard height widgets == GetWindowFontSize() + GetStyle().FramePadding.y*2 + GetStyle().ItemSpacing.y
// ID scopes // ID scopes
// If you are creating widgets in a loop you most likely want to push a unique identifier so ImGui can differentiate them // If you are creating widgets in a loop you most likely want to push a unique identifier so ImGui can differentiate them
@ -212,7 +222,9 @@ namespace ImGui
IMGUI_API void TextV(const char* fmt, va_list args); IMGUI_API void TextV(const char* fmt, va_list args);
IMGUI_API void TextColored(const ImVec4& col, const char* fmt, ...); // shortcut for PushStyleColor(ImGuiCol_Text, col); Text(fmt, ...); PopStyleColor(); IMGUI_API void TextColored(const ImVec4& col, const char* fmt, ...); // shortcut for PushStyleColor(ImGuiCol_Text, col); Text(fmt, ...); PopStyleColor();
IMGUI_API void TextColoredV(const ImVec4& col, const char* fmt, va_list args); IMGUI_API void TextColoredV(const ImVec4& col, const char* fmt, va_list args);
IMGUI_API void TextWrapped(const char* fmt, ...); // shortcut for PushTextWrapPos(0.0f); Text(fmt, ...); PopTextWrapPos(); IMGUI_API void TextDisabled(const char* fmt, ...); // shortcut for PushStyleColor(ImGuiCol_Text, style.Colors[ImGuiCol_TextDisabled]); Text(fmt, ...); PopStyleColor();
IMGUI_API void TextDisabledV(const char* fmt, va_list args);
IMGUI_API void TextWrapped(const char* fmt, ...); // shortcut for PushTextWrapPos(0.0f); Text(fmt, ...); PopTextWrapPos();. Note that this won't work on an auto-resizing window if there's no other widgets to extend the window width, yoy may need to set a size using SetNextWindowSize().
IMGUI_API void TextWrappedV(const char* fmt, va_list args); IMGUI_API void TextWrappedV(const char* fmt, va_list args);
IMGUI_API void TextUnformatted(const char* text, const char* text_end = NULL); // doesn't require null terminated string if 'text_end' is specified. no copy done to any bounded stack buffer, recommended for long chunks of text IMGUI_API void TextUnformatted(const char* text, const char* text_end = NULL); // doesn't require null terminated string if 'text_end' is specified. no copy done to any bounded stack buffer, recommended for long chunks of text
IMGUI_API void LabelText(const char* label, const char* fmt, ...); // display text+label aligned the same way as value+label widgets IMGUI_API void LabelText(const char* label, const char* fmt, ...); // display text+label aligned the same way as value+label widgets
@ -220,7 +232,7 @@ namespace ImGui
IMGUI_API void Bullet(); IMGUI_API void Bullet();
IMGUI_API void BulletText(const char* fmt, ...); IMGUI_API void BulletText(const char* fmt, ...);
IMGUI_API void BulletTextV(const char* fmt, va_list args); IMGUI_API void BulletTextV(const char* fmt, va_list args);
IMGUI_API bool Button(const char* label, const ImVec2& size = ImVec2(0,0), bool repeat_when_held = false); IMGUI_API bool Button(const char* label, const ImVec2& size = ImVec2(0,0));
IMGUI_API bool SmallButton(const char* label); IMGUI_API bool SmallButton(const char* label);
IMGUI_API bool InvisibleButton(const char* str_id, const ImVec2& size); IMGUI_API bool InvisibleButton(const char* str_id, const ImVec2& size);
IMGUI_API void Image(ImTextureID user_texture_id, const ImVec2& size, const ImVec2& uv0 = ImVec2(0,0), const ImVec2& uv1 = ImVec2(1,1), const ImVec4& tint_col = ImVec4(1,1,1,1), const ImVec4& border_col = ImVec4(0,0,0,0)); IMGUI_API void Image(ImTextureID user_texture_id, const ImVec2& size, const ImVec2& uv0 = ImVec2(0,0), const ImVec2& uv1 = ImVec2(1,1), const ImVec4& tint_col = ImVec4(1,1,1,1), const ImVec4& border_col = ImVec4(0,0,0,0));
@ -242,19 +254,6 @@ namespace ImGui
IMGUI_API void PlotHistogram(const char* label, const float* values, int values_count, int values_offset = 0, const char* overlay_text = NULL, float scale_min = FLT_MAX, float scale_max = FLT_MAX, ImVec2 graph_size = ImVec2(0,0), size_t stride = sizeof(float)); IMGUI_API void PlotHistogram(const char* label, const float* values, int values_count, int values_offset = 0, const char* overlay_text = NULL, float scale_min = FLT_MAX, float scale_max = FLT_MAX, ImVec2 graph_size = ImVec2(0,0), size_t stride = sizeof(float));
IMGUI_API void PlotHistogram(const char* label, float (*values_getter)(void* data, int idx), void* data, int values_count, int values_offset = 0, const char* overlay_text = NULL, float scale_min = FLT_MAX, float scale_max = FLT_MAX, ImVec2 graph_size = ImVec2(0,0)); IMGUI_API void PlotHistogram(const char* label, float (*values_getter)(void* data, int idx), void* data, int values_count, int values_offset = 0, const char* overlay_text = NULL, float scale_min = FLT_MAX, float scale_max = FLT_MAX, ImVec2 graph_size = ImVec2(0,0));
// Widgets: Sliders (tip: ctrl+click on a slider to input text)
IMGUI_API bool SliderFloat(const char* label, float* v, float v_min, float v_max, const char* display_format = "%.3f", float power = 1.0f); // adjust display_format to decorate the value with a prefix or a suffix. Use power!=1.0 for logarithmic sliders
IMGUI_API bool SliderFloat2(const char* label, float v[2], float v_min, float v_max, const char* display_format = "%.3f", float power = 1.0f);
IMGUI_API bool SliderFloat3(const char* label, float v[3], float v_min, float v_max, const char* display_format = "%.3f", float power = 1.0f);
IMGUI_API bool SliderFloat4(const char* label, float v[4], float v_min, float v_max, const char* display_format = "%.3f", float power = 1.0f);
IMGUI_API bool SliderAngle(const char* label, float* v_rad, float v_degrees_min = -360.0f, float v_degrees_max = +360.0f);
IMGUI_API bool SliderInt(const char* label, int* v, int v_min, int v_max, const char* display_format = "%.0f");
IMGUI_API bool SliderInt2(const char* label, int v[2], int v_min, int v_max, const char* display_format = "%.0f");
IMGUI_API bool SliderInt3(const char* label, int v[3], int v_min, int v_max, const char* display_format = "%.0f");
IMGUI_API bool SliderInt4(const char* label, int v[4], int v_min, int v_max, const char* display_format = "%.0f");
IMGUI_API bool VSliderFloat(const char* label, const ImVec2& size, float* v, float v_min, float v_max, const char* display_format = "%.3f", float power = 1.0f);
IMGUI_API bool VSliderInt(const char* label, const ImVec2& size, int* v, int v_min, int v_max, const char* display_format = "%.0f");
// Widgets: Drags (tip: ctrl+click on a drag box to input text) // Widgets: Drags (tip: ctrl+click on a drag box to input text)
IMGUI_API bool DragFloat(const char* label, float* v, float v_speed = 1.0f, float v_min = 0.0f, float v_max = 0.0f, const char* display_format = "%.3f", float power = 1.0f); // If v_min >= v_max we have no bound IMGUI_API bool DragFloat(const char* label, float* v, float v_speed = 1.0f, float v_min = 0.0f, float v_max = 0.0f, const char* display_format = "%.3f", float power = 1.0f); // If v_min >= v_max we have no bound
IMGUI_API bool DragFloat2(const char* label, float v[2], float v_speed = 1.0f, float v_min = 0.0f, float v_max = 0.0f, const char* display_format = "%.3f", float power = 1.0f); IMGUI_API bool DragFloat2(const char* label, float v[2], float v_speed = 1.0f, float v_min = 0.0f, float v_max = 0.0f, const char* display_format = "%.3f", float power = 1.0f);
@ -276,6 +275,19 @@ namespace ImGui
IMGUI_API bool InputInt3(const char* label, int v[3], ImGuiInputTextFlags extra_flags = 0); IMGUI_API bool InputInt3(const char* label, int v[3], ImGuiInputTextFlags extra_flags = 0);
IMGUI_API bool InputInt4(const char* label, int v[4], ImGuiInputTextFlags extra_flags = 0); IMGUI_API bool InputInt4(const char* label, int v[4], ImGuiInputTextFlags extra_flags = 0);
// Widgets: Sliders (tip: ctrl+click on a slider to input text)
IMGUI_API bool SliderFloat(const char* label, float* v, float v_min, float v_max, const char* display_format = "%.3f", float power = 1.0f); // adjust display_format to decorate the value with a prefix or a suffix. Use power!=1.0 for logarithmic sliders
IMGUI_API bool SliderFloat2(const char* label, float v[2], float v_min, float v_max, const char* display_format = "%.3f", float power = 1.0f);
IMGUI_API bool SliderFloat3(const char* label, float v[3], float v_min, float v_max, const char* display_format = "%.3f", float power = 1.0f);
IMGUI_API bool SliderFloat4(const char* label, float v[4], float v_min, float v_max, const char* display_format = "%.3f", float power = 1.0f);
IMGUI_API bool SliderAngle(const char* label, float* v_rad, float v_degrees_min = -360.0f, float v_degrees_max = +360.0f);
IMGUI_API bool SliderInt(const char* label, int* v, int v_min, int v_max, const char* display_format = "%.0f");
IMGUI_API bool SliderInt2(const char* label, int v[2], int v_min, int v_max, const char* display_format = "%.0f");
IMGUI_API bool SliderInt3(const char* label, int v[3], int v_min, int v_max, const char* display_format = "%.0f");
IMGUI_API bool SliderInt4(const char* label, int v[4], int v_min, int v_max, const char* display_format = "%.0f");
IMGUI_API bool VSliderFloat(const char* label, const ImVec2& size, float* v, float v_min, float v_max, const char* display_format = "%.3f", float power = 1.0f);
IMGUI_API bool VSliderInt(const char* label, const ImVec2& size, int* v, int v_min, int v_max, const char* display_format = "%.0f");
// Widgets: Trees // Widgets: Trees
IMGUI_API bool TreeNode(const char* str_label_id); // if returning 'true' the node is open and the user is responsible for calling TreePop IMGUI_API bool TreeNode(const char* str_label_id); // if returning 'true' the node is open and the user is responsible for calling TreePop
IMGUI_API bool TreeNode(const char* str_id, const char* fmt, ...); // " IMGUI_API bool TreeNode(const char* str_id, const char* fmt, ...); // "
@ -297,11 +309,16 @@ namespace ImGui
IMGUI_API void ListBoxFooter(); // terminate the scrolling region IMGUI_API void ListBoxFooter(); // terminate the scrolling region
// Widgets: Menus // Widgets: Menus
// FIXME-WIP: v1.39 in development IMGUI_API bool BeginMainMenuBar(); // create and append to a full screen menu-bar. only call EndMainMenuBar() if this returns true!
IMGUI_API bool MenuItem(const char* label, const char* shortcut = NULL, bool selected = false); // bool enabled = true IMGUI_API void EndMainMenuBar();
IMGUI_API bool MenuItem(const char* label, const char* shortcut, bool* p_selected); // bool enabled = true IMGUI_API bool BeginMenuBar(); // append to menu-bar of current window (requires ImGuiWindowFlags_MenuBar flag set). only call EndMenuBar() if this returns true!
IMGUI_API void EndMenuBar();
IMGUI_API bool BeginMenu(const char* label, bool enabled = true); // create a sub-menu entry. only call EndMenu() if this returns true!
IMGUI_API void EndMenu();
IMGUI_API bool MenuItem(const char* label, const char* shortcut = NULL, bool selected = false, bool enabled = true); // return true when activated. shortcuts are displayed for convenience but not processed by ImGui at the moment
IMGUI_API bool MenuItem(const char* label, const char* shortcut, bool* p_selected, bool enabled = true); // return true when activated + toggle (*p_selected) if p_selected != NULL
// Widgets: Value() Helpers. Output single value in "name: value" format (tip: freely declare your own within the ImGui namespace!) // Widgets: Value() Helpers. Output single value in "name: value" format (tip: freely declare more in your code to handle your types. you can add functions to the ImGui namespace)
IMGUI_API void Value(const char* prefix, bool b); IMGUI_API void Value(const char* prefix, bool b);
IMGUI_API void Value(const char* prefix, int v); IMGUI_API void Value(const char* prefix, int v);
IMGUI_API void Value(const char* prefix, unsigned int v); IMGUI_API void Value(const char* prefix, unsigned int v);
@ -321,15 +338,16 @@ namespace ImGui
IMGUI_API bool IsItemHovered(); // was the last item hovered by mouse? IMGUI_API bool IsItemHovered(); // was the last item hovered by mouse?
IMGUI_API bool IsItemHoveredRect(); // was the last item hovered by mouse? even if another item is active while we are hovering this IMGUI_API bool IsItemHoveredRect(); // was the last item hovered by mouse? even if another item is active while we are hovering this
IMGUI_API bool IsItemActive(); // was the last item active? (e.g. button being held, text field being edited- items that don't interact will always return false) IMGUI_API bool IsItemActive(); // was the last item active? (e.g. button being held, text field being edited- items that don't interact will always return false)
IMGUI_API bool IsAnyItemActive(); //
IMGUI_API bool IsItemVisible(); IMGUI_API bool IsItemVisible();
IMGUI_API bool IsAnyItemHovered();
IMGUI_API bool IsAnyItemActive();
IMGUI_API ImVec2 GetItemRectMin(); // get bounding rect of last item in screen space IMGUI_API ImVec2 GetItemRectMin(); // get bounding rect of last item in screen space
IMGUI_API ImVec2 GetItemRectMax(); // " IMGUI_API ImVec2 GetItemRectMax(); // "
IMGUI_API ImVec2 GetItemRectSize(); // " IMGUI_API ImVec2 GetItemRectSize(); // "
IMGUI_API bool IsWindowFocused(); // is current window focused (differentiate child windows from each others) IMGUI_API bool IsWindowFocused(); // is current window focused (differentiate child windows from each others)
IMGUI_API bool IsRootWindowFocused(); // is current root window focused IMGUI_API bool IsRootWindowFocused(); // is current root window focused (top parent window in case of child windows)
IMGUI_API bool IsRootWindowOrAnyChildFocused(); // is current root window or any of its child (including current window) focused IMGUI_API bool IsRootWindowOrAnyChildFocused(); // is current root window or any of its child (including current window) focused
IMGUI_API bool IsRectClipped(const ImVec2& size); // test if rectangle of given size starting from cursor pos is out of clipping region. to perform coarse clipping on user's side (as an optimization) IMGUI_API bool IsRectVisible(const ImVec2& size); // test if rectangle of given size starting from cursor pos is visible (not clipped). to perform coarse clipping on user's side (as an optimization)
IMGUI_API bool IsKeyDown(int key_index); // key_index into the keys_down[512] array, imgui doesn't know the semantic of each entry IMGUI_API bool IsKeyDown(int key_index); // key_index into the keys_down[512] array, imgui doesn't know the semantic of each entry
IMGUI_API bool IsKeyPressed(int key_index, bool repeat = true); // " IMGUI_API bool IsKeyPressed(int key_index, bool repeat = true); // "
IMGUI_API bool IsMouseDown(int button); IMGUI_API bool IsMouseDown(int button);
@ -350,7 +368,7 @@ namespace ImGui
IMGUI_API const char* GetStyleColName(ImGuiCol idx); IMGUI_API const char* GetStyleColName(ImGuiCol idx);
IMGUI_API ImVec2 CalcItemRectClosestPoint(const ImVec2& pos, bool on_edge = false, float outward = +0.0f); // utility to find the closest point the last item bounding rectangle edge. useful to visually link items IMGUI_API ImVec2 CalcItemRectClosestPoint(const ImVec2& pos, bool on_edge = false, float outward = +0.0f); // utility to find the closest point the last item bounding rectangle edge. useful to visually link items
IMGUI_API ImVec2 CalcTextSize(const char* text, const char* text_end = NULL, bool hide_text_after_double_hash = false, float wrap_width = -1.0f); IMGUI_API ImVec2 CalcTextSize(const char* text, const char* text_end = NULL, bool hide_text_after_double_hash = false, float wrap_width = -1.0f);
IMGUI_API void CalcListClipping(int items_count, float items_height, int* out_items_display_start, int* out_items_display_end); // helper to manually clip large list of items. see comments in implementation IMGUI_API void CalcListClipping(int items_count, float items_height, int* out_items_display_start, int* out_items_display_end); // calculate coarse clipping for large list of evenly sized items. Prefer using the ImGuiListClipper higher-level helper if you can.
IMGUI_API void BeginChildFrame(ImGuiID id, const ImVec2& size); // helper to create a child window / scrolling region that looks like a normal widget frame IMGUI_API void BeginChildFrame(ImGuiID id, const ImVec2& size); // helper to create a child window / scrolling region that looks like a normal widget frame
IMGUI_API void EndChildFrame(); IMGUI_API void EndChildFrame();
@ -359,24 +377,28 @@ namespace ImGui
IMGUI_API void ColorConvertRGBtoHSV(float r, float g, float b, float& out_h, float& out_s, float& out_v); IMGUI_API void ColorConvertRGBtoHSV(float r, float g, float b, float& out_h, float& out_s, float& out_v);
IMGUI_API void ColorConvertHSVtoRGB(float h, float s, float v, float& out_r, float& out_g, float& out_b); IMGUI_API void ColorConvertHSVtoRGB(float h, float s, float v, float& out_r, float& out_g, float& out_b);
// Proxy functions to access the MemAllocFn/MemFreeFn pointers in ImGui::GetIO() // Helpers functions to access the MemAllocFn/MemFreeFn pointers in ImGui::GetIO()
IMGUI_API void* MemAlloc(size_t sz); IMGUI_API void* MemAlloc(size_t sz);
IMGUI_API void MemFree(void* ptr); IMGUI_API void MemFree(void* ptr);
// Internal state access - if you want to share ImGui state between modules (e.g. DLL) or allocate it yourself // Internal state/context access - if you want to use multiple ImGui context, or share context between modules (e.g. DLL), or allocate the memory yourself
IMGUI_API const char* GetVersion(); IMGUI_API const char* GetVersion();
IMGUI_API void* GetInternalState(); IMGUI_API void* GetInternalState();
IMGUI_API size_t GetInternalStateSize(); IMGUI_API size_t GetInternalStateSize();
IMGUI_API void SetInternalState(void* state, bool construct = false); IMGUI_API void SetInternalState(void* state, bool construct = false);
// Obsolete (will be removed) // Obsolete (will be removed)
IMGUI_API void GetDefaultFontData(const void** fnt_data, unsigned int* fnt_size, const void** png_data, unsigned int* png_size); // OBSOLETE #ifndef IMGUI_DISABLE_OBSOLETE_FUNCTIONS
static inline void OpenNextNode(bool open) { ImGui::SetNextTreeNodeOpened(open, 0); } // OBSOLETE IMGUI_API void GetDefaultFontData(const void** fnt_data, unsigned int* fnt_size, const void** png_data, unsigned int* png_size); // OBSOLETE 1.30+
static inline bool GetWindowIsFocused() { return ImGui::IsWindowFocused(); } // OBSOLETE static inline void OpenNextNode(bool open) { ImGui::SetNextTreeNodeOpened(open, 0); } // OBSOLETE 1.34+
static inline ImVec2 GetItemBoxMin() { return GetItemRectMin(); } // OBSOLETE static inline bool GetWindowIsFocused() { return ImGui::IsWindowFocused(); } // OBSOLETE 1.36+
static inline ImVec2 GetItemBoxMax() { return GetItemRectMax(); } // OBSOLETE static inline bool GetWindowCollapsed() { return ImGui::IsWindowCollapsed(); } // OBSOLETE 1.39+
static inline bool IsClipped(const ImVec2& size) { return IsRectClipped(size); } // OBSOLETE static inline ImVec2 GetItemBoxMin() { return GetItemRectMin(); } // OBSOLETE 1.36+
static inline bool IsMouseHoveringBox(const ImVec2& rect_min, const ImVec2& rect_max) { return IsMouseHoveringRect(rect_min, rect_max); } // OBSOLETE static inline ImVec2 GetItemBoxMax() { return GetItemRectMax(); } // OBSOLETE 1.36+
static inline bool IsClipped(const ImVec2& size) { return !IsRectVisible(size); } // OBSOLETE 1.38+
static inline bool IsRectClipped(const ImVec2& size) { return !IsRectVisible(size); } // OBSOLETE 1.39+
static inline bool IsMouseHoveringBox(const ImVec2& rect_min, const ImVec2& rect_max) { return IsMouseHoveringRect(rect_min, rect_max); } // OBSOLETE 1.36+
#endif
} // namespace ImGui } // namespace ImGui
@ -393,13 +415,15 @@ enum ImGuiWindowFlags_
ImGuiWindowFlags_AlwaysAutoResize = 1 << 6, // Resize every window to its content every frame ImGuiWindowFlags_AlwaysAutoResize = 1 << 6, // Resize every window to its content every frame
ImGuiWindowFlags_ShowBorders = 1 << 7, // Show borders around windows and items ImGuiWindowFlags_ShowBorders = 1 << 7, // Show borders around windows and items
ImGuiWindowFlags_NoSavedSettings = 1 << 8, // Never load/save settings in .ini file ImGuiWindowFlags_NoSavedSettings = 1 << 8, // Never load/save settings in .ini file
ImGuiWindowFlags_MenuBar = 1 << 9, // Has a menu-bar
// [Internal] // [Internal]
ImGuiWindowFlags_ChildWindow = 1 << 9, // For internal use by BeginChild() ImGuiWindowFlags_ChildWindow = 1 << 20, // Don't use! For internal use by BeginChild()
ImGuiWindowFlags_ChildWindowAutoFitX = 1 << 10, // For internal use by BeginChild() ImGuiWindowFlags_ChildWindowAutoFitX = 1 << 21, // Don't use! For internal use by BeginChild()
ImGuiWindowFlags_ChildWindowAutoFitY = 1 << 11, // For internal use by BeginChild() ImGuiWindowFlags_ChildWindowAutoFitY = 1 << 22, // Don't use! For internal use by BeginChild()
ImGuiWindowFlags_ComboBox = 1 << 12, // For internal use by ComboBox() ImGuiWindowFlags_ComboBox = 1 << 23, // Don't use! For internal use by ComboBox()
ImGuiWindowFlags_Tooltip = 1 << 13, // For internal use by BeginTooltip() ImGuiWindowFlags_Tooltip = 1 << 24, // Don't use! For internal use by BeginTooltip()
ImGuiWindowFlags_Popup = 1 << 14 // For internal use by BeginPopup() ImGuiWindowFlags_Popup = 1 << 25, // Don't use! For internal use by BeginPopup()
ImGuiWindowFlags_ChildMenu = 1 << 26 // Don't use! For internal use by BeginMenu()
}; };
// Flags for ImGui::InputText() // Flags for ImGui::InputText()
@ -445,6 +469,7 @@ enum ImGuiKey_
enum ImGuiCol_ enum ImGuiCol_
{ {
ImGuiCol_Text, ImGuiCol_Text,
ImGuiCol_TextDisabled,
ImGuiCol_WindowBg, ImGuiCol_WindowBg,
ImGuiCol_ChildWindowBg, ImGuiCol_ChildWindowBg,
ImGuiCol_Border, ImGuiCol_Border,
@ -454,6 +479,7 @@ enum ImGuiCol_
ImGuiCol_FrameBgActive, ImGuiCol_FrameBgActive,
ImGuiCol_TitleBg, ImGuiCol_TitleBg,
ImGuiCol_TitleBgCollapsed, ImGuiCol_TitleBgCollapsed,
ImGuiCol_MenuBarBg,
ImGuiCol_ScrollbarBg, ImGuiCol_ScrollbarBg,
ImGuiCol_ScrollbarGrab, ImGuiCol_ScrollbarGrab,
ImGuiCol_ScrollbarGrabHovered, ImGuiCol_ScrollbarGrabHovered,
@ -493,6 +519,7 @@ enum ImGuiStyleVar_
ImGuiStyleVar_Alpha, // float ImGuiStyleVar_Alpha, // float
ImGuiStyleVar_WindowPadding, // ImVec2 ImGuiStyleVar_WindowPadding, // ImVec2
ImGuiStyleVar_WindowRounding, // float ImGuiStyleVar_WindowRounding, // float
ImGuiStyleVar_WindowMinSize, // ImVec2
ImGuiStyleVar_ChildWindowRounding, // float ImGuiStyleVar_ChildWindowRounding, // float
ImGuiStyleVar_FramePadding, // ImVec2 ImGuiStyleVar_FramePadding, // ImVec2
ImGuiStyleVar_FrameRounding, // float ImGuiStyleVar_FrameRounding, // float
@ -507,7 +534,9 @@ enum ImGuiAlign_
ImGuiAlign_Left = 1 << 0, ImGuiAlign_Left = 1 << 0,
ImGuiAlign_Center = 1 << 1, ImGuiAlign_Center = 1 << 1,
ImGuiAlign_Right = 1 << 2, ImGuiAlign_Right = 1 << 2,
ImGuiAlign_Default = ImGuiAlign_Left, ImGuiAlign_Top = 1 << 3,
ImGuiAlign_VCenter = 1 << 4,
ImGuiAlign_Default = ImGuiAlign_Left | ImGuiAlign_Top,
}; };
// Enumeration for ColorEditMode() // Enumeration for ColorEditMode()
@ -586,6 +615,8 @@ struct ImGuiIO
float MouseDoubleClickMaxDist; // = 6.0f // Distance threshold to stay in to validate a double-click, in pixels. float MouseDoubleClickMaxDist; // = 6.0f // Distance threshold to stay in to validate a double-click, in pixels.
float MouseDragThreshold; // = 6.0f // Distance threshold before considering we are dragging float MouseDragThreshold; // = 6.0f // Distance threshold before considering we are dragging
int KeyMap[ImGuiKey_COUNT]; // <unset> // Map of indices into the KeysDown[512] entries array int KeyMap[ImGuiKey_COUNT]; // <unset> // Map of indices into the KeysDown[512] entries array
float KeyRepeatDelay; // = 0.250f // When holding a key/button, time before it starts repeating, in seconds. (for actions where 'repeat' is active)
float KeyRepeatRate; // = 0.020f // When holding a key/button, rate at which it repeats, in seconds.
void* UserData; // = NULL // Store your own data for retrieval by callbacks. void* UserData; // = NULL // Store your own data for retrieval by callbacks.
ImFontAtlas* Fonts; // <auto> // Load and assemble one or more fonts into a single tightly packed texture. Output to Fonts array. ImFontAtlas* Fonts; // <auto> // Load and assemble one or more fonts into a single tightly packed texture. Output to Fonts array.
@ -641,6 +672,7 @@ struct ImGuiIO
bool WantCaptureMouse; // Mouse is hovering a window or widget is active (= ImGui will use your mouse input) bool WantCaptureMouse; // Mouse is hovering a window or widget is active (= ImGui will use your mouse input)
bool WantCaptureKeyboard; // Widget is active (= ImGui will use your keyboard input) bool WantCaptureKeyboard; // Widget is active (= ImGui will use your keyboard input)
float Framerate; // Framerate estimation, in frame per second. Rolling average estimation based on IO.DeltaTime over 120 frames float Framerate; // Framerate estimation, in frame per second. Rolling average estimation based on IO.DeltaTime over 120 frames
int MetricsAllocs; // Number of active memory allocations
int MetricsRenderVertices; // Vertices processed during last call to Render() int MetricsRenderVertices; // Vertices processed during last call to Render()
int MetricsActiveWindows; // Number of visible windows (exclude child windows) int MetricsActiveWindows; // Number of visible windows (exclude child windows)
@ -706,7 +738,9 @@ public:
inline const value_type& back() const { IM_ASSERT(Size > 0); return Data[Size-1]; } inline const value_type& back() const { IM_ASSERT(Size > 0); return Data[Size-1]; }
inline void swap(ImVector<T>& rhs) { const size_t rhs_size = rhs.Size; rhs.Size = Size; Size = rhs_size; const size_t rhs_cap = rhs.Capacity; rhs.Capacity = Capacity; Capacity = rhs_cap; value_type* rhs_data = rhs.Data; rhs.Data = Data; Data = rhs_data; } inline void swap(ImVector<T>& rhs) { const size_t rhs_size = rhs.Size; rhs.Size = Size; Size = rhs_size; const size_t rhs_cap = rhs.Capacity; rhs.Capacity = Capacity; Capacity = rhs_cap; value_type* rhs_data = rhs.Data; rhs.Data = Data; Data = rhs_data; }
inline void resize(size_t new_size) { if (new_size > Capacity) reserve(new_size); Size = new_size; } inline size_t _grow_capacity(size_t new_size) { size_t new_capacity = Capacity ? (Capacity + Capacity/2) : 8; return new_capacity > new_size ? new_capacity : new_size; }
inline void resize(size_t new_size) { if (new_size > Capacity) reserve(_grow_capacity(new_size)); Size = new_size; }
inline void reserve(size_t new_capacity) inline void reserve(size_t new_capacity)
{ {
if (new_capacity <= Capacity) return; if (new_capacity <= Capacity) return;
@ -717,7 +751,7 @@ public:
Capacity = new_capacity; Capacity = new_capacity;
} }
inline void push_back(const value_type& v) { if (Size == Capacity) reserve(Capacity ? Capacity * 2 : 4); Data[Size++] = v; } inline void push_back(const value_type& v) { if (Size == Capacity) reserve(_grow_capacity(Size+1)); Data[Size++] = v; }
inline void pop_back() { IM_ASSERT(Size > 0); Size--; } inline void pop_back() { IM_ASSERT(Size > 0); Size--; }
inline iterator erase(const_iterator it) { IM_ASSERT(it >= begin() && it < end()); const ptrdiff_t off = it - begin(); memmove(Data + off, Data + off + 1, (Size - (size_t)off - 1) * sizeof(value_type)); Size--; return Data + off; } inline iterator erase(const_iterator it) { IM_ASSERT(it >= begin() && it < end()); const ptrdiff_t off = it - begin(); memmove(Data + off, Data + off + 1, (Size - (size_t)off - 1) * sizeof(value_type)); Size--; return Data + off; }
@ -870,6 +904,38 @@ struct ImColor
static ImColor HSV(float h, float s, float v, float a = 1.0f) { float r,g,b; ImGui::ColorConvertHSVtoRGB(h, s, v, r, g, b); return ImColor(r,g,b,a); } static ImColor HSV(float h, float s, float v, float a = 1.0f) { float r,g,b; ImGui::ColorConvertHSVtoRGB(h, s, v, r, g, b); return ImColor(r,g,b,a); }
}; };
// Helper: Manually clip large list of items.
// If you are displaying thousands of even spaced items and you have a random access to the list, you can perform clipping yourself to save on CPU.
// Usage:
// ImGuiListClipper clipper(count, ImGui::GetTextLineHeightWithSpacing());
// for (int i = clipper.DisplayStart; i < clipper.DisplayEnd; i++) // display only visible items
// ImGui::Text("line number %d", i);
// clipper.End();
struct ImGuiListClipper
{
float ItemsHeight;
int ItemsCount, DisplayStart, DisplayEnd;
ImGuiListClipper() { ItemsHeight = 0.0f; ItemsCount = DisplayStart = DisplayEnd = -1; }
ImGuiListClipper(int count, float height) { ItemsCount = -1; Begin(count, height); }
~ImGuiListClipper() { IM_ASSERT(ItemsCount == -1); } // user forgot to call End()
void Begin(int count, float height) // items_height: generally pass GetTextLineHeightWithSpacing() or GetItemsLineHeightWithSpacing()
{
IM_ASSERT(ItemsCount == -1);
ItemsCount = count;
ItemsHeight = height;
ImGui::CalcListClipping(ItemsCount, ItemsHeight, &DisplayStart, &DisplayEnd); // calculate how many to clip/display
ImGui::SetCursorPosY(ImGui::GetCursorPosY() + DisplayStart * ItemsHeight); // advance cursor
}
void End()
{
IM_ASSERT(ItemsCount >= 0);
ImGui::SetCursorPosY(ImGui::GetCursorPosY() + (ItemsCount - DisplayEnd) * ItemsHeight); // advance cursor
ItemsCount = -1;
}
};
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
// Draw List // Draw List
// Hold a series of drawing commands. The user provides a renderer for ImDrawList. // Hold a series of drawing commands. The user provides a renderer for ImDrawList.

View File

@ -1,7 +1,7 @@
// [ImGui] this is a slightly modified version of stb_truetype.h 1.02 // [ImGui] this is a slightly modified version of stb_truetype.h 1.05
// [ImGui] we added stbtt_PackFontRangesGatherRects() and stbtt_PackFontRangesRenderIntoRects() and modified stbtt_PackBegin() // [ImGui] we added stbtt_PackFontRangesGatherRects() and stbtt_PackFontRangesRenderIntoRects() and modified stbtt_PackBegin()
// stb_truetype.h - v1.02 - public domain // stb_truetype.h - v1.05 - public domain
// authored from 2009-2014 by Sean Barrett / RAD Game Tools // authored from 2009-2014 by Sean Barrett / RAD Game Tools
// //
// This library processes TrueType files: // This library processes TrueType files:
@ -37,12 +37,20 @@
// Johan Duparc // Johan Duparc
// Hou Qiming // Hou Qiming
// Fabian "ryg" Giesen // Fabian "ryg" Giesen
// Martins Mozeiko
// Cap Petschulat
// Omar Cornut
// github:aloucks
// Peter LaValle
// //
// Misc other: // Misc other:
// Ryan Gordon // Ryan Gordon
// //
// VERSION HISTORY // VERSION HISTORY
// //
// 1.05 (2015-04-15) fix misplaced definitions for STBTT_STATIC
// 1.04 (2015-04-15) typo in example
// 1.03 (2015-04-12) STBTT_STATIC, fix memory leak in new packing, various fixes
// 1.02 (2014-12-10) fix various warnings & compile issues w/ stb_rect_pack, C++ // 1.02 (2014-12-10) fix various warnings & compile issues w/ stb_rect_pack, C++
// 1.01 (2014-12-08) fix subpixel position when oversampling to exactly match // 1.01 (2014-12-08) fix subpixel position when oversampling to exactly match
// non-oversampled; STBTT_POINT_SIZE for packed case only // non-oversampled; STBTT_POINT_SIZE for packed case only
@ -86,6 +94,9 @@
// before the #include of this file. This expands out the actual // before the #include of this file. This expands out the actual
// implementation into that C/C++ file. // implementation into that C/C++ file.
// //
// To make the implementation private to the file that generates the implementation,
// #define STBTT_STATIC
//
// Simple 3D API (don't ship this, but it's fine for tools and quick start) // Simple 3D API (don't ship this, but it's fine for tools and quick start)
// stbtt_BakeFontBitmap() -- bake a font to a bitmap for use as texture // stbtt_BakeFontBitmap() -- bake a font to a bitmap for use as texture
// stbtt_GetBakedQuad() -- compute quad to draw for a given char // stbtt_GetBakedQuad() -- compute quad to draw for a given char
@ -225,16 +236,16 @@
#define STB_TRUETYPE_IMPLEMENTATION // force following include to generate implementation #define STB_TRUETYPE_IMPLEMENTATION // force following include to generate implementation
#include "stb_truetype.h" #include "stb_truetype.h"
char ttf_buffer[1<<20]; unsigned char ttf_buffer[1<<20];
unsigned char temp_bitmap[512*512]; unsigned char temp_bitmap[512*512];
stbtt_bakedchar cdata[96]; // ASCII 32..126 is 95 glyphs stbtt_bakedchar cdata[96]; // ASCII 32..126 is 95 glyphs
GLstbtt_uint ftex; GLuint ftex;
void my_stbtt_initfont(void) void my_stbtt_initfont(void)
{ {
fread(ttf_buffer, 1, 1<<20, fopen("c:/windows/fonts/times.ttf", "rb")); fread(ttf_buffer, 1, 1<<20, fopen("c:/windows/fonts/times.ttf", "rb"));
stbtt_BakeFontBitmap(data,0, 32.0, temp_bitmap,512,512, 32,96, cdata); // no guarantee this fits! stbtt_BakeFontBitmap(ttf_buffer,0, 32.0, temp_bitmap,512,512, 32,96, cdata); // no guarantee this fits!
// can free ttf_buffer at this point // can free ttf_buffer at this point
glGenTextures(1, &ftex); glGenTextures(1, &ftex);
glBindTexture(GL_TEXTURE_2D, ftex); glBindTexture(GL_TEXTURE_2D, ftex);
@ -246,6 +257,7 @@ void my_stbtt_initfont(void)
void my_stbtt_print(float x, float y, char *text) void my_stbtt_print(float x, float y, char *text)
{ {
// assume orthographic projection with units = screen pixels, origin at top left // assume orthographic projection with units = screen pixels, origin at top left
glEnable(GL_TEXTURE_2D);
glBindTexture(GL_TEXTURE_2D, ftex); glBindTexture(GL_TEXTURE_2D, ftex);
glBegin(GL_QUADS); glBegin(GL_QUADS);
while (*text) { while (*text) {
@ -379,12 +391,6 @@ int main(int arg, char **argv)
typedef char stbtt__check_size32[sizeof(stbtt_int32)==4 ? 1 : -1]; typedef char stbtt__check_size32[sizeof(stbtt_int32)==4 ? 1 : -1];
typedef char stbtt__check_size16[sizeof(stbtt_int16)==2 ? 1 : -1]; typedef char stbtt__check_size16[sizeof(stbtt_int16)==2 ? 1 : -1];
#ifdef STBTT_STATIC
#define STBTT_DEF static
#else
#define STBTT_DEF extern
#endif
// #define your own STBTT_sort() to override this to avoid qsort // #define your own STBTT_sort() to override this to avoid qsort
#ifndef STBTT_sort #ifndef STBTT_sort
#include <stdlib.h> #include <stdlib.h>
@ -437,6 +443,12 @@ int main(int arg, char **argv)
#ifndef __STB_INCLUDE_STB_TRUETYPE_H__ #ifndef __STB_INCLUDE_STB_TRUETYPE_H__
#define __STB_INCLUDE_STB_TRUETYPE_H__ #define __STB_INCLUDE_STB_TRUETYPE_H__
#ifdef STBTT_STATIC
#define STBTT_DEF static
#else
#define STBTT_DEF extern
#endif
#ifdef __cplusplus #ifdef __cplusplus
extern "C" { extern "C" {
#endif #endif
@ -1059,7 +1071,6 @@ STBTT_DEF int stbtt_FindGlyphIndex(const stbtt_fontinfo *info, int unicode_codep
stbtt_uint16 searchRange = ttUSHORT(data+index_map+8) >> 1; stbtt_uint16 searchRange = ttUSHORT(data+index_map+8) >> 1;
stbtt_uint16 entrySelector = ttUSHORT(data+index_map+10); stbtt_uint16 entrySelector = ttUSHORT(data+index_map+10);
stbtt_uint16 rangeShift = ttUSHORT(data+index_map+12) >> 1; stbtt_uint16 rangeShift = ttUSHORT(data+index_map+12) >> 1;
stbtt_uint16 item, offset, start, end;
// do a binary search of the segments // do a binary search of the segments
stbtt_uint32 endCount = index_map + 14; stbtt_uint32 endCount = index_map + 14;
@ -1076,8 +1087,8 @@ STBTT_DEF int stbtt_FindGlyphIndex(const stbtt_fontinfo *info, int unicode_codep
// now decrement to bias correctly to find smallest // now decrement to bias correctly to find smallest
search -= 2; search -= 2;
while (entrySelector) { while (entrySelector) {
stbtt_uint16 end;
searchRange >>= 1; searchRange >>= 1;
start = ttUSHORT(data + search + searchRange*2 + segcount*2 + 2);
end = ttUSHORT(data + search + searchRange*2); end = ttUSHORT(data + search + searchRange*2);
if (unicode_codepoint > end) if (unicode_codepoint > end)
search += searchRange*2; search += searchRange*2;
@ -1085,19 +1096,21 @@ STBTT_DEF int stbtt_FindGlyphIndex(const stbtt_fontinfo *info, int unicode_codep
} }
search += 2; search += 2;
item = (stbtt_uint16) ((search - endCount) >> 1); {
stbtt_uint16 offset, start;
stbtt_uint16 item = (stbtt_uint16) ((search - endCount) >> 1);
STBTT_assert(unicode_codepoint <= ttUSHORT(data + endCount + 2*item)); STBTT_assert(unicode_codepoint <= ttUSHORT(data + endCount + 2*item));
start = ttUSHORT(data + index_map + 14 + segcount*2 + 2 + 2*item); start = ttUSHORT(data + index_map + 14 + segcount*2 + 2 + 2*item);
end = ttUSHORT(data + index_map + 14 + 2 + 2*item); if (unicode_codepoint < start)
if (unicode_codepoint < start) return 0;
return 0;
offset = ttUSHORT(data + index_map + 14 + segcount*6 + 2 + 2*item); offset = ttUSHORT(data + index_map + 14 + segcount*6 + 2 + 2*item);
if (offset == 0) if (offset == 0)
return (stbtt_uint16) (unicode_codepoint + ttSHORT(data + index_map + 14 + segcount*4 + 2 + 2*item)); return (stbtt_uint16) (unicode_codepoint + ttSHORT(data + index_map + 14 + segcount*4 + 2 + 2*item));
return ttUSHORT(data + offset + (unicode_codepoint-start)*2 + index_map + 14 + segcount*6 + 2 + 2*item); return ttUSHORT(data + offset + (unicode_codepoint-start)*2 + index_map + 14 + segcount*6 + 2 + 2*item);
}
} else if (format == 12 || format == 13) { } else if (format == 12 || format == 13) {
stbtt_uint32 ngroups = ttULONG(data+index_map+12); stbtt_uint32 ngroups = ttULONG(data+index_map+12);
stbtt_int32 low,high; stbtt_int32 low,high;
@ -2054,8 +2067,8 @@ STBTT_DEF void stbtt_GetBakedQuad(stbtt_bakedchar *chardata, int pw, int ph, int
float d3d_bias = opengl_fillrule ? 0 : -0.5f; float d3d_bias = opengl_fillrule ? 0 : -0.5f;
float ipw = 1.0f / pw, iph = 1.0f / ph; float ipw = 1.0f / pw, iph = 1.0f / ph;
stbtt_bakedchar *b = chardata + char_index; stbtt_bakedchar *b = chardata + char_index;
int round_x = STBTT_ifloor((*xpos + b->xoff) + 0.5); int round_x = STBTT_ifloor((*xpos + b->xoff) + 0.5f);
int round_y = STBTT_ifloor((*ypos + b->yoff) + 0.5); int round_y = STBTT_ifloor((*ypos + b->yoff) + 0.5f);
q->x0 = round_x + d3d_bias; q->x0 = round_x + d3d_bias;
q->y0 = round_y + d3d_bias; q->y0 = round_y + d3d_bias;
@ -2209,7 +2222,7 @@ static void stbtt__h_prefilter(unsigned char *pixels, int w, int h, int stride_i
for (j=0; j < h; ++j) { for (j=0; j < h; ++j) {
int i; int i;
unsigned int total; unsigned int total;
memset(buffer, 0, kernel_width); STBTT_memset(buffer, 0, kernel_width);
total = 0; total = 0;
@ -2263,7 +2276,7 @@ static void stbtt__v_prefilter(unsigned char *pixels, int w, int h, int stride_i
for (j=0; j < w; ++j) { for (j=0; j < w; ++j) {
int i; int i;
unsigned int total; unsigned int total;
memset(buffer, 0, kernel_width); STBTT_memset(buffer, 0, kernel_width);
total = 0; total = 0;
@ -2333,7 +2346,7 @@ STBTT_DEF int stbtt_PackFontRangesGatherRects(stbtt_pack_context *spc, stbtt_fon
for (j=0; j < ranges[i].num_chars_in_range; ++j) { for (j=0; j < ranges[i].num_chars_in_range; ++j) {
int x0,y0,x1,y1; int x0,y0,x1,y1;
int glyph = stbtt_FindGlyphIndex(info,ranges[i].first_unicode_char_in_range + j); int glyph = stbtt_FindGlyphIndex(info,ranges[i].first_unicode_char_in_range + j);
if (glyph) { if (glyph) {
stbtt_GetGlyphBitmapBoxSubpixel(info,glyph, stbtt_GetGlyphBitmapBoxSubpixel(info,glyph,
scale * spc->h_oversample, scale * spc->h_oversample,
scale * spc->v_oversample, scale * spc->v_oversample,
@ -2341,10 +2354,10 @@ STBTT_DEF int stbtt_PackFontRangesGatherRects(stbtt_pack_context *spc, stbtt_fon
&x0,&y0,&x1,&y1); &x0,&y0,&x1,&y1);
rects[k].w = (stbrp_coord) (x1-x0 + spc->padding + spc->h_oversample-1); rects[k].w = (stbrp_coord) (x1-x0 + spc->padding + spc->h_oversample-1);
rects[k].h = (stbrp_coord) (y1-y0 + spc->padding + spc->v_oversample-1); rects[k].h = (stbrp_coord) (y1-y0 + spc->padding + spc->v_oversample-1);
} else { } else {
rects[k].w = rects[k].h = 1; rects[k].w = rects[k].h = 1;
} }
++k; ++k;
} }
} }
@ -2453,6 +2466,7 @@ STBTT_DEF int stbtt_PackFontRanges(stbtt_pack_context *spc, unsigned char *fontd
return_value = stbtt_PackFontRangesRenderIntoRects(spc, &info, ranges, num_ranges, rects); return_value = stbtt_PackFontRangesRenderIntoRects(spc, &info, ranges, num_ranges, rects);
STBTT_free(rects, spc->user_allocator_context);
return return_value; return return_value;
} }
@ -2473,8 +2487,8 @@ STBTT_DEF void stbtt_GetPackedQuad(stbtt_packedchar *chardata, int pw, int ph, i
stbtt_packedchar *b = chardata + char_index; stbtt_packedchar *b = chardata + char_index;
if (align_to_integer) { if (align_to_integer) {
float x = (float) STBTT_ifloor((*xpos + b->xoff) + 0.5); float x = (float) STBTT_ifloor((*xpos + b->xoff) + 0.5f);
float y = (float) STBTT_ifloor((*ypos + b->yoff) + 0.5); float y = (float) STBTT_ifloor((*ypos + b->yoff) + 0.5f);
q->x0 = x; q->x0 = x;
q->y0 = y; q->y0 = y;
q->x1 = x + b->xoff2 - b->xoff; q->x1 = x + b->xoff2 - b->xoff;

BIN
web/examples_03.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 23 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.2 KiB