Fixed draw_string(), font size not ignored anymore on fx9860

This commit is contained in:
mibi88 2022-11-20 15:49:10 +01:00
parent a6fb6122db
commit 2ace52aff9
2 changed files with 43 additions and 7 deletions

View File

@ -38,7 +38,7 @@ UI:
- A decent keymap that can input all relevant characters into the shell
Test cases:
- [ ] Chute tridimensionnelle
- [ ] Chute tridimensionnelle (Memory error on G35+eII)
- [ ] Bad Apple
- [ ] Island of the Dead Kings
- [ ] Synchro-Donjon

View File

@ -9,6 +9,12 @@
#include "py/obj.h"
#include <gint/display.h>
#ifdef FX9860G
extern font_t font_4x4;
extern font_t font_4x6;
extern font_t font_5x7;
#endif
/* TODO: casioplot: Call show_screen() when program finishes */
static color_t get_color(mp_obj_t color)
@ -100,15 +106,45 @@ static mp_obj_t draw_string(size_t n, mp_obj_t const *args)
int y = mp_obj_get_int(args[1]);
size_t text_len;
char const *text = mp_obj_str_get_data(args[2], &text_len);
color_t color = get_color(args[3]);
/* TODO: casioplot: draw_string(): Don't ignore the size parameter */
/* It is normally "small", "medium" or "large" */
/* TODO: casioplot: draw_string(): Add fonts for CG50 */
color_t color;
font_t const *old_font = dfont(NULL);
if(n >= 4) {
color = get_color(args[3]);
}
#ifdef FX9860G
dfont(&font_4x6);
#else
dfont(NULL);
#endif
if(n == 5) {
(void)args[4];
if(MP_QSTR_small == mp_obj_str_get_qstr(args[4])){
#ifdef FX9860G
dfont(&font_4x4);
#else
dfont(NULL);
#endif
}else if(MP_QSTR_medium == mp_obj_str_get_qstr(args[4])){
#ifdef FX9860G
dfont(&font_4x6);
#else
dfont(NULL);
#endif
}else if(MP_QSTR_large == mp_obj_str_get_qstr(args[4])){
#ifdef FX9860G
dfont(&font_5x7);
#else
dfont(NULL);
#endif
}else{
mp_raise_ValueError("Unknown font size");
}
}
if(n < 4) {
color = C_BLACK;
}
font_t const *old_font = dfont(NULL);
dtext_opt(x, y, color, C_NONE, DTEXT_LEFT, DTEXT_TOP, text, text_len);
dfont(old_font);
@ -119,7 +155,7 @@ MP_DEFINE_CONST_FUN_OBJ_0(show_screen_obj, show_screen);
MP_DEFINE_CONST_FUN_OBJ_0(clear_screen_obj, clear_screen);
MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(set_pixel_obj, 2, 3, set_pixel);
MP_DEFINE_CONST_FUN_OBJ_2(get_pixel_obj, get_pixel);
MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(draw_string_obj, 4, 5, draw_string);
MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(draw_string_obj, 3, 5, draw_string);
STATIC const mp_rom_map_elem_t casioplot_module_globals_table[] = {
{ MP_OBJ_NEW_QSTR(MP_QSTR___name__), MP_OBJ_NEW_QSTR(MP_QSTR_casioplot) },