LiteRGSS 0.1.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/ext/LiteRGSS/Bitmap.cpp +316 -0
- data/ext/LiteRGSS/Bitmap.h +24 -0
- data/ext/LiteRGSS/BlendMode.cpp +202 -0
- data/ext/LiteRGSS/BlendMode.h +20 -0
- data/ext/LiteRGSS/CBitmap_Element.cpp +50 -0
- data/ext/LiteRGSS/CBitmap_Element.h +17 -0
- data/ext/LiteRGSS/CDrawable_Element.cpp +38 -0
- data/ext/LiteRGSS/CDrawable_Element.h +30 -0
- data/ext/LiteRGSS/CRect_Element.h +15 -0
- data/ext/LiteRGSS/CShaderSprite_Element.cpp +17 -0
- data/ext/LiteRGSS/CShaderSprite_Element.h +17 -0
- data/ext/LiteRGSS/CSprite_Element.cpp +15 -0
- data/ext/LiteRGSS/CSprite_Element.h +36 -0
- data/ext/LiteRGSS/CText_Element.cpp +12 -0
- data/ext/LiteRGSS/CText_Element.h +29 -0
- data/ext/LiteRGSS/CTone_Element.h +17 -0
- data/ext/LiteRGSS/CViewport_Element.cpp +224 -0
- data/ext/LiteRGSS/CViewport_Element.h +57 -0
- data/ext/LiteRGSS/Color.cpp +200 -0
- data/ext/LiteRGSS/Color.h +22 -0
- data/ext/LiteRGSS/Fonts.cpp +126 -0
- data/ext/LiteRGSS/Fonts.h +20 -0
- data/ext/LiteRGSS/Graphics.cpp +314 -0
- data/ext/LiteRGSS/Graphics.h +31 -0
- data/ext/LiteRGSS/Graphics.local.cpp +365 -0
- data/ext/LiteRGSS/Graphics.local.h +37 -0
- data/ext/LiteRGSS/Image.cpp +460 -0
- data/ext/LiteRGSS/Image.h +32 -0
- data/ext/LiteRGSS/Input.cpp +664 -0
- data/ext/LiteRGSS/Input.h +38 -0
- data/ext/LiteRGSS/LiteRGSS.cpp +34 -0
- data/ext/LiteRGSS/LiteRGSS.h +113 -0
- data/ext/LiteRGSS/Rect.cpp +324 -0
- data/ext/LiteRGSS/Rect.h +24 -0
- data/ext/LiteRGSS/Shader.cpp +279 -0
- data/ext/LiteRGSS/Shader.h +13 -0
- data/ext/LiteRGSS/ShaderSprite.cpp +78 -0
- data/ext/LiteRGSS/ShaderSprite.h +8 -0
- data/ext/LiteRGSS/Sprite.cpp +495 -0
- data/ext/LiteRGSS/Sprite.h +43 -0
- data/ext/LiteRGSS/Table.cpp +228 -0
- data/ext/LiteRGSS/Table.h +29 -0
- data/ext/LiteRGSS/Table32.cpp +228 -0
- data/ext/LiteRGSS/Table32.h +29 -0
- data/ext/LiteRGSS/Text.cpp +574 -0
- data/ext/LiteRGSS/Text.h +52 -0
- data/ext/LiteRGSS/Texture.hpp +735 -0
- data/ext/LiteRGSS/Tone.cpp +228 -0
- data/ext/LiteRGSS/Tone.h +22 -0
- data/ext/LiteRGSS/Viewport.cpp +491 -0
- data/ext/LiteRGSS/Viewport.h +33 -0
- data/ext/LiteRGSS/Yuki.cpp +29 -0
- data/ext/LiteRGSS/Yuki.h +8 -0
- data/ext/LiteRGSS/Yuki_Gif.cpp +218 -0
- data/ext/LiteRGSS/Yuki_Gif.h +25 -0
- data/ext/LiteRGSS/extconf.rb +8 -0
- data/ext/LiteRGSS/libnsgif.c +1169 -0
- data/ext/LiteRGSS/libnsgif.h +183 -0
- data/ext/LiteRGSS/libnsgif.hpp +184 -0
- data/ext/LiteRGSS/lodepng.cpp +6245 -0
- data/ext/LiteRGSS/lodepng.h +1769 -0
- data/ext/LiteRGSS/lzw.c +377 -0
- data/ext/LiteRGSS/lzw.h +105 -0
- data/ext/LiteRGSS/sf_Text2.cpp +690 -0
- data/ext/LiteRGSS/sf_Text2.hpp +549 -0
- data/ext/LiteRGSS/utils/log.h +21 -0
- metadata +112 -0
@@ -0,0 +1,20 @@
|
|
1
|
+
#ifndef L_BLENDMODE_HEADER
|
2
|
+
#define L_BLENDMODE_HEADER
|
3
|
+
|
4
|
+
VALUE rb_BlendMode_setColorSrcFactor(VALUE self, VALUE val);
|
5
|
+
VALUE rb_BlendMode_getColorSrcFactor(VALUE self);
|
6
|
+
VALUE rb_BlendMode_setColorDestFactor(VALUE self, VALUE val);
|
7
|
+
VALUE rb_BlendMode_getColorDestFactor(VALUE self);
|
8
|
+
VALUE rb_BlendMode_setAlphaSrcFactor(VALUE self, VALUE val);
|
9
|
+
VALUE rb_BlendMode_getAlphaSrcFactor(VALUE self);
|
10
|
+
VALUE rb_BlendMode_setAlphaDestFactor(VALUE self, VALUE val);
|
11
|
+
VALUE rb_BlendMode_getAlphaDestFactor(VALUE self);
|
12
|
+
VALUE rb_BlendMode_setColorEquation(VALUE self, VALUE val);
|
13
|
+
VALUE rb_BlendMode_getColorEquation(VALUE self);
|
14
|
+
VALUE rb_BlendMode_setAlphaEquation(VALUE self, VALUE val);
|
15
|
+
VALUE rb_BlendMode_getAlphaEquation(VALUE self);
|
16
|
+
VALUE rb_BlendMode_setBlendType(VALUE self, VALUE val);
|
17
|
+
VALUE rb_BlendMode_getBlendType(VALUE self);
|
18
|
+
VALUE rb_BlendMode_Copy(VALUE self);
|
19
|
+
|
20
|
+
#endif
|
@@ -0,0 +1,50 @@
|
|
1
|
+
#include "CBitmap_Element.h"
|
2
|
+
|
3
|
+
|
4
|
+
CBitmap_Element::CBitmap_Element()
|
5
|
+
{
|
6
|
+
text = new sf::Texture();
|
7
|
+
//img = nullptr;
|
8
|
+
}
|
9
|
+
|
10
|
+
CBitmap_Element::~CBitmap_Element()
|
11
|
+
{
|
12
|
+
if(text != nullptr)
|
13
|
+
{
|
14
|
+
delete text;
|
15
|
+
text = nullptr;
|
16
|
+
}
|
17
|
+
/*if(img != nullptr)
|
18
|
+
{
|
19
|
+
delete img;
|
20
|
+
img = nullptr;
|
21
|
+
}*/
|
22
|
+
}
|
23
|
+
|
24
|
+
sf::Texture* CBitmap_Element::getTexture()
|
25
|
+
{
|
26
|
+
return text;
|
27
|
+
}
|
28
|
+
|
29
|
+
void CBitmap_Element::copy(CBitmap_Element* original) {
|
30
|
+
sf::Image img = original->getTexture()->copyToImage();
|
31
|
+
text->loadFromImage(img);
|
32
|
+
}
|
33
|
+
|
34
|
+
sf::Image* CBitmap_Element::getImage()
|
35
|
+
{
|
36
|
+
/*if(img == nullptr)
|
37
|
+
{
|
38
|
+
if(text->getSize().x > 0)
|
39
|
+
{
|
40
|
+
|
41
|
+
}
|
42
|
+
else
|
43
|
+
img = new sf::Image();
|
44
|
+
}*/
|
45
|
+
if(!has_image())
|
46
|
+
{
|
47
|
+
img = text->copyToImage();
|
48
|
+
}
|
49
|
+
return &img;
|
50
|
+
}
|
@@ -0,0 +1,17 @@
|
|
1
|
+
#ifndef CBITMAP_ELEMENT_H
|
2
|
+
#define CBITMAP_ELEMENT_H
|
3
|
+
#include <SFML/Graphics.hpp>
|
4
|
+
|
5
|
+
class CBitmap_Element {
|
6
|
+
sf::Texture* text;
|
7
|
+
sf::Image img;
|
8
|
+
public:
|
9
|
+
CBitmap_Element();
|
10
|
+
~CBitmap_Element();
|
11
|
+
sf::Texture* getTexture();
|
12
|
+
sf::Image* getImage();
|
13
|
+
void copy(CBitmap_Element* original);
|
14
|
+
bool has_image() { return img.getSize().x != 0; }; //return img != nullptr; };
|
15
|
+
};
|
16
|
+
|
17
|
+
#endif
|
@@ -0,0 +1,38 @@
|
|
1
|
+
#include "CDrawable_Element.h"
|
2
|
+
#include <iostream>
|
3
|
+
|
4
|
+
CDrawable_Element::CDrawable_Element()
|
5
|
+
{
|
6
|
+
origin_stack = nullptr;
|
7
|
+
linkedRect = nullptr;
|
8
|
+
index = 0;
|
9
|
+
}
|
10
|
+
|
11
|
+
void CDrawable_Element::setOriginStack(std::vector<CDrawable_Element*> *o)
|
12
|
+
{
|
13
|
+
/* Removing from the old stack */
|
14
|
+
if(origin_stack != nullptr)
|
15
|
+
{
|
16
|
+
auto it = std::find(origin_stack->begin(), origin_stack->end(), this);
|
17
|
+
if(it != origin_stack->end())
|
18
|
+
origin_stack->erase(it);
|
19
|
+
}
|
20
|
+
origin_stack = o;
|
21
|
+
if(o != nullptr)
|
22
|
+
{
|
23
|
+
origin_stack->push_back(this);
|
24
|
+
if(index == 0)
|
25
|
+
index = o->size();
|
26
|
+
}
|
27
|
+
}
|
28
|
+
|
29
|
+
|
30
|
+
void CDrawable_Element::setIndex(unsigned long nindex)
|
31
|
+
{
|
32
|
+
index = nindex;
|
33
|
+
}
|
34
|
+
|
35
|
+
unsigned long CDrawable_Element::getIndex()
|
36
|
+
{
|
37
|
+
return index;
|
38
|
+
}
|
@@ -0,0 +1,30 @@
|
|
1
|
+
#ifndef CDrawable_Element_H
|
2
|
+
#define CDrawable_Element_H
|
3
|
+
#include "ruby.h" // Windows Build Patch
|
4
|
+
#include <SFML/Graphics.hpp>
|
5
|
+
#include "sf_Text2.hpp"
|
6
|
+
#include <vector>
|
7
|
+
#include <algorithm>
|
8
|
+
|
9
|
+
class CRect_Element;
|
10
|
+
class CTone_Element;
|
11
|
+
|
12
|
+
class CDrawable_Element {
|
13
|
+
protected:
|
14
|
+
std::vector<CDrawable_Element*> *origin_stack;
|
15
|
+
CRect_Element* linkedRect;
|
16
|
+
unsigned long index;
|
17
|
+
public:
|
18
|
+
CDrawable_Element();
|
19
|
+
void setOriginStack(std::vector<CDrawable_Element*> *o);
|
20
|
+
void overrideOrigineStack(std::vector<CDrawable_Element*> *o) {origin_stack = o;};
|
21
|
+
void setIndex(unsigned long nindex);
|
22
|
+
unsigned long getIndex();
|
23
|
+
virtual void draw(sf::RenderTarget& target) const = 0;
|
24
|
+
virtual void drawFast(sf::RenderTarget& target) const = 0;
|
25
|
+
virtual bool isViewport() const = 0;
|
26
|
+
virtual bool isPureSprite() const = 0;
|
27
|
+
void setLinkedRect(CRect_Element* _rect) { linkedRect = _rect; };
|
28
|
+
CRect_Element* getLinkedRect() { return linkedRect; };
|
29
|
+
};
|
30
|
+
#endif
|
@@ -0,0 +1,15 @@
|
|
1
|
+
#ifndef CRECT_ELEMENT_H
|
2
|
+
#define CRECT_ELEMENT_H
|
3
|
+
#include <SFML/Graphics.hpp>
|
4
|
+
#include "CDrawable_Element.h"
|
5
|
+
class CRect_Element {
|
6
|
+
private:
|
7
|
+
sf::IntRect rect;
|
8
|
+
CDrawable_Element* target;
|
9
|
+
public:
|
10
|
+
sf::IntRect* getRect() { return ▭ };
|
11
|
+
void setElement(CDrawable_Element* _target) {target = _target;};
|
12
|
+
CDrawable_Element* getElement() { return target; };
|
13
|
+
};
|
14
|
+
|
15
|
+
#endif
|
@@ -0,0 +1,17 @@
|
|
1
|
+
#include "CShaderSprite_Element.h"
|
2
|
+
|
3
|
+
void CShaderSprite_Element::draw(sf::RenderTarget& target) const
|
4
|
+
{
|
5
|
+
if(drawable && visible)
|
6
|
+
{
|
7
|
+
if (render_states == nullptr)
|
8
|
+
target.draw(sprite);
|
9
|
+
else
|
10
|
+
target.draw(sprite, *render_states);//, render_states->shader);
|
11
|
+
}
|
12
|
+
}
|
13
|
+
|
14
|
+
void CShaderSprite_Element::drawFast(sf::RenderTarget& target) const
|
15
|
+
{
|
16
|
+
draw(target);
|
17
|
+
}
|
@@ -0,0 +1,17 @@
|
|
1
|
+
#ifndef CShaderSprite_Element_H
|
2
|
+
#define CShaderSprite_Element_H
|
3
|
+
#include "CSprite_Element.h"
|
4
|
+
|
5
|
+
class CShaderSprite_Element : public CSprite_Element {
|
6
|
+
protected:
|
7
|
+
sf::RenderStates* render_states;
|
8
|
+
public:
|
9
|
+
CShaderSprite_Element() : CSprite_Element(), render_states(nullptr) {};
|
10
|
+
void draw(sf::RenderTarget& target) const override;
|
11
|
+
void drawFast(sf::RenderTarget& target) const override;
|
12
|
+
bool isViewport() const override { return false; };
|
13
|
+
bool isPureSprite() const override { return true; };
|
14
|
+
void setRenderState(sf::RenderStates* states) { render_states = states; };
|
15
|
+
VALUE rRenderStates;
|
16
|
+
};
|
17
|
+
#endif
|
@@ -0,0 +1,15 @@
|
|
1
|
+
#include "CViewport_Element.h"
|
2
|
+
#include <iostream>
|
3
|
+
|
4
|
+
void CSprite_Element::draw(sf::RenderTarget& target) const
|
5
|
+
{
|
6
|
+
CSprite_Element::drawFast(target);
|
7
|
+
}
|
8
|
+
|
9
|
+
void CSprite_Element::drawFast(sf::RenderTarget& target) const
|
10
|
+
{
|
11
|
+
if(drawable && visible)
|
12
|
+
{
|
13
|
+
target.draw(sprite);
|
14
|
+
}
|
15
|
+
}
|
@@ -0,0 +1,36 @@
|
|
1
|
+
#ifndef CSprite_Element_H
|
2
|
+
#define CSprite_Element_H
|
3
|
+
#include "ruby.h"
|
4
|
+
#include "CDrawable_Element.h"
|
5
|
+
|
6
|
+
class CSprite_Element : public CDrawable_Element {
|
7
|
+
protected:
|
8
|
+
sf::Sprite sprite;
|
9
|
+
bool drawable;
|
10
|
+
bool visible;
|
11
|
+
public:
|
12
|
+
CSprite_Element() : CDrawable_Element(), drawable(false), visible(true) {};
|
13
|
+
void draw(sf::RenderTarget& target) const override;
|
14
|
+
void drawFast(sf::RenderTarget& target) const override;
|
15
|
+
bool isViewport() const override { return false; };
|
16
|
+
bool isPureSprite() const override { return true; };
|
17
|
+
sf::Sprite* getSprite() { return &sprite;};
|
18
|
+
void setDrawable(bool value) { drawable = value;};
|
19
|
+
bool getDrawable() { return drawable; };
|
20
|
+
void setVisible(bool value) { visible = value;};
|
21
|
+
bool getVisible() { return visible; };
|
22
|
+
/* Instance variable for Ruby */
|
23
|
+
VALUE rViewport;
|
24
|
+
VALUE rBitmap;
|
25
|
+
VALUE rX;
|
26
|
+
VALUE rY;
|
27
|
+
VALUE rZ;
|
28
|
+
VALUE rOX;
|
29
|
+
VALUE rOY;
|
30
|
+
VALUE rAngle;
|
31
|
+
VALUE rZoomX;
|
32
|
+
VALUE rZoomY;
|
33
|
+
VALUE rRect;
|
34
|
+
VALUE rMirror;
|
35
|
+
};
|
36
|
+
#endif
|
@@ -0,0 +1,29 @@
|
|
1
|
+
#ifndef CText_Element_H
|
2
|
+
#define CText_Element_H
|
3
|
+
#include "ruby.h"
|
4
|
+
#include "CDrawable_Element.h"
|
5
|
+
|
6
|
+
class CText_Element : public CDrawable_Element {
|
7
|
+
private:
|
8
|
+
sf::Text2 text;
|
9
|
+
bool visible;
|
10
|
+
public:
|
11
|
+
CText_Element() : CDrawable_Element(), visible(true) {};
|
12
|
+
void draw(sf::RenderTarget& target) const override;
|
13
|
+
void drawFast(sf::RenderTarget& target) const override;
|
14
|
+
bool isViewport() const override { return false; };
|
15
|
+
bool isPureSprite() const override { return false; };
|
16
|
+
sf::Text2* getText() { return &text;};
|
17
|
+
void setVisible(bool value) { visible = value;};
|
18
|
+
bool getVisible() { return visible; };
|
19
|
+
/* Instance variable for Ruby */
|
20
|
+
VALUE rViewport;
|
21
|
+
VALUE rX;
|
22
|
+
VALUE rY;
|
23
|
+
VALUE rZ;
|
24
|
+
VALUE rwidth;
|
25
|
+
VALUE rheight;
|
26
|
+
VALUE rtext;
|
27
|
+
VALUE rAlign;
|
28
|
+
};
|
29
|
+
#endif
|
@@ -0,0 +1,17 @@
|
|
1
|
+
#ifndef CTONE_ELEMENT_H
|
2
|
+
#define CTONE_ELEMENT_H
|
3
|
+
#include <SFML/Graphics.hpp>
|
4
|
+
#include "CViewport_Element.h"
|
5
|
+
|
6
|
+
class CTone_Element {
|
7
|
+
private:
|
8
|
+
sf::Glsl::Vec4 tonevalues;
|
9
|
+
CViewport_Element* target;
|
10
|
+
public:
|
11
|
+
sf::Glsl::Vec4* getTone() { return &tonevalues; };
|
12
|
+
void setElement(CViewport_Element* element) {target = element;};
|
13
|
+
CViewport_Element* getElement() { return target;};
|
14
|
+
};
|
15
|
+
|
16
|
+
|
17
|
+
#endif
|
@@ -0,0 +1,224 @@
|
|
1
|
+
#include "LiteRGSS.h"
|
2
|
+
#include "CViewport_Element.h"
|
3
|
+
#include "Graphics.local.h"
|
4
|
+
|
5
|
+
sf::RenderTexture* CViewport_Element::render = nullptr;
|
6
|
+
sf::Sprite* CViewport_Element::render_sprite = nullptr;
|
7
|
+
|
8
|
+
CViewport_Element::CViewport_Element() : CDrawable_Element()
|
9
|
+
{
|
10
|
+
linkedTone = nullptr;
|
11
|
+
render_states = nullptr;
|
12
|
+
color_copy = nullptr;
|
13
|
+
rRenderState = Qnil;
|
14
|
+
}
|
15
|
+
|
16
|
+
CViewport_Element::~CViewport_Element()
|
17
|
+
{
|
18
|
+
if(!game_window || !game_window->isOpen())
|
19
|
+
std::cerr << "Game window release thus viewport " << this << " not freed." << std::endl;
|
20
|
+
if (rRenderState == Qnil && render_states)
|
21
|
+
{
|
22
|
+
if (render_states->shader)
|
23
|
+
{
|
24
|
+
delete render_states->shader;
|
25
|
+
render_states->shader = nullptr;
|
26
|
+
}
|
27
|
+
delete render_states;
|
28
|
+
}
|
29
|
+
if(color_copy)
|
30
|
+
delete color_copy;
|
31
|
+
};
|
32
|
+
|
33
|
+
void CViewport_Element::draw(sf::RenderTarget& target) const
|
34
|
+
{
|
35
|
+
if (!visible)
|
36
|
+
return;
|
37
|
+
if(render_states)
|
38
|
+
{
|
39
|
+
sf::Color* col;
|
40
|
+
// Loading Window View
|
41
|
+
/* sf::View wview = view;
|
42
|
+
wview.setRotation(0);
|
43
|
+
wview.setViewport(sf::FloatRect(0.f, 0.f, 1.f, 1.f));
|
44
|
+
wview.setSize(ScreenWidth, ScreenHeight);
|
45
|
+
target.setView(wview);*/
|
46
|
+
// Loading Target view
|
47
|
+
const sf::Vector2f view_size = view.getSize();
|
48
|
+
sf::View tview = view;
|
49
|
+
//tview.setViewport(sf::FloatRect(0.0f, 0.0f, view_size.x / ScreenWidth, view_size.y / ScreenHeight));
|
50
|
+
render->setView(tview);
|
51
|
+
// Clearing render
|
52
|
+
if (render_states->shader)
|
53
|
+
col = check_up_color();
|
54
|
+
else
|
55
|
+
col = const_cast<sf::Color*>(&sf::Color::Transparent);
|
56
|
+
render->clear(*col);
|
57
|
+
// Drawing sprites
|
58
|
+
for(auto sp = stack.begin();sp != stack.end();sp++)
|
59
|
+
(*sp)->drawFast(*render);
|
60
|
+
render->display();
|
61
|
+
// Update internal texture & draw result to Window
|
62
|
+
render_sprite->setTexture(render->getTexture());
|
63
|
+
//render_sprite->setTextureRect(sf::IntRect(0, 0, static_cast<int>(view_size.x), static_cast<int>(view_size.y)));
|
64
|
+
target.draw(*render_sprite, *render_states);
|
65
|
+
/*sf::Sprite sp(render->getTexture());
|
66
|
+
sp.setTextureRect(sf::IntRect(0, 0, static_cast<int>(view_size.x), static_cast<int>(view_size.y)));
|
67
|
+
target.draw(sp, *render_states);*/
|
68
|
+
}
|
69
|
+
else
|
70
|
+
{
|
71
|
+
target.setView(view);
|
72
|
+
drawFast(target);
|
73
|
+
}
|
74
|
+
}
|
75
|
+
|
76
|
+
void CViewport_Element::drawFast(sf::RenderTarget& target) const
|
77
|
+
{
|
78
|
+
for(auto sp = stack.begin();sp != stack.end();sp++)
|
79
|
+
{
|
80
|
+
(*sp)->drawFast(target);
|
81
|
+
}
|
82
|
+
}
|
83
|
+
|
84
|
+
bool CViewport_Element::isViewport() const
|
85
|
+
{
|
86
|
+
return true;
|
87
|
+
}
|
88
|
+
|
89
|
+
bool CViewport_Element::isPureSprite() const
|
90
|
+
{
|
91
|
+
return false;
|
92
|
+
}
|
93
|
+
|
94
|
+
sf::RenderStates * CViewport_Element::getRenderStates()
|
95
|
+
{
|
96
|
+
return render_states;
|
97
|
+
}
|
98
|
+
|
99
|
+
void CViewport_Element::setRenderStates(sf::RenderStates * states)
|
100
|
+
{
|
101
|
+
if (rRenderState == Qnil && render_states)
|
102
|
+
{
|
103
|
+
if (render_states->shader)
|
104
|
+
{
|
105
|
+
delete render_states->shader;
|
106
|
+
render_states->shader = nullptr;
|
107
|
+
}
|
108
|
+
}
|
109
|
+
render_states = states;
|
110
|
+
}
|
111
|
+
|
112
|
+
void CViewport_Element::bind(CDrawable_Element* sprite)
|
113
|
+
{
|
114
|
+
//stack.push_back(sprite);
|
115
|
+
sprite->setOriginStack(&stack);
|
116
|
+
}
|
117
|
+
|
118
|
+
void CViewport_Element::clearStack()
|
119
|
+
{
|
120
|
+
stack.clear();
|
121
|
+
}
|
122
|
+
|
123
|
+
sf::Glsl::Vec4* CViewport_Element::getTone()
|
124
|
+
{
|
125
|
+
return &tone;
|
126
|
+
};
|
127
|
+
|
128
|
+
void CViewport_Element::updatetone()
|
129
|
+
{
|
130
|
+
if(render_states && render_states->shader)
|
131
|
+
const_cast<sf::Shader*>(render_states->shader)->setUniform("tone", tone);
|
132
|
+
}
|
133
|
+
|
134
|
+
void CViewport_Element::setLinkedTone(CTone_Element * _tone)
|
135
|
+
{
|
136
|
+
linkedTone = _tone;
|
137
|
+
}
|
138
|
+
|
139
|
+
CTone_Element * CViewport_Element::getLinkedTone()
|
140
|
+
{
|
141
|
+
return linkedTone;
|
142
|
+
}
|
143
|
+
|
144
|
+
sf::Color* CViewport_Element::check_up_color() const
|
145
|
+
{
|
146
|
+
sf::Color* col = reinterpret_cast<sf::Color*>(RDATA(rColor)->data);
|
147
|
+
if (*col != *color_copy)
|
148
|
+
{
|
149
|
+
sf::Glsl::Vec4 color(col->r / 255.0f, col->g / 255.0f, col->b / 255.0f, col->a / 255.0f);
|
150
|
+
const_cast<sf::Shader*>(render_states->shader)->setUniform("color", color);
|
151
|
+
color_copy->r = col->r;
|
152
|
+
color_copy->g = col->g;
|
153
|
+
color_copy->b = col->b;
|
154
|
+
color_copy->a = col->a;
|
155
|
+
}
|
156
|
+
return col;
|
157
|
+
}
|
158
|
+
|
159
|
+
/* ---- Shader Part ---- */
|
160
|
+
/* Thaks to https://github.com/Ancurio/mkxp/blob/master/shader/sprite.frag (Ancurio & urkle) */
|
161
|
+
const std::string ViewportGlobalFragmentShader = \
|
162
|
+
"uniform sampler2D texture;" \
|
163
|
+
"uniform vec4 tone;" \
|
164
|
+
"uniform vec4 color;" \
|
165
|
+
"const vec3 lumaF = vec3(.299, .587, .114);" \
|
166
|
+
"void main()" \
|
167
|
+
"{" \
|
168
|
+
" vec4 frag = texture2D(texture, gl_TexCoord[0].xy);" \
|
169
|
+
/*" frag.rgb = mix(frag.rgb, gl_Color.rgb, cola);" \*/
|
170
|
+
" frag.rgb = mix(frag.rgb, color.rgb, color.a);" \
|
171
|
+
" float luma = dot(frag.rgb, lumaF);" \
|
172
|
+
" frag.rgb += tone.rgb;" \
|
173
|
+
" frag.rgb = mix(frag.rgb, vec3(luma), tone.w);" \
|
174
|
+
" frag.a *= gl_Color.a;" \
|
175
|
+
" gl_FragColor = frag;" \
|
176
|
+
"}";
|
177
|
+
|
178
|
+
|
179
|
+
sf::Glsl::Vec4 __Viewport_reset_tone(0.0f, 0.0f, 0.0f, 0.0f);
|
180
|
+
|
181
|
+
|
182
|
+
/*void CViewport_Element::reset_render()
|
183
|
+
{
|
184
|
+
if(render == nullptr)
|
185
|
+
return;
|
186
|
+
const sf::Vector2f sz = getView()->getSize();
|
187
|
+
render->create(static_cast<unsigned int>(sz.x), static_cast<unsigned int>(sz.y));
|
188
|
+
}*/
|
189
|
+
|
190
|
+
void CViewport_Element::create_render()
|
191
|
+
{
|
192
|
+
// If the global viewport render doesn't exist, we create it
|
193
|
+
if (!render)
|
194
|
+
{
|
195
|
+
render = new sf::RenderTexture();
|
196
|
+
render->create(ScreenWidth, ScreenHeight);
|
197
|
+
render->setSmooth(SmoothScreen);
|
198
|
+
render_sprite = new sf::Sprite();
|
199
|
+
}
|
200
|
+
// Return if the render texture (internal_texture) is already created
|
201
|
+
if(render_states != nullptr)
|
202
|
+
return;
|
203
|
+
// Creation of the render states
|
204
|
+
render_states = new sf::RenderStates(new sf::Shader());
|
205
|
+
// Shader initialialization
|
206
|
+
sf::Shader* shader = const_cast<sf::Shader*>(render_states->shader);
|
207
|
+
if (shader->loadFromMemory(ViewportGlobalFragmentShader, sf::Shader::Fragment))
|
208
|
+
{
|
209
|
+
shader->setUniform("texture", sf::Shader::CurrentTexture);
|
210
|
+
shader->setUniform("tone", __Viewport_reset_tone);
|
211
|
+
shader->setUniform("color", __Viewport_reset_tone);
|
212
|
+
}
|
213
|
+
color_copy = new sf::Color(0, 0, 0, 0);
|
214
|
+
}
|
215
|
+
|
216
|
+
void CViewport_Element::setVisible(bool value)
|
217
|
+
{
|
218
|
+
visible = value;
|
219
|
+
}
|
220
|
+
|
221
|
+
const std::vector<CDrawable_Element*>* CViewport_Element::getStack()
|
222
|
+
{
|
223
|
+
return &stack;
|
224
|
+
}
|