diff options
author | Yuqian Yang <crupest@crupest.life> | 2025-09-26 21:43:58 +0800 |
---|---|---|
committer | Yuqian Yang <crupest@crupest.life> | 2025-09-26 21:43:58 +0800 |
commit | 38aca5bc750b0679dd7f2b7bb5e5a0b6f983dd8b (patch) | |
tree | 1d5ed476d05fc277cf48215cf8037851259b45c3 /demos/platform/graphics/Base.cpp | |
parent | 57763bb30b86737810bdd8458ba62b378481b994 (diff) | |
download | cru-38aca5bc750b0679dd7f2b7bb5e5a0b6f983dd8b.tar.gz cru-38aca5bc750b0679dd7f2b7bb5e5a0b6f983dd8b.tar.bz2 cru-38aca5bc750b0679dd7f2b7bb5e5a0b6f983dd8b.zip |
Organize platform graphics demo.
Diffstat (limited to 'demos/platform/graphics/Base.cpp')
-rw-r--r-- | demos/platform/graphics/Base.cpp | 37 |
1 files changed, 37 insertions, 0 deletions
diff --git a/demos/platform/graphics/Base.cpp b/demos/platform/graphics/Base.cpp new file mode 100644 index 00000000..be39f7e0 --- /dev/null +++ b/demos/platform/graphics/Base.cpp @@ -0,0 +1,37 @@ +#include "Base.h" +#include <cru/base/io/CFileStream.h> +#include <cru/platform/bootstrap/GraphicsBootstrap.h> +#include <cru/platform/graphics/Factory.h> +#include <cru/platform/graphics/Image.h> +#include <cru/platform/graphics/ImageFactory.h> + +CruPlatformGraphicsDemo::CruPlatformGraphicsDemo(std::string file_name, + int width, int height) + : file_name_(std::move(file_name)) { + factory_.reset(cru::platform::bootstrap::CreateGraphicsFactory()); + image_ = factory_->GetImageFactory()->CreateBitmap(width, height); + painter_ = image_->CreatePainter(); +} + +CruPlatformGraphicsDemo::~CruPlatformGraphicsDemo() { + painter_->EndDraw(); + + cru::io::CFileStream file_stream(file_name_.c_str(), "wb"); + + factory_->GetImageFactory()->EncodeToStream( + image_.get(), &file_stream, cru::platform::graphics::ImageFormat::Png, + 1.0f); +} + +cru::platform::graphics::IGraphicsFactory* +CruPlatformGraphicsDemo::GetFactory() { + return factory_.get(); +} + +cru::platform::graphics::IImage* CruPlatformGraphicsDemo::GetImage() { + return image_.get(); +} + +cru::platform::graphics::IPainter* CruPlatformGraphicsDemo::GetPainter() { + return painter_.get(); +} |