Viewport: Initial viewport branch+ platform api commit (squashed from previous commits, still very WIP) (#1542)

This commit is contained in:
omar
2018-02-27 23:07:45 +01:00
parent b5ced477f4
commit 735267d27c
4 changed files with 847 additions and 62 deletions

View File

@ -40,6 +40,7 @@ struct ImGuiMenuColumns;
struct ImGuiDrawContext;
struct ImGuiTextEditState;
struct ImGuiPopupRef;
struct ImGuiViewport;
struct ImGuiWindow;
struct ImGuiWindowSettings;
@ -51,6 +52,7 @@ typedef int ImGuiNavHighlightFlags; // flags: for RenderNavHighlight()
typedef int ImGuiNavDirSourceFlags; // flags: for GetNavInputAmount2d() // enum ImGuiNavDirSourceFlags_
typedef int ImGuiSeparatorFlags; // flags: for Separator() - internal // enum ImGuiSeparatorFlags_
typedef int ImGuiSliderFlags; // flags: for SliderBehavior() // enum ImGuiSliderFlags_
typedef int ImGuiViewportFlags; // flags: for Viewport() // enum ImGuiViewportFlags_
//-------------------------------------------------------------------------
// STB libraries
@ -335,7 +337,8 @@ struct IMGUI_API ImRect
void Add(const ImRect& r) { if (Min.x > r.Min.x) Min.x = r.Min.x; if (Min.y > r.Min.y) Min.y = r.Min.y; if (Max.x < r.Max.x) Max.x = r.Max.x; if (Max.y < r.Max.y) Max.y = r.Max.y; }
void Expand(const float amount) { Min.x -= amount; Min.y -= amount; Max.x += amount; Max.y += amount; }
void Expand(const ImVec2& amount) { Min.x -= amount.x; Min.y -= amount.y; Max.x += amount.x; Max.y += amount.y; }
void Translate(const ImVec2& v) { Min.x += v.x; Min.y += v.y; Max.x += v.x; Max.y += v.y; }
void Translate(const ImVec2& d) { Min.x += d.x; Min.y += d.y; Max.x += d.x; Max.y += d.y; }
void Translate(float dx, float dy) { Min.x += dx; Min.y += dy; Max.x += dx; Max.y += dy; }
void ClipWith(const ImRect& r) { Min = ImMax(Min, r.Min); Max = ImMin(Max, r.Max); } // Simple version, may lead to an inverted rectangle, which is fine for Contains/Overlaps test but not for display.
void ClipWithFull(const ImRect& r) { Min = ImClamp(Min, r.Min, r.Max); Max = ImClamp(Max, r.Min, r.Max); } // Full version, ensure both points are fully clipped.
void Floor() { Min.x = (float)(int)Min.x; Min.y = (float)(int)Min.y; Max.x = (float)(int)Max.x; Max.y = (float)(int)Max.y; }
@ -419,9 +422,11 @@ struct ImGuiWindowSettings
ImGuiID Id;
ImVec2 Pos;
ImVec2 Size;
ImVec2 ViewportOsDesktopPos;
ImGuiID ViewportId;
bool Collapsed;
ImGuiWindowSettings() { Name = NULL; Id = 0; Pos = Size = ImVec2(0,0); Collapsed = false; }
ImGuiWindowSettings() { Name = NULL; Id = ViewportId = 0; Pos = Size = ImVec2(0,0); ViewportOsDesktopPos = ImVec2(FLT_MAX, FLT_MAX); Collapsed = false; }
};
struct ImGuiSettingsHandler
@ -514,6 +519,41 @@ struct ImDrawDataBuilder
IMGUI_API void FlattenIntoSingleLayer();
};
enum ImGuiViewportFlags_
{
ImGuiViewportFlags_MainViewport = 1 << 0,
ImGuiViewportFlags_NoDecoration = 1 << 1, // Platform Window: Disable platform title bar, borders, etc.
ImGuiViewportFlags_NoFocusOnAppearing = 1 << 2, // Platform Window: Don't take focus when created.
ImGuiViewportFlags_NoInputs = 1 << 3 // Platform Window: Make mouse pass through so we can drag this window while peaking behind it.
};
struct ImGuiViewport
{
ImGuiID ID;
int Idx;
ImGuiViewportFlags Flags;
int LastFrameActive;
int LastFrameAsRefViewport; // Last frame number this viewport was io.MouseViewportRef
char* Name; // Name (OPTIONAL)
ImVec2 Pos; // Position in imgui virtual space (Pos.y == 0.0)
ImVec2 Size;
ImDrawData DrawData;
ImDrawDataBuilder DrawDataBuilder;
// [Optional] OS/Platform Layer data. This is to allow the creation/manipulate of multiple OS/Platform windows. Not all back-ends will allow this.
ImVec2 PlatformOsDesktopPos; // Position in OS desktop/native space
void* PlatformUserData; // void* to hold custom data structure for the platform (e.g. windowing info, render context)
void* PlatformHandle; // void* for FindViewportByPlatformHandle(). (e.g. HWND, GlfwWindow*)
bool PlatformRequestClose; // Platform window requested closure
bool PlatformRequestResize; // Platform window requested resize
void* RendererUserData; // void* to hold custom data structure for the renderer (e.g. framebuffer)
ImGuiViewport(ImGuiID id, int idx) { ID = id; Idx = idx; Flags = 0; LastFrameActive = LastFrameAsRefViewport = -1; Name = NULL; PlatformUserData = PlatformHandle = NULL; PlatformRequestClose = PlatformRequestResize = false; RendererUserData = NULL; }
~ImGuiViewport() { IM_ASSERT(PlatformUserData == NULL && RendererUserData == NULL); if (Name) ImGui::MemFree(Name); }
ImRect GetRect() const { return ImRect(Pos.x, Pos.y, Pos.x + Size.x, Pos.y + Size.y); }
float GetNextX() const { const float SPACING = 4.0f; return Pos.x + Size.x + SPACING; }
};
struct ImGuiNavMoveResult
{
ImGuiID ID; // Best candidate
@ -538,6 +578,7 @@ struct ImGuiNextWindowData
ImGuiCond SizeConstraintCond;
ImGuiCond FocusCond;
ImGuiCond BgAlphaCond;
ImGuiCond ViewportCond;
ImVec2 PosVal;
ImVec2 PosPivotVal;
ImVec2 SizeVal;
@ -547,10 +588,11 @@ struct ImGuiNextWindowData
ImGuiSizeCallback SizeCallback;
void* SizeCallbackUserData;
float BgAlphaVal;
ImGuiID ViewportId;
ImGuiNextWindowData()
{
PosCond = SizeCond = ContentSizeCond = CollapsedCond = SizeConstraintCond = FocusCond = BgAlphaCond = 0;
PosCond = SizeCond = ContentSizeCond = CollapsedCond = SizeConstraintCond = FocusCond = BgAlphaCond = ViewportCond = 0;
PosVal = PosPivotVal = SizeVal = ImVec2(0.0f, 0.0f);
ContentSizeVal = ImVec2(0.0f, 0.0f);
CollapsedVal = false;
@ -558,11 +600,12 @@ struct ImGuiNextWindowData
SizeCallback = NULL;
SizeCallbackUserData = NULL;
BgAlphaVal = FLT_MAX;
ViewportId = 0;
}
void Clear()
{
PosCond = SizeCond = ContentSizeCond = CollapsedCond = SizeConstraintCond = FocusCond = BgAlphaCond = 0;
PosCond = SizeCond = ContentSizeCond = CollapsedCond = SizeConstraintCond = FocusCond = BgAlphaCond = ViewportCond = 0;
}
};
@ -614,6 +657,12 @@ struct ImGuiContext
bool NextTreeNodeOpenVal; // Storage for SetNextTreeNode** functions
ImGuiCond NextTreeNodeOpenCond;
// Viewports
ImVector<ImGuiViewport*>Viewports;
ImGuiViewport* MouseViewport;
ImGuiViewport* MouseLastViewport;
ImGuiViewport* MouseLastHoveredViewport;
// Navigation data (for gamepad/keyboard)
ImGuiWindow* NavWindow; // Focused window for navigation. Could be called 'FocusWindow'
ImGuiID NavId; // Focused item for navigation
@ -650,8 +699,6 @@ struct ImGuiContext
ImGuiNavMoveResult NavMoveResultOther; // Best move request candidate within NavWindow's flattened hierarchy (when using the NavFlattened flag)
// Render
ImDrawData DrawData; // Main ImDrawData instance to pass render information to the user
ImDrawDataBuilder DrawDataBuilder;
float ModalWindowDarkeningRatio;
ImDrawList OverlayDrawList; // Optional software render of mouse cursors, if io.MouseDrawCursor is set + a few debug overlays
ImGuiMouseCursor MouseCursor;
@ -741,6 +788,9 @@ struct ImGuiContext
NextTreeNodeOpenVal = false;
NextTreeNodeOpenCond = 0;
MouseViewport = NULL;
MouseLastViewport = MouseLastHoveredViewport = NULL;
NavWindow = NULL;
NavId = NavActivateId = NavActivateDownId = NavActivatePressedId = NavInputId = 0;
NavJustTabbedId = NavJustMovedToId = NavNextActivateId = 0;
@ -904,7 +954,10 @@ struct IMGUI_API ImGuiWindow
{
char* Name;
ImGuiID ID; // == ImHash(Name)
ImGuiWindowFlags Flags; // See enum ImGuiWindowFlags_
ImGuiWindowFlags Flags, FlagsPreviousFrame; // See enum ImGuiWindowFlags_
ImGuiViewport* Viewport; // Always set in Begin(), only inactive windows may have a NULL value here
ImGuiID ViewportId; // Inactive windows preserve their last viewport id (since the viewport may disappear with the window inactivity)
ImVec2 ViewportOsDesktopPos;
ImVec2 PosFloat;
ImVec2 Pos; // Position rounded-up to nearest pixel
ImVec2 Size; // Current size (==SizeFull or collapsed title bar size)
@ -1032,6 +1085,15 @@ namespace ImGui
IMGUI_API void Initialize(ImGuiContext* context);
IMGUI_API void Shutdown(ImGuiContext* context); // Since 1.60 this is a _private_ function. You can call DestroyContext() to destroy the context created by CreateContext().
// Viewports
IMGUI_API ImGuiViewport* Viewport(ImGuiID id, ImGuiViewportFlags flags, const ImVec2& os_desktop_pos, const ImVec2& size); // os_desktop_pos allows imgui to reposition windows relative to each order when moving from one viewport to the other.
inline ImVector<ImGuiViewport*>&GetViewports() { return GImGui->Viewports; }
inline ImGuiViewport* GetMainViewport() { return GImGui->Viewports[0]; }
IMGUI_API ImGuiViewport* FindViewportByID(ImGuiID id);
IMGUI_API ImGuiViewport* FindViewportByPlatformHandle(void* platform_handle);
IMGUI_API void SetNextWindowViewport(ImGuiID id);
IMGUI_API void ShowViewportThumbnails();
IMGUI_API void MarkIniSettingsDirty();
IMGUI_API ImGuiSettingsHandler* FindSettingsHandler(const char* type_name);
IMGUI_API ImGuiWindowSettings* FindWindowSettings(ImGuiID id);