· 6 years ago · Oct 20, 2019, 11:56 PM
1/* *
2 * fgui - an extensive oop gui framework *
3 * */
4
5#pragma once
6
7// includes
8#include <string>
9#include <functional>
10#include <WinUser.h>
11// framework includes
12#include "color.hh"
13#include "definitions.hh"
14#include "../../valve_sdk/interfaces/ISurface.hpp"
15
16namespace fgui {
17
18 /*
19 * Thanks to @zxvnme for giving me the idea to use this.
20 *
21 *
22 * NOTE1: If you don't have a function to match the template, you don't have to do anything.
23 * (Same thing goes for the input aliases.)
24 *
25 *
26 * NOTE2: You can use WINAPI functions for the input system too.
27 */
28 /*
29 void rectangle(int x, int y, int w, int h, fgui::color color)
30 {
31 //ctx::game::surface->draw_set_color(color.m_red, color.m_green, color.m_blue, color.m_alpha);
32 //ctx::game::surface->draw_filled_rect(x, y, x + w, y + h);
33 g_VGuiSurface->DrawSetColor(color.m_red, color.m_green, color.m_blue, color.m_alpha);
34 g_VGuiSurface->DrawFilledRect(x, y, x + w, y + h);
35 }
36 */
37
38 void texture(unsigned char* data, int x, int y, int width, int height, float scale)
39 {
40
41 static int textureid;
42
43 static bool once(true);
44
45 if (!once)
46 {
47 textureid = g_VGuiSurface->CreateNewTextureID(true);
48 if (!textureid)
49
50
51 g_VGuiSurface->DrawSetTextureRGBA(textureid, data, width, height);
52
53 once = true; // <----- Call stack points me here when crash
54 }
55
56 if (!g_VGuiSurface->IsTextureIDValid(textureid)) {
57 g_VGuiSurface->DrawSetColor(255, 255, 255, 255);
58 g_VGuiSurface->DrawSetTexture(textureid);
59 g_VGuiSurface->DrawTexturedRect(x, y, x + width * scale, y + height * scale);
60 }
61 }
62
63
64 RECT GetViewport()
65 {
66 RECT Viewport = { 0, 0, 0, 0 };
67 int w = 1920, h = 1080;
68 Viewport.right = w; Viewport.bottom = h;
69 return Viewport;
70 }
71
72
73 void screensize(int& width, int& height)
74 {
75 int width = GetSystemMetrics(SM_CXSCREEN);
76 int height = GetSystemMetrics(SM_CYSCREEN);
77 }
78 void createfont(fgui::font& font, const std::string_view family, int size, int flags, bool bold)
79 {
80
81 }
82 void gettextsize(const fgui::font& font, const std::string_view text)
83 {
84 //g_VGuiSurface->GetTextSize(font, text);
85 }
86
87 void outline(int x, int y, int width, int height, fgui::color color)
88 {
89 g_VGuiSurface->DrawSetColor(color.m_red,color.m_green,color.m_blue,color.m_alpha);
90 g_VGuiSurface->DrawOutlinedRect(x, y, x + width, y + height);
91 }
92
93 void line(int x, int y, int x2, int y2, fgui::color color)
94 {
95 g_VGuiSurface->DrawSetColor(color.m_red, color.m_green, color.m_blue, color.m_alpha);
96 g_VGuiSurface->DrawLine(x, y, x2, y2);
97 }
98
99 void text(int x, int y, fgui::color color, fgui::font font, const std::string_view text)
100 {
101 g_VGuiSurface->DrawSetColor(color.m_red, color.m_green, color.m_blue, color.m_alpha);
102 //g_VGuiSurface->DrawPrintText(text,)
103 }
104
105 void coloredgradient(int x, int y, int width, int height, fgui::color color1, fgui::color color2, bool is_horizontal)
106 {
107
108 }
109 void clippedrectangle(int x, int y, int width, int height)
110 {
111 //g_VGuiSurface->
112 }
113
114 void alpha(int x, int y, int width, int height)
115 {
116
117 }
118
119
120 bool get_key_state(int key)
121 {
122 return GetAsyncKeyState(key);
123 }
124
125 fgui::point get_mouse_position()
126 {
127 // NOTE: This is the Win API POINT struct.
128 POINT temporary_point = { 0, 0 };
129
130 // get cursor position;
131 GetCursorPos(&temporary_point);
132
133 return { temporary_point.x, temporary_point.y };
134 }
135
136
137 // render manager aliases
138 using create_font_alias = std::add_pointer_t<void(fgui::font& font, const std::string_view family, int size, int flags, bool bold)>; // only call this once!
139 using screen_size_alias = std::add_pointer_t<void(int& width, int& height)>;
140 using text_size_alias = std::add_pointer_t<fgui::dimension(const fgui::font &font, const std::string_view text)>;
141 using rectangle_alias = std::add_pointer_t<void(int x, int y, int width, int height, fgui::color color)>;
142 using colored_gradient_alias = std::add_pointer_t<void(int x, int y, int width, int height, fgui::color color1, fgui::color color2, bool is_horizontal)>;
143 using outline_alias = std::add_pointer_t<void(int x, int y, int width, int height, fgui::color color)>;
144 using line_alias = std::add_pointer_t<void(int x, int y, int x2, int y2, fgui::color color)>;
145 using polygon_alias = std::add_pointer_t<void(int count, fgui::vertex* vertex, fgui::color color)>;
146 using text_alias = std::add_pointer_t<void(int x, int y, fgui::color color, fgui::font font, const std::string_view text)>;
147 using alpha_alias = std::add_pointer_t<void(int x, int y, int width, int height)>;
148 using circle_alias = std::add_pointer_t<void(int x, int y, int radius, int segments, fgui::color color)>;
149 using texture_alias = std::add_pointer_t<void(unsigned char* data, int x, int y, int width, int height, float scale)>;
150 using gradient_alias = std::add_pointer_t<void(int x, int y, int w, int h, int alpha1, int alpha2, fgui::color color, bool is_horizontal)>;
151 using rounded_rectangle_alias = std::add_pointer_t<void(int x, int y, int width, int height, int radius, fgui::color color)>;
152 using clip_rect_alias = std::add_pointer_t<void(int x, int y, int width, int height)>;
153
154 struct rendering_functions {
155
156 //
157 // Most of this stuff you will be able to do with a rectangle.
158 //
159
160 create_font_alias create_font; // *
161 screen_size_alias get_screen_size; // *
162 text_size_alias get_text_size; // *
163 rectangle_alias rect; // *
164 outline_alias outline; // *
165 line_alias line; // *
166 polygon_alias polygon;
167 text_alias text; // *
168 circle_alias circle;
169 texture_alias texture;
170 gradient_alias gradient;
171 colored_gradient_alias colored_gradient; // * fucking hate your stupid alias, just do it better grrrr
172 rounded_rectangle_alias rounded_rect;
173 alpha_alias alpha; /**/
174 // ^ (The framework is using this function, but it's not necessary.)
175 clip_rect_alias clip_rect; /**/
176 // ^ (The framework is also using this function, if you remove it, scrolling will be affected, but it will still work.)
177
178 }; inline rendering_functions render;
179
180 // input system aliases
181 using mouse_position_alias = std::add_pointer_t<fgui::point()>;
182 using key_held_alias = std::add_pointer_t<fgui::state(const fgui::key &key)>;
183 using scroll_delta_alias = std::add_pointer_t<fgui::delta()>;
184
185 struct input_functions {
186
187 mouse_position_alias get_mouse_position; // * - GetCursorPos
188 key_held_alias get_key_state; // * - GetAsyncKeyState
189
190 scroll_delta_alias get_scroll_delta; // * - On WNDPROC hook, scroll_delta = (wParam / 120)
191 // just make a function that returns "scroll_delta".
192 // NOTE: This function is not necessary. If you remove it, you won't be able to scroll with your mouse wheel.
193
194 }; inline input_functions input;
195}