使用只能指针代替裸指针

This commit is contained in:
Jie
2024-09-30 13:34:05 +08:00
parent 7c049db4ac
commit 1237b164bf
12 changed files with 246 additions and 25 deletions

View File

@@ -1,7 +1,9 @@
#include <mediaService.h>
#include <memory>
#include <videoService.h>
MediaService::MediaService(const std::string& filename, int width, int height){
auto type = UtilTool::CheckFileType(filename);
type = UtilTool::CheckFileType(filename);
client_width = width;
client_height = height;
float scale = .0f;
@@ -9,14 +11,34 @@ MediaService::MediaService(const std::string& filename, int width, int height){
{
case MediaType::IMAGE:
imageService = new ImageService(filename);
texture = &imageService->GetTexture();
sprite = new sf::Sprite();
texture = imageService->GetTexture();
sprite = std::make_shared<sf::Sprite>();
sprite->setTexture(*texture);
scale = imageService->GetScale(client_width, client_height);
sprite->setScale(scale, scale);
break;
case MediaType::VIDEO:
break;
default:
break;
}
}
void MediaService::SetWindow(std::shared_ptr<sf::RenderWindow> window){
this->window = window;
}
void MediaService::Play(){
switch (type)
{
case MediaType::IMAGE:
window->clear();
window->draw(*sprite);
window->display();
break;
default:
break;
}
}
}

1
src/videoService.cc Normal file
View File

@@ -0,0 +1 @@
#include "videoService.h"