mirror of
https://github.com/Drezil/imgui.git
synced 2024-12-18 06:06:35 +00:00
Merge branch 'thedmd-2016-08-use_bgra_colors'
This commit is contained in:
commit
28974dfbbb
@ -26,6 +26,9 @@
|
||||
//---- Don't define obsolete functions names
|
||||
//#define IMGUI_DISABLE_OBSOLETE_FUNCTIONS
|
||||
|
||||
//---- Pack colors to BGRA instead of RGBA (remove need to post process vertex buffer in back ends)
|
||||
//#define IMGUI_USE_BGRA_PACKED_COLOR
|
||||
|
||||
//---- Implement STB libraries in a namespace to avoid conflicts
|
||||
//#define IMGUI_STB_NAMESPACE ImGuiStb
|
||||
|
||||
|
30
imgui.cpp
30
imgui.cpp
@ -1195,16 +1195,20 @@ int ImTextCountUtf8BytesFromStr(const ImWchar* in_text, const ImWchar* in_text_e
|
||||
ImVec4 ImGui::ColorConvertU32ToFloat4(ImU32 in)
|
||||
{
|
||||
float s = 1.0f/255.0f;
|
||||
return ImVec4((in & 0xFF) * s, ((in >> 8) & 0xFF) * s, ((in >> 16) & 0xFF) * s, (in >> 24) * s);
|
||||
return ImVec4(
|
||||
((in >> IM_COL32_R_SHIFT) & 0xFF) * s,
|
||||
((in >> IM_COL32_G_SHIFT) & 0xFF) * s,
|
||||
((in >> IM_COL32_B_SHIFT) & 0xFF) * s,
|
||||
((in >> IM_COL32_A_SHIFT) & 0xFF) * s);
|
||||
}
|
||||
|
||||
ImU32 ImGui::ColorConvertFloat4ToU32(const ImVec4& in)
|
||||
{
|
||||
ImU32 out;
|
||||
out = ((ImU32)IM_F32_TO_INT8_SAT(in.x));
|
||||
out |= ((ImU32)IM_F32_TO_INT8_SAT(in.y)) << 8;
|
||||
out |= ((ImU32)IM_F32_TO_INT8_SAT(in.z)) << 16;
|
||||
out |= ((ImU32)IM_F32_TO_INT8_SAT(in.w)) << 24;
|
||||
out = ((ImU32)IM_F32_TO_INT8_SAT(in.x)) << IM_COL32_R_SHIFT;
|
||||
out |= ((ImU32)IM_F32_TO_INT8_SAT(in.y)) << IM_COL32_G_SHIFT;
|
||||
out |= ((ImU32)IM_F32_TO_INT8_SAT(in.z)) << IM_COL32_B_SHIFT;
|
||||
out |= ((ImU32)IM_F32_TO_INT8_SAT(in.w)) << IM_COL32_A_SHIFT;
|
||||
return out;
|
||||
}
|
||||
|
||||
@ -1212,14 +1216,14 @@ ImU32 ImGui::GetColorU32(ImGuiCol idx, float alpha_mul)
|
||||
{
|
||||
ImVec4 c = GImGui->Style.Colors[idx];
|
||||
c.w *= GImGui->Style.Alpha * alpha_mul;
|
||||
return ImGui::ColorConvertFloat4ToU32(c);
|
||||
return ColorConvertFloat4ToU32(c);
|
||||
}
|
||||
|
||||
ImU32 ImGui::GetColorU32(const ImVec4& col)
|
||||
{
|
||||
ImVec4 c = col;
|
||||
c.w *= GImGui->Style.Alpha;
|
||||
return ImGui::ColorConvertFloat4ToU32(c);
|
||||
return ColorConvertFloat4ToU32(c);
|
||||
}
|
||||
|
||||
// Convert rgb floats ([0-1],[0-1],[0-1]) to hsv floats ([0-1],[0-1],[0-1]), from Foley & van Dam p592
|
||||
@ -8845,7 +8849,7 @@ bool ImGui::BeginMenu(const char* label, bool enabled)
|
||||
tb.y = ta.y + ImMax((tb.y - extra) - ta.y, -100.0f); // triangle is maximum 200 high to limit the slope and the bias toward large sub-menus // FIXME: Multiply by fb_scale?
|
||||
tc.y = ta.y + ImMin((tc.y + extra) - ta.y, +100.0f);
|
||||
moving_within_opened_triangle = ImIsPointInTriangle(g.IO.MousePos, ta, tb, tc);
|
||||
//window->DrawList->PushClipRectFullScreen(); window->DrawList->AddTriangleFilled(ta, tb, tc, moving_within_opened_triangle ? 0x80008000 : 0x80000080); window->DrawList->PopClipRect(); // Debug
|
||||
//window->DrawList->PushClipRectFullScreen(); window->DrawList->AddTriangleFilled(ta, tb, tc, moving_within_opened_triangle ? IM_COL32(0,128,0,128) : IM_COL32(128,0,0,128)); window->DrawList->PopClipRect(); // Debug
|
||||
}
|
||||
}
|
||||
|
||||
@ -9204,7 +9208,7 @@ void ImGui::EndGroup()
|
||||
|
||||
window->DC.GroupStack.pop_back();
|
||||
|
||||
//window->DrawList->AddRect(group_bb.Min, group_bb.Max, 0xFFFF00FF); // Debug
|
||||
//window->DrawList->AddRect(group_bb.Min, group_bb.Max, IM_COL32(255,0,255,255)); // Debug
|
||||
}
|
||||
|
||||
// Gets back to previous line and continue with horizontal layout
|
||||
@ -9542,13 +9546,7 @@ void ImGui::ValueColor(const char* prefix, ImU32 v)
|
||||
{
|
||||
Text("%s: %08X", prefix, v);
|
||||
SameLine();
|
||||
|
||||
ImVec4 col;
|
||||
col.x = (float)((v >> 0) & 0xFF) / 255.0f;
|
||||
col.y = (float)((v >> 8) & 0xFF) / 255.0f;
|
||||
col.z = (float)((v >> 16) & 0xFF) / 255.0f;
|
||||
col.w = (float)((v >> 24) & 0xFF) / 255.0f;
|
||||
ColorButton(col, true);
|
||||
ColorButton(ColorConvertU32ToFloat4(v), true);
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
|
25
imgui.h
25
imgui.h
@ -1034,6 +1034,23 @@ struct ImGuiSizeConstraintCallbackData
|
||||
ImVec2 DesiredSize; // Read-write. Desired size, based on user's mouse position. Write to this field to restrain resizing.
|
||||
};
|
||||
|
||||
// Helpers macros to generate 32-bits encoded colors
|
||||
#ifdef IMGUI_USE_BGRA_PACKED_COLOR
|
||||
#define IM_COL32_R_SHIFT 16
|
||||
#define IM_COL32_G_SHIFT 8
|
||||
#define IM_COL32_B_SHIFT 0
|
||||
#define IM_COL32_A_SHIFT 24
|
||||
#else
|
||||
#define IM_COL32_R_SHIFT 0
|
||||
#define IM_COL32_G_SHIFT 8
|
||||
#define IM_COL32_B_SHIFT 16
|
||||
#define IM_COL32_A_SHIFT 24
|
||||
#endif
|
||||
#define IM_COL32(R,G,B,A) (((ImU32)(A)<<IM_COL32_A_SHIFT) | ((ImU32)(B)<<IM_COL32_B_SHIFT) | ((ImU32)(G)<<IM_COL32_G_SHIFT) | ((ImU32)(R)<<IM_COL32_R_SHIFT))
|
||||
#define IM_COL32_WHITE IM_COL32(255,255,255,255) // Opaque white
|
||||
#define IM_COL32_BLACK IM_COL32(0,0,0,255) // Opaque black
|
||||
#define IM_COL32_BLACK_TRANS IM_COL32(0,0,0,0) // Transparent black
|
||||
|
||||
// ImColor() helper to implicity converts colors to either ImU32 (packed 4x1 byte) or ImVec4 (4x1 float)
|
||||
// Prefer using IM_COL32() macros if you want a guaranteed compile-time ImU32 for usage with ImDrawList API.
|
||||
// Avoid storing ImColor! Store either u32 of ImVec4. This is not a full-featured color class.
|
||||
@ -1044,7 +1061,7 @@ struct ImColor
|
||||
|
||||
ImColor() { Value.x = Value.y = Value.z = Value.w = 0.0f; }
|
||||
ImColor(int r, int g, int b, int a = 255) { float sc = 1.0f/255.0f; Value.x = (float)r * sc; Value.y = (float)g * sc; Value.z = (float)b * sc; Value.w = (float)a * sc; }
|
||||
ImColor(ImU32 rgba) { float sc = 1.0f/255.0f; Value.x = (float)(rgba&0xFF) * sc; Value.y = (float)((rgba>>8)&0xFF) * sc; Value.z = (float)((rgba>>16)&0xFF) * sc; Value.w = (float)(rgba >> 24) * sc; }
|
||||
ImColor(ImU32 rgba) { float sc = 1.0f/255.0f; Value.x = (float)((rgba>>IM_COL32_R_SHIFT)&0xFF) * sc; Value.y = (float)((rgba>>IM_COL32_G_SHIFT)&0xFF) * sc; Value.z = (float)((rgba>>IM_COL32_B_SHIFT)&0xFF) * sc; Value.w = (float)((rgba>>IM_COL32_A_SHIFT)&0xFF) * sc; }
|
||||
ImColor(float r, float g, float b, float a = 1.0f) { Value.x = r; Value.y = g; Value.z = b; Value.w = a; }
|
||||
ImColor(const ImVec4& col) { Value = col; }
|
||||
inline operator ImU32() const { return ImGui::ColorConvertFloat4ToU32(Value); }
|
||||
@ -1090,12 +1107,6 @@ struct ImGuiListClipper
|
||||
// Hold a series of drawing commands. The user provides a renderer for ImDrawData which essentially contains an array of ImDrawList.
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
// Helpers macros to generate 32-bits encoded colors
|
||||
#define IM_COL32(R,G,B,A) (((ImU32)(A)<<24) | ((ImU32)(B)<<16) | ((ImU32)(G)<<8) | ((ImU32)(R)))
|
||||
#define IM_COL32_WHITE (0xFFFFFFFF)
|
||||
#define IM_COL32_BLACK (0xFF000000)
|
||||
#define IM_COL32_BLACK_TRANS (0x00000000) // Transparent black
|
||||
|
||||
// Draw callbacks for advanced uses.
|
||||
// NB- You most likely do NOT need to use draw callbacks just to create your own widget or customized UI rendering (you can poke into the draw list for that)
|
||||
// Draw callback may be useful for example, A) Change your GPU render state, B) render a complex 3D scene inside a UI element (without an intermediate texture/render target), etc.
|
||||
|
@ -355,18 +355,18 @@ void ImGui::ShowTestWindow(bool* p_open)
|
||||
|
||||
ImGui::Text("Test paragraph 1:");
|
||||
ImVec2 pos = ImGui::GetCursorScreenPos();
|
||||
ImGui::GetWindowDrawList()->AddRectFilled(ImVec2(pos.x + wrap_width, pos.y), ImVec2(pos.x + wrap_width + 10, pos.y + ImGui::GetTextLineHeight()), 0xFFFF00FF);
|
||||
ImGui::GetWindowDrawList()->AddRectFilled(ImVec2(pos.x + wrap_width, pos.y), ImVec2(pos.x + wrap_width + 10, pos.y + ImGui::GetTextLineHeight()), IM_COL32(255,0,255,255));
|
||||
ImGui::PushTextWrapPos(ImGui::GetCursorPos().x + wrap_width);
|
||||
ImGui::Text("lazy dog. This paragraph is made to fit within %.0f pixels. The quick brown fox jumps over the lazy dog.", wrap_width);
|
||||
ImGui::GetWindowDrawList()->AddRect(ImGui::GetItemRectMin(), ImGui::GetItemRectMax(), 0xFF00FFFF);
|
||||
ImGui::GetWindowDrawList()->AddRect(ImGui::GetItemRectMin(), ImGui::GetItemRectMax(), IM_COL32(255,255,0,255));
|
||||
ImGui::PopTextWrapPos();
|
||||
|
||||
ImGui::Text("Test paragraph 2:");
|
||||
pos = ImGui::GetCursorScreenPos();
|
||||
ImGui::GetWindowDrawList()->AddRectFilled(ImVec2(pos.x + wrap_width, pos.y), ImVec2(pos.x + wrap_width + 10, pos.y + ImGui::GetTextLineHeight()), 0xFFFF00FF);
|
||||
ImGui::GetWindowDrawList()->AddRectFilled(ImVec2(pos.x + wrap_width, pos.y), ImVec2(pos.x + wrap_width + 10, pos.y + ImGui::GetTextLineHeight()), IM_COL32(255,0,255,255));
|
||||
ImGui::PushTextWrapPos(ImGui::GetCursorPos().x + wrap_width);
|
||||
ImGui::Text("aaaaaaaa bbbbbbbb, cccccccc,dddddddd. eeeeeeee ffffffff. gggggggg!hhhhhhhh");
|
||||
ImGui::GetWindowDrawList()->AddRect(ImGui::GetItemRectMin(), ImGui::GetItemRectMax(), 0xFF00FFFF);
|
||||
ImGui::GetWindowDrawList()->AddRect(ImGui::GetItemRectMin(), ImGui::GetItemRectMax(), IM_COL32(255,255,0,255));
|
||||
ImGui::PopTextWrapPos();
|
||||
|
||||
ImGui::TreePop();
|
||||
@ -2063,7 +2063,7 @@ static void ShowExampleAppCustomRendering(bool* p_open)
|
||||
}
|
||||
draw_list->PushClipRect(canvas_pos, ImVec2(canvas_pos.x+canvas_size.x, canvas_pos.y+canvas_size.y)); // clip lines within the canvas (if we resize it, etc.)
|
||||
for (int i = 0; i < points.Size - 1; i += 2)
|
||||
draw_list->AddLine(ImVec2(canvas_pos.x + points[i].x, canvas_pos.y + points[i].y), ImVec2(canvas_pos.x + points[i+1].x, canvas_pos.y + points[i+1].y), 0xFF00FFFF, 2.0f);
|
||||
draw_list->AddLine(ImVec2(canvas_pos.x + points[i].x, canvas_pos.y + points[i].y), ImVec2(canvas_pos.x + points[i+1].x, canvas_pos.y + points[i+1].y), IM_COL32(255,255,0,255), 2.0f);
|
||||
draw_list->PopClipRect();
|
||||
if (adding_preview)
|
||||
points.pop_back();
|
||||
|
@ -429,7 +429,7 @@ void ImDrawList::AddPolyline(const ImVec2* points, const int points_count, ImU32
|
||||
{
|
||||
// Anti-aliased stroke
|
||||
const float AA_SIZE = 1.0f;
|
||||
const ImU32 col_trans = col & 0x00ffffff;
|
||||
const ImU32 col_trans = col & IM_COL32(255,255,255,0);
|
||||
|
||||
const int idx_count = thick_line ? count*18 : count*12;
|
||||
const int vtx_count = thick_line ? points_count*4 : points_count*3;
|
||||
@ -602,7 +602,7 @@ void ImDrawList::AddConvexPolyFilled(const ImVec2* points, const int points_coun
|
||||
{
|
||||
// Anti-aliased Fill
|
||||
const float AA_SIZE = 1.0f;
|
||||
const ImU32 col_trans = col & 0x00ffffff;
|
||||
const ImU32 col_trans = col & IM_COL32(255,255,255,0);
|
||||
const int idx_count = (points_count-2)*3 + points_count*6;
|
||||
const int vtx_count = (points_count*2);
|
||||
PrimReserve(idx_count, vtx_count);
|
||||
@ -1119,7 +1119,7 @@ void ImFontAtlas::GetTexDataAsRGBA32(unsigned char** out_pixels, int* out_wid
|
||||
const unsigned char* src = pixels;
|
||||
unsigned int* dst = TexPixelsRGBA32;
|
||||
for (int n = TexWidth * TexHeight; n > 0; n--)
|
||||
*dst++ = ((unsigned int)(*src++) << 24) | 0x00FFFFFF;
|
||||
*dst++ = IM_COL32(255, 255, 255, (unsigned int)(*src++));
|
||||
}
|
||||
|
||||
*out_pixels = (unsigned char*)TexPixelsRGBA32;
|
||||
|
Loading…
Reference in New Issue
Block a user