Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Made the demo thingy properly center text. #7

Merged
merged 3 commits into from
Jun 10, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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);
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

much nicer thx :)

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(just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P_OBJ_NEW_QSTR(MP_QSTR_BTN_MID), MP_OBJ_NEW_SMALL_INT(BADGE_BUTTON_MID)},
{MP_OBJ_NEW_QSTR(MP_QSTR_BTN_A), MP_OBJ_NEW_SMALL_INT(BADGE_BUTTON_A)},
{MP_OBJ_NEW_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},
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

are we implementing some API here or do we decide for ourselves what needs to be exposed?

in any case the current implementation is ugly so removing the function altogether seems like an improvement to me, would appreciate a second set of eyes :)


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

Expand Down