Skip to content

Commit 033ac95

Browse files
committed
Update
1 parent f302448 commit 033ac95

File tree

13 files changed

+89
-27
lines changed

13 files changed

+89
-27
lines changed

examples/benchmark/sprite.png

-1.08 KB
Loading

examples/simple/conf.chai

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
/**
2+
* ChaiLove callback; Configure the application.
3+
*/
4+
def conf(t) {
5+
t.window.width = 400
6+
t.window.height = 300
7+
}

examples/simple/main.chai

+2-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,8 @@ def load() {
1111
}
1212

1313
def draw() {
14-
love.graphics.print("Congrats! You created your first ChaiLove application!", 120, 230)
14+
love.graphics.print("Congrats!", 170, 150)
15+
love.graphics.print("You created your first ChaiLove application!", 30, 170)
1516
love.graphics.draw(logo, x, y)
1617
}
1718

src/ChaiLove.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ bool ChaiLove::load(const std::string& file, const void* data, unsigned int data
8888
// Load up the window dimensions.
8989
window.load(app, config);
9090

91-
graphics.load();
91+
graphics.load(app);
9292
image.load();
9393
keyboard.load();
9494
joystick.load(app);

src/love/Types/Graphics/Font.cpp

+10
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,16 @@ Font::Font() {
1212
font = pntr_load_font_default();
1313
}
1414

15+
Font::Font(int size) {
16+
font = pntr_load_font_default();
17+
if (font != NULL) {
18+
float scale = (float)size / 8.0f;
19+
pntr_font* newFont = pntr_font_scale(font, scale, scale, PNTR_FILTER_NEARESTNEIGHBOR);
20+
pntr_unload_font(font);
21+
font = newFont;
22+
}
23+
}
24+
1525
Font::Font(const std::string& filename, int glyphWidth, int glyphHeight, const std::string& letters) {
1626
font = pntr_load_font_tty(filename.c_str(), glyphWidth, glyphHeight, letters.c_str());
1727
}

src/love/Types/Graphics/Font.h

+1
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ namespace Graphics {
1616
class Font {
1717
public:
1818
Font();
19+
Font(int size);
1920
Font(const std::string& filename, int glyphWidth, int glyphHeight, const std::string& letters);
2021
Font(const std::string& filename, int ptsize);
2122
~Font();

src/love/graphics.cpp

+48-18
Original file line numberDiff line numberDiff line change
@@ -18,20 +18,22 @@ graphics::graphics() {
1818
}
1919

2020
pntr_image* graphics::getScreen() {
21-
if (ChaiLove::hasInstance()) {
22-
return ChaiLove::getInstance()->screen;
21+
if (m_app != NULL) {
22+
return m_app->screen;
2323
}
2424
return NULL;
2525
}
2626

27-
bool graphics::load() {
27+
bool graphics::load(pntr_app* app) {
2828
// Set the default font.
2929
graphics::setFont();
3030

3131
// Match the default colors of Love2D
3232
color_back = pntr_new_color(0, 0, 0, 255); // Black
3333
color_front = pntr_new_color(255, 255, 255, 255); // White
3434

35+
m_app = app;
36+
3537
return true;
3638
}
3739

@@ -229,18 +231,10 @@ std::string graphics::getDefaultFilter() {
229231

230232

231233
int graphics::getWidth() {
232-
pntr_image* screen = getScreen();
233-
if (screen != NULL) {
234-
return screen->width;
235-
}
236-
return 800;
234+
return pntr_app_width(m_app);
237235
}
238236
int graphics::getHeight() {
239-
pntr_image* screen = getScreen();
240-
if (screen != NULL) {
241-
return screen->height;
242-
}
243-
return 600;
237+
return pntr_app_height(m_app);
244238
}
245239

246240
Point graphics::getDimensions() {
@@ -278,23 +272,59 @@ graphics& graphics::ellipse(const std::string& drawmode, int x, int y, int radiu
278272
}
279273

280274
Font* graphics::newFont(const std::string& filename, int glyphWidth, int glyphHeight, const std::string& letters) {
281-
return new Font(filename, glyphWidth, glyphHeight, letters);
275+
Font* font = new Font(filename, glyphWidth, glyphHeight, letters);
276+
if (font->loaded()) {
277+
return font;
278+
}
279+
280+
delete font;
281+
return NULL;
282282
}
283283

284284
Font* graphics::newFont(const std::string& filename, int size) {
285-
return new Font(filename, size);
285+
Font* font = new Font(filename, size);
286+
if (font->loaded()) {
287+
return font;
288+
}
289+
290+
delete font;
291+
return NULL;
286292
}
287293

288294
Font* graphics::newFont(const std::string& filename) {
289-
return new Font(filename, 12);
295+
Font* font = new Font(filename, 16);
296+
if (font->loaded()) {
297+
return font;
298+
}
299+
300+
delete font;
301+
return NULL;
290302
}
291303

292304
Font* graphics::newFont() {
293-
return new Font();
305+
Font* font = new Font();
306+
if (font->loaded()) {
307+
return font;
308+
}
309+
310+
delete font;
311+
return NULL;
312+
}
313+
314+
Font* graphics::newFont(int size) {
315+
Font* font = new Font(size);
316+
if (font->loaded()) {
317+
return font;
318+
}
319+
320+
delete font;
321+
return NULL;
294322
}
295323

296324
graphics& graphics::setFont(Font* font) {
297-
activeFont = font;
325+
if (font != NULL) {
326+
activeFont = font;
327+
}
298328
return *this;
299329
}
300330

src/love/graphics.h

+14-2
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
#include <vector>
55

66
#include "pntr_app.h"
7+
#include "config.h"
78
#include "Types/Graphics/Image.h"
89
#include "Types/Graphics/Quad.h"
910
#include "Types/Graphics/Font.h"
@@ -24,7 +25,7 @@ namespace love {
2425
class graphics {
2526
public:
2627
graphics();
27-
bool load();
28+
bool load(pntr_app* app);
2829

2930
/**
3031
* Draws a rectangle.
@@ -108,12 +109,21 @@ class graphics {
108109
* Creates a new TrueType font, with the given font size.
109110
*
110111
* @param filename (default) The path to the TrueType .ttf font. When not provided, will return the default font.
111-
* @param size (12) The size of the font to create.
112+
* @param size (16) The size of the font to create.
112113
*
113114
* @return The created TrueType font.
114115
*/
115116
Font* newFont(const std::string& filename, int size);
116117
Font* newFont(const std::string& filename);
118+
119+
/**
120+
* Creates a new pixel font at the given size.
121+
*
122+
* @param size (8) The size of the font to create.
123+
*
124+
* @return The created Pixel font.
125+
*/
126+
Font* newFont(int size);
117127
Font* newFont();
118128

119129
/**
@@ -308,6 +318,8 @@ class graphics {
308318
Font defaultFont;
309319

310320
int m_smooth = 1;
321+
322+
pntr_app* m_app = NULL;
311323
};
312324

313325
} // namespace love

src/love/script.cpp

+1
Original file line numberDiff line numberDiff line change
@@ -303,6 +303,7 @@ script::script(const std::string& file) {
303303
chai.add(fun<Font*, graphics, const std::string&, int>(&graphics::newFont), "newFont");
304304
chai.add(fun<Font*, graphics, const std::string&>(&graphics::newFont), "newFont");
305305
chai.add(fun<Font*, graphics, const std::string&, int, int, const std::string&>(&graphics::newFont), "newFont");
306+
chai.add(fun<Font*, graphics, int>(&graphics::newFont), "newFont");
306307
chai.add(fun<Font*, graphics>(&graphics::newFont), "newFont");
307308
chai.add(fun<love::graphics&, graphics, Font*>(&graphics::setFont), "setFont");
308309
chai.add(fun<love::graphics&, graphics>(&graphics::setFont), "setFont");

src/main.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -144,8 +144,8 @@ pntr_app Main(int argc, char* argv[]) {
144144
(void)argc;
145145
(void)argv;
146146
return (pntr_app) {
147-
.width = 640,
148-
.height = 480,
147+
.width = 800,
148+
.height = 600,
149149
.title = "ChaiLove",
150150
.init = Init,
151151
.update = Update,

vendor/libretro-common

Submodule libretro-common updated 56 files

0 commit comments

Comments
 (0)