SDLU/examples/main.cpp

82 lines
2.4 KiB
C++
Raw Permalink Normal View History

2020-05-16 10:34:20 +00:00
#include "header.hpp"
2021-04-23 13:08:51 +00:00
#include <SDL_events.h>
2020-05-18 17:52:12 +00:00
#include <math.h>
#include <cmath>
2020-05-16 10:34:20 +00:00
int main(int argc, char** argv)
{
2021-04-23 13:08:51 +00:00
sdlu::Initialize();
2020-05-16 18:49:04 +00:00
2021-04-23 22:12:34 +00:00
sdlu::Time test = sdlu::Microseconds(420);
std::cout << test.AsSeconds() << std::endl;
2020-05-18 14:27:03 +00: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));
}
}
2021-04-23 23:21:15 +00:00
sdlu::Clock timer;
2020-05-18 14:53:01 +00:00
Uint64 diff = 1;
2020-05-16 18:09:21 +00:00
MyWindow window(800, 800, "Test");
2021-04-23 13:08:51 +00:00
window.SetTitle("New Title");
2020-05-16 18:09:21 +00:00
2020-05-18 14:27:03 +00:00
window.SetIcon(64, 64, icon_data);
2021-04-23 14:29:26 +00:00
window.SetMouseCursor(sdlu::Cursor::Type::Crosshair);
2020-05-18 14:53:01 +00:00
window.SetMaxFramerate(144);
2020-05-18 14:27:03 +00:00
2020-05-16 18:09:21 +00:00
SDL_Event event;
2020-05-19 12:57:35 +00:00
2020-05-23 14:13:41 +00:00
sdlu::Rectangle rect(sdlu::Vec2f(100, 100), sdlu::Vec2f(300, 200));
rect.SetColor(sdlu::Color::Blue);
2020-05-19 12:57:35 +00:00
std::string title = "";
2020-05-16 21:36:21 +00:00
while (window.IsOpen())
{
2020-05-19 12:57:35 +00:00
title = "";
2020-05-16 21:36:21 +00:00
while (window.PollEvent(&event))
2020-05-16 18:49:04 +00:00
{
2020-05-16 21:36:21 +00:00
switch (event.window.event)
{
case SDL_WINDOWEVENT_CLOSE:
window.Close();
break;
2020-05-17 12:53:08 +00:00
case SDL_WINDOWEVENT_RESIZED:
std::cout << "If you see this, something isn't working." << std::endl;
break;
2020-05-16 21:36:21 +00:00
}
2020-05-16 18:49:04 +00:00
}
2020-05-16 21:36:21 +00:00
2020-05-19 13:20:25 +00: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 21:36:21 +00:00
2020-05-23 14:13:41 +00:00
window.Draw(rect);
2020-05-16 21:36:21 +00:00
window.Display();
2020-05-18 14:53:01 +00:00
2021-04-23 23:21:15 +00:00
diff = timer.Restart().AsMicroseconds();
2020-05-19 12:57:35 +00: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-16 18:09:21 +00:00
2021-04-23 13:08:51 +00:00
sdlu::Quit();
2020-05-16 10:34:20 +00:00
return 0;
2021-04-24 12:35:49 +00:00
}