diff --git a/App.cpp b/App.cpp index 3ae2ac0..6e4f7a4 100644 --- a/App.cpp +++ b/App.cpp @@ -1,6 +1,7 @@ #include "App.h" using namespace Engine; +using namespace MiniEngine; namespace App { @@ -9,7 +10,15 @@ namespace App { Window wnd(1024,768); Renderer rnd=wnd.getRenderer(); - rnd.clear(); + + /* + /// Sample Code of Brush + Brush b(wnd,Rect(wnd.getSize().w/2-50,wnd.getSize().h/2-50,100,100)); + Texture t=rnd.loadImage("D:\\sample.png"); + Rect dst(0,0,wnd.getSize().w,wnd.getSize().h); + b.copyTo(t,dst,false); rnd.update(); + SDL_Delay(2000); + */ } } diff --git a/MiniEngine/Widget.cpp b/MiniEngine/Widget.cpp new file mode 100644 index 0000000..d0b8e6d --- /dev/null +++ b/MiniEngine/Widget.cpp @@ -0,0 +1,67 @@ +#include "Widget.h" + +using namespace Engine; +using namespace std; + +namespace MiniEngine +{ + +struct Brush::impl +{ + Renderer rnd; + Rect area; + impl(const Renderer& incrnd) : rnd(incrnd) + { + + } +}; +Brush::Brush(const Window& wnd,Rect DrawableArea) /// Protected +{ + pimpl=new impl(wnd.getRenderer()); + pimpl->area=DrawableArea; +} +void Brush::copy(Texture t,Rect src,Rect dst,bool autoZoom) +{ + dst.x+=pimpl->area.x; + dst.y+=pimpl->area.y; + if(dst.w>pimpl->area.w) dst.w=pimpl->area.w; + if(dst.h>pimpl->area.h) dst.h=pimpl->area.h; + if(autoZoom) + { + + } + else + { + if(src.w>pimpl->area.w) src.w=pimpl->area.w; + if(src.h>pimpl->area.h) src.h=pimpl->area.h; + } + pimpl->rnd.copy(t,src,dst); +} +void Brush::copyTo(Texture t,Rect dst,bool autoZoom) +{ + dst.x+=pimpl->area.x; + dst.y+=pimpl->area.y; + + if(dst.w>pimpl->area.w) dst.w=pimpl->area.w; + if(dst.h>pimpl->area.h) dst.h=pimpl->area.h; + + if(autoZoom) + { + pimpl->rnd.copyTo(t,dst); + } + else + { + int w=t.getw(); + int h=t.geth(); + if(w>pimpl->area.w) w=pimpl->area.w; + if(h>pimpl->area.h) h=pimpl->area.h; + Rect src(0,0,w,h); + pimpl->rnd.copy(t,src,dst); + } +} +Brush::~Brush() +{ + delete pimpl; +} + +}/// End of namespace MiniEngine diff --git a/MiniEngine/Widget.h b/MiniEngine/Widget.h new file mode 100644 index 0000000..6351a6f --- /dev/null +++ b/MiniEngine/Widget.h @@ -0,0 +1,76 @@ +#pragma once +#include "../config.h" +#include + +#define _MINI_ENGINE_IMPL_COPY_DECL(ClassName) _SDL_ENGINE_IMPL_COPY_DECL(ClassName) +#define _MINI_ENGINE_IMPL _SDL_ENGINE_IMPL +namespace MiniEngine +{ + +class Stage; + +class Brush +{ +public: + ~Brush(); + _MINI_ENGINE_IMPL_COPY_DECL(Brush) + + void copy(Engine::Texture t,Engine::Rect src,Engine::Rect dst,bool autoZoom); + void copyFill(Engine::Texture t,Engine::Rect src,bool autoZoom); + void copyTo(Engine::Texture t,Engine::Rect dst,bool autoZoom); + void copyFullFill(Engine::Texture t); +public: + Brush(const Engine::Window& rnd,Engine::Rect DrawableArea); +private: + _MINI_ENGINE_IMPL + friend class Stage; +}; + +class Stage +{ +public: + Stage(); + ~Stage(); +}; + +class Drawable +{ +public: + virtual int Draw(const Brush& brush)=0; + virtual Engine::Rect getSize()=0; +}; + +class BaseButton +{ +public: + BaseButton(); + BaseButton(const BaseButton&); + BaseButton& operator = (const BaseButton&); + BaseButton(BaseButton&&); + BaseButton& operator = (BaseButton&&); + + virtual int Draw(const Brush& brush); + + virtual ~BaseButton(); +private: + struct impl; + impl* pimpl; +}; + +class SimpleButton : public BaseButton +{ +public: + /// Default Style + SimpleButton(); + SimpleButton(std::string word, + Engine::RGBA color_word, + Engine::RGBA color_background, + Engine::RGBA color_highlight); + SimpleButton(const SimpleButton&); + SimpleButton& operator = (const SimpleButton&); + SimpleButton(SimpleButton&&); + SimpleButton& operator = (SimpleButton&&); + ~SimpleButton(); +}; + +}/// End of namespace MiniEngine. diff --git a/basic_config.h b/basic_config.h index 0e897ad..c279469 100644 --- a/basic_config.h +++ b/basic_config.h @@ -8,8 +8,6 @@ #include #include -using namespace std; - /// If you have configured SDL2 header files, /// they will be used first. diff --git a/mini_engine.h b/mini_engine.h index 1aa4894..c796884 100644 --- a/mini_engine.h +++ b/mini_engine.h @@ -6,6 +6,10 @@ /// InitManager #include "InitManager.h" +/******************************************************************************/ +/// Widget +#include "MiniEngine/Widget.h" + /******************************************************************************/ /// Application #include "App.h" diff --git a/sdl_engine.h b/sdl_engine.h index cc5474d..0776167 100644 --- a/sdl_engine.h +++ b/sdl_engine.h @@ -48,7 +48,7 @@ public: _SDL_ENGINE_IMPL_COPY_DECL(Window); - Renderer getRenderer(); + Renderer getRenderer() const; void resetRenderer(); Rect getSize(); @@ -75,7 +75,7 @@ private: class Renderer { public: - ~Renderer(); + virtual ~Renderer(); _SDL_ENGINE_IMPL_COPY_DECL(Renderer); int clear(); diff --git a/sdl_engine_window.hpp b/sdl_engine_window.hpp index 6f20d34..3d16a0c 100644 --- a/sdl_engine_window.hpp +++ b/sdl_engine_window.hpp @@ -36,7 +36,7 @@ Window::~Window() delete pimpl; } -Renderer Window::getRenderer() +Renderer Window::getRenderer() const { return pimpl->rnd; }