SDLU/SDLU_Example/main.cpp

76 lines
2.4 KiB
C++
Raw Normal View History

2020-05-16 12:34:20 +02:00
#include "header.hpp"
2020-05-18 19:52:12 +02:00
#include <math.h>
#include <cmath>
2020-05-16 12:34:20 +02:00
int main(int argc, char** argv)
{
2020-05-16 20:49:04 +02:00
SDL_Init(SDL_INIT_VIDEO);
2020-05-18 16:27:03 +02:00
Uint32* icon_data = new Uint32[64 * 64];
for (int y = 0; y < 64; y++)
{
for (int x = 0; x < 64; x++)
{
icon_data[64 * y + x] = 0x004400FF;
icon_data[64 * y + x] |= (((Uint32)((y / 64.f) * 255) << 24));
icon_data[64 * y + x] |= (((Uint32)((x / 64.f) * 255) << 8));
}
}
2020-05-18 16:53:01 +02:00
std::chrono::steady_clock::time_point start = std::chrono::steady_clock::now();
Uint64 diff = 1;
2020-05-16 20:09:21 +02:00
MyWindow window(800, 800, "Test");
SDL_SetWindowTitle(window.GetWindow(), "New Title");
2020-05-16 20:09:21 +02:00
2020-05-18 16:27:03 +02:00
window.SetIcon(64, 64, icon_data);
2020-05-18 18:29:37 +02:00
window.SetMouseCursor(SDL_SYSTEM_CURSOR_CROSSHAIR);
2020-05-18 16:53:01 +02:00
window.SetMaxFramerate(144);
2020-05-18 16:27:03 +02:00
2020-05-16 20:09:21 +02:00
SDL_Event event;
2020-05-17 12:25:09 +02:00
float t = 0.f;
2020-05-19 14:57:35 +02:00
std::string title = "";
2020-05-16 23:36:21 +02:00
while (window.IsOpen())
{
2020-05-19 14:57:35 +02:00
title = "";
2020-05-16 23:36:21 +02:00
while (window.PollEvent(&event))
2020-05-16 20:49:04 +02:00
{
2020-05-16 23:36:21 +02:00
switch (event.window.event)
{
case SDL_WINDOWEVENT_CLOSE:
window.Close();
break;
2020-05-17 14:53:08 +02:00
case SDL_WINDOWEVENT_RESIZED:
std::cout << "If you see this, something isn't working." << std::endl;
break;
2020-05-16 23:36:21 +02:00
}
2020-05-16 20:49:04 +02:00
}
2020-05-16 23:36:21 +02:00
2020-05-19 15:20:25 +02:00
sdlu::Vector2i mousePos = sdlu::Mouse::GetPosition(window) - sdlu::Vector2i(400, 400);
// TODO: Check HSV color conversion, the SV values seem to be ignored
window.Clear(sdlu::Color::FromHSV(std::atan2(mousePos.y, mousePos.x) / PI * 180 + 180,
100, 100));
2020-05-16 23:36:21 +02:00
window.Display();
2020-05-18 18:29:37 +02:00
t += 0.08;
2020-05-18 16:53:01 +02:00
diff = std::chrono::duration_cast<std::chrono::microseconds>
(std::chrono::steady_clock::now() - start).count();
2020-05-19 14:57:35 +02:00
title += (std::to_string(1000000 / diff) + " FPS | Mouse: ");
title += (sdlu::Mouse::IsButtonDown(sdlu::Mouse::Button::Left)) ? "L " : "l ";
title += (sdlu::Mouse::IsButtonDown(sdlu::Mouse::Button::Middle)) ? "M " : "m ";
title += (sdlu::Mouse::IsButtonDown(sdlu::Mouse::Button::Right)) ? "R " : "r ";
title += (sdlu::Mouse::IsButtonDown(sdlu::Mouse::Button::XButton1)) ? "X1 " : "x1 ";
title += (sdlu::Mouse::IsButtonDown(sdlu::Mouse::Button::XButton2)) ? "X2" : "x2";
window.SetTitle(title);
2020-05-18 16:53:01 +02:00
start = std::chrono::steady_clock::now();
}
2020-05-16 20:09:21 +02:00
2020-05-16 20:49:04 +02:00
SDL_Quit();
2020-05-16 12:34:20 +02:00
return 0;
}