Skip to content

Commit

Permalink
Merge pull request #7 from Peetz0r/demo-centered
Browse files Browse the repository at this point in the history
Made the demo thingy properly center text.
  • Loading branch information
raboof authored Jun 10, 2017
2 parents 74e0643 + 64bf344 commit 385ff98
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 55 deletions.
1 change: 1 addition & 0 deletions esp32/PermanentMarker36.c
91 changes: 36 additions & 55 deletions esp32/modugfx.c
Original file line number Diff line number Diff line change
Expand Up @@ -36,25 +36,19 @@

#ifndef UNIX
#include "board_framebuffer.h"
#include "ginput_lld_toggle_config.h"
#endif

#include "gfx.h"
#include "gfxconf.h"
#include "ginput_lld_toggle_config.h"

#include "py/mperrno.h"
#include "py/mphal.h"
#include "py/runtime.h"

const char *font_list[] = {"Roboto-Black22", "Roboto-BlackItalic24",
"Roboto-Regular12", "Roboto-Regular18",
"Roboto-Regular22", "PermanentMarker22"};

typedef struct _ugfx_obj_t { mp_obj_base_t base; } ugfx_obj_t;

STATIC mp_obj_t ugfx_init(void) {
// gwinSetDefaultFont(gdispOpenFont(font_list[0]));
// gwinSetDefaultStyle(&WhiteWidgetStyle, FALSE);
gfxInit();
return mp_const_none;
}
Expand All @@ -66,14 +60,6 @@ STATIC mp_obj_t ugfx_deinit(void) {
}
STATIC MP_DEFINE_CONST_FUN_OBJ_0(ugfx_deinit_obj, ugfx_deinit);

/// \method print_fonts()
///
/// Prints the list of installed fonts
///
STATIC mp_obj_t ugfx_print_fonts(void) {
return mp_obj_new_list(6, (void **)font_list);
}
STATIC MP_DEFINE_CONST_FUN_OBJ_0(ugfx_print_fonts_obj, ugfx_print_fonts);

// PRIMITIVES

Expand Down Expand Up @@ -559,34 +545,28 @@ STATIC mp_obj_t ugfx_demo(mp_obj_t hacking) {
font_t permanentMarker;

robotoBlackItalic = gdispOpenFont("Roboto_BlackItalic24");
permanentMarker = gdispOpenFont("PermanentMarker22");
permanentMarker = gdispOpenFont("PermanentMarker36");

uint16_t hackingWidth = gdispGetStringWidth(mp_obj_str_get_str(hacking), permanentMarker);

gdispClear(White);
gdispDrawString(150, 25, "STILL", robotoBlackItalic, Black);
gdispDrawString(130, 50, mp_obj_str_get_str(hacking), permanentMarker, Black);
gdispDrawStringBox(0, 6, 296, 40, "STILL", robotoBlackItalic, Black, justifyCenter);
gdispDrawStringBox(0, 42, 276, 40, mp_obj_str_get_str(hacking), permanentMarker, Black, justifyCenter);
// underline:
gdispDrawLine(
127 + 3, 50 + 22,
127 + 3 +
gdispGetStringWidth(mp_obj_str_get_str(hacking), permanentMarker) +
14,
50 + 22, Black);
296/2 - hackingWidth/2 - 14,
42 + 36 + 2,
296/2 + hackingWidth/2 + 14,
42 + 36 + 2,
Black);
// cursor:
gdispDrawLine(
127 + 3 +
gdispGetStringWidth(mp_obj_str_get_str(hacking), permanentMarker) +
10,
50 + 2,
127 + 3 +
gdispGetStringWidth(mp_obj_str_get_str(hacking), permanentMarker) +
10,
50 + 22 - 2, Black);
gdispDrawString(140, 75, "Anyway", robotoBlackItalic, Black);
gdispFillCircle(60, 60, 50, Black);
gdispFillCircle(60, 60, 40, White);
gdispFillCircle(60, 60, 30, Black);
gdispFillCircle(60, 60, 20, White);
gdispFillCircle(60, 60, 10, Black);
276/2 + hackingWidth/2 + 2 + 3,
42 + 4,
276/2 + hackingWidth/2 + 2,
42 + 36,
Black);
gdispDrawStringBox(0, 82, 296, 40, "Anyway", robotoBlackItalic, Black, justifyCenter);
gdispFlush();

return mp_const_none;
Expand All @@ -609,22 +589,25 @@ STATIC const mp_rom_map_elem_t ugfx_module_globals_table[] = {
MP_OBJ_NEW_SMALL_INT(justifyCenter)},
{MP_OBJ_NEW_QSTR(MP_QSTR_justifyRight), MP_OBJ_NEW_SMALL_INT(justifyRight)},

{MP_OBJ_NEW_QSTR(MP_QSTR_JOY_UP), MP_OBJ_NEW_SMALL_INT(BADGE_BUTTON_UP)},
{MP_OBJ_NEW_QSTR(MP_QSTR_JOY_DOWN),
MP_OBJ_NEW_SMALL_INT(BADGE_BUTTON_DOW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_QSTR(MP_QSTR_BTN_B), MP_OBJ_NEW_SMALL_INT(BADGE_BUTTON_B)},
{MP_OBJ_NEW_QSTR(MP_QSTR_BTN_SELECT),
MP_OBJ_NEW_SMALL_INT(BADGE_BUTTON_SELECT)},
{MP_OBJ_NEW_QSTR(MP_QSTR_BTN_START),
MP_OBJ_NEW_SMALL_INT(BADGE_BUTTON_START)},
{MP_OBJ_NEW_QSTR(MP_QSTR_BTN_FLASH),
MP_OBJ_NEW_SMALL_INT(BADGE_BUTTON_FLASH)},
#endif


{MP_OBJ_NEW_QSTR(MP_QSTR_clear), (mp_obj_t)&ugfx_clear_obj},
{MP_OBJ_NEW_QSTR(MP_QSTR_flush), (mp_obj_t)&ugfx_flush_obj},
Expand Down Expand Up @@ -655,8 +638,6 @@ STATIC const mp_rom_map_elem_t ugfx_module_globals_table[] = {
{MP_OBJ_NEW_QSTR(MP_QSTR_polygon), (mp_obj_t)&ugfx_polygon_obj},
{MP_OBJ_NEW_QSTR(MP_QSTR_fill_polygon), (mp_obj_t)&ugfx_fill_polygon_obj},

{MP_OBJ_NEW_QSTR(MP_QSTR_print_fonts), (mp_obj_t)&ugfx_print_fonts_obj},

{MP_OBJ_NEW_QSTR(MP_QSTR_demo), (mp_obj_t)&ugfx_demo_obj},
};

Expand Down

0 comments on commit 385ff98

Please sign in to comment.