Blamite Game Engine - blam!  00296.01.12.21.0102.blamite
The core library for the Blamite Game Engine.
d2d_test.hpp
Go to the documentation of this file.
1 #pragma once
2 
3 #include "../../debug_ui.h"
4 
8 #include <Strings/components/utils/converters/converters.h>
9 
10 namespace Blam::DebugUI::Windows
11 {
19  {
20  private:
21  // direct2d drawing test //////
22 
23 
24  // rectangle
25  bool draw_rect = true;
26  bool rect_limit_to_window = true;
27  float shift_limits[2] = { -5, 5 };
28  float rect[4] = { 50, 500, 50, 250 };
29  float rect_color[3] = { 255, 255, 255 };
30  float r_thickness = 5;
31 
32  // text
33  bool draw_text = true;
34  std::wstring f_text = L"Test message";
35  std::wstring font_name = L"Ubuntu";
36  char text[512] = "Test message";
37  char font[512] = "Ubuntu";
38  float font_rect[4] = { 575, 700, 150, 600 };
39  float font_color[3] = { 255, 255, 255 };
40  float font_size = 50;
41 
42  // text zone
43  bool draw_text_zone = true;
44  float zone_thickness = 2;
45 
46  float zone_color[3] = { 255, 0, 0 };
47 
48  public:
53 
58 
62  void Draw()
63  {
64  if (show)
65  {
66  ImGui::Begin("Direct2D Testing", &show);
67 
68  ImGui::PushStyleColor(ImGuiCol_Text, ImVec4(0, 128, 255, 1));
69  ImGui::Text("rectangle");
70  ImGui::PopStyleColor();
71 
72  ImGui::Checkbox("show rectangle", &draw_rect);
73  ImGui::Checkbox("limit to window", &rect_limit_to_window);
74  ImGui::ColorEdit3("rect color", rect_color, ImGuiColorEditFlags_RGB);
75  ImGui::DragFloat4("rect", rect);
76  ImGui::DragFloat("thickness", &r_thickness);
77 
78  D2D1_SIZE_F target_size = BlamRendering::DirectX::D2D::GetD2DRenderTarget()->GetSize();
79 
80 
81 
82  float rect_shift[2] = { 0, 0 };
83  ImGui::SliderFloat2("shift", rect_shift, shift_limits[0], shift_limits[1]);
84 
85  ImGui::InputFloat2("shift bounds", shift_limits);
86 
87  ImGui::SameLine(); Blam::DebugUI::Widgets::ShowHelpMarker("this controls the min and max bounds of the above sliders \r\nlarger numbers means faster movement");
88 
90  {
91  if ((rect[0] > 0 || rect_shift[0] > 0) && (rect[1] < target_size.height || rect_shift[0] < 0))
92  {
93  rect[0] = rect[0] + rect_shift[0];
94  rect[1] = rect[1] + rect_shift[0];
95  }
96 
97  if ((rect[2] > 0 || rect_shift[1] > 0) && (rect[3] < target_size.width || rect_shift[1] < 0))
98  {
99  rect[2] = rect[2] + rect_shift[1];
100  rect[3] = rect[3] + rect_shift[1];
101  }
102  }
103  else
104  {
105  rect[0] = rect[0] + rect_shift[0];
106  rect[1] = rect[1] + rect_shift[0];
107  rect[2] = rect[2] + rect_shift[1];
108  rect[3] = rect[3] + rect_shift[1];
109  }
110 
111  ImGui::Separator();
112 
113 
114  ImGui::PushStyleColor(ImGuiCol_Text, ImVec4(0, 128, 255, 1));
115  ImGui::Text("directdraw text");
116  ImGui::PopStyleColor();
117 
118  ImGui::Checkbox("show text", &draw_text);
119  ImGui::Checkbox("show text zone", &draw_text_zone);
120 
121  ImGui::InputText("text", text, 512);
122  f_text = BlamStrings::Converters::ConvertStringToWstring(text);
123 
124  ImGui::InputText("font", font, 512);
125  font_name = BlamStrings::Converters::ConvertStringToWstring(font);
126 
127  ImGui::DragFloat("size", &font_size);
128  ImGui::ColorEdit3("text color", font_color, ImGuiColorEditFlags_RGB);
129  ImGui::DragFloat4("text rect", font_rect);
130 
131 
132 
133 
134  //Direct2D testing stuff
135  if (draw_rect)
136  {
137  D2D1_RECT_F rect_f = D2D1::RectF(rect[2], rect[0], rect[3], rect[1]);
138 
139  BlamRendering::DirectX::Drawing::DrawRect(rect_color[0], rect_color[1], rect_color[2], rect_f, r_thickness);
140  }
141 
142  if (draw_text)
143  {
144  BlamRendering::DirectX::Drawing::DWDrawText(f_text, font_name, font_size, font_rect[2], font_rect[1], font_rect[3], font_rect[0], font_color[0], font_color[1], font_color[2]);
145 
146  if (draw_text_zone)
147  {
148  ImGui::PushStyleColor(ImGuiCol_Text, ImVec4(zone_color[0], zone_color[1], zone_color[2], 1));
149  ImGui::Text("text zone");
150  ImGui::PopStyleColor();
151 
152 
153 
154 
155  ImGui::ColorEdit3("zone color", zone_color, ImGuiColorEditFlags_RGB);
156 
157  ImGui::DragFloat("zone thickness", &zone_thickness);
158 
159 
160  D2D1_RECT_F text_border = D2D1::RectF(font_rect[2], font_rect[0], font_rect[3], font_rect[1]);
161 
162  BlamRendering::DirectX::Drawing::DrawRect(zone_color[0], zone_color[1], zone_color[2], text_border, zone_thickness);
163  }
164  }
165 
166  //BlamRendering::DirectX::Drawing::DrawBitmap();
167 
168 
169  ImGui::End();
170  }
171  }
172  };
173 }
rect_limit_to_window
bool rect_limit_to_window
Definition: Line.cpp:10
Blam::DebugUI::Widgets::ShowHelpMarker
BLAM void ShowHelpMarker(const char *desc)
Shows a help indicator.
Definition: widgets.cpp:7
BlamRendering::DirectX::D2D::GetD2DRenderTarget
BLAM ID2D1DeviceContext * GetD2DRenderTarget()
Retrieves the Direct2D render target.
Definition: render_manage.cpp:598
rendering.h
drawing.h
widgets.h
Blam::DebugUI::Windows::Direct2DTest::Direct2DTest
Direct2DTest()
Empty constructor.
Definition: d2d_test.hpp:52
Blam::DebugUI::ImGUIDrawingGroup::show
bool show
Controls whether or not the group should be shown. May not be used in all groups.
Definition: debug_ui.h:362
BlamRendering::DirectX::Drawing::DrawRect
BLAM HRESULT DrawRect(D2D1_COLOR_F outline_color, D2D1_COLOR_F fill_color, D2D1_RECT_F rect, float thickness, StackItemDrawMode mode)
Draws a rectangle.
Definition: rect.cpp:9
Blam::DebugUI::ImGUIDrawingGroup
Class representing an ImGUI drawing group/draw list item.
Definition: debug_ui.h:359
Blam::DebugUI::Windows::Direct2DTest
Dialog used to test early implementation of Direct2D.
Definition: d2d_test.hpp:18
Blam::DebugUI::Windows::Direct2DTest::Draw
void Draw()
Draws the window and any Direct2D primitives that have been enabled.
Definition: d2d_test.hpp:62
Blam::DebugUI::Windows::Direct2DTest::~Direct2DTest
~Direct2DTest()
Empty destructor.
Definition: d2d_test.hpp:57
Blam::DebugUI::Windows
Legacy namespace to contain data for the legacy ImGUI console.
Definition: debug_ui.h:434
Text
@ Text
Master text object that wraps around both BitmapText and DWText.
Definition: render_stack.h:73
BlamRendering::DirectX::Drawing::DWDrawText
BLAM HRESULT DWDrawText(std::wstring text, std::wstring font, float size, D2D1_RECT_F area, D2D1_COLOR_F color)
Draws a string using DirectWrite.
Definition: dwtext.cpp:16