Move old files to SDLEngine.

This commit is contained in:
Kirigaya Kazuto 2017-03-02 12:25:11 +08:00
parent f49793113a
commit 20b17d9f66
31 changed files with 4 additions and 266 deletions

View File

@ -1,187 +0,0 @@
#include "MiniEngine_Simple.h"
#include <functional>
#include <vector>
#include <map>
#include <mutex>
using namespace MiniEngine;
class Drawable
{
public:
virtual void update(Renderer& rnd)=0;
virtual ~Drawable()
{
}
};
class Interactive : public Drawable
{
public:
virtual void handle(SDL_Event e,int& running,int& update)=0;
};
class SimpleButton : public Interactive
{
public:
enum class ButtonStatus {normal,mouseover,clicked};
/// StatusChanged API
function<void(int& running,int& update,ButtonStatus& currentStatus,ButtonStatus newStatus)> onStatusChanged;
virtual ~SimpleButton()
{
/// Disable the button while destructing
disable();
}
SimpleButton(Rect rect)
{
r=rect;
bstatus=ButtonStatus::normal;
}
void setNormalColor(RGBA NormalColor)
{
normal=NormalColor;
}
void setMouseoverColor(RGBA MouseoverColor)
{
mouseover=MouseoverColor;
}
void setClickedColor(RGBA ClickedColor)
{
clicked=ClickedColor;
}
void enable()
{
disid=RegistDispatcher([this](SDL_Event e,int& r,int& u){handle(e,r,u);});
upid=RegistUpdater([this](Renderer& rnd){update(rnd);});
}
void disable()
{
UnregistUpdater(upid);
UnregistDispatcher(disid);
}
virtual void update(Renderer& rnd) override
{
RGBA old=rnd.getColor();
switch(bstatus)
{
case ButtonStatus::normal:rnd.setColor(normal);break;
case ButtonStatus::mouseover:rnd.setColor(mouseover);break;
case ButtonStatus::clicked:rnd.setColor(clicked);break;
}
rnd.fillRect(r);
rnd.setColor(old);
}
virtual void handle(SDL_Event e,int& running,int& update) override
{
switch(e.type)
{
case SDL_MOUSEMOTION:
{
if(Point(e.motion.x,e.motion.y).inRect(r))
{
if(bstatus!=ButtonStatus::mouseover)
{
if(onStatusChanged)
onStatusChanged(running,update,bstatus,ButtonStatus::mouseover);
else
{
bstatus=ButtonStatus::mouseover;
update=1;
}
}
}
else
{
if(bstatus!=ButtonStatus::normal)
{
if(onStatusChanged)
onStatusChanged(running,update,bstatus,ButtonStatus::normal);
else
{
bstatus=ButtonStatus::normal;
update=1;
}
}
}
}
break;
case SDL_MOUSEBUTTONDOWN:
{
if(Point(e.button.x,e.button.y).inRect(r))
{
if(bstatus!=ButtonStatus::clicked)
{
if(onStatusChanged)
onStatusChanged(running,update,bstatus,ButtonStatus::clicked);
else
{
bstatus=ButtonStatus::clicked;
update=1;
}
}
}
}
break;
case SDL_MOUSEBUTTONUP:
{
if(Point(e.button.x,e.button.y).inRect(r))
{
if(bstatus!=ButtonStatus::mouseover)
{
if(onStatusChanged)
onStatusChanged(running,update,bstatus,ButtonStatus::mouseover);
else
{
bstatus=ButtonStatus::mouseover;
update=1;
}
}
}
}
break;
}
}
private:
int disid,upid;
Rect r;
/// normal
/// mouseover(MouseOver) -> clicked(Clicked) -> mouseover(ButtonUp)
RGBA normal,mouseover,clicked;
/// Status 0:Deactivate 1:MouseOver 2:Clicked
ButtonStatus bstatus;
};
/**
//Example Code
int main()
{
SDLSystem::Init();
Window wnd("Title Is Here",1024,768);
Renderer rnd=wnd.getRenderer();
SimpleButton button(Rect(0,0,150,150));
button.onStatusChanged=[](int& r,int& u,SimpleButton::ButtonStatus& s,SimpleButton::ButtonStatus ns)
{
printf("Status From %d to %d\n",static_cast<int>(s),static_cast<int>(ns));
if(s!=ns) u=1;
s=ns;
};
button.setNormalColor(RGBA(255,0,0,255));
button.setMouseoverColor(RGBA(0,255,0,255));
button.setClickedColor(RGBA(0,0,255,255));
button.enable();
EventLoop(rnd);
SDLSystem::Quit();
return 0;
}
*/

