font renderer update

This commit is contained in:
Turanszki Janos
2020-04-25 15:14:01 +01:00
parent 7bdcfc14c6
commit 2f70a2aa8e
28 changed files with 423 additions and 288 deletions
+34 -34
View File
@@ -7,12 +7,12 @@ This is a reference and explanation of Lua scripting features in Wicked Engine.
4. [Engine Bindings](#engine-bindings)
1. [BackLog (Console)](#backlog)
2. [Renderer](#renderer)
3. [Font](#font)
4. [Sprite](#sprite)
3. [Sprite](#sprite)
1. [ImageParams](#imageparams)
2. [SpriteAnim](#spriteanim)
3. [MovingTexAnim](#movingtexanim)
4. [DrawRecAnim](#drawrecanim)
4. [SpriteFont](#spritefont)
5. [Texture](#texture)
6. [Audio](#audio)
1. [Sound](#sound)
@@ -130,33 +130,6 @@ You can use the Renderer with the following functions, all of which are in the g
- ClearWorld()
- ReloadShaders(opt string path)
### Font
Gives you the ability to render text with a custom font.
- [constructor]Font(opt string text)
- SetStyle(string fontstyle, opt int size = 16)
- SetText(opt string text)
- SetSize(int size)
- SetPos(Vector pos)
- SetSpacing(Vector spacing)
- SetAlign(WIFALIGN Halign, opt WIFALIGN Valign)
- [outer]WIFALIGN_LEFT : int
- [outer]WIFALIGN_CENTER : int
- [outer]WIFALIGN_MID : int
- [outer]WIFALIGN_RIGHT : int
- [outer]WIFALIGN_TOP : int
- [outer]WIFALIGN_BOTTOM : int
- SetColor(Vector color)
- SetColor(int colorHexCode)
- SetShadowColor(Vector shadowcolor)
- SetShadowColor(int colorHexCode)
- GetText() : string result
- GetSize() : int result
- GetPos() : Vector result
- GetSpacing() : Vector result
- GetAlign() : WIFALIGN halign,valign
- GetColor() : Vector result
- GetShadowColor() : Vector result
### Sprite
Render images on the screen.
- [constructor]Sprite(opt string texture, opt string maskTexture)
@@ -278,6 +251,33 @@ Animate sprite frame by frame.
- GetFrameCount() : int result
- GetHorizontalFrameCount() : int result
### SpriteFont
Gives you the ability to render text with a custom font.
- [constructor]SpriteFont(opt string text)
- SetStyle(string fontstyle, opt int size = 16)
- SetText(opt string text)
- SetSize(int size)
- SetPos(Vector pos)
- SetSpacing(Vector spacing)
- SetAlign(WIFALIGN Halign, opt WIFALIGN Valign)
- [outer]WIFALIGN_LEFT : int
- [outer]WIFALIGN_CENTER : int
- [outer]WIFALIGN_MID : int
- [outer]WIFALIGN_RIGHT : int
- [outer]WIFALIGN_TOP : int
- [outer]WIFALIGN_BOTTOM : int
- SetColor(Vector color)
- SetColor(int colorHexCode)
- SetShadowColor(Vector shadowcolor)
- SetShadowColor(int colorHexCode)
- GetText() : string result
- GetSize() : int result
- GetPos() : Vector result
- GetSpacing() : Vector result
- GetAlign() : WIFALIGN halign,valign
- GetColor() : Vector result
- GetShadowColor() : Vector result
### Texture
Just holds texture information in VRAM.
- [void-constructor]Texture()
@@ -618,20 +618,20 @@ A RenderPath is a high level system that represents a part of the whole applicat
- SetLayerMask(uint mask)
#### RenderPath2D
It can hold Sprites and Fonts and can sort them by layers, update and render them.
It can hold Sprites and SpriteFonts and can sort them by layers, update and render them.
- [constructor]RenderPath2D()
- AddSprite(Sprite sprite, opt string layer)
- AddFont(Font font, opt string layer)
- RemoveFont(Font font)
- AddFont(SpriteFont font, opt string layer)
- RemoveFont(SpriteFont font)
- ClearSprites()
- ClearFonts()
- GetSpriteOrder(Sprite sprite) : int? result
- GetFontOrder(Font font) : int? result
- GetFontOrder(SpriteFont font) : int? result
- AddLayer(string name)
- GetLayers() : string? result
- SetLayerOrder(string name, int order)
- SetSpriteOrder(Sprite sprite, int order)
- SetFontOrder(Font font, int order)
- SetFontOrder(SpriteFont font, int order)
#### RenderPath3D
A 3D scene can either be rendered by a Forward or Deferred render path, or path tracing.
+11 -5
View File
@@ -93,8 +93,10 @@ This is a reference for the C++ features of Wicked Engine
6. [wiEmittedParticle](#wiemittedparticle)
7. [wiHairParticle](#wihairparticle)
8. [wiOcean](#wiocean)
9. [wiGPUSortLib](#wigpusortlib)
10. [wiGPUBVH](#wigpubvh)
9. [wiSprite](#wisprite)
10. [wiSpriteFont](#wispritefont)
11. [wiGPUSortLib](#wigpusortlib)
12. [wiGPUBVH](#wigpubvh)
4. [GUI](#gui)
1. [wiGUI](#wigui)
2. [wiWidget](#wiwidget)
@@ -200,7 +202,7 @@ Before a RenderPath is destroyed, Unload will be called, so deleting resources c
### RenderPath2D
[[Header]](../WickedEngine/RenderPath2D.h) [[Cpp]](../WickedEngine/RenderPath2D.cpp)
Capable of handling 2D rendering to offscreen buffer in Render() function, or just the screen in Compose() function. It has some functionality to render wiSprite and wiFont onto rendering layers and stenciling with 3D rendered scene. It has a [GUI](#gui) that is automatically updated and rendered if any elements have been added to it.
Capable of handling 2D rendering to offscreen buffer in Render() function, or just the screen in Compose() function. It has some functionality to render wiSprite and wiSpriteFont onto rendering layers and stenciling with 3D rendered scene. It has a [GUI](#gui) that is automatically updated and rendered if any elements have been added to it.
### RenderPath3D
[[Header]](../WickedEngine/RenderPath3D.h) [[Cpp]](../WickedEngine/RenderPath3D.cpp)
@@ -775,9 +777,9 @@ Describe all parameters of how and where to draw the image on the screen.
[[Header]](../WickedEngine/wiFont.h) [[Cpp]](../WickedEngine/wiFont.cpp)
This can render fonts to the screen in a simple manner. You can render a font as simple as this:
```cpp
wiFont("write this!", wiFontParams(10, 20)).Draw(cmd);
wiFont::Draw("write this!", wiFontParams(10, 20), cmd);
```
Which will write the text <i>write this!</i> to 10, 20 pixel position onto the screen. There are many other parameters to describe the font's position, size, color, etc. See the wiFontParams structure for more details. Note that wiFont internally does string conversion, so it is recommended to avoid repeatedly creating wiFont resources during the frame!
Which will write the text <i>write this!</i> to 10, 20 pixel position onto the screen. There are many other parameters to describe the font's position, size, color, etc. See the wiFontParams structure for more details.
- wiFontParams <br/>
Describe all parameters of how and where to draw the font on the screen.
@@ -799,6 +801,10 @@ A helper facility to render and animate images. It uses the [wiImage](#wiimage)
- Anim <br/>
Several different simple animation utilities, like animated textures, wobbling, rotation, fade out, etc...
### wiSpriteFont
[[Header]](../WickedEngine/wiSprite.h) [[Cpp]](../WickedEngine/wiSprite.cpp)
A helper facility to render fonts. It uses the [wiFont](#wifont) renderer internally. It performs string conversion
### wiTextureHelper
[[Header]](../WickedEngine/wiTextureHelper.h) [[Cpp]](../WickedEngine/wiTextureHelper.cpp)
This is used to generate procedural textures, such as uniform colors, noise, etc...
+1 -1
View File
@@ -63,7 +63,7 @@ void Editor::Initialize()
void EditorLoadingScreen::Load()
{
font = wiFont("Loading...", wiFontParams((int)(wiRenderer::GetDevice()->GetScreenWidth()*0.5f), (int)(wiRenderer::GetDevice()->GetScreenHeight()*0.5f), 36,
font = wiSpriteFont("Loading...", wiFontParams((int)(wiRenderer::GetDevice()->GetScreenWidth()*0.5f), (int)(wiRenderer::GetDevice()->GetScreenHeight()*0.5f), 36,
WIFALIGN_CENTER, WIFALIGN_CENTER));
AddFont(&font);
+1 -1
View File
@@ -28,7 +28,7 @@ class EditorLoadingScreen : public LoadingScreen
{
private:
wiSprite sprite;
wiFont font;
wiSpriteFont font;
public:
void Load() override;
void Update(float dt) override;
+25 -25
View File
@@ -206,7 +206,7 @@ void TestsRenderer::Load()
break;
case 16:
{
static wiFont font("This test plays a vibration on the first controller's left motor (if device supports it) \n and changes the LED to a random color (if device supports it)");
static wiSpriteFont font("This test plays a vibration on the first controller's left motor (if device supports it) \n and changes the LED to a random color (if device supports it)");
font.params.h_align = WIFALIGN_CENTER;
font.params.v_align = WIFALIGN_CENTER;
font.params.size = 20;
@@ -371,8 +371,8 @@ void TestsRenderer::RunJobSystemTest()
ss << "wiJobSystem::Dispatch() took " << time << " milliseconds" << std::endl;
}
static wiFont font;
font = wiFont(ss.str());
static wiSpriteFont font;
font = wiSpriteFont(ss.str());
font.params.posX = wiRenderer::GetDevice()->GetScreenWidth() / 2;
font.params.posY = wiRenderer::GetDevice()->GetScreenHeight() / 2;
font.params.h_align = WIFALIGN_CENTER;
@@ -382,8 +382,8 @@ void TestsRenderer::RunJobSystemTest()
}
void TestsRenderer::RunFontTest()
{
static wiFont font;
static wiFont font_upscaled;
static wiSpriteFont font;
static wiSpriteFont font_upscaled;
int arial = wiFont::AddFontStyle(wiFont::GetFontPath() + "arial.ttf");
font.SetText("This is Arial, size 32 wiFont");
@@ -396,15 +396,15 @@ void TestsRenderer::RunFontTest()
font_upscaled.params = font.params;
font_upscaled.params.posY += font.textHeight();
font.style = arial;
font_upscaled.style = arial;
font.params.style = arial;
font_upscaled.params.style = arial;
font_upscaled.params.size = 14;
font_upscaled.params.scaling = 32.0f / 14.0f;
AddFont(&font);
AddFont(&font_upscaled);
static wiFont font_aligned;
static wiSpriteFont font_aligned;
font_aligned = font;
font_aligned.params.posY += font.textHeight() * 2;
font_aligned.params.size = 38;
@@ -413,7 +413,7 @@ void TestsRenderer::RunFontTest()
font_aligned.SetText("Center aligned, red shadow, bigger");
AddFont(&font_aligned);
static wiFont font_aligned2;
static wiSpriteFont font_aligned2;
font_aligned2 = font_aligned;
font_aligned2.params.posY += font_aligned.textHeight();
font_aligned2.params.shadowColor = wiColor::Purple();
@@ -432,17 +432,17 @@ void TestsRenderer::RunFontTest()
ss << s << "\t";
}
}
static wiFont font_japanese;
static wiSpriteFont font_japanese;
font_japanese = font_aligned2;
font_japanese.params.posY += font_aligned2.textHeight();
font_japanese.style = wiFont::AddFontStyle("yumin.ttf");
font_japanese.params.style = wiFont::AddFontStyle("yumin.ttf");
font_japanese.params.shadowColor = wiColor::Transparent();
font_japanese.params.h_align = WIFALIGN_CENTER;
font_japanese.params.size = 34;
font_japanese.SetText(ss.str());
AddFont(&font_japanese);
static wiFont font_colored;
static wiSpriteFont font_colored;
font_colored.params.color = wiColor::Cyan();
font_colored.params.h_align = WIFALIGN_CENTER;
font_colored.params.v_align = WIFALIGN_TOP;
@@ -466,7 +466,7 @@ void TestsRenderer::RunSpriteTest()
// Info:
{
static wiFont font("For more information, please see \nTests.cpp, RunSpriteTest() function.");
static wiSpriteFont font("For more information, please see \nTests.cpp, RunSpriteTest() function.");
font.params.posX = 10;
font.params.posY = 200;
AddFont(&font);
@@ -478,7 +478,7 @@ void TestsRenderer::RunSpriteTest()
sprite.params = params;
AddSprite(&sprite);
static wiFont font("No animation: ");
static wiSpriteFont font("No animation: ");
font.params.h_align = WIFALIGN_CENTER;
font.params.v_align = WIFALIGN_BOTTOM;
font.params.posX = int(sprite.params.pos.x);
@@ -497,7 +497,7 @@ void TestsRenderer::RunSpriteTest()
sprite.anim.repeatable = true;
AddSprite(&sprite);
static wiFont font("Fade animation: ");
static wiSpriteFont font("Fade animation: ");
font.params.h_align = WIFALIGN_CENTER;
font.params.v_align = WIFALIGN_BOTTOM;
font.params.posX = int(sprite.params.pos.x);
@@ -516,7 +516,7 @@ void TestsRenderer::RunSpriteTest()
sprite.anim.wobbleAnim.speed = 1.4f;
AddSprite(&sprite);
static wiFont font("Wobble animation: ");
static wiSpriteFont font("Wobble animation: ");
font.params.h_align = WIFALIGN_CENTER;
font.params.v_align = WIFALIGN_BOTTOM;
font.params.posX = int(sprite.params.pos.x);
@@ -535,7 +535,7 @@ void TestsRenderer::RunSpriteTest()
sprite.anim.repeatable = true;
AddSprite(&sprite);
static wiFont font("Rotate animation: ");
static wiSpriteFont font("Rotate animation: ");
font.params.h_align = WIFALIGN_CENTER;
font.params.v_align = WIFALIGN_BOTTOM;
font.params.posX = int(sprite.params.pos.x);
@@ -558,7 +558,7 @@ void TestsRenderer::RunSpriteTest()
sprite.anim.movingTexAnim.speedY = 2; // scroll the texture vertically. This value is pixels/second. So because our texture here is 1x2 pixels, just scroll it once fully per second with a value of 2
AddSprite(&sprite);
static wiFont font("MovingTex + mask: ");
static wiSpriteFont font("MovingTex + mask: ");
font.params.h_align = WIFALIGN_CENTER;
font.params.v_align = WIFALIGN_BOTTOM;
font.params.posX = int(sprite.params.pos.x);
@@ -578,7 +578,7 @@ void TestsRenderer::RunSpriteTest()
sprite.params = params; // nothing extra, just display the full spritesheet
AddSprite(&sprite);
static wiFont font("Spritesheet: \n(without animation)");
static wiSpriteFont font("Spritesheet: \n(without animation)");
font.params.h_align = WIFALIGN_CENTER;
font.params.v_align = WIFALIGN_BOTTOM;
font.params.posX = int(sprite.params.pos.x);
@@ -599,7 +599,7 @@ void TestsRenderer::RunSpriteTest()
sprite.anim.drawRectAnim.frameCount = 4; // animate only a single line horizontally
AddSprite(&sprite);
static wiFont font("single line anim: \n(4 frames)");
static wiSpriteFont font("single line anim: \n(4 frames)");
font.params.h_align = WIFALIGN_CENTER;
font.params.v_align = WIFALIGN_BOTTOM;
font.params.posX = int(sprite.params.pos.x);
@@ -621,7 +621,7 @@ void TestsRenderer::RunSpriteTest()
sprite.anim.drawRectAnim.horizontalFrameCount = 1; // ...but this time, limit the horizontal frame count. This way, we can get it to only animate vertically
AddSprite(&sprite);
static wiFont font("single line: \n(4 vertical frames)");
static wiSpriteFont font("single line: \n(4 vertical frames)");
font.params.h_align = WIFALIGN_CENTER;
font.params.v_align = WIFALIGN_BOTTOM;
font.params.posX = int(sprite.params.pos.x);
@@ -643,7 +643,7 @@ void TestsRenderer::RunSpriteTest()
sprite.anim.drawRectAnim.horizontalFrameCount = 4; // all horizontal frames
AddSprite(&sprite);
static wiFont font("multiline: \n(all 16 frames)");
static wiSpriteFont font("multiline: \n(all 16 frames)");
font.params.h_align = WIFALIGN_CENTER;
font.params.v_align = WIFALIGN_BOTTOM;
font.params.posX = int(sprite.params.pos.x);
@@ -665,7 +665,7 @@ void TestsRenderer::RunSpriteTest()
sprite.anim.drawRectAnim.horizontalFrameCount = 4; // all horizontal frames
AddSprite(&sprite);
static wiFont font("irregular multiline: \n(14 frames)");
static wiSpriteFont font("irregular multiline: \n(14 frames)");
font.params.h_align = WIFALIGN_CENTER;
font.params.v_align = WIFALIGN_BOTTOM;
font.params.posX = int(sprite.params.pos.x);
@@ -692,7 +692,7 @@ void TestsRenderer::RunSpriteTest()
sprite.anim.repeatable = true; // looping
AddSprite(&sprite);
static wiFont font("For the following spritesheets, credits belong to: https://mrbubblewand.wordpress.com/download/");
static wiSpriteFont font("For the following spritesheets, credits belong to: https://mrbubblewand.wordpress.com/download/");
font.params.v_align = WIFALIGN_BOTTOM;
font.params.posX = int(sprite.params.pos.x - sprite.params.siz.x * 0.5f);
font.params.posY = int(sprite.params.pos.y - sprite.params.siz.y * 0.5f);
@@ -760,7 +760,7 @@ void TestsRenderer::RunSpriteTest()
}
void TestsRenderer::RunNetworkTest()
{
static wiFont font;
static wiSpriteFont font;
wiNetwork::Connection connection;
connection.ipaddress = { 127,0,0,1 }; // localhost
+2 -2
View File
@@ -108,7 +108,7 @@ void MainComponent::Run()
// Until engine is not loaded, present initialization screen...
CommandList cmd = wiRenderer::GetDevice()->BeginCommandList();
wiRenderer::GetDevice()->PresentBegin(cmd);
wiFont(wiBackLog::getText(), wiFontParams(4, 4, infoDisplay.size)).Draw(cmd);
wiFont::Draw(wiBackLog::getText(), wiFontParams(4, 4, infoDisplay.size), cmd);
wiRenderer::GetDevice()->PresentEnd(cmd);
return;
}
@@ -319,7 +319,7 @@ void MainComponent::Compose(CommandList cmd)
}
ss.precision(2);
wiFont(ss.str(), wiFontParams(4, 4, infoDisplay.size, WIFALIGN_LEFT, WIFALIGN_TOP, 0, 0, wiColor(255,255,255,255), wiColor(0,0,0,255))).Draw(cmd);
wiFont::Draw(ss.str(), wiFontParams(4, 4, infoDisplay.size, WIFALIGN_LEFT, WIFALIGN_TOP, 0, 0, wiColor(255,255,255,255), wiColor(0,0,0,255)), cmd);
}
wiProfiler::DrawData(4, 120, cmd);
+7 -7
View File
@@ -1,7 +1,7 @@
#include "RenderPath2D.h"
#include "wiResourceManager.h"
#include "wiSprite.h"
#include "wiFont.h"
#include "wiSpriteFont.h"
#include "wiRenderer.h"
using namespace wiGraphics;
@@ -110,7 +110,7 @@ void RenderPath2D::Update(float dt)
{
if (y.sprite != nullptr)
{
y.sprite->Update(dt * GetSpriteSpeed());
y.sprite->Update(dt);
}
}
}
@@ -125,7 +125,7 @@ void RenderPath2D::FixedUpdate()
{
if (y.sprite != nullptr)
{
y.sprite->FixedUpdate(GetSpriteSpeed());
y.sprite->FixedUpdate();
}
}
}
@@ -300,7 +300,7 @@ int RenderPath2D::GetSpriteOrder(wiSprite* sprite)
return 0;
}
void RenderPath2D::AddFont(wiFont* font, const std::string& layer)
void RenderPath2D::AddFont(wiSpriteFont* font, const std::string& layer)
{
for (auto& x : layers)
{
@@ -313,7 +313,7 @@ void RenderPath2D::AddFont(wiFont* font, const std::string& layer)
}
SortLayers();
}
void RenderPath2D::RemoveFont(wiFont* font)
void RenderPath2D::RemoveFont(wiSpriteFont* font)
{
for (auto& x : layers)
{
@@ -338,7 +338,7 @@ void RenderPath2D::ClearFonts()
}
CleanLayers();
}
int RenderPath2D::GetFontOrder(wiFont* font)
int RenderPath2D::GetFontOrder(wiSpriteFont* font)
{
for (auto& x : layers)
{
@@ -393,7 +393,7 @@ void RenderPath2D::SetSpriteOrder(wiSprite* sprite, int order)
}
SortLayers();
}
void RenderPath2D::SetFontOrder(wiFont* font, int order)
void RenderPath2D::SetFontOrder(wiSpriteFont* font, int order)
{
for (auto& x : layers)
{
+6 -9
View File
@@ -5,7 +5,7 @@
#include <string>
class wiSprite;
class wiFont;
class wiSpriteFont;
struct RenderItem2D
{
@@ -15,7 +15,7 @@ struct RenderItem2D
FONT,
} type;
wiSprite* sprite = nullptr;
wiFont* font = nullptr;
wiSpriteFont* font = nullptr;
int order = 0;
};
struct RenderLayer2D
@@ -37,7 +37,6 @@ private:
wiGraphics::RenderPass renderpass_final;
wiGUI GUI;
float spriteSpeed = 1.0f;
protected:
void ResizeBuffers() override;
@@ -59,20 +58,18 @@ public:
void AddSprite(wiSprite* sprite, const std::string& layer = "");
void RemoveSprite(wiSprite* sprite);
void ClearSprites();
void SetSpriteSpeed(float value) { spriteSpeed = value; }
float GetSpriteSpeed() { return spriteSpeed; }
int GetSpriteOrder(wiSprite* sprite);
void AddFont(wiFont* font, const std::string& layer = "");
void RemoveFont(wiFont* font);
void AddFont(wiSpriteFont* font, const std::string& layer = "");
void RemoveFont(wiSpriteFont* font);
void ClearFonts();
int GetFontOrder(wiFont* font);
int GetFontOrder(wiSpriteFont* font);
std::vector<RenderLayer2D> layers{ 1 };
void AddLayer(const std::string& name);
void SetLayerOrder(const std::string& name, int order);
void SetSpriteOrder(wiSprite* sprite, int order);
void SetFontOrder(wiFont* font, int order);
void SetFontOrder(wiSpriteFont* font, int order);
void SortLayers();
void CleanLayers();
+5 -5
View File
@@ -1,6 +1,6 @@
#include "RenderPath2D_BindLua.h"
#include "wiSprite_BindLua.h"
#include "wiFont_BindLua.h"
#include "wiSpriteFont_BindLua.h"
#include <sstream>
@@ -78,7 +78,7 @@ int RenderPath2D_BindLua::AddFont(lua_State* L)
int argc = wiLua::SGetArgCount(L);
if (argc > 0)
{
wiFont_BindLua* font = Luna<wiFont_BindLua>::lightcheck(L, 1);
wiSpriteFont_BindLua* font = Luna<wiSpriteFont_BindLua>::lightcheck(L, 1);
if (font != nullptr)
{
RenderPath2D* ccomp = dynamic_cast<RenderPath2D*>(component);
@@ -145,7 +145,7 @@ int RenderPath2D_BindLua::RemoveFont(lua_State* L)
int argc = wiLua::SGetArgCount(L);
if (argc > 0)
{
wiFont_BindLua* font = Luna<wiFont_BindLua>::lightcheck(L, 1);
wiSpriteFont_BindLua* font = Luna<wiSpriteFont_BindLua>::lightcheck(L, 1);
if (font != nullptr)
{
RenderPath2D* ccomp = dynamic_cast<RenderPath2D*>(component);
@@ -246,7 +246,7 @@ int RenderPath2D_BindLua::GetFontOrder(lua_State* L)
int argc = wiLua::SGetArgCount(L);
if (argc > 0)
{
wiFont_BindLua* font = Luna<wiFont_BindLua>::lightcheck(L, 1);
wiSpriteFont_BindLua* font = Luna<wiSpriteFont_BindLua>::lightcheck(L, 1);
if (font != nullptr)
{
RenderPath2D* ccomp = dynamic_cast<RenderPath2D*>(component);
@@ -395,7 +395,7 @@ int RenderPath2D_BindLua::SetFontOrder(lua_State* L)
RenderPath2D* ccomp = dynamic_cast<RenderPath2D*>(component);
if (ccomp != nullptr)
{
wiFont_BindLua* font = Luna<wiFont_BindLua>::lightcheck(L, 1);
wiSpriteFont_BindLua* font = Luna<wiSpriteFont_BindLua>::lightcheck(L, 1);
if (font != nullptr)
{
ccomp->SetFontOrder(&font->font, wiLua::SGetInt(L, 2));
+2 -1
View File
@@ -25,8 +25,9 @@
#include "wiBackLog.h"
#include "wiIntersect.h"
#include "wiImage.h"
#include "wiSprite.h"
#include "wiFont.h"
#include "wiSprite.h"
#include "wiSpriteFont.h"
#include "wiScene.h"
#include "wiEmittedParticle.h"
#include "wiHairParticle.h"
+4 -2
View File
@@ -328,7 +328,7 @@
<ClInclude Include="$(MSBuildThisFileDirectory)wiEnums.h" />
<ClInclude Include="$(MSBuildThisFileDirectory)wiFadeManager.h" />
<ClInclude Include="$(MSBuildThisFileDirectory)wiFont.h" />
<ClInclude Include="$(MSBuildThisFileDirectory)wiFont_BindLua.h" />
<ClInclude Include="$(MSBuildThisFileDirectory)wiSpriteFont_BindLua.h" />
<ClInclude Include="$(MSBuildThisFileDirectory)wiGraphics.h" />
<ClInclude Include="$(MSBuildThisFileDirectory)wiGraphicsDevice_DX11.h" />
<ClInclude Include="$(MSBuildThisFileDirectory)wiGraphicsDevice.h" />
@@ -361,6 +361,7 @@
<ClInclude Include="$(MSBuildThisFileDirectory)wiScene_Decl.h" />
<ClInclude Include="$(MSBuildThisFileDirectory)wiSpinLock.h" />
<ClInclude Include="$(MSBuildThisFileDirectory)wiSprite.h" />
<ClInclude Include="$(MSBuildThisFileDirectory)wiSpriteFont.h" />
<ClInclude Include="$(MSBuildThisFileDirectory)wiSprite_BindLua.h" />
<ClInclude Include="$(MSBuildThisFileDirectory)wiStartupArguments.h" />
<ClInclude Include="$(MSBuildThisFileDirectory)wiTextureHelper.h" />
@@ -654,7 +655,7 @@
<ClCompile Include="$(MSBuildThisFileDirectory)wiEmittedParticle.cpp" />
<ClCompile Include="$(MSBuildThisFileDirectory)wiFadeManager.cpp" />
<ClCompile Include="$(MSBuildThisFileDirectory)wiFont.cpp" />
<ClCompile Include="$(MSBuildThisFileDirectory)wiFont_BindLua.cpp" />
<ClCompile Include="$(MSBuildThisFileDirectory)wiSpriteFont_BindLua.cpp" />
<ClCompile Include="$(MSBuildThisFileDirectory)wiGraphicsDevice_DX11.cpp" />
<ClCompile Include="$(MSBuildThisFileDirectory)wiGUI.cpp" />
<ClCompile Include="$(MSBuildThisFileDirectory)wiHairParticle.cpp" />
@@ -685,6 +686,7 @@
<ClCompile Include="$(MSBuildThisFileDirectory)wiScene_BindLua.cpp" />
<ClCompile Include="$(MSBuildThisFileDirectory)wiScene_Serializers.cpp" />
<ClCompile Include="$(MSBuildThisFileDirectory)wiSprite.cpp" />
<ClCompile Include="$(MSBuildThisFileDirectory)wiSpriteFont.cpp" />
<ClCompile Include="$(MSBuildThisFileDirectory)wiSprite_BindLua.cpp" />
<ClCompile Include="$(MSBuildThisFileDirectory)wiStartupArguments.cpp" />
<ClCompile Include="$(MSBuildThisFileDirectory)wiTextureHelper.cpp" />
@@ -186,9 +186,6 @@
<ClInclude Include="$(MSBuildThisFileDirectory)ResourceMapping.h">
<Filter>ENGINE\Graphics\GPUMapping</Filter>
</ClInclude>
<ClInclude Include="$(MSBuildThisFileDirectory)wiFont_BindLua.h">
<Filter>ENGINE\Scripting\LuaBindings</Filter>
</ClInclude>
<ClInclude Include="$(MSBuildThisFileDirectory)wiNetwork_BindLua.h">
<Filter>ENGINE\Scripting\LuaBindings</Filter>
</ClInclude>
@@ -1128,6 +1125,12 @@
<ClInclude Include="$(MSBuildThisFileDirectory)Utility\replace_new.h">
<Filter>UTILITY</Filter>
</ClInclude>
<ClInclude Include="$(MSBuildThisFileDirectory)wiSpriteFont.h">
<Filter>ENGINE\Graphics</Filter>
</ClInclude>
<ClInclude Include="$(MSBuildThisFileDirectory)wiSpriteFont_BindLua.h">
<Filter>ENGINE\Scripting\LuaBindings</Filter>
</ClInclude>
</ItemGroup>
<ItemGroup>
<ClCompile Include="$(MSBuildThisFileDirectory)LUA\lapi.c">
@@ -1259,9 +1262,6 @@
<ClCompile Include="$(MSBuildThisFileDirectory)wiBackLog_BindLua.cpp">
<Filter>ENGINE\Scripting\LuaBindings</Filter>
</ClCompile>
<ClCompile Include="$(MSBuildThisFileDirectory)wiFont_BindLua.cpp">
<Filter>ENGINE\Scripting\LuaBindings</Filter>
</ClCompile>
<ClCompile Include="$(MSBuildThisFileDirectory)wiNetwork_BindLua.cpp">
<Filter>ENGINE\Scripting\LuaBindings</Filter>
</ClCompile>
@@ -1886,6 +1886,12 @@
<ClCompile Include="$(MSBuildThisFileDirectory)wiProfiler.cpp">
<Filter>ENGINE\Tools</Filter>
</ClCompile>
<ClCompile Include="$(MSBuildThisFileDirectory)wiSpriteFont.cpp">
<Filter>ENGINE\Graphics</Filter>
</ClCompile>
<ClCompile Include="$(MSBuildThisFileDirectory)wiSpriteFont_BindLua.cpp">
<Filter>ENGINE\Scripting\LuaBindings</Filter>
</ClCompile>
</ItemGroup>
<ItemGroup>
<Text Include="$(MSBuildThisFileDirectory)..\features.txt" />
+3 -2
View File
@@ -5,6 +5,7 @@
#include "wiTextureHelper.h"
#include "wiSpinLock.h"
#include "wiFont.h"
#include "wiSpriteFont.h"
#include "wiImage.h"
#include "wiLua.h"
@@ -35,7 +36,7 @@ namespace wiBackLog
int scroll = 0;
stringstream inputArea;
int historyPos = 0;
wiFont font;
wiSpriteFont font;
wiSpinLock logLock;
std::unique_ptr<Texture> backgroundTex;
@@ -98,7 +99,7 @@ namespace wiBackLog
font.params.posX = 50;
font.params.posY = (int)pos + (int)scroll;
font.Draw(cmd);
wiFont(inputArea.str().c_str(), wiFontParams(10, wiRenderer::GetDevice()->GetScreenHeight() - 10, WIFONTSIZE_DEFAULT, WIFALIGN_LEFT, WIFALIGN_BOTTOM)).Draw(cmd);
wiFont::Draw(inputArea.str(), wiFontParams(10, wiRenderer::GetDevice()->GetScreenHeight() - 10, WIFONTSIZE_DEFAULT, WIFALIGN_LEFT, WIFALIGN_BOTTOM), cmd);
}
}
+138 -91
View File
@@ -17,6 +17,7 @@
#include <unordered_map>
#include <unordered_set>
#include <vector>
#include <string>
using namespace std;
using namespace wiGraphics;
@@ -29,7 +30,7 @@ using namespace wiRectPacker;
namespace wiFont_Internal
{
std::string FONTPATH = wiHelper::GetOriginalWorkingDirectory() + "../WickedEngine/fonts/";
string FONTPATH = wiHelper::GetOriginalWorkingDirectory() + "../WickedEngine/fonts/";
GPUBuffer indexBuffer;
GPUBuffer constantBuffer;
BlendState blendState;
@@ -101,7 +102,8 @@ namespace wiFont_Internal
XMHALF2 Tex;
};
uint32_t WriteVertices(volatile FontVertex* vertexList, const std::wstring& text, wiFontParams params, int style)
template<typename T>
uint32_t WriteVertices(volatile FontVertex* vertexList, const T* text, wiFontParams params)
{
uint32_t quadCount = 0;
int16_t line = 0;
@@ -126,9 +128,11 @@ namespace wiFont_Internal
}
};
for (auto& code : text)
size_t i = 0;
while(text[i] != 0)
{
const int32_t hash = glyphhash(code, style, params.size);
int code = (int)text[i++];
const int32_t hash = glyphhash(code, params.style, params.size);
if (glyph_lookup.count(hash) == 0)
{
@@ -212,17 +216,10 @@ namespace wiFont_Internal
}
using namespace wiFont_Internal;
wiFont::wiFont(const std::string& text, wiFontParams params, int style) : params(params), style(style)
namespace wiFont
{
SetText(text);
}
wiFont::wiFont(const std::wstring& text, wiFontParams params, int style) : params(params), style(style)
{
SetText(text);
}
void wiFont::Initialize()
void Initialize()
{
if (initialized)
{
@@ -232,7 +229,7 @@ void wiFont::Initialize()
// add default font if there is none yet:
if (fontStyles.empty())
{
AddFontStyle(FONTPATH + "arial.ttf");
AddFontStyle((FONTPATH + "arial.ttf").c_str());
}
GraphicsDevice* device = wiRenderer::GetDevice();
@@ -323,7 +320,7 @@ void wiFont::Initialize()
initialized.store(true);
}
void wiFont::LoadShaders()
void LoadShaders()
{
std::string path = wiRenderer::GetShaderPath();
@@ -454,19 +451,19 @@ void UpdatePendingGlyphs()
}
}
}
const Texture* wiFont::GetAtlas()
const Texture* GetAtlas()
{
return &texture;
}
const std::string& wiFont::GetFontPath()
const std::string& GetFontPath()
{
return FONTPATH;
}
void wiFont::SetFontPath(const std::string& path)
void SetFontPath(const std::string& path)
{
FONTPATH = path;
}
int wiFont::AddFontStyle(const string& fontName)
int AddFontStyle(const std::string& fontName)
{
for (size_t i = 0; i < fontStyles.size(); i++)
{
@@ -482,9 +479,77 @@ int wiFont::AddFontStyle(const string& fontName)
}
void wiFont::Draw(CommandList cmd) const
template<typename T>
int textWidth_internal(const T* text, const wiFontParams& params)
{
if (!initialized.load() || text.length() <= 0)
if (params.style >= (int)fontStyles.size())
{
return 0;
}
int maxWidth = 0;
int currentLineWidth = 0;
size_t i = 0;
while (text[i] != 0)
{
int code = (int)text[i++];
const int32_t hash = glyphhash(code, params.style, params.size);
if (glyph_lookup.count(hash) == 0)
{
// glyph not packed yet, we just continue (it will be added if it is actually rendered)
continue;
}
if (code == '\n')
{
currentLineWidth = 0;
}
else if (code == ' ')
{
currentLineWidth += WHITESPACE_SIZE;
}
else if (code == '\t')
{
currentLineWidth += TAB_SIZE;
}
else
{
const Glyph& glyph = glyph_lookup.at(hash);
currentLineWidth += int((glyph.width + params.spacingX) * params.scaling);
}
maxWidth = std::max(maxWidth, currentLineWidth);
}
return maxWidth;
}
template<typename T>
int textHeight_internal(const T* text, const wiFontParams& params)
{
if (params.style >= (int)fontStyles.size())
{
return 0;
}
int height = LINEBREAK_SIZE;
size_t i = 0;
while (text[i] != 0)
{
int code = (int)text[i++];
if (code == '\n')
{
height += LINEBREAK_SIZE;
}
}
return height;
}
template<typename T>
void Draw_internal(const T* text, size_t text_length, const wiFontParams& params, CommandList cmd)
{
if (!initialized.load())
{
return;
}
@@ -492,25 +557,24 @@ void wiFont::Draw(CommandList cmd) const
wiFontParams newProps = params;
if (params.h_align == WIFALIGN_CENTER)
newProps.posX -= textWidth() / 2;
newProps.posX -= textWidth(text, params) / 2;
else if (params.h_align == WIFALIGN_RIGHT)
newProps.posX -= textWidth();
newProps.posX -= textWidth(text, params);
if (params.v_align == WIFALIGN_CENTER)
newProps.posY -= textHeight() / 2;
newProps.posY -= textHeight(text, params) / 2;
else if (params.v_align == WIFALIGN_BOTTOM)
newProps.posY -= textHeight();
newProps.posY -= textHeight(text, params);
GraphicsDevice* device = wiRenderer::GetDevice();
GraphicsDevice::GPUAllocation mem = device->AllocateGPU(sizeof(FontVertex) * text.length() * 4, cmd);
GraphicsDevice::GPUAllocation mem = device->AllocateGPU(sizeof(FontVertex) * text_length * 4, cmd);
if (!mem.IsValid())
{
return;
}
volatile FontVertex* textBuffer = (volatile FontVertex*)mem.data;
const int quadCount = WriteVertices(textBuffer, text, newProps, style);
const uint32_t quadCount = WriteVertices(textBuffer, text, newProps);
device->EventBegin("Font", cmd);
@@ -532,7 +596,7 @@ void wiFont::Draw(CommandList cmd) const
};
device->BindVertexBuffers(vbs, 0, arraysize(vbs), strides, offsets, cmd);
assert(text.length() * 4 < 65536 && "The index buffer currently only supports so many characters!");
assert(text_length * 4 < 65536 && "The index buffer currently only supports so many characters!");
device->BindIndexBuffer(&indexBuffer, INDEXFORMAT_16BIT, 0, cmd);
FontCB cb;
@@ -565,82 +629,65 @@ void wiFont::Draw(CommandList cmd) const
UpdatePendingGlyphs();
}
int wiFont::textWidth() const
void Draw(const char* text, const wiFontParams& params, CommandList cmd)
{
if (style >= (int)fontStyles.size())
size_t text_length = strlen(text);
if (text_length == 0)
{
return 0;
return;
}
int maxWidth = 0;
int currentLineWidth = 0;
for (auto& code : text)
Draw_internal(text, text_length, params, cmd);
}
void Draw(const wchar_t* text, const wiFontParams& params, CommandList cmd)
{
size_t text_length = wcslen(text);
if (text_length == 0)
{
const int32_t hash = glyphhash(code, style, params.size);
if (glyph_lookup.count(hash) == 0)
{
// glyph not packed yet, we just continue (it will be added if it is actually rendered)
continue;
}
if (code == '\n')
{
currentLineWidth = 0;
}
else if (code == ' ')
{
currentLineWidth += WHITESPACE_SIZE;
}
else if (code == '\t')
{
currentLineWidth += TAB_SIZE;
}
else
{
const Glyph& glyph = glyph_lookup.at(hash);
currentLineWidth += int((glyph.width + params.spacingX) * params.scaling);
}
maxWidth = std::max(maxWidth, currentLineWidth);
return;
}
return maxWidth;
Draw_internal(text, text_length, params, cmd);
}
int wiFont::textHeight() const
void Draw(const string& text, const wiFontParams& params, CommandList cmd)
{
if (style >= (int)fontStyles.size())
{
return 0;
}
int height = LINEBREAK_SIZE;
for(auto& code : text)
{
if (code == '\n')
{
height += LINEBREAK_SIZE;
}
}
return height;
Draw_internal(text.c_str(), text.length(), params, cmd);
}
void Draw(const wstring& text, const wiFontParams& params, CommandList cmd)
{
Draw_internal(text.c_str(), text.length(), params, cmd);
}
void wiFont::SetText(const string& text)
int textWidth(const char* text, const wiFontParams& params)
{
wiHelper::StringConvert(text, this->text);
return textWidth_internal(text, params);
}
void wiFont::SetText(const wstring& text)
int textWidth(const wchar_t* text, const wiFontParams& params)
{
this->text = text;
return textWidth_internal(text, params);
}
wstring wiFont::GetText() const
int textWidth(const string& text, const wiFontParams& params)
{
return text;
return textWidth_internal(text.c_str(), params);
}
string wiFont::GetTextA() const
int textWidth(const wstring& text, const wiFontParams& params)
{
string retval;
wiHelper::StringConvert(this->text, retval);
return retval;
return textWidth_internal(text.c_str(), params);
}
int textHeight(const char* text, const wiFontParams& params)
{
return textHeight_internal(text, params);
}
int textHeight(const wchar_t* text, const wiFontParams& params)
{
return textHeight_internal(text, params);
}
int textHeight(const string& text, const wiFontParams& params)
{
return textHeight_internal(text.c_str(), params);
}
int textHeight(const wstring& text, const wiFontParams& params)
{
return textHeight_internal(text.c_str(), params);
}
}
+20 -22
View File
@@ -27,6 +27,7 @@ struct wiFontParams
wiColor color;
wiColor shadowColor;
int h_wrap = -1; // wrap start in pixels (-1 default for no wrap)
int style = 0;
wiFontParams(int posX = 0, int posY = 0, int size = WIFONTSIZE_DEFAULT, wiFontAlign h_align = WIFALIGN_LEFT, wiFontAlign v_align = WIFALIGN_TOP
, int spacingX = 0, int spacingY = 0, wiColor color = wiColor(255, 255, 255, 255), wiColor shadowColor = wiColor(0,0,0,0))
@@ -34,37 +35,34 @@ struct wiFontParams
{}
};
class wiFont
namespace wiFont
{
public:
static void Initialize();
void Initialize();
static void LoadShaders();
static const wiGraphics::Texture* GetAtlas();
void LoadShaders();
const wiGraphics::Texture* GetAtlas();
// Returns the font directory
static const std::string& GetFontPath();
const std::string& GetFontPath();
// Sets the font directory
static void SetFontPath(const std::string& path);
void SetFontPath(const std::string& path);
// Create a font. Returns fontStyleID that is reusable. If font already exists, just return its ID
static int AddFontStyle(const std::string& fontName);
int AddFontStyle(const std::string& fontName);
std::wstring text;
wiFontParams params;
int style;
void Draw(const char* text, const wiFontParams& params, wiGraphics::CommandList cmd);
void Draw(const wchar_t* text, const wiFontParams& params, wiGraphics::CommandList cmd);
void Draw(const std::string& text, const wiFontParams& params, wiGraphics::CommandList cmd);
void Draw(const std::wstring& text, const wiFontParams& params, wiGraphics::CommandList cmd);
wiFont(const std::string& text = "", wiFontParams params = wiFontParams(), int style = 0);
wiFont(const std::wstring& text, wiFontParams params = wiFontParams(), int style = 0);
void Draw(wiGraphics::CommandList cmd) const;
int textWidth(const char* text, const wiFontParams& params);
int textWidth(const wchar_t* text, const wiFontParams& params);
int textWidth(const std::string& text, const wiFontParams& params);
int textWidth(const std::wstring& text, const wiFontParams& params);
int textWidth() const;
int textHeight() const;
void SetText(const std::string& text);
void SetText(const std::wstring& text);
std::wstring GetText() const;
std::string GetTextA() const;
int textHeight(const char* text, const wiFontParams& params);
int textHeight(const wchar_t* text, const wiFontParams& params);
int textHeight(const std::string& text, const wiFontParams& params);
int textHeight(const std::wstring& text, const wiFontParams& params);
};
+2 -2
View File
@@ -20,7 +20,7 @@
#include "Vector_BindLua.h"
#include "Matrix_BindLua.h"
#include "wiInput_BindLua.h"
#include "wiFont_BindLua.h"
#include "wiSpriteFont_BindLua.h"
#include "wiBackLog_BindLua.h"
#include "wiNetwork_BindLua.h"
#include "wiIntersect_BindLua.h"
@@ -72,7 +72,7 @@ wiLua* wiLua::GetGlobal()
Vector_BindLua::Bind();
Matrix_BindLua::Bind();
wiInput_BindLua::Bind();
wiFont_BindLua::Bind();
wiSpriteFont_BindLua::Bind();
wiBackLog_BindLua::Bind();
wiNetwork_BindLua::Bind();
wiIntersect_BindLua::Bind();
+6 -8
View File
@@ -226,19 +226,17 @@ namespace wiProfiler
}
}
wiFont font;
font.SetText(ss.str());
font.params = wiFontParams(x, y, WIFONTSIZE_DEFAULT, WIFALIGN_LEFT, WIFALIGN_TOP, 0, 0, wiColor(255, 255, 255, 255), wiColor(0, 0, 0, 255));
wiFontParams params = wiFontParams(x, y, WIFONTSIZE_DEFAULT, WIFALIGN_LEFT, WIFALIGN_TOP, 0, 0, wiColor(255, 255, 255, 255), wiColor(0, 0, 0, 255));
wiImageParams fx;
fx.pos.x = (float)font.params.posX;
fx.pos.y = (float)font.params.posY;
fx.siz.x = (float)font.textWidth();
fx.siz.y = (float)font.textHeight();
fx.pos.x = (float)params.posX;
fx.pos.y = (float)params.posY;
fx.siz.x = (float)wiFont::textWidth(ss.str(), params);
fx.siz.y = (float)wiFont::textHeight(ss.str(), params);
fx.color = wiColor(20, 20, 20, 230);
wiImage::Draw(wiTextureHelper::getWhite(), fx, cmd);
font.Draw(cmd);
wiFont::Draw(ss.str(), params, cmd);
}
void SetEnabled(bool value)
+1 -1
View File
@@ -36,7 +36,7 @@ void wiSprite::DrawNormal(CommandList cmd) const
}
}
void wiSprite::FixedUpdate(float speed)
void wiSprite::FixedUpdate()
{
}
+1 -1
View File
@@ -15,7 +15,7 @@ private:
public:
wiSprite(const std::string& newTexture = "", const std::string& newMask = "");
virtual void FixedUpdate(float speed);
virtual void FixedUpdate();
virtual void Update(float dt);
void Draw(wiGraphics::CommandList cmd) const;
void DrawNormal(wiGraphics::CommandList cmd) const;
+48
View File
@@ -0,0 +1,48 @@
#include "wiSpriteFont.h"
#include "wiHelper.h"
using namespace std;
using namespace wiGraphics;
void wiSpriteFont::FixedUpdate()
{
}
void wiSpriteFont::Update(float dt)
{
}
void wiSpriteFont::Draw(CommandList cmd) const
{
wiFont::Draw(text, params, cmd);
}
int wiSpriteFont::textWidth() const
{
return wiFont::textWidth(text, params);
}
int wiSpriteFont::textHeight() const
{
return wiFont::textHeight(text, params);
}
void wiSpriteFont::SetText(const string& value)
{
wiHelper::StringConvert(value, text);
}
void wiSpriteFont::SetText(const wstring& value)
{
text = value;
}
string wiSpriteFont::GetTextA() const
{
string retVal;
wiHelper::StringConvert(text, retVal);
return retVal;
}
const wstring& wiSpriteFont::GetText() const
{
return text;
}
+31
View File
@@ -0,0 +1,31 @@
#pragma once
#include "wiFont.h"
#include <string>
class wiSpriteFont
{
private:
public:
std::wstring text;
wiFontParams params;
wiSpriteFont() = default;
wiSpriteFont(const std::string& value, const wiFontParams& params = wiFontParams()) :params(params)
{
SetText(value);
}
virtual void FixedUpdate();
virtual void Update(float dt);
void Draw(wiGraphics::CommandList cmd) const;
int textWidth() const;
int textHeight() const;
void SetText(const std::string& value);
void SetText(const std::wstring& value);
std::string GetTextA() const;
const std::wstring& GetText() const;
};
@@ -1,40 +1,40 @@
#include "wiFont_BindLua.h"
#include "wiSpriteFont_BindLua.h"
#include "wiFont.h"
#include "CommonInclude.h"
#include "Vector_BindLua.h"
using namespace std;
const char wiFont_BindLua::className[] = "Font";
const char wiSpriteFont_BindLua::className[] = "SpriteFont";
Luna<wiFont_BindLua>::FunctionType wiFont_BindLua::methods[] = {
lunamethod(wiFont_BindLua, GetText),
lunamethod(wiFont_BindLua, SetSize),
lunamethod(wiFont_BindLua, SetPos),
lunamethod(wiFont_BindLua, SetSpacing),
lunamethod(wiFont_BindLua, SetAlign),
lunamethod(wiFont_BindLua, SetColor),
lunamethod(wiFont_BindLua, SetShadowColor),
Luna<wiSpriteFont_BindLua>::FunctionType wiSpriteFont_BindLua::methods[] = {
lunamethod(wiSpriteFont_BindLua, GetText),
lunamethod(wiSpriteFont_BindLua, SetSize),
lunamethod(wiSpriteFont_BindLua, SetPos),
lunamethod(wiSpriteFont_BindLua, SetSpacing),
lunamethod(wiSpriteFont_BindLua, SetAlign),
lunamethod(wiSpriteFont_BindLua, SetColor),
lunamethod(wiSpriteFont_BindLua, SetShadowColor),
lunamethod(wiFont_BindLua, SetStyle),
lunamethod(wiFont_BindLua, SetText),
lunamethod(wiFont_BindLua, GetSize),
lunamethod(wiFont_BindLua, GetPos),
lunamethod(wiFont_BindLua, GetSpacing),
lunamethod(wiFont_BindLua, GetAlign),
lunamethod(wiFont_BindLua, GetColor),
lunamethod(wiFont_BindLua, GetShadowColor),
lunamethod(wiSpriteFont_BindLua, SetStyle),
lunamethod(wiSpriteFont_BindLua, SetText),
lunamethod(wiSpriteFont_BindLua, GetSize),
lunamethod(wiSpriteFont_BindLua, GetPos),
lunamethod(wiSpriteFont_BindLua, GetSpacing),
lunamethod(wiSpriteFont_BindLua, GetAlign),
lunamethod(wiSpriteFont_BindLua, GetColor),
lunamethod(wiSpriteFont_BindLua, GetShadowColor),
{ NULL, NULL }
};
Luna<wiFont_BindLua>::PropertyType wiFont_BindLua::properties[] = {
Luna<wiSpriteFont_BindLua>::PropertyType wiSpriteFont_BindLua::properties[] = {
{ NULL, NULL }
};
wiFont_BindLua::wiFont_BindLua(const wiFont& font) : font(font)
wiSpriteFont_BindLua::wiSpriteFont_BindLua(const wiSpriteFont& font) : font(font)
{
}
wiFont_BindLua::wiFont_BindLua(lua_State* L)
wiSpriteFont_BindLua::wiSpriteFont_BindLua(lua_State* L)
{
int argc = wiLua::SGetArgCount(L);
if (argc > 0)
@@ -45,13 +45,13 @@ wiFont_BindLua::wiFont_BindLua(lua_State* L)
}
int wiFont_BindLua::SetStyle(lua_State* L)
int wiSpriteFont_BindLua::SetStyle(lua_State* L)
{
int argc = wiLua::SGetArgCount(L);
if (argc > 0)
{
string name = wiLua::SGetString(L, 1);
font.style = wiFont::AddFontStyle(name);
font.params.style = wiFont::AddFontStyle(name.c_str());
}
else
{
@@ -59,7 +59,7 @@ int wiFont_BindLua::SetStyle(lua_State* L)
}
return 0;
}
int wiFont_BindLua::SetText(lua_State* L)
int wiSpriteFont_BindLua::SetText(lua_State* L)
{
int argc = wiLua::SGetArgCount(L);
if (argc > 0)
@@ -68,7 +68,7 @@ int wiFont_BindLua::SetText(lua_State* L)
font.SetText("");
return 0;
}
int wiFont_BindLua::SetSize(lua_State* L)
int wiSpriteFont_BindLua::SetSize(lua_State* L)
{
int argc = wiLua::SGetArgCount(L);
if (argc > 0)
@@ -79,7 +79,7 @@ int wiFont_BindLua::SetSize(lua_State* L)
wiLua::SError(L, "SetSize(int size) not enough arguments!");
return 0;
}
int wiFont_BindLua::SetPos(lua_State* L)
int wiSpriteFont_BindLua::SetPos(lua_State* L)
{
int argc = wiLua::SGetArgCount(L);
if (argc > 0)
@@ -97,7 +97,7 @@ int wiFont_BindLua::SetPos(lua_State* L)
wiLua::SError(L, "SetPos(Vector pos) not enough arguments!");
return 0;
}
int wiFont_BindLua::SetSpacing(lua_State* L)
int wiSpriteFont_BindLua::SetSpacing(lua_State* L)
{
int argc = wiLua::SGetArgCount(L);
if (argc > 0)
@@ -115,7 +115,7 @@ int wiFont_BindLua::SetSpacing(lua_State* L)
wiLua::SError(L, "SetSpacing(Vector spacing) not enough arguments!");
return 0;
}
int wiFont_BindLua::SetAlign(lua_State* L)
int wiSpriteFont_BindLua::SetAlign(lua_State* L)
{
int argc = wiLua::SGetArgCount(L);
if (argc > 0)
@@ -130,7 +130,7 @@ int wiFont_BindLua::SetAlign(lua_State* L)
wiLua::SError(L, "SetAlign(WIFALIGN Halign, opt WIFALIGN Valign) not enough arguments!");
return 0;
}
int wiFont_BindLua::SetColor(lua_State* L)
int wiSpriteFont_BindLua::SetColor(lua_State* L)
{
int argc = wiLua::SGetArgCount(L);
if (argc > 0)
@@ -152,7 +152,7 @@ int wiFont_BindLua::SetColor(lua_State* L)
wiLua::SError(L, "SetColor(Vector value) not enough arguments!");
return 0;
}
int wiFont_BindLua::SetShadowColor(lua_State* L)
int wiSpriteFont_BindLua::SetShadowColor(lua_State* L)
{
int argc = wiLua::SGetArgCount(L);
if (argc > 0)
@@ -175,50 +175,50 @@ int wiFont_BindLua::SetShadowColor(lua_State* L)
return 0;
}
int wiFont_BindLua::GetText(lua_State* L)
int wiSpriteFont_BindLua::GetText(lua_State* L)
{
wiLua::SSetString(L, font.GetTextA());
return 1;
}
int wiFont_BindLua::GetSize(lua_State* L)
int wiSpriteFont_BindLua::GetSize(lua_State* L)
{
wiLua::SSetInt(L, font.params.size);
return 1;
}
int wiFont_BindLua::GetPos(lua_State* L)
int wiSpriteFont_BindLua::GetPos(lua_State* L)
{
Luna<Vector_BindLua>::push(L, new Vector_BindLua(XMVectorSet((float)font.params.posX, (float)font.params.posY, 0, 0)));
return 1;
}
int wiFont_BindLua::GetSpacing(lua_State* L)
int wiSpriteFont_BindLua::GetSpacing(lua_State* L)
{
Luna<Vector_BindLua>::push(L, new Vector_BindLua(XMVectorSet((float)font.params.spacingX, (float)font.params.spacingY, 0, 0)));
return 1;
}
int wiFont_BindLua::GetAlign(lua_State* L)
int wiSpriteFont_BindLua::GetAlign(lua_State* L)
{
wiLua::SSetInt(L, font.params.h_align);
wiLua::SSetInt(L, font.params.v_align);
return 2;
}
int wiFont_BindLua::GetColor(lua_State* L)
int wiSpriteFont_BindLua::GetColor(lua_State* L)
{
Luna<Vector_BindLua>::push(L, new Vector_BindLua(XMLoadFloat4(&font.params.color.toFloat4())));
return 1;
}
int wiFont_BindLua::GetShadowColor(lua_State* L)
int wiSpriteFont_BindLua::GetShadowColor(lua_State* L)
{
Luna<Vector_BindLua>::push(L, new Vector_BindLua(XMLoadFloat4(&font.params.color.toFloat4())));
return 1;
}
void wiFont_BindLua::Bind()
void wiSpriteFont_BindLua::Bind()
{
static bool initialized = false;
if (!initialized)
{
initialized = true;
Luna<wiFont_BindLua>::Register(wiLua::GetGlobal()->GetLuaState());
Luna<wiSpriteFont_BindLua>::Register(wiLua::GetGlobal()->GetLuaState());
wiLua::GetGlobal()->RunText("WIFALIGN_LEFT = 0");
@@ -1,19 +1,19 @@
#pragma once
#include "wiLua.h"
#include "wiLuna.h"
#include "wiFont.h"
#include "wiSpriteFont.h"
class wiFont_BindLua
class wiSpriteFont_BindLua
{
public:
wiFont font;
wiSpriteFont font;
static const char className[];
static Luna<wiFont_BindLua>::FunctionType methods[];
static Luna<wiFont_BindLua>::PropertyType properties[];
static Luna<wiSpriteFont_BindLua>::FunctionType methods[];
static Luna<wiSpriteFont_BindLua>::PropertyType properties[];
wiFont_BindLua(const wiFont& font);
wiFont_BindLua(lua_State* L);
wiSpriteFont_BindLua(const wiSpriteFont& font);
wiSpriteFont_BindLua(lua_State* L);
int SetStyle(lua_State* L);
int SetText(lua_State* L);
+2 -2
View File
@@ -7,9 +7,9 @@ namespace wiVersion
// main engine core
const int major = 0;
// minor features, major updates
const int minor = 39;
const int minor = 40;
// minor bug fixes, alterations, refactors, updates
const int revision = 80;
const int revision = 0;
const std::string version_string = std::to_string(major) + "." + std::to_string(minor) + "." + std::to_string(revision);
+8 -8
View File
@@ -101,7 +101,7 @@ void wiWidget::RenderTooltip(const wiGUI* gui, CommandList cmd) const
}
wiFontParams fontProps = wiFontParams((int)tooltipPos.x, (int)tooltipPos.y, WIFONTSIZE_DEFAULT, WIFALIGN_LEFT, WIFALIGN_TOP);
fontProps.color = wiColor(25, 25, 25, 255);
wiFont tooltipFont = wiFont(tooltip, fontProps);
wiSpriteFont tooltipFont = wiSpriteFont(tooltip, fontProps);
if (!scriptTip.empty())
{
tooltipFont.SetText(tooltip + "\n" + scriptTip);
@@ -460,7 +460,7 @@ void wiLabel::Render(const wiGUI* gui, CommandList cmd) const
wiFont wiTextInputField::font_input;
wiSpriteFont wiTextInputField::font_input;
wiTextInputField::wiTextInputField(const std::string& name)
{
SetName(name);
@@ -1226,8 +1226,8 @@ void wiComboBox::Render(const wiGUI* gui, CommandList cmd) const
if (selected >= 0)
{
wiFont(items[selected], wiFontParams((int)(translation.x + scale.x*0.5f), (int)(translation.y + scale.y*0.5f), WIFONTSIZE_DEFAULT, WIFALIGN_CENTER, WIFALIGN_CENTER, 0, 0,
font.params.color, font.params.shadowColor)).Draw(cmd);
wiFont::Draw(items[selected], wiFontParams((int)(translation.x + scale.x*0.5f), (int)(translation.y + scale.y*0.5f), WIFONTSIZE_DEFAULT, WIFALIGN_CENTER, WIFALIGN_CENTER, 0, 0,
font.params.color, font.params.shadowColor), cmd);
}
// drop-down
@@ -1293,8 +1293,8 @@ void wiComboBox::Render(const wiGUI* gui, CommandList cmd) const
}
}
wiImage::Draw(wiTextureHelper::getWhite(), fx, cmd);
wiFont(items[i], wiFontParams((int)(translation.x + scale.x*0.5f), (int)(translation.y + scale.y*0.5f + GetItemOffset(i)), WIFONTSIZE_DEFAULT, WIFALIGN_CENTER, WIFALIGN_CENTER, 0, 0,
font.params.color, font.params.shadowColor)).Draw(cmd);
wiFont::Draw(items[i], wiFontParams((int)(translation.x + scale.x*0.5f), (int)(translation.y + scale.y*0.5f + GetItemOffset(i)), WIFONTSIZE_DEFAULT, WIFALIGN_CENTER, WIFALIGN_CENTER, 0, 0,
font.params.color, font.params.shadowColor), cmd);
}
}
}
@@ -2829,8 +2829,8 @@ void wiTreeList::Render(const wiGUI* gui, CommandList cmd) const
}
// Item name text:
wiFont(item.name, wiFontParams((int)name_box.pos.x + 1, (int)(name_box.pos.y + name_box.siz.y * 0.5f), WIFONTSIZE_DEFAULT, WIFALIGN_LEFT, WIFALIGN_CENTER, 0, 0,
font.params.color, font.params.shadowColor)).Draw(cmd);
wiFont::Draw(item.name, wiFontParams((int)name_box.pos.x + 1, (int)(name_box.pos.y + name_box.siz.y * 0.5f), WIFONTSIZE_DEFAULT, WIFALIGN_LEFT, WIFALIGN_CENTER, 0, 0,
font.params.color, font.params.shadowColor), cmd);
}
}
void wiTreeList::OnSelect(function<void(wiEventArgs args)> func)
+4 -4
View File
@@ -5,8 +5,8 @@
#include "wiGraphicsDevice.h"
#include "wiIntersect.h"
#include "wiScene.h"
#include "wiFont.h"
#include "wiSprite.h"
#include "wiSpriteFont.h"
#include <string>
#include <list>
@@ -77,7 +77,7 @@ public:
virtual void RenderTooltip(const wiGUI* gui, wiGraphics::CommandList cmd) const;
wiSprite sprites[WIDGETSTATE_COUNT];
wiFont font;
wiSpriteFont font;
XMFLOAT3 translation = XMFLOAT3(0, 0, 0);
XMFLOAT3 scale = XMFLOAT3(1, 1, 1);
@@ -127,13 +127,13 @@ class wiTextInputField : public wiWidget
{
protected:
std::function<void(wiEventArgs args)> onInputAccepted;
static wiFont font_input;
static wiSpriteFont font_input;
public:
wiTextInputField(const std::string& name = "");
virtual ~wiTextInputField();
wiFont font_description;
wiSpriteFont font_description;
void SetValue(const std::string& newValue);
void SetValue(int newValue);
+1 -1
View File
@@ -411,7 +411,7 @@ runProcess(function()
path.SetLightShaftsEnabled(true)
main.SetActivePath(path)
local font = Font("This script is showcasing how to perform scene collision with raycasts for character and camera.\nControls:\n#####################\n\nWASD/arrows/left analog stick: walk\nSHIFT/right shoulder button: movement speed\nSPACE/gamepad X/gamepad button 2: Jump\nRight Mouse Button/Right thumbstick: rotate camera\nScoll middle mouse/Left-Right triggers: adjust camera distance\nESCAPE key: quit\nR: reload script");
local font = SpriteFont("This script is showcasing how to perform scene collision with raycasts for character and camera.\nControls:\n#####################\n\nWASD/arrows/left analog stick: walk\nSHIFT/right shoulder button: movement speed\nSPACE/gamepad X/gamepad button 2: Jump\nRight Mouse Button/Right thumbstick: rotate camera\nScoll middle mouse/Left-Right triggers: adjust camera distance\nESCAPE key: quit\nR: reload script");
font.SetSize(24)
font.SetPos(Vector(10, GetScreenHeight() - 10))
font.SetAlign(WIFALIGN_LEFT, WIFALIGN_BOTTOM)
+2 -2
View File
@@ -1945,7 +1945,7 @@ runProcess(function()
help_text = help_text .. "\n\nCombos:"
help_text = help_text .. "\n\t Revolver action: A, B, C, D (Hit action buttons in quick succession)"
help_text = help_text .. "\n\t Airborne heat: 2B, 8, 8C (Uppercut, then jump cancel into Air Kick)"
local font = Font(help_text);
local font = SpriteFont(help_text);
font.SetSize(20)
font.SetPos(Vector(10, GetScreenHeight() - 10))
font.SetAlign(WIFALIGN_LEFT, WIFALIGN_BOTTOM)
@@ -1953,7 +1953,7 @@ runProcess(function()
font.SetShadowColor(Vector(0,0,0,1))
path.AddFont(font)
local info = Font("");
local info = SpriteFont("");
info.SetSize(24)
info.SetPos(Vector(GetScreenWidth() / 2.5, GetScreenHeight() - 10))
info.SetAlign(WIFALIGN_LEFT, WIFALIGN_BOTTOM)