ra8-firmware 0.1.0
Bare-metal firmware for the Renesas RA8 family (RA8D2 / RA8P1)
Loading...
Searching...
No Matches
sh_cover.c
Go to the documentation of this file.
1
18#include "ra8_gfx.h"
19#include "ra8_gfx_font.h"
20#include "sh_app.h"
21
37
39static void sh_cover_button(int32_t y, const char* label)
40{
41 (void)
44 y + ((k_sh_cv_btn_h - (int32_t)k_sh_glyph_h) / 2),
45 label,
47 (uint32_t)k_sh_col_barfg,
48 (uint32_t)k_sh_col_bar);
49}
50
52{
53 (void)ra8_gfx_clear((uint32_t)k_sh_col_bg);
54 sh_titlebar("< Library", nullptr);
56 const sh_entry_t* e = &g_sh.entry[g_sh.selected];
57 char buf[k_sh_linebuf];
58 const int32_t panel_w = (int32_t)k_sh_fb_w - k_sh_cv_panel_x - (int32_t)k_sh_pad;
59 sh_fit(buf, sizeof buf, e->title, sh_cells(panel_w));
62 buf,
64 (uint32_t)k_sh_col_card,
65 (uint32_t)k_sh_col_bg);
66 sh_fit(buf, sizeof buf, e->author, sh_cells(panel_w));
69 buf,
71 (uint32_t)k_sh_col_sub,
72 (uint32_t)k_sh_col_bg);
73
76 e->from_sd ? "Source: SD card" : "Source: baked (MRAM)",
78 (uint32_t)k_sh_col_sub,
79 (uint32_t)k_sh_col_bg);
80
81 sh_cover_button(k_sh_cv_read_y, "Read this book");
82 sh_cover_button(k_sh_cv_toc_y, "Table of Contents");
83}
84
86static bool sh_in_rect(int32_t x, int32_t y, int32_t rx, int32_t ry, int32_t rw, int32_t rh)
87{
88 return (x >= rx) && (x < (rx + rw)) && (y >= ry) && (y < (ry + rh));
89}
90
102
103bool sh_cover_loupe_map(int32_t px, int32_t py, int32_t* out_cx, int32_t* out_cy)
104{
105 if (g_sh.open_fmt != k_sh_fmt_rabook) {
106 return false; /* EPUB covers are decoded rasters, not the gray4 image pool */
107 }
108 const uint32_t cover = g_sh.book_src.hdr.cover_image_index;
109 if ((g_sh.book_src.vm == nullptr) || (cover == k_book_nil)) {
110 return false;
111 }
112 return sh_image_loupe_map(&g_sh.book_src,
113 cover,
118 px,
119 py,
120 out_cx,
121 out_cy);
122}
123
125{
126 if ((g_sh.open_fmt != k_sh_fmt_rabook) || (g_sh.book_src.vm == nullptr)) {
127 return;
128 }
129 const uint32_t cover = g_sh.book_src.hdr.cover_image_index;
130 if (cover == k_book_nil) {
131 return;
132 }
133 const int32_t dx = ((int32_t)k_sh_fb_w - (int32_t)k_sh_loupe_w) / 2;
134 const int32_t dy = ((int32_t)k_sh_fb_h - (int32_t)k_sh_loupe_h) / 2;
135 (void)sh_image_loupe(&g_sh.book_src, cover, g_sh.loupe_cx, g_sh.loupe_cy, dx, dy);
136}
@ k_book_nil
Absent index / "applies to all chapters".
Definition book.h:129
Software 2D graphics primitives layered on top of a caller-ownedframebuffer (DRW / D/AVE 2D / GLCDC r...
ra8_err_t ra8_gfx_clear(uint32_t color)
Fill the bound framebuffer's clip region with a single colour.
ra8_err_t ra8_gfx_text_out(int32_t x, int32_t y, const char *str, const ra8_gfx_font_t *font, uint32_t fg_color, uint32_t bg_color)
Render a NUL-terminated ASCII string.
ra8_err_t ra8_gfx_rect(int32_t x, int32_t y, int32_t w, int32_t h, uint32_t color, bool filled)
Draw an axis-aligned rectangle.
Bitmap font descriptor + bundled font handles for ra8_gfx.
const ra8_gfx_font_t ra8_gfx_font_8x16
Bundled 8x16 IBM PC VGA bitmap font, ASCII 0x20..0x7E.
Shared contract for the ereader_shelf multi-screen e-reader.
void sh_book_cover_fullscreen(int32_t x, int32_t y, int32_t w, int32_t h)
Draw the open book's cover full-size, aspect-fit into the box.
Definition sh_book.c:341
int32_t sh_cells(int32_t pixels)
Cells of the 8px bitmap font that fit in pixels.
Definition sh_util.c:28
void sh_titlebar(const char *title, const char *right)
Fill the header bar and draw title left + optional right text.
Definition sh_util.c:76
@ k_sh_loupe_w
Lens window width in framebuffer pixels.
Definition sh_app.h:85
@ k_sh_loupe_h
Lens window height in framebuffer pixels.
Definition sh_app.h:86
bool sh_image_loupe_map(const book_src_t *src, uint32_t img_idx, int32_t box_x, int32_t box_y, int32_t box_w, int32_t box_h, int32_t px, int32_t py, int32_t *out_cx, int32_t *out_cy)
Map a framebuffer touch point over an aspect-fit image box to full-resolution source coordinates (lou...
Definition sh_image.c:305
@ k_sh_glyph_h
Bitmap font cell height.
Definition sh_app.h:49
@ k_sh_fb_h
Panel height in pixels.
Definition sh_app.h:47
@ k_sh_pad
Outer margin / content inset.
Definition sh_app.h:52
@ k_sh_linebuf
Per-line draw buffer bytes.
Definition sh_app.h:59
@ k_sh_fb_w
Panel width in pixels.
Definition sh_app.h:46
ra8_err_t sh_image_loupe(const book_src_t *src, uint32_t img_idx, int32_t src_cx, int32_t src_cy, int32_t dst_x, int32_t dst_y)
Draw the magnifier loupe: a k_sh_loupe_zoom-magnified 1:1 window of a full-resolution 4bpp source ima...
Definition sh_image.c:273
sh_cover_act_t
Result of a tap on the cover screen.
Definition sh_app.h:446
@ k_sh_cover_read
Open the reader at chapter 0.
Definition sh_app.h:448
@ k_sh_cover_none
Tap hit nothing actionable.
Definition sh_app.h:447
@ k_sh_cover_toc
Open the table of contents.
Definition sh_app.h:449
sh_state_t g_sh
The single whole-app state instance (defined in main.c).
Definition main.c:64
void sh_fit(char *dst, size_t cap, const char *src, int32_t max_chars)
Copy src into dst (cap bytes), truncating past max_chars with "..".
Definition sh_util.c:33
@ k_sh_col_barfg
Text on the bar.
Definition sh_app.h:106
@ k_sh_col_bg
App background (dark wood).
Definition sh_app.h:98
@ k_sh_col_card
Card / page fill (paper).
Definition sh_app.h:100
@ k_sh_col_sub
Secondary ink (author / hints).
Definition sh_app.h:103
@ k_sh_col_bar
Header / title-bar fill.
Definition sh_app.h:99
@ k_sh_fmt_rabook
book RBKC container (demand-paged chunks).
Definition sh_classify.h:38
sh_cover_layout_t
Cover-page geometry (framebuffer pixels).
Definition sh_cover.c:23
@ k_sh_cv_toc_y
"Contents" button top.
Definition sh_cover.c:34
@ k_sh_cv_title_y
Title baseline.
Definition sh_cover.c:29
@ k_sh_cv_box_y
Cover box top.
Definition sh_cover.c:25
@ k_sh_cv_btn_pad
Button text inset.
Definition sh_cover.c:35
@ k_sh_cv_panel_x
Right text panel left.
Definition sh_cover.c:28
@ k_sh_cv_btn_h
Action button height.
Definition sh_cover.c:32
@ k_sh_cv_auth_y
Author baseline.
Definition sh_cover.c:30
@ k_sh_cv_box_x
Cover box left.
Definition sh_cover.c:24
@ k_sh_cv_box_h
Cover box height.
Definition sh_cover.c:27
@ k_sh_cv_read_y
"Read" button top.
Definition sh_cover.c:33
@ k_sh_cv_box_w
Cover box width.
Definition sh_cover.c:26
@ k_sh_cv_btn_w
Action button width.
Definition sh_cover.c:31
void sh_cover_loupe_render(void)
Draw the magnifier loupe over the cover at the current pan centre.
Definition sh_cover.c:124
bool sh_cover_loupe_map(int32_t px, int32_t py, int32_t *out_cx, int32_t *out_cy)
Map a cover-screen touch to full-res source coordinates for the loupe.
Definition sh_cover.c:103
static void sh_cover_button(int32_t y, const char *label)
Draw a filled action button with a left-inset label.
Definition sh_cover.c:39
static bool sh_in_rect(int32_t x, int32_t y, int32_t rx, int32_t ry, int32_t rw, int32_t rh)
Inclusive-left / exclusive-right point-in-rect test.
Definition sh_cover.c:86
sh_cover_act_t sh_cover_action(int32_t x, int32_t y)
Classify a cover-screen tap into a sh_cover_act_t.
Definition sh_cover.c:91
void sh_cover_render(void)
Render the selected book's cover / title page.
Definition sh_cover.c:51
One shelf book, sourced from MRAM (baked) or the SD card, in either the .rabook or ....
Definition sh_app.h:141
bool from_sd
true: read sd_name from SD; false: use blob.
Definition sh_app.h:142
char title[k_sh_title_cap]
Display title.
Definition sh_app.h:150
char author[k_sh_author_cap]
Display author.
Definition sh_app.h:151