Skip to content

Commit

Permalink
Linux version now works
Browse files Browse the repository at this point in the history
  • Loading branch information
sam-astro committed Jan 16, 2022
1 parent ebc3954 commit f537cf4
Show file tree
Hide file tree
Showing 34 changed files with 3,604 additions and 11 deletions.
2 changes: 1 addition & 1 deletion Slang/Main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
#include <iostream>
#include <fstream>
#include <string>
#define DEVELOPER_MESSAGES true
#define DEVELOPER_MESSAGES false
#define EXAMPLE_PROJECT false

#if defined(__unix__)
Expand Down
2 changes: 1 addition & 1 deletion Slang/builtin.h
Original file line number Diff line number Diff line change
Expand Up @@ -288,7 +288,7 @@ boost::any SLBFunction(const string& name, const vector<boost::any>& args)
any_cast<Sprite>(args[0]).Load();
else if (name == "SLB.Graphics.Text")
{
Text t(StringRaw(AnyAsString(args[0])), StringRaw(AnyAsString(args[1])), any_cast<Vec2>(args[2]), AnyAsFloat(args[3]), AnyAsFloat(args[4]), AnyAsInt(args[5]), AnyAsInt(args[6]), AnyAsInt(args[7]));
Text t(StringRaw(AnyAsString(args[0])), StringRaw(AnyAsString(args[1])), any_cast<Vec2>(args[2]), AnyAsFloat(args[3]), AnyAsFloat(args[4]), (Uint8)AnyAsFloat(args[5]), (Uint8)AnyAsFloat(args[6]), (Uint8)AnyAsFloat(args[7]));
return t;
}
else if (name == "SLB.Graphics.DrawText")
Expand Down
21 changes: 12 additions & 9 deletions Slang/graphics.h
Original file line number Diff line number Diff line change
Expand Up @@ -516,24 +516,27 @@ class Sprite
class Text
{
public:
Text(std::string content, std::string pathToFont, Vec2 position, float fontSize, double angle, int r, int g, int b)
Text(std::string content, std::string pathToFont, Vec2 position, float fontSize, double angle, Uint8 r, Uint8 g, Uint8 b)
: position(position), angle(angle), content(content), pathToFont(pathToFont), fontSize(fontSize), r(r), g(g), b(b)
{
rect.x = position.x;
rect.y = position.y;

font = TTF_OpenFont(pathToFont.c_str(), fontSize);

Load();
}

int Load()
{
SDL_Color color = { (Uint8)r, (Uint8)g, (Uint8)b };
cout << "Load" << endl;
SDL_Color color = { r, g, b };

SDL_Surface* surface = TTF_RenderText_Solid(font, content.c_str(), color);

SDL_DestroyTexture(texture);

//if(texture != NULL)
// SDL_DestroyTexture(texture);
cout << "Loaded" << endl;
texture = SDL_CreateTextureFromSurface(gRenderer, surface);

TTF_SizeText(font, content.c_str(), &rect.w, &rect.h);
Expand All @@ -551,7 +554,7 @@ class Text

int Update()
{
SDL_Color color = { (Uint8)r, (Uint8)g, (Uint8)b };
SDL_Color color = { r, g, b };

SDL_Surface* surface = TTF_RenderText_Solid(font, content.c_str(), color);

Expand Down Expand Up @@ -715,9 +718,9 @@ class Text
Vec2 scale;
float fontSize;
double angle;
int r;
int g;
int b;
Uint8 r;
Uint8 g;
Uint8 b;
std::string content;
std::string pathToFont;

Expand Down
Loading

0 comments on commit f537cf4

Please sign in to comment.