change CMakeLists.txt and util_test.cc

This commit is contained in:
Jie
2024-07-25 15:46:49 +08:00
parent 83cc278754
commit 4d7249aca2
3 changed files with 47 additions and 6 deletions

29
main.cc
View File

@@ -1,14 +1,32 @@
#include <cstdio>
#include <SFML/System.hpp>
#include <SFML/Graphics.hpp>
#include <SFML/Window.hpp>
#include <spdlog/spdlog.h>
#include "UtilTool.h"
constexpr int CLIENT_WIDTH = 800;
constexpr int CLIENT_HEIGHT = 600;
int main(int argc, char** const argv){
spdlog::info("Hello, World!");
sf::RenderWindow window(sf::VideoMode(800, 600), "mp");
int main(int argc, char** argv){
spdlog::info("Current WorkDir Is: {}",argv[0]);
if(argc != 2){
spdlog::error("Usage: mp filename ");
return 0;
}
if(!UtilTool::CheckFileIsImage(argv[1])){
spdlog::info("Unsupport File Type: {}",argv[1]);
return 0;
}
sf::Texture texture;
texture.loadFromFile(argv[1]);
sf::RenderWindow window(sf::VideoMode(CLIENT_WIDTH, CLIENT_HEIGHT), "mp");
sf::Sprite sprite;
sprite.setTexture(texture);
auto imgSize = texture.getSize();
auto scale = std::min(CLIENT_WIDTH/imgSize.x,CLIENT_HEIGHT/imgSize.y);
sprite.setScale(scale, scale);
bool running = true;
while(running){
@@ -22,8 +40,13 @@ int main(int argc, char** const argv){
running = false;
}
}
if(event.type == sf::Event::Resized){
auto scale = std::min(event.size.width / imgSize.x, event.size.height / imgSize.y);
sprite.setScale(scale, scale);
}
}
window.clear();
window.draw(sprite);
window.display();
}
return 0;