mirror of
https://github.com/Kiritow/MiniEngine.git
synced 2024-03-22 13:11:22 +08:00
[New] Widget added.
[Update] SDL Engine updated.
This commit is contained in:
parent
88d5a9c96b
commit
39c4d04d03
11
App.cpp
11
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);
|
||||
*/
|
||||
}
|
||||
}
|
||||
|
|
67
MiniEngine/Widget.cpp
Normal file
67
MiniEngine/Widget.cpp
Normal file
|
@ -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
|
76
MiniEngine/Widget.h
Normal file
76
MiniEngine/Widget.h
Normal file
|
@ -0,0 +1,76 @@
|
|||
#pragma once
|
||||
#include "../config.h"
|
||||
#include <string>
|
||||
|
||||
#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.
|
|
@ -8,8 +8,6 @@
|
|||
#include <cstdlib>
|
||||
#include <cstring>
|
||||
|
||||
using namespace std;
|
||||
|
||||
/// If you have configured SDL2 header files,
|
||||
/// they will be used first.
|
||||
|
||||
|
|
|
@ -6,6 +6,10 @@
|
|||
/// InitManager
|
||||
#include "InitManager.h"
|
||||
|
||||
/******************************************************************************/
|
||||
/// Widget
|
||||
#include "MiniEngine/Widget.h"
|
||||
|
||||
/******************************************************************************/
|
||||
/// Application
|
||||
#include "App.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();
|
||||
|
|
|
@ -36,7 +36,7 @@ Window::~Window()
|
|||
delete pimpl;
|
||||
}
|
||||
|
||||
Renderer Window::getRenderer()
|
||||
Renderer Window::getRenderer() const
|
||||
{
|
||||
return pimpl->rnd;
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue
Block a user