View File

@ -1,13 +1,11 @@
# MiniEngine # MiniEngine (In maintenance)
A C++ Mini Engine. Based on SDL2. A C++ Mini Engine. Based on SDL2.
C++编写的SDL2引擎. C++编写的SDL2引擎.(维护中)
### 编译说明 ### 编译说明
Simple版本: 直接在cpp文件中include这个hpp文件.(目前可用)
**>>目前无法编译项目<<**   **>>目前无法编译项目<<**  
Windows: 请使用Codeblocks 16.01(推荐)载入所有.cpp文件.接下来Codeblocks会完成其余的工作. Windows: 请使用Codeblocks 16.01(推荐)载入所有.cpp文件.接下来Codeblocks会完成其余的工作.
@ -26,4 +24,6 @@ C4droid: 长按编译键选择编译模式为Makefile. 选择编译目标为SDL2
[前往SDL2官网下载最新版本](http://www.libsdl.org/download-2.0.php) [前往SDL2官网下载最新版本](http://www.libsdl.org/download-2.0.php)
[C4droid on GooglePlay](https://play.google.com/store/apps/details?id=com.n0n3m4.droidc&hl=en) [C4droid on GooglePlay](https://play.google.com/store/apps/details?id=com.n0n3m4.droidc&hl=en)
### 项目状态
解决Brush和Board的问题中

View File

@ -1,75 +0,0 @@
#include "MiniEngine.h"
using namespace MiniEngine;
#include <iostream>
using namespace std;
int AppMain()
{
Window wnd("Sample Program",1280,720);
Renderer rnd=wnd.getRenderer();
rnd.setBlendMode(BlendMode::Blend);
Font font("D:\\msyh.ttf",18);
MusicPlayer mp;
Music mlogin=mp.loadMusic("res/1.mp3");
Texture tlogin=rnd.loadTexture("res/page.jpg");
tlogin.setBlendMode(BlendMode::Blend);
Texture tlogin2=rnd.loadTexture("res/page2.jpg");
tlogin2.setBlendMode(BlendMode::Blend);
mp.play(mlogin,0);
int fade=0;
int fadex=0;
int aa=255;
int ba=0;
EventHandle::RegistDispatcher(SDL_QUIT,[](SDL_Event e,int& r,int& u){r=0;u=1;});
EventHandle::RegistDispatcher(SDL_KEYDOWN,[&](SDL_Event e,int& r,int& u){
if(e.key.keysym.sym==SDLK_RETURN)
{
fade=1;
u=1;
}
else if(e.key.keysym.sym==SDLK_KP_ENTER)
{
fadex=1;
u=1;
}
});
EventHandle::RegistUpdater([&](Renderer& rnd){
if(fade)
{
cout<<"Fading..."<<endl;
--aa;
++ba;
if(aa==0)
{
fade=0;
cout<<"Fade Stop"<<endl;
}
}
if(fadex)
{
cout<<"FadingX..."<<endl;
++aa;
--ba;
if(aa==255)
{
fadex=0;
cout<<"FadeX Stop"<<endl;
}
}
tlogin.setAlphaMode(aa);
rnd.copyTo(tlogin,Point(0,0));
tlogin2.setAlphaMode(ba);
rnd.copyTo(tlogin2,Point(0,0));
});
EventHandle::Loop(rnd);
return 0;
}