2024-07-25 15:46:49 +08:00
|
|
|
#include <cstdio>
|
2024-06-18 10:04:50 +08:00
|
|
|
#include <SFML/System.hpp>
|
|
|
|
#include <SFML/Graphics.hpp>
|
|
|
|
#include <SFML/Window.hpp>
|
2024-06-18 11:16:30 +08:00
|
|
|
#include <spdlog/spdlog.h>
|
2024-07-25 15:46:49 +08:00
|
|
|
#include "UtilTool.h"
|
2024-06-18 10:04:50 +08:00
|
|
|
|
2024-07-25 15:46:49 +08:00
|
|
|
constexpr int CLIENT_WIDTH = 800;
|
|
|
|
constexpr int CLIENT_HEIGHT = 600;
|
2024-06-18 10:04:50 +08:00
|
|
|
|
2024-07-25 15:46:49 +08:00
|
|
|
|
|
|
|
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;
|
|
|
|
}
|
2024-06-18 10:04:50 +08:00
|
|
|
sf::Texture texture;
|
2024-07-25 15:46:49 +08:00
|
|
|
texture.loadFromFile(argv[1]);
|
|
|
|
sf::RenderWindow window(sf::VideoMode(CLIENT_WIDTH, CLIENT_HEIGHT), "mp");
|
2024-06-18 10:04:50 +08:00
|
|
|
sf::Sprite sprite;
|
2024-07-25 15:46:49 +08:00
|
|
|
sprite.setTexture(texture);
|
|
|
|
auto imgSize = texture.getSize();
|
2024-09-05 15:25:02 +08:00
|
|
|
auto scale = std::min(static_cast<float>(CLIENT_WIDTH)/imgSize.x,static_cast<float>(CLIENT_HEIGHT)/imgSize.y);
|
2024-07-25 15:46:49 +08:00
|
|
|
sprite.setScale(scale, scale);
|
2024-06-18 10:04:50 +08:00
|
|
|
bool running = true;
|
|
|
|
|
|
|
|
while(running){
|
|
|
|
sf::Event event;
|
|
|
|
while(window.pollEvent(event)){
|
|
|
|
if(event.type == sf::Event::Closed){
|
|
|
|
running = false;
|
|
|
|
}
|
|
|
|
if(event.type == sf::Event::KeyPressed){
|
|
|
|
if(event.key.code == sf::Keyboard::Escape){
|
|
|
|
running = false;
|
|
|
|
}
|
|
|
|
}
|
2024-09-05 15:25:02 +08:00
|
|
|
|
2024-06-18 10:04:50 +08:00
|
|
|
}
|
|
|
|
window.clear();
|
2024-07-25 15:46:49 +08:00
|
|
|
window.draw(sprite);
|
2024-06-18 10:04:50 +08:00
|
|
|
window.display();
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|