mirror of
https://github.com/ocornut/imgui.git
synced 2024-11-27 16:29:02 +08:00
Apply Omar feedback and convert remaining 0xAABBGGRR's into IM_COL32(RR,GG,BB,AA) format.
This commit is contained in:
parent
d75d2b1871
commit
1999c01db8
12
imgui.cpp
12
imgui.cpp
@ -8849,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
|
||||
}
|
||||
}
|
||||
|
||||
@ -9205,7 +9205,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
|
||||
@ -9545,10 +9545,10 @@ void ImGui::ValueColor(const char* prefix, ImU32 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;
|
||||
col.x = (float)((v >> IM_COL32_R_SHIFT) & 0xFF) / 255.0f;
|
||||
col.y = (float)((v >> IM_COL32_G_SHIFT) & 0xFF) / 255.0f;
|
||||
col.z = (float)((v >> IM_COL32_B_SHIFT) & 0xFF) / 255.0f;
|
||||
col.w = (float)((v >> IM_COL32_A_SHIFT) & 0xFF) / 255.0f;
|
||||
ColorButton(col, true);
|
||||
}
|
||||
|
||||
|
36
imgui.h
36
imgui.h
@ -827,6 +827,23 @@ struct ImGuiIO
|
||||
// Helpers
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
// 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))
|
||||
#define IM_COL32_BLACK (IM_COL32(0,0,0,255))
|
||||
#define IM_COL32_BLACK_TRANS (IM_COL32(0,0,0,0)) // Transparent black
|
||||
|
||||
// Lightweight std::vector<> like class to avoid dragging dependencies (also: windows implementation of STL with debug enabled is absurdly slow, so let's bypass it so our code runs fast in debug).
|
||||
// Our implementation does NOT call c++ constructors because we don't use them in ImGui. Don't use this class as a straight std::vector replacement in your code!
|
||||
template<typename T>
|
||||
@ -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,23 +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
|
||||
#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 (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