ux-alignment.cpp
Go to the documentation of this file.
1 #include "ux-alignment.h"
2 #include <imgui.h>
3 #include <imgui_impl_glfw.h>
4 #include <vector>
5 #include <memory>
6 
7 #ifdef _WIN32
8 #undef APIENTRY
9 #define GLFW_EXPOSE_NATIVE_WIN32
10 #define GLFW_EXPOSE_NATIVE_WGL
11 #include <GLFW/glfw3native.h>
12 
13 #include <Windows.h>
14 #endif
15 
16 #define MAGIC 250
17 
19 {
20 #ifdef _WIN32
21  try
22  {
23  auto hwn = glfwGetWin32Window(win);
24  if (hwn == nullptr)
25  return true;
26 
30 
31  ImGui::SetNextWindowPos({ 0, 0 });
32 
34  ImGui::Begin("is_gui_aligned", nullptr, flags);
35 
36  auto DrawList = ImGui::GetWindowDrawList();
37  if (DrawList == nullptr)
38  return true;
39 
40  DrawList->AddRectFilled({ 0,0 }, { 1,1 }, ImColor(MAGIC / 255.f, 0.f, 0.f, 1.f));
41 
42  ImGui::End();
44 
45  ImGui::Render();
46 
47  glfwSwapBuffers(win);
48 
50 
51  SetFocus(hwn);
52 
53  int width = 1;
54  int height = 1;
55 
56  HDC hdc = GetDC(hwn);
57  if (hdc == nullptr)
58  return true;
59 
60  std::shared_ptr<HDC> shared_hdc(&hdc, [&](HDC* hdc) {ReleaseDC(hwn, *hdc); DeleteDC(*hdc);});
61 
62  HDC hCaptureDC = CreateCompatibleDC(hdc);
63  if (hCaptureDC == nullptr)
64  return true;
65 
66  std::shared_ptr<HDC> shared_capture_hdc(&hCaptureDC, [&](HDC* hdc) {ReleaseDC(hwn, *hdc); DeleteDC(*hdc);});
67 
68  HBITMAP hCaptureBitmap = CreateCompatibleBitmap(hdc, width, height);
69  if (hCaptureBitmap == nullptr)
70  return true;
71 
72  std::shared_ptr<HBITMAP> shared_bmp(&hCaptureBitmap, [&](HBITMAP* bmp) {DeleteObject(bmp);});
73 
74  auto original = SelectObject(hCaptureDC, hCaptureBitmap);
75  if (original == nullptr)
76  return true;
77 
78  if (!BitBlt(hCaptureDC, 0, 0, width, height, hdc, 0, 0, SRCCOPY | CAPTUREBLT))
79  return true;
80 
81  BITMAPINFO bmi = { 0 };
82  bmi.bmiHeader.biSize = sizeof(bmi.bmiHeader);
83  bmi.bmiHeader.biWidth = width;
84  bmi.bmiHeader.biHeight = height;
85  bmi.bmiHeader.biPlanes = 1;
86  bmi.bmiHeader.biBitCount = 32;
87  bmi.bmiHeader.biCompression = BI_RGB;
88 
89  std::vector<RGBQUAD> pPixels(width * height);
90 
91  auto res = GetDIBits(
92  hCaptureDC,
93  hCaptureBitmap,
94  0,
95  height,
96  pPixels.data(),
97  &bmi,
98  DIB_RGB_COLORS
99  );
100 
101  if (res <= 0 || res == ERROR_INVALID_PARAMETER)
102  return true;
103 
104  auto ret = pPixels[0].rgbRed == MAGIC;
105  return ret;
106  }
107  catch (...)
108  {
109  return true;
110  }
111 #else
112  return true;
113 #endif
114 }
IMGUI_API void PushStyleVar(ImGuiStyleVar idx, float val)
Definition: imgui.cpp:4650
Definition: imgui.h:88
IMGUI_API void SetNextWindowPos(const ImVec2 &pos, ImGuiSetCond cond=0)
Definition: imgui.cpp:4923
GLdouble f
IMGUI_API ImDrawList * GetWindowDrawList()
Definition: imgui.cpp:5045
IMGUI_API bool Begin(const char *name, bool *p_open=NULL, ImGuiWindowFlags flags=0)
Definition: imgui.cpp:3772
IMGUI_API void PopStyleVar(int count=1)
Definition: imgui.cpp:4675
GLint GLsizei GLsizei height
bool is_gui_aligned(GLFWwindow *win)
GLFWAPI void glfwSwapBuffers(GLFWwindow *window)
Swaps the front and back buffers of the specified window.
Definition: context.c:641
GLbitfield flags
IMGUI_API void End()
Definition: imgui.cpp:4330
The header of the native access functions.
void ImGui_ImplGlfw_NewFrame(float scale_factor)
GLuint res
Definition: glext.h:8856
struct GLFWwindow GLFWwindow
GLint GLsizei width
IMGUI_API void Render()
Definition: imgui.cpp:2619
#define MAGIC
GLFWAPI HWND glfwGetWin32Window(GLFWwindow *handle)


librealsense2
Author(s): Sergey Dorodnicov , Doron Hirshberg , Mark Horn , Reagan Lopez , Itay Carpis
autogenerated on Mon May 3 2021 02:50:13