Skip to content

Commit

Permalink
Merge pull request #732 from xtruan/xtruan/eurocorp_menu
Browse files Browse the repository at this point in the history
Eurocorp menu style & exposed 3 more fonts in canvas
  • Loading branch information
RogueMaster committed Aug 16, 2023
2 parents 831dcde + ff1ffd6 commit dbbc65b
Show file tree
Hide file tree
Showing 10 changed files with 206 additions and 50 deletions.
2 changes: 1 addition & 1 deletion applications/external/chess/application.fam
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,6 @@ App(
fap_category="Games",
fap_author="Struan Clark (xtruan)",
fap_weburl="https://github.com/xtruan/flipper-chess",
fap_version=(1, 8),
fap_version=(1, 9),
fap_description="Chess for Flipper",
)
2 changes: 1 addition & 1 deletion applications/external/chess/flipchess.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
#include "views/flipchess_startscreen.h"
#include "views/flipchess_scene_1.h"

#define FLIPCHESS_VERSION "v1.8.0"
#define FLIPCHESS_VERSION "v1.9.0"

#define TEXT_BUFFER_SIZE 96
#define TEXT_SIZE (TEXT_BUFFER_SIZE - 1)
Expand Down
12 changes: 10 additions & 2 deletions applications/external/chess/views/flipchess_startscreen.c
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,18 @@ void flipchess_startscreen_draw(Canvas* canvas, FlipChessStartscreenModel* model

canvas_draw_icon(canvas, 0, 0, &I_FLIPR_128x64);

#ifdef CANVAS_HAS_FONT_SCUMM_ROMAN_OUTLINE
const uint8_t text_x_pos = 2;
const uint8_t text_y_pos = 12;
canvas_set_font(canvas, FontScummRomanOutline);
#else
const uint8_t text_x_pos = 4;
const uint8_t text_y_pos = 11;
canvas_set_font(canvas, FontPrimary);
canvas_draw_str(canvas, 4, 11, "Chess");
#endif
canvas_draw_str(canvas, text_x_pos, text_y_pos, "Chess");
canvas_set_font(canvas, FontSecondary);
canvas_draw_str(canvas, 62, 11, FLIPCHESS_VERSION);
canvas_draw_str(canvas, 62, text_y_pos, FLIPCHESS_VERSION);

//canvas_set_font(canvas, FontSecondary);
//canvas_draw_str(canvas, 10, 11, "How about a nice game of...");
Expand Down
13 changes: 13 additions & 0 deletions applications/services/gui/canvas.c
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,10 @@ const CanvasFontParameters canvas_font_params[FontTotalNumber] = {
[FontKeyboard] = {.leading_default = 11, .leading_min = 9, .height = 7, .descender = 2},
[FontBigNumbers] = {.leading_default = 18, .leading_min = 16, .height = 15, .descender = 0},
[FontBatteryPercent] = {.leading_default = 11, .leading_min = 9, .height = 6, .descender = 0},
[FontScummRomanOutline] =
{.leading_default = 12, .leading_min = 11, .height = 12, .descender = 2},
[FontScummRoman] = {.leading_default = 12, .leading_min = 11, .height = 10, .descender = 2},
[FontEurocorp] = {.leading_default = 12, .leading_min = 11, .height = 16, .descender = 2},
};

Canvas* canvas_init() {
Expand Down Expand Up @@ -161,6 +165,15 @@ void canvas_set_font(Canvas* canvas, Font font) {
case FontBatteryPercent:
u8g2_SetFont(&canvas->fb, u8g2_font_5x7_tf); //u8g2_font_micro_tr);
break;
case FontScummRomanOutline:
u8g2_SetFont(&canvas->fb, u8g2_font_lucasarts_scumm_subtitle_o_tr);
break;
case FontScummRoman:
u8g2_SetFont(&canvas->fb, u8g2_font_lucasarts_scumm_subtitle_r_tr);
break;
case FontEurocorp:
u8g2_SetFont(&canvas->fb, u8g2_font_eurocorp_tr);
break;
default:
furi_crash(NULL);
break;
Expand Down
8 changes: 8 additions & 0 deletions applications/services/gui/canvas.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,21 @@ typedef enum {
ColorXOR = 0x02,
} Color;

/** Provide defines to permit checking if new are fonts available*/
#define CANVAS_HAS_FONT_SCUMM_ROMAN_OUTLINE = 1
#define CANVAS_HAS_FONT_SCUMM_ROMAN = 1
#define CANVAS_HAS_FONT_EUROCORP = 1

/** Fonts enumeration */
typedef enum {
FontPrimary,
FontSecondary,
FontKeyboard,
FontBigNumbers,
FontBatteryPercent,
FontScummRomanOutline,
FontScummRoman,
FontEurocorp,

// Keep last for fonts number calculation
FontTotalNumber,
Expand Down
46 changes: 46 additions & 0 deletions applications/services/gui/modules/menu.c
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,15 @@ static void menu_short_name(MenuItem* item, FuriString* name) {
}
}

static void menu_string_to_upper_case(FuriString* str) {
for(size_t i = 0; i < furi_string_size(str); i++) {
char c = furi_string_get_char(str, i);
if(c >= 'a' && c <= 'z') {
furi_string_set_char(str, i, c - 'a' + 'A');
}
}
}

static void menu_centered_icon(
Canvas* canvas,
MenuItem* item,
Expand Down Expand Up @@ -327,6 +336,41 @@ static void menu_draw_callback(Canvas* canvas, void* _model) {

break;
}
case MenuStyleEurocorp: {
FuriString* name = furi_string_alloc();

for(uint8_t i = 0; i < 3; i++) {
canvas_set_color(canvas, ColorBlack);
#ifdef CANVAS_HAS_FONT_EUROCORP
canvas_set_font(canvas, FontEurocorp);
#else
canvas_set_font(canvas, FontPrimary);
#endif
shift_position = (position + items_count + i - 1) % items_count;
item = MenuItemArray_get(model->items, shift_position);
menu_short_name(item, name);
menu_string_to_upper_case(name);
size_t scroll_counter = menu_scroll_counter(model, i == 1);
if(i == 1) {
canvas_draw_box(canvas, 0, 22, 128, 22);
canvas_set_color(canvas, ColorWhite);
// Clip corner
for(uint8_t i = 0; i < 6; i++) {
for(uint8_t j = 0; j < 6; j++) {
if(j - i >= 0) {
canvas_draw_dot(canvas, 128 - i, 22 + j - i);
}
}
}
}
elements_scrollable_text_line(
canvas, 2, 19 + 22 * i, 128 - 3, name, scroll_counter, false, false);
}

furi_string_free(name);

break;
}
default:
break;
}
Expand Down Expand Up @@ -553,6 +597,7 @@ static void menu_process_up(Menu* menu) {

switch(CFW_SETTINGS()->menu_style) {
case MenuStyleList:
case MenuStyleEurocorp:
if(position > 0) {
position--;
if(vertical_offset && vertical_offset == position) {
Expand Down Expand Up @@ -600,6 +645,7 @@ static void menu_process_down(Menu* menu) {

switch(CFW_SETTINGS()->menu_style) {
case MenuStyleList:
case MenuStyleEurocorp:
if(position < count - 1) {
position++;
if(vertical_offset < count - 8 && vertical_offset == position - 7) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ const char* const menu_style_names[MenuStyleCount] = {
"PS4",
"Vertical",
"C64",
"Eurocorp",
};
static void cfw_app_scene_interface_mainmenu_menu_style_changed(VariableItem* item) {
CfwApp* app = variable_item_get_context(item);
Expand Down
1 change: 1 addition & 0 deletions lib/cfw/cfw.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ typedef enum {
MenuStylePs4,
MenuStyleVertical,
MenuStyleC64,
MenuStyleEurocorp,
MenuStyleCount,
} MenuStyle;

Expand Down
1 change: 1 addition & 0 deletions lib/u8g2/u8g2.h
Original file line number Diff line number Diff line change
Expand Up @@ -5813,6 +5813,7 @@ extern const uint8_t u8g2_font_px437wyse700b_tn[] U8G2_FONT_SECTION("u8g2_font_p
extern const uint8_t u8g2_font_px437wyse700b_mf[] U8G2_FONT_SECTION("u8g2_font_px437wyse700b_mf");
extern const uint8_t u8g2_font_px437wyse700b_mr[] U8G2_FONT_SECTION("u8g2_font_px437wyse700b_mr");
extern const uint8_t u8g2_font_px437wyse700b_mn[] U8G2_FONT_SECTION("u8g2_font_px437wyse700b_mn");
extern const uint8_t u8g2_font_eurocorp_tr[] U8G2_FONT_SECTION("u8g2_font_eurocorp_tr");

/* end font list */

Expand Down

0 comments on commit dbbc65b

Please sign in to comment.