Browse Source

Added SetCursorScreenPos() helper (WindowPos+CursorPos = SrceenPos)

ocornut 10 years ago
parent
commit
584c7ffac8
2 changed files with 10 additions and 1 deletions
  1. 8 0
      imgui.cpp
  2. 2 1
      imgui.h

+ 8 - 0
imgui.cpp

@@ -3111,6 +3111,8 @@ void ImGui::SetWindowFontScale(float scale)
     window->FontWindowScale = scale;
 }
 
+// NB: internally we store CursorPos in absolute screen coordinates because it is more convenient.
+// Conversion happens as we pass the value to user, but it makes our naming convention dodgy. May want to rename 'DC.CursorPos'.
 ImVec2 ImGui::GetCursorPos()
 {
     ImGuiWindow* window = GetCurrentWindow();
@@ -3141,6 +3143,12 @@ ImVec2 ImGui::GetCursorScreenPos()
     return window->DC.CursorPos;
 }
 
+void ImGui::SetCursorScreenPos(const ImVec2& screen_pos)
+{
+    ImGuiWindow* window = GetCurrentWindow();
+    window->DC.CursorPos = screen_pos;
+}
+
 void ImGui::SetScrollPosHere()
 {
     ImGuiWindow* window = GetCurrentWindow();

+ 2 - 1
imgui.h

@@ -206,7 +206,8 @@ namespace ImGui
     IMGUI_API void          SetCursorPos(const ImVec2& pos);                                    // "
     IMGUI_API void          SetCursorPosX(float x);                                             // "
     IMGUI_API void          SetCursorPosY(float y);                                             // "
-    IMGUI_API ImVec2        GetCursorScreenPos();                                               // cursor position in screen space
+    IMGUI_API ImVec2        GetCursorScreenPos();                                               // 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 float         GetTextLineSpacing();
     IMGUI_API float         GetTextLineHeight();