Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include "Gui.h"
- // Data
- static INT64 g_Time = 0;
- static INT64 g_TicksPerSecond = 0;
- static GuiContext GDefaultContext;
- GuiContext* GGui = &GDefaultContext;
- GuiIO::GuiIO()
- {
- DisplaySize = Vector2(-1.0f, -1.0f);
- DeltaTime = 1.0f / 60.0f;
- MousePos = Vector2(-1, -1);
- MousePosPrev = Vector2(-1, -1);
- MouseDoubleClickTime = 0.30f;
- MouseDoubleClickMaxDist = 6.0f;
- MouseDragThreshold = 6.0f;
- for (int i = 0; i < ARRAYSIZE(MouseDownDuration); i++)
- MouseDownDuration[i] = MouseDownDurationPrev[i] = -1.0f;
- for (int i = 0; i < ARRAYSIZE(KeysDownDuration); i++)
- KeysDownDuration[i] = KeysDownDurationPrev[i] = -1.0f;
- KeyRepeatDelay = 0.250f;
- KeyRepeatRate = 0.050f;
- MouseDragging = false;
- MouseDraggingTo = Vector2(0.0f, 0.0f);
- }
- GuiIO& Gui::GetIO()
- {
- return GGui->IO;
- }
- float Gui::GetTime()
- {
- return GGui->Time;
- }
- int Gui::GetFrameCount()
- {
- return GGui->FrameCount;
- }
- void Gui::NewFrame()
- {
- GuiContext& g = *GGui;
- ASSERT(g.IO.DeltaTime >= 0.0f);
- ASSERT(g.IO.DisplaySize.x >= 0.0f && g.IO.DisplaySize.y >= 0.0f);
- if (!g.Initialized)
- {
- g.Initialized = true;
- }
- g.Time += g.IO.DeltaTime;
- g.FrameCount += 1;
- // Update inputs state
- if (g.IO.MousePos.x < 0 && g.IO.MousePos.y < 0)
- g.IO.MousePos = Vector2(-9999.0f, -9999.0f);
- if ((g.IO.MousePos.x < 0 && g.IO.MousePos.y < 0) || (g.IO.MousePos.x < 0 && g.IO.MousePosPrev.y < 0))
- g.IO.MouseDelta = Vector2(0.0f, 0.0f);
- else
- g.IO.MouseDelta = g.IO.MousePos - g.IO.MousePosPrev;
- g.IO.MousePosPrev = g.IO.MousePos;
- for (int i = 0; i < ARRAYSIZE(g.IO.MouseDown); i++)
- {
- g.IO.MouseClicked[i] = g.IO.MouseDown[i] && g.IO.MouseDownDuration[i] < 0.0f;
- g.IO.MouseReleased[i] = !g.IO.MouseDown[i] && g.IO.MouseDownDuration[i] >= 0.0f;
- g.IO.MouseDownDurationPrev[i] = g.IO.MouseDownDuration[i];
- g.IO.MouseDownDuration[i] = g.IO.MouseDown[i] ? (g.IO.MouseDownDuration[i] < 0.0f ? 0.0f : g.IO.MouseDownDuration[i] + g.IO.DeltaTime) : -1.0f;
- g.IO.MouseDoubleClicked[i] = false;
- if (g.IO.MouseClicked[i])
- {
- if (g.Time - g.IO.MouseClickedTime[i] < g.IO.MouseDoubleClickTime)
- {
- if (LengthSqr(g.IO.MousePos - g.IO.MouseClickedPos[i]) < g.IO.MouseDoubleClickMaxDist * g.IO.MouseDoubleClickMaxDist)
- g.IO.MouseDoubleClicked[i] = true;
- g.IO.MouseClickedTime[i] = -FLT_MAX;
- }
- else
- {
- g.IO.MouseClickedTime[i] = g.Time;
- }
- g.IO.MouseClickedPos[i] = g.IO.MousePos;
- }
- else if (g.IO.MouseDown[i])
- {
- //Drag
- }
- }
- // Calculate frame-rate for the user, as a feature
- g.FramerateSecPerFrameAccum += g.IO.DeltaTime - g.FramerateSecPerFrame[g.FramerateSecPerFrameIdx];
- g.FramerateSecPerFrame[g.FramerateSecPerFrameIdx] = g.IO.DeltaTime;
- g.FramerateSecPerFrameIdx = (g.FramerateSecPerFrameIdx + 1) % ARRAYSIZE(g.FramerateSecPerFrame);
- g.IO.Framerate = 1.0f / (g.FramerateSecPerFrameAccum / (float)ARRAYSIZE(g.FramerateSecPerFrame));
- }
- bool GUI_DX11_Init()
- {
- if (!QueryPerformanceFrequency((LARGE_INTEGER *)&g_TicksPerSecond))
- return false;
- if (!QueryPerformanceCounter((LARGE_INTEGER *)&g_Time))
- return false;
- return true;
- }
- void GUI_DX11_NewFrame(HWND hWnd)
- {
- GuiIO& io = Gui::GetIO();
- // Setup display size (every frame to accommodate for window resizing)
- //RECT rect;
- //GetClientRect(hWnd, &rect);
- io.DisplaySize = Vector2(1920, 1080);//= Vector2((float)(rect.right - rect.left), (float)(rect.bottom - rect.top));
- // Setup time step
- INT64 current_time;
- QueryPerformanceCounter((LARGE_INTEGER *)¤t_time);
- io.DeltaTime = (float)(current_time - g_Time) / g_TicksPerSecond;
- g_Time = current_time;
- //Start the frame
- Gui::NewFrame();
- }
- GUI_API LRESULT Gui_WndProcHandler(HWND, UINT msg, WPARAM wParam, LPARAM lParam)
- {
- GuiIO& io = Gui::GetIO();
- switch (msg)
- {
- case WM_LBUTTONDOWN:
- io.MouseDown[0] = true;
- return true;
- case WM_LBUTTONUP:
- io.MouseDown[0] = false;
- return true;
- case WM_RBUTTONDOWN:
- io.MouseDown[1] = true;
- return true;
- case WM_RBUTTONUP:
- io.MouseDown[1] = false;
- return true;
- case WM_MBUTTONDOWN:
- io.MouseDown[2] = true;
- return true;
- case WM_MBUTTONUP:
- io.MouseDown[2] = false;
- return true;
- case WM_MOUSEWHEEL:
- io.MouseWheel += GET_WHEEL_DELTA_WPARAM(wParam) > 0 ? +1.0f : -1.0f;
- return true;
- case WM_MOUSEMOVE:
- io.MousePos.x = (signed short)(lParam);
- io.MousePos.y = (signed short)(lParam >> 16);
- return true;
- case WM_KEYDOWN:
- if (wParam < 256)
- io.KeysDown[wParam] = 1;
- return true;
- case WM_KEYUP:
- if (wParam < 256)
- io.KeysDown[wParam] = 0;
- return true;
- case WM_CHAR:
- // TODO: Create AddInputCharacter
- return true;
- }
- return 0;
- }
- GuiWindow::GuiWindow()
- {
- HubPos = Vector2(80.0f, 60.0f);
- HubSize = Vector2(0.0f, 0.0f);
- BarWidth = 0.0f;
- BarWidthMaximumEverGet = 0.0f;
- HubActive = true;
- HubWasActive = true;
- Pos = Vector2(0.0f, 0.0f);
- Size = Vector2(0.0f, 0.0f);
- MinX = 0;
- MinY = 12;
- MaxX = 12;
- MaxY = 12;
- Active = false;
- WasActive = false;
- ItemsLastPos = Vector2(0.0f, 0.0f);
- ItemsCurrentPos = Vector2(0.0f, 0.0f);
- ItemsCount = 0;
- ItemsCountDisplay = 0;
- ItemsCreatedCount = 0;
- ExpansionActive = false;
- ExpansionWasActive = false;
- ExpansionPop = false;
- //Tabs
- TabsItemsCount = 0;
- TabsItemsCountLast = 0;
- TabsLastPosBeforePop = Vector2(0.0f, 0.0f);
- TabsActive = false;
- TabsArrayState;
- //Scroll
- ScrollNeeded = false;
- ScrollWasActive = false;
- ScrollPos = Vector2(0, 0);
- //ScrollPos = Vector2(Pos.x - 22.0f, (Pos.y + Size.x) - 17.0f);
- ScrollSize = Vector2(4, 0);
- ScrollState = 0;
- ScrollStateCount = Vector2(0,0);
- ScrollIsDragging = false;
- DragWidth = 0.0f;
- //DragRect = Rect(HubPos.x + 40.0f, HubPos.y, 0.0f, 40.0f);
- }
- GuiWindow& Gui::GetWindow()
- {
- return GGui->Window;
- }
- GuiStyle::GuiStyle()
- {
- HubPadding = Vector2(11.0f, 11.f);
- HubItemsSpacing = 5.0f;
- TabsItemsOffset = 24.0f;
- ItemsOffset = 24.0f;
- ItemsMaximum = 7;
- TabsX = 105.0f;
- OffsetFromScrollbar = 15.0f;
- }
- GuiStyle& Gui::GetStyle()
- {
- return GGui->Style;
- }
- bool Gui::Begin()
- {
- GuiContext& g = *GGui;
- GuiWindow& window = GetWindow();
- GuiStyle& style = GetStyle();
- const int current_frame = GetFrameCount();
- window.ExpansionPop = true;
- // Initialize Hub
- std::string connectionStatus = XorStrA("Online");
- //char ConnectionStatus[7] = "Online";
- char hubText[256];
- sprintf(hubText, "FPS %.f", GetIO().Framerate);
- float Text_Hub_Length = g_pDrawManager->GetTextLength(0, hubText);
- Text_Hub_Length += g_pDrawManager->GetTextLength(0, connectionStatus.c_str());
- if(window.BarWidthMaximumEverGet <= Text_Hub_Length + style.HubItemsSpacing + (style.HubPadding.y * 2) - 5.0f || current_frame <= 300)
- window.BarWidthMaximumEverGet = Text_Hub_Length + style.HubItemsSpacing + (style.HubPadding.y * 2) - 5.0f;
- window.BarWidth = window.BarWidthMaximumEverGet;
- window.ItemsLastPos = window.HubPos;
- window.ItemsCurrentPos = window.HubPos;
- /*-----------------*/
- /* DRAWING */
- /*-----------------*/
- //Draw Hub red rect
- g_pDrawManager->AddFillRect(window.HubPos.x, window.HubPos.y, 40.0f, 40.0f, 0xB80000D9);
- window.HubSize = Vector2(40.0f, 40.0f);
- window.ItemsCurrentPos.x += window.HubSize.x;
- if (window.HubActive)
- {
- g_pDrawManager->AddFillRect(window.HubPos.x + 9, window.HubPos.y + 14, 9, 2, 0xFFFFFFFF);
- g_pDrawManager->AddFillRect(window.HubPos.x + 12, window.HubPos.y + 19, 16, 2, 0xFFFFFFFF);
- g_pDrawManager->AddFillRect(window.HubPos.x + 19, window.HubPos.y + 24, 9, 2, 0xFFFFFFFF);
- window.Active = false;
- }
- else
- {
- g_pDrawManager->AddLine(window.HubPos.x + 14, window.HubPos.y + 22, window.HubPos.x + 21, window.HubPos.y + 29, 0xFFFFFFFF, 2);
- g_pDrawManager->AddLine(window.HubPos.x + 27, window.HubPos.y + 22, window.HubPos.x + 20, window.HubPos.y + 28, 0xFFFFFFFF, 2);
- g_pDrawManager->AddFillRect(window.HubPos.x + 19, window.HubPos.y + 12, 2, 16, 0xFFFFFFFF);
- window.Active = true;
- }
- std::string hackVersion = XorStrA("Dune v1.0");
- // Initialize Window
- //const char HackVersion[256] = "Dune v1.0";
- if (window.Active)
- window.BarWidth += g_pDrawManager->GetTextLength(0, hackVersion.c_str()) + 168.0f;
- //Draw Hub background text
- g_pDrawManager->AddFillRect(window.ItemsCurrentPos.x, window.ItemsCurrentPos.y, window.BarWidth, window.HubSize.y, 0x131313D9);
- window.ItemsLastPos = window.ItemsCurrentPos;
- window.ItemsCurrentPos = Vector2(window.ItemsCurrentPos.x + style.HubPadding.x, window.ItemsCurrentPos.y + style.HubPadding.y);
- if (window.Active)
- {
- g_pDrawManager->AddText(window.ItemsCurrentPos.x, window.ItemsCurrentPos.y, 0xFFFFFFFF, 0, notting, hackVersion.c_str());
- window.ItemsLastPos = window.ItemsCurrentPos;
- window.ItemsCurrentPos.x += g_pDrawManager->GetTextLength(0, hackVersion.c_str()) + 168.0f;
- }
- //Draw Text for fps
- g_pDrawManager->AddText(window.ItemsCurrentPos.x, window.ItemsCurrentPos.y, 0xFFFFFFFF, 0, notting, hubText);
- window.ItemsLastPos = window.ItemsCurrentPos;
- window.ItemsCurrentPos.x += g_pDrawManager->GetTextLength(0, hubText);
- //Draw Text for status
- g_pDrawManager->AddText(window.ItemsCurrentPos.x, window.ItemsCurrentPos.y, 0xFFFFFFFF, 0, notting, connectionStatus.c_str());
- window.ItemsLastPos = window.ItemsCurrentPos;
- window.ItemsCurrentPos = Vector2(window.ItemsCurrentPos.x + g_pDrawManager->GetTextLength(0, connectionStatus.c_str()) - 7.0f, window.ItemsCurrentPos.y + 8.0f);
- //Draw cercle status
- g_pDrawManager->AddFillCircle(window.ItemsCurrentPos.x, window.ItemsCurrentPos.y, 3.0f, 0x00D000FF);
- window.ItemsLastPos = window.ItemsCurrentPos;
- window.ItemsCurrentPos = window.Pos;
- //Setting the final menu size
- window.HubSize = Vector2(40.0f + window.BarWidth, 40.0f);
- if (window.Active)
- {
- window.Pos.x = window.HubPos.x;
- window.Pos.y = window.HubPos.y + 40.0f;
- window.Size = Vector2(window.HubSize.x, 192.0f);
- window.ItemsLastPos = window.ItemsCurrentPos;
- window.ItemsCurrentPos = window.Pos;
- if (window.TabsActive)
- {
- window.Pos.x += style.TabsX;
- window.Size.x -= style.TabsX;
- }
- //Draw window
- g_pDrawManager->AddFillRect(window.Pos.x, window.Pos.y, window.Size.x, window.Size.y, 0xF9F9F9D9);
- }
- //Dragging & moving the Window/Hub
- if (IsMouseHoveringRect(Vector2(window.HubPos.x + 40.0f, window.HubPos.y), Vector2(window.BarWidth, 40.0f)))
- {
- if (IsMouseDown(0) && !IsMouseReleased(0))
- g.IO.MouseDragging = true;
- else
- g.IO.MouseDragging = false;
- }
- if (g.IO.MouseDragging)
- {
- window.HubPos.x = g.IO.MousePos.x - g.IO.MouseDraggingTo.x;
- window.HubPos.y = g.IO.MousePos.y - g.IO.MouseDraggingTo.y;
- }
- else
- {
- g.IO.MouseDraggingTo.x = g.IO.MousePos.x - window.HubPos.x;
- g.IO.MouseDraggingTo.y = g.IO.MousePos.y - window.HubPos.y;
- }
- //Opening window
- if (IsMouseHoveringRect(Vector2(window.HubPos.x, window.HubPos.y), Vector2(40.0f, 40.0f)) && IsMouseClicked(0, true) && !g.IO.MouseDragging)
- window.HubActive = !(window.HubActive);
- //Scrolling & Items disposition in window
- if (window.ItemsCreatedCount >= style.ItemsMaximum)
- window.ScrollNeeded = true;
- else
- window.ScrollNeeded = false;
- if (window.ScrollNeeded && window.Active)
- {
- if (0 - g.IO.MouseWheel > window.ItemsCreatedCount - style.ItemsMaximum)
- g.IO.MouseWheel = -(window.ItemsCreatedCount - style.ItemsMaximum);
- else
- {
- if (0 - g.IO.MouseWheel < 0)
- {
- g.IO.MouseWheel = 0.f;
- }
- else
- window.ScrollState = 0 - g.IO.MouseWheel;
- }
- window.ScrollPos = Vector2(window.Pos.x + window.Size.x - window.MaxX - window.ScrollSize.x, window.Pos.y + 12.0f);
- window.ScrollSize.y = window.Size.y - 24.0f;
- g_pDrawManager->AddFillRect(window.ScrollPos.x, window.ScrollPos.y, window.ScrollSize.x, window.ScrollSize.y, 0xD9D9D9D9, 2.0f);
- if (window.ScrollState > 0)
- window.ScrollPos.y += ((window.Size.y - 24.0f) / ((window.ItemsCreatedCount - style.ItemsMaximum) + 1) ) * window.ScrollState;
- window.ScrollSize.y = (window.Size.y - 24.0f) / ((window.ItemsCreatedCount - style.ItemsMaximum) + 1);
- g_pDrawManager->AddFillRect(window.ScrollPos.x, window.ScrollPos.y, window.ScrollSize.x, window.ScrollSize.y, 0xF1F1F1FF, 2.0f);
- }
- return true;
- }
- void Gui::End()
- {
- GuiWindow& window = GetWindow();
- if(window.TabsItemsCount > 0)
- window.TabsItemsCount = 0;
- if (window.ItemsCreatedCount != window.ItemsCountDisplay)
- window.ItemsCreatedCount = window.ItemsCountDisplay;
- if (window.ItemsCountDisplay > 0)
- window.ItemsCountDisplay = 0;
- window.ExpansionPop = true;
- }
- bool Gui::Tab(const char* label, bool* p_state)
- {
- GuiContext& g = *GGui;
- GuiWindow& window = GetWindow();
- GuiStyle& style = GetStyle();
- if (!window.Active)
- return false;
- if(!window.TabsActive)
- window.TabsActive = true;
- //Adding a new items in the list
- window.TabsItemsCountLast = window.TabsItemsCount;
- window.TabsItemsCount += 1;
- //Add state in Array
- if (window.TabsArrayState.size() == window.TabsItemsCountLast)
- window.TabsArrayState.push_back(*p_state);
- //Set the p_state at the same value of the array
- *p_state = window.TabsArrayState[window.TabsItemsCountLast];
- //printf("TabsItemsCount: %d\nArraySize: %i \n", window.TabsItemsCount, window.TabsArrayState.size());
- if (window.TabsItemsCountLast == 0)
- {
- //TopOffset
- g_pDrawManager->AddFillRect(window.ItemsCurrentPos.x, window.ItemsCurrentPos.y, style.TabsX, window.MinY, 0xFFFFFFD9);
- //DownOffset
- g_pDrawManager->AddFillRect(window.ItemsCurrentPos.x, (window.ItemsCurrentPos.y + window.Size.y) - window.MaxY, style.TabsX, window.MaxY, 0xFFFFFFD9);
- window.ItemsLastPos = window.ItemsCurrentPos;
- window.ItemsCurrentPos.y += window.MinY;
- }
- if (window.TabsItemsCountLast >= 1 )
- window.ItemsCurrentPos.y += style.TabsItemsOffset;
- if (!window.ScrollIsDragging && IsMouseHoveringRect(Vector2(window.ItemsCurrentPos.x, window.ItemsCurrentPos.y), Vector2(style.TabsX, style.TabsItemsOffset))
- && IsMouseClicked(0, true)
- && !g.IO.MouseDragging)
- {
- if (window.ScrollWasActive)
- {
- window.ScrollState = 0;
- g.IO.MouseWheel = 0.f;
- }
- for (int i = 0; i <= window.TabsArrayState.size(); i++)
- {
- if (window.TabsArrayState[i] && i != window.TabsItemsCountLast)
- {
- window.TabsArrayState[i] = false;
- }
- if (i == window.TabsItemsCountLast)
- {
- window.TabsArrayState[i] = true;
- }
- }
- //*p_state = !(*p_state);
- }
- if (window.TabsArrayState[window.TabsItemsCountLast])
- {
- g_pDrawManager->AddFillRect(window.ItemsCurrentPos.x, window.ItemsCurrentPos.y, 4.0f, style.TabsItemsOffset, 0xB80000D9);
- g_pDrawManager->AddFillRect(window.ItemsCurrentPos.x + 4.0f, window.ItemsCurrentPos.y, style.TabsX - 4.0f, style.TabsItemsOffset, 0xF0F0F0D9);
- g_pDrawManager->AddText(window.ItemsCurrentPos.x + 23.0f, window.ItemsCurrentPos.y + 4.0f, 0xB80000FF, 1, notting, label);
- window.ItemsLastPos = window.ItemsCurrentPos;
- //Adding LastPos for TabPop() function to reset the position of the tab
- window.TabsLastPosBeforePop = window.ItemsCurrentPos;
- window.ItemsCurrentPos = Vector2(window.Pos.x + 23.0f, window.Pos.y + window.MinY);
- }
- else
- {
- if(IsMouseHoveringRect(Vector2(window.ItemsCurrentPos.x, window.ItemsCurrentPos.y), Vector2(style.TabsX, style.TabsItemsOffset)))
- g_pDrawManager->AddFillRect(window.ItemsCurrentPos.x, window.ItemsCurrentPos.y, style.TabsX, style.TabsItemsOffset, 0xF0F0F0D9);
- else
- g_pDrawManager->AddFillRect(window.ItemsCurrentPos.x, window.ItemsCurrentPos.y, style.TabsX, style.TabsItemsOffset, 0xFFFFFFD9);
- g_pDrawManager->AddText(window.ItemsCurrentPos.x + 23.0f, window.ItemsCurrentPos.y + 4.0f, Colors::Black, 1, notting, label);
- return false;
- }
- return true;
- }
- void Gui::TabPop()
- {
- GuiWindow& window = GetWindow();
- GuiStyle& style = GetStyle();
- //printf("Pop: %i\n", window.TabsItemsCountLast);
- window.ItemsCurrentPos = window.TabsLastPosBeforePop;
- if (window.ScrollNeeded)
- window.ScrollWasActive = true;
- else
- window.ScrollWasActive = false;
- }
- bool Gui::Button(const char* label)
- {
- //Todo
- }
- bool Gui::SwitchCheck(const char* label, bool* p_state)
- {
- GuiContext& g = *GGui;
- GuiWindow& window = GetWindow();
- GuiStyle& style = GetStyle();
- window.ItemsCount = window.ItemsCountDisplay;
- window.ItemsCountDisplay += 1;
- //Check if the this item is max the maximum of item can be display
- if (window.ScrollNeeded && window.ItemsCount < window.ScrollState || window.ItemsCountDisplay > style.ItemsMaximum + window.ScrollState)
- return *p_state;
- float rightWinOffset = window.Size.x - 23.0f - window.MaxX - window.ScrollSize.x - style.OffsetFromScrollbar;
- window.ItemsLastPos = window.ItemsCurrentPos;
- if (!window.ScrollIsDragging && IsMouseHoveringRect(Vector2(window.ItemsCurrentPos.x, window.ItemsCurrentPos.y), Vector2(rightWinOffset, style.ItemsOffset))
- && !g.IO.MouseDragging)
- {
- g_pDrawManager->AddFillRect(window.ItemsCurrentPos.x, window.ItemsCurrentPos.y, rightWinOffset, style.ItemsOffset, 0xF1F1F1A0);
- if (IsMouseClicked(0, true))
- {
- *p_state = !(*p_state);
- }
- }
- if (!window.ExpansionPop && window.ExpansionWasActive)
- g_pDrawManager->AddText(window.ItemsCurrentPos.x + 23.0f, window.ItemsCurrentPos.y + 4.0f, Colors::Black, 1, notting, label);
- else
- g_pDrawManager->AddText(window.ItemsCurrentPos.x, window.ItemsCurrentPos.y + 4.0f, Colors::Black, 1, notting, label);
- if (window.TabsActive)
- window.ItemsCurrentPos.x = (window.Pos.x + window.Size.x) - window.MaxX - window.ScrollSize.x - style.OffsetFromScrollbar - 23.0f;
- //Todo: Ajouter un mode de positionnement normal dependament la longeur du text
- //Debug
- //g_pDrawManager->AddRect(window.ItemsCurrentPos.x, window.ItemsCurrentPos.y, rightWinOffset, style.ItemsOffset, Colors::DarkViolet, 0.0f);
- if (*p_state)
- {
- window.ItemsCurrentPos.y += 9.0f;
- g_pDrawManager->AddFillRect(window.ItemsCurrentPos.x, window.ItemsCurrentPos.y, 23.0f, 8.0f, 0xD06F71FF, 4.0f);
- window.ItemsCurrentPos.x += 10.0f;
- window.ItemsCurrentPos.y -= 2.0f;
- g_pDrawManager->AddFillCircle(window.ItemsCurrentPos.x, window.ItemsCurrentPos.y, 6.0f, 0xB80000FF);
- window.ItemsCurrentPos = window.ItemsLastPos;
- window.ItemsCurrentPos.y += style.ItemsOffset;
- return true;
- }
- else
- {
- window.ItemsCurrentPos.y += 7.0f;
- g_pDrawManager->AddFillRect(window.ItemsCurrentPos.x, window.ItemsCurrentPos.y, 23.0f, 8.0f, 0xD9D9D9FF, 4.0f);
- window.ItemsCurrentPos.y -= 2.0f;
- g_pDrawManager->AddFillCircle(window.ItemsCurrentPos.x, window.ItemsCurrentPos.y, 6.0f, 0xF1F1F1FF);
- window.ItemsCurrentPos = window.ItemsLastPos;
- window.ItemsCurrentPos.y += style.ItemsOffset;
- return false;
- }
- }
- bool Gui::ExpansionPanel(const char* label, bool* p_state)
- {
- GuiContext& g = *GGui;
- GuiWindow& window = GetWindow();
- GuiStyle& style = GetStyle();
- //Setting the ExpansionPush
- window.ExpansionPop = false;
- float rightWinOffset = window.Size.x - 23.0f - window.MaxX - window.ScrollSize.x - style.OffsetFromScrollbar;
- window.ItemsCount = window.ItemsCountDisplay;
- window.ItemsCountDisplay += 1;
- if(*p_state)
- window.ExpansionWasActive = true;
- else
- window.ExpansionPop = true;
- if (window.ScrollNeeded && window.ItemsCount < window.ScrollState || window.ItemsCountDisplay > style.ItemsMaximum + window.ScrollState)
- return *p_state;
- window.ItemsLastPos = window.ItemsCurrentPos;
- if (!window.ScrollIsDragging && IsMouseHoveringRect(Vector2(window.ItemsCurrentPos.x, window.ItemsCurrentPos.y), Vector2(rightWinOffset, style.ItemsOffset))
- && !g.IO.MouseDragging)
- {
- g_pDrawManager->AddFillRect(window.ItemsCurrentPos.x, window.ItemsCurrentPos.y, rightWinOffset, style.ItemsOffset, 0xF1F1F1A0);
- if (IsMouseClicked(0, true))
- {
- *p_state = !(*p_state);
- }
- }
- g_pDrawManager->AddText(window.ItemsCurrentPos.x, window.ItemsCurrentPos.y + 4.0f, Colors::Black, 1, notting, label);
- if (*p_state)
- {
- g_pDrawManager->AddFillCircle(window.ItemsCurrentPos.x + rightWinOffset - 14.0f, window.ItemsCurrentPos.y + 11.0f, 1.5f, 0x0000004D);
- g_pDrawManager->AddFillCircle(window.ItemsCurrentPos.x + rightWinOffset - 15.0f, window.ItemsCurrentPos.y + 12.0f, 1.5f, 0x0000004D);
- g_pDrawManager->AddFillCircle(window.ItemsCurrentPos.x + rightWinOffset - 16.0f, window.ItemsCurrentPos.y + 13.0f, 1.5f, 0x0000004D);
- g_pDrawManager->AddFillCircle(window.ItemsCurrentPos.x + rightWinOffset - 17.0f, window.ItemsCurrentPos.y + 14.0f, 1.5f, 0x0000004D);
- g_pDrawManager->AddFillCircle(window.ItemsCurrentPos.x + rightWinOffset - 18.0f, window.ItemsCurrentPos.y + 15.0f, 1.5f, 0x0000004D);
- g_pDrawManager->AddFillCircle(window.ItemsCurrentPos.x + rightWinOffset - 13.0f, window.ItemsCurrentPos.y + 11.0f, 1.5f, 0x0000004D);
- g_pDrawManager->AddFillCircle(window.ItemsCurrentPos.x + rightWinOffset - 12.0f, window.ItemsCurrentPos.y + 12.0f, 1.5f, 0x0000004D);
- g_pDrawManager->AddFillCircle(window.ItemsCurrentPos.x + rightWinOffset - 11.0f, window.ItemsCurrentPos.y + 13.0f, 1.5f, 0x0000004D);
- g_pDrawManager->AddFillCircle(window.ItemsCurrentPos.x + rightWinOffset - 10.0f, window.ItemsCurrentPos.y + 14.0f, 1.5f, 0x0000004D);
- g_pDrawManager->AddFillCircle(window.ItemsCurrentPos.x + rightWinOffset - 9.0f, window.ItemsCurrentPos.y + 15.0f, 1.5f, 0x0000004D);
- window.ExpansionActive = true;
- window.ItemsCurrentPos = window.ItemsLastPos;
- window.ItemsCurrentPos.y += style.ItemsOffset;
- return true;
- }
- else
- {
- g_pDrawManager->AddFillCircle(window.ItemsCurrentPos.x + rightWinOffset - 14.0f, window.ItemsCurrentPos.y + 15.0f, 1.5f, 0x0000004D);
- g_pDrawManager->AddFillCircle(window.ItemsCurrentPos.x + rightWinOffset - 15.0f, window.ItemsCurrentPos.y + 14.0f, 1.5f, 0x0000004D);
- g_pDrawManager->AddFillCircle(window.ItemsCurrentPos.x + rightWinOffset - 16.0f, window.ItemsCurrentPos.y + 13.0f, 1.5f, 0x0000004D);
- g_pDrawManager->AddFillCircle(window.ItemsCurrentPos.x + rightWinOffset - 17.0f, window.ItemsCurrentPos.y + 12.0f, 1.5f, 0x0000004D);
- g_pDrawManager->AddFillCircle(window.ItemsCurrentPos.x + rightWinOffset - 18.0f, window.ItemsCurrentPos.y + 11.0f, 1.5f, 0x0000004D);
- g_pDrawManager->AddFillCircle(window.ItemsCurrentPos.x + rightWinOffset - 13.0f, window.ItemsCurrentPos.y + 15.0f, 1.5f, 0x0000004D);
- g_pDrawManager->AddFillCircle(window.ItemsCurrentPos.x + rightWinOffset - 12.0f, window.ItemsCurrentPos.y + 14.0f, 1.5f, 0x0000004D);
- g_pDrawManager->AddFillCircle(window.ItemsCurrentPos.x + rightWinOffset - 11.0f, window.ItemsCurrentPos.y + 13.0f, 1.5f, 0x0000004D);
- g_pDrawManager->AddFillCircle(window.ItemsCurrentPos.x + rightWinOffset - 10.0f, window.ItemsCurrentPos.y + 12.0f, 1.5f, 0x0000004D);
- g_pDrawManager->AddFillCircle(window.ItemsCurrentPos.x + rightWinOffset - 9.0f, window.ItemsCurrentPos.y + 11.0f, 1.5f, 0x0000004D);
- window.ExpansionActive = false;
- window.ItemsCurrentPos = window.ItemsLastPos;
- window.ItemsCurrentPos.y += style.ItemsOffset;
- return false;
- }
- //window.ExpansionPop = true;
- return true;
- }
- void Gui::ExpansionPanelPop()
- {
- GuiWindow& window = GetWindow();
- window.ExpansionPop = true;
- }
- void Gui::Divider()
- {
- }
- bool Gui::SliderFloat(const char* label, float* v, float v_min, float v_max, int precision, const char* display_format)
- {
- GuiContext& g = *GGui;
- GuiWindow& window = GetWindow();
- GuiStyle& style = GetStyle();
- window.ItemsCount = window.ItemsCountDisplay;
- window.ItemsCountDisplay += 1;
- //Check if the this item is max the maximum of item can be display
- if (window.ScrollNeeded && window.ItemsCount < window.ScrollState || window.ItemsCountDisplay > style.ItemsMaximum + window.ScrollState)
- return false;
- window.ItemsLastPos = window.ItemsCurrentPos;
- bool slideActive = false;
- bool Hovering = false;
- window.ScrollIsDragging = false;
- std::stringstream ss;
- ss << std::fixed << std::setprecision(precision) << *v << display_format;
- std::string text = ss.str();
- if (!window.ExpansionPop && window.ExpansionWasActive)
- {
- window.ItemsCurrentPos.x += 23.0f;
- g_pDrawManager->AddText(window.ItemsCurrentPos.x, window.ItemsCurrentPos.y + 4.0f, Colors::Black, 1, notting, label);
- //window.ItemsCurrentPos.x += 23.0f;
- }
- else
- g_pDrawManager->AddText(window.ItemsCurrentPos.x, window.ItemsCurrentPos.y + 4.0f, Colors::Black, 1, notting, label);
- window.ItemsCurrentPos.x += 84.0f;
- window.ItemsCurrentPos.y += 12.0f;
- float SliderLenght = 170;
- if (!window.ExpansionPop && window.ExpansionWasActive)
- SliderLenght -= 23.0f;
- g_pDrawManager->AddFillRect(window.ItemsCurrentPos.x, window.ItemsCurrentPos.y, SliderLenght, 2.0f, 0xD9D9D9FF);
- g_pDrawManager->AddText(window.ItemsCurrentPos.x + SliderLenght + 10.0f, window.ItemsCurrentPos.y - 8.0f, Colors::Black, 1, notting, text.c_str());
- g_pDrawManager->AddFillRect(window.ItemsCurrentPos.x + SliderLenght + 8.0f, window.ItemsCurrentPos.y + 8.0f, g_pDrawManager->GetTextLength(1, text.c_str()) - 6.0f, 1, 0xD9D9D9FF);
- if (IsMouseHoveringRect(Vector2(window.ItemsCurrentPos.x - 50.0f, window.ItemsCurrentPos.y - 12.0f), Vector2(SliderLenght + 100.0f, style.ItemsOffset))
- && !g.IO.MouseDragging)
- {
- if (IsMouseClicked(0, true) && !IsMouseReleased(0))
- slideActive = true;
- else
- slideActive = false;
- Hovering = true;
- }
- //Debug
- //g_pDrawManager->AddRect(window.ItemsCurrentPos.x - 50.0f, window.ItemsCurrentPos.y - 12.0f, SliderLenght + 100.0f, style.ItemsOffset, Colors::DarkViolet, 0.0f);
- if (v)
- {
- float vm = ((*v) - v_min) * SliderLenght / ((v_max)-v_min);
- g_pDrawManager->AddFillRect(window.ItemsCurrentPos.x, window.ItemsCurrentPos.y, vm, 2.0f, 0xB80000FF);
- if (!slideActive && !Hovering)
- g_pDrawManager->AddFillCircle(window.ItemsCurrentPos.x + vm - 5.0f, window.ItemsCurrentPos.y - 3.0f, 4.0f, 0xB80000FF);
- if (Hovering && g.IO.MouseDownDuration[0] == -1.0f)
- {
- g_pDrawManager->AddFillCircle(window.ItemsCurrentPos.x + vm - 9.0f, window.ItemsCurrentPos.y - 7.0f, 8.0f, 0xB8000033);
- g_pDrawManager->AddFillCircle(window.ItemsCurrentPos.x + vm - 5.0f, window.ItemsCurrentPos.y - 3.0f, 4.0f, 0xB80000FF);
- }
- if (Hovering && g.IO.MouseDownDuration[0] >= 0)
- {
- window.ScrollIsDragging = true;
- g_pDrawManager->AddFillCircle(window.ItemsCurrentPos.x + vm - 7.0f, window.ItemsCurrentPos.y - 5.0f, 6.0f, 0xB80000FF);
- }
- }
- if (v && slideActive)
- {
- *v = (g.IO.MousePos.x - window.ItemsCurrentPos.x) * (v_max - v_min) / SliderLenght;
- if (*v > v_max)
- *v = v_max;
- if (*v < v_min)
- *v = v_min;
- }
- //Set the offset for next item position
- window.ItemsCurrentPos = window.ItemsLastPos;
- window.ItemsCurrentPos.y += style.ItemsOffset;
- return true;
- }
- bool Gui::SliderInt(const char* label, int* v, int v_min, int v_max, const char* display_format)
- {
- GuiContext& g = *GGui;
- GuiWindow& window = GetWindow();
- GuiStyle& style = GetStyle();
- window.ItemsCount = window.ItemsCountDisplay;
- window.ItemsCountDisplay += 1;
- //Check if the this item is max the maximum of item can be display
- if (window.ScrollNeeded && window.ItemsCount < window.ScrollState || window.ItemsCountDisplay > style.ItemsMaximum + window.ScrollState)
- return false;
- window.ItemsLastPos = window.ItemsCurrentPos;
- bool slideActive = false;
- bool Hovering = false;
- window.ScrollIsDragging = false;
- std::stringstream ss;
- ss << std::fixed << std::setprecision(0) << *v << display_format;
- std::string text = ss.str();
- if (!window.ExpansionPop && window.ExpansionWasActive)
- {
- window.ItemsCurrentPos.x += 23.0f;
- g_pDrawManager->AddText(window.ItemsCurrentPos.x, window.ItemsCurrentPos.y + 4.0f, Colors::Black, 1, notting, label);
- //window.ItemsCurrentPos.x += 23.0f;
- }
- else
- g_pDrawManager->AddText(window.ItemsCurrentPos.x, window.ItemsCurrentPos.y + 4.0f, Colors::Black, 1, notting, label);
- window.ItemsCurrentPos.x += 84.0f;
- window.ItemsCurrentPos.y += 12.0f;
- float SliderLenght = 170;
- if (!window.ExpansionPop && window.ExpansionWasActive)
- SliderLenght -= 23.0f;
- g_pDrawManager->AddFillRect(window.ItemsCurrentPos.x, window.ItemsCurrentPos.y, SliderLenght, 2.0f, 0xD9D9D9FF);
- g_pDrawManager->AddText(window.ItemsCurrentPos.x + SliderLenght + 10.0f, window.ItemsCurrentPos.y - 8.0f, Colors::Black, 1, notting,text.c_str());
- g_pDrawManager->AddFillRect(window.ItemsCurrentPos.x + SliderLenght + 8.0f, window.ItemsCurrentPos.y + 8.0f, g_pDrawManager->GetTextLength(1, text.c_str()) - 6.0f, 1, 0xD9D9D9FF);
- if (IsMouseHoveringRect(Vector2(window.ItemsCurrentPos.x - 50.0f, window.ItemsCurrentPos.y - 12.0f), Vector2(SliderLenght + 100.0f, style.ItemsOffset))
- && !g.IO.MouseDragging)
- {
- if (IsMouseClicked(0, true) && !IsMouseReleased(0))
- slideActive = true;
- else
- slideActive = false;
- Hovering = true;
- }
- //Debug
- //g_pDrawManager->AddRect(window.ItemsCurrentPos.x - 50.0f, window.ItemsCurrentPos.y - 12.0f, SliderLenght + 100.0f, style.ItemsOffset, Colors::DarkViolet, 0.0f);
- if (v)
- {
- float vm = ((*v) - v_min) * SliderLenght / ((v_max) - v_min);
- g_pDrawManager->AddFillRect(window.ItemsCurrentPos.x, window.ItemsCurrentPos.y, vm, 2.0f, 0xB80000FF);
- if (!slideActive && !Hovering)
- g_pDrawManager->AddFillCircle(window.ItemsCurrentPos.x + vm - 5.0f, window.ItemsCurrentPos.y - 3.0f, 4.0f, 0xB80000FF);
- if (Hovering && g.IO.MouseDownDuration[0] == -1.0f)
- {
- g_pDrawManager->AddFillCircle(window.ItemsCurrentPos.x + vm - 9.0f, window.ItemsCurrentPos.y - 7.0f, 8.0f, 0xB8000033);
- g_pDrawManager->AddFillCircle(window.ItemsCurrentPos.x + vm - 5.0f, window.ItemsCurrentPos.y - 3.0f, 4.0f, 0xB80000FF);
- }
- if (Hovering && g.IO.MouseDownDuration[0] >= 0)
- {
- window.ScrollIsDragging = true;
- g_pDrawManager->AddFillCircle(window.ItemsCurrentPos.x + vm - 7.0f, window.ItemsCurrentPos.y - 5.0f, 6.0f, 0xB80000FF);
- }
- }
- if (v && slideActive)
- {
- *v = (g.IO.MousePos.x - window.ItemsCurrentPos.x) * (v_max - v_min) / SliderLenght;
- if (*v > v_max)
- *v = v_max;
- if (*v < v_min)
- *v = v_min;
- }
- //Set the offset for next item position
- window.ItemsCurrentPos = window.ItemsLastPos;
- window.ItemsCurrentPos.y += style.ItemsOffset;
- return true;
- }
- bool Gui::SliderDegree(const char* label, int* v, int v_min, int v_max, const char* display_format)
- {
- GuiContext& g = *GGui;
- GuiWindow& window = GetWindow();
- GuiStyle& style = GetStyle();
- window.ItemsCount = window.ItemsCountDisplay;
- window.ItemsCountDisplay += 1;
- //Check if the this item is max the maximum of item can be display
- if (window.ScrollNeeded && window.ItemsCount < window.ScrollState || window.ItemsCountDisplay > style.ItemsMaximum + window.ScrollState)
- return false;
- window.ItemsLastPos = window.ItemsCurrentPos;
- bool slideActive = false;
- bool Hovering = false;
- window.ScrollIsDragging = false;
- std::stringstream ss;
- ss << std::fixed << std::setprecision(0) << *v << display_format;
- std::string text = ss.str();
- if (!window.ExpansionPop && window.ExpansionWasActive)
- {
- window.ItemsCurrentPos.x += 23.0f;
- g_pDrawManager->AddText(window.ItemsCurrentPos.x, window.ItemsCurrentPos.y + 4.0f, Colors::Black, 1, notting, label);
- //window.ItemsCurrentPos.x += 23.0f;
- }
- else
- g_pDrawManager->AddText(window.ItemsCurrentPos.x, window.ItemsCurrentPos.y + 4.0f, Colors::Black, 1, notting, label);
- window.ItemsCurrentPos.x += 84.0f;
- window.ItemsCurrentPos.y += 12.0f;
- float SliderLenght = 170;
- if (!window.ExpansionPop && window.ExpansionActive)
- SliderLenght -= 23.0f;
- g_pDrawManager->AddFillRect(window.ItemsCurrentPos.x, window.ItemsCurrentPos.y, SliderLenght, 2.0f, 0xD9D9D9FF);
- g_pDrawManager->AddText(window.ItemsCurrentPos.x + SliderLenght + 10.0f, window.ItemsCurrentPos.y - 8.0f, Colors::Black, 1, notting, text.c_str());
- g_pDrawManager->AddFillRect(window.ItemsCurrentPos.x + SliderLenght + 8.0f, window.ItemsCurrentPos.y + 8.0f, g_pDrawManager->GetTextLength(1, text.c_str()) - 6.0f, 1, 0xD9D9D9FF);
- if (IsMouseHoveringRect(Vector2(window.ItemsCurrentPos.x - 50.0f, window.ItemsCurrentPos.y - 12.0f), Vector2(SliderLenght + 100.0f, style.ItemsOffset))
- && !g.IO.MouseDragging)
- {
- if (IsMouseClicked(0, true) && !IsMouseReleased(0))
- slideActive = true;
- else
- slideActive = false;
- Hovering = true;
- }
- //Debug
- //g_pDrawManager->AddRect(window.ItemsCurrentPos.x - 50.0f, window.ItemsCurrentPos.y - 12.0f, SliderLenght + 100.0f, style.ItemsOffset, Colors::DarkViolet, 0.0f);
- if (v)
- {
- float vm = ((*v) - v_min) * SliderLenght / ((v_max)-v_min);
- g_pDrawManager->AddFillRect(window.ItemsCurrentPos.x, window.ItemsCurrentPos.y, vm, 2.0f, 0xB80000FF);
- if (!slideActive && !Hovering)
- g_pDrawManager->AddFillCircle(window.ItemsCurrentPos.x + vm - 5.0f, window.ItemsCurrentPos.y - 3.0f, 4.0f, 0xB80000FF);
- if (Hovering && g.IO.MouseDownDuration[0] == -1.0f)
- {
- g_pDrawManager->AddFillCircle(window.ItemsCurrentPos.x + vm - 9.0f, window.ItemsCurrentPos.y - 7.0f, 8.0f, 0xB8000033);
- g_pDrawManager->AddFillCircle(window.ItemsCurrentPos.x + vm - 5.0f, window.ItemsCurrentPos.y - 3.0f, 4.0f, 0xB80000FF);
- }
- if (Hovering && g.IO.MouseDownDuration[0] >= 0)
- {
- window.ScrollIsDragging = true;
- g_pDrawManager->AddFillCircle(window.ItemsCurrentPos.x + vm - 7.0f, window.ItemsCurrentPos.y - 5.0f, 6.0f, 0xB80000FF);
- }
- }
- if (v && slideActive)
- {
- *v = (g.IO.MousePos.x - window.ItemsCurrentPos.x) * (v_max - v_min) / SliderLenght;
- if (*v > v_max)
- *v = v_max;
- if (*v < v_min)
- *v = v_min;
- }
- //Set the offset for next item position
- window.ItemsCurrentPos = window.ItemsLastPos;
- window.ItemsCurrentPos.y += style.ItemsOffset;
- return true;
- }
- bool Gui::IsKeyDown(int key_index)
- {
- if (key_index < 0) return false;
- ASSERT(key_index > = 0 && hey_index < ARRAYSIZE(GGui->IO.KeysDown));
- return GGui->IO.KeysDown[key_index];
- }
- bool Gui::IsKeyPressed(int key_index, bool repeat)
- {
- GuiContext& g = *GGui;
- if (key_index < 0) return false;
- ASSERT(key_index >= 0 && key_index < ARRAYSIZE(g.IO.KeysDown));
- const float t = g.IO.KeysDownDuration[key_index];
- if (t == 0.0f)
- return true;
- if (repeat && t > g.IO.KeyRepeatDelay)
- {
- float delay = g.IO.KeyRepeatDelay, rate = g.IO.KeyRepeatRate;
- if ((fmodf(t - delay, rate) > rate*0.5f) != (fmodf(t - delay - g.IO.DeltaTime, rate) > rate*0.5f))
- return true;
- }
- return false;
- }
- bool Gui::IsKeyReleased(int key_index)
- {
- GuiContext& g = *GGui;
- if (key_index < 0) return false;
- ASSERT(key_index >= 0 && key_index < ARRAYSIZE(g.IO.KeysDown));
- if (g.IO.KeysDownDurationPrev[key_index] >= 0.0f && !g.IO.KeysDown[key_index])
- return true;
- return false;
- }
- bool Gui::IsMouseDown(int button)
- {
- GuiContext& g = *GGui;
- ASSERT(button >= 0 && button < ARRAYSIZE(g.IO.MouseDown));
- return g.IO.MouseDown[button];
- }
- bool Gui::IsMouseClicked(int button, bool repeat)
- {
- GuiContext& g = *GGui;
- ASSERT(button >= 0 && button < ARRAYSIZE(g.IO.MouseDown));
- const float t = g.IO.MouseDownDuration[button];
- if (t == 0.0f)
- return true;
- if (repeat && t > g.IO.KeyRepeatDelay)
- {
- float delay = g.IO.KeyRepeatDelay, rate = g.IO.KeyRepeatRate;
- if ((fmodf(t - delay, rate) > rate - 0.5f) != (fmodf(t - delay - g.IO.DeltaTime, rate) > rate*0.5f))
- return true;
- }
- return false;
- }
- bool Gui::IsMouseDoubleClicked(int button)
- {
- GuiContext& g = *GGui;
- ASSERT(button >= 0 && button < ARRAYSIZE(g.IO.MouseDown));
- return g.IO.MouseDoubleClicked[button];
- }
- bool Gui::IsMouseReleased(int button)
- {
- GuiContext& g = *GGui;
- ASSERT(button >= 0 && button < ARRAYSIZE(g.IO.MouseDown));
- return g.IO.MouseReleased[button];
- }
- bool Gui::IsMouseHoveringRect(const Vector2& r_min, const Vector2& r_max, bool clip)
- {
- GuiContext& g = *GGui;
- //clip
- Rect rect_clipped(r_min, r_max);
- if (clip)
- rect_clipped.Add(Vector4(r_min.x, r_min.y, r_min.x + r_max.x, r_min.y + r_max.y));
- //rect_clipped.Clip(Vector4(r_min.x, r_min.y, r_min.x + r_max.x, r_min.y + r_max.y));
- //rect_clipped.Add(Vector4(0,0,0,0));
- return rect_clipped.Contains(g.IO.MousePos);
- }
- Vector2 Gui::GetMousePos()
- {
- return GGui->IO.MousePos;
- }
- U32 Hash(const void* data, int data_size, U32 seed)
- {
- static U32 crc32_lut[256] = { 0 };
- if (!crc32_lut[1])
- {
- const U32 polynomial = 0xEDB88320;
- for (U32 i = 0; i < 256; i++)
- {
- U32 crc = i;
- for (U32 j = 0; j < 8; j++)
- crc = (crc >> 1) ^ (U32(-int(crc & 1)) & polynomial);
- crc32_lut[i] = crc;
- }
- }
- seed = ~seed;
- U32 crc = seed;
- const unsigned char* current = (const unsigned char*)data;
- if (data_size > 0)
- {
- // Known size
- while (data_size--)
- crc = (crc >> 8) ^ crc32_lut[(crc & 0xFF) ^ *current++];
- }
- else
- {
- // Zero-terminated string
- while (unsigned char c = *current++)
- {
- // We support a syntax of "label###id" where only "###id" is included in the hash, and only "label" gets displayed.
- // Because this syntax is rarely used we are optimizing for the common case.
- // - If we reach ### in the string we discard the hash so far and reset to the seed.
- // - We don't do 'current += 2; continue;' after handling ### to keep the code smaller.
- if (c == '#' && current[0] == '#' && current[1] == '#')
- crc = seed;
- crc = (crc >> 8) ^ crc32_lut[(crc & 0xFF) ^ c];
- }
- }
- return ~crc;
- }
- int Gui::FormatString(char* buf, int buf_size, const char* fmt, ...)
- {
- va_list args;
- va_start(args, fmt);
- int w = vsnprintf(buf, buf_size, fmt, args);
- va_end(args);
- if (buf == NULL)
- return w;
- if (w == -1 || w >= buf_size)
- w = buf_size - 1;
- buf[w] = 0;
- return w;
- }
- const char* Gui::FindRenderedTextEnd(const char* text, const char* text_end)
- {
- const char* text_display_end = text;
- if (!text_end)
- text_end = (const char*)-1;
- while (text_display_end < text_end && *text_display_end != '\0' && (text_display_end[0] != '#' || text_display_end[1] != '#'))
- text_display_end++;
- return text_display_end;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement