summaryrefslogtreecommitdiff
path: root/src/ui/mediaui.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/ui/mediaui.c')
-rw-r--r--src/ui/mediaui.c88
1 files changed, 78 insertions, 10 deletions
diff --git a/src/ui/mediaui.c b/src/ui/mediaui.c
index 22552027..aa45d73a 100644
--- a/src/ui/mediaui.c
+++ b/src/ui/mediaui.c
@@ -30,6 +30,7 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */
30#include "lang.h" 30#include "lang.h"
31 31
32#include <the_Foundation/path.h> 32#include <the_Foundation/path.h>
33#include <the_Foundation/stringlist.h>
33 34
34static const char *volumeChar_(float volume) { 35static const char *volumeChar_(float volume) {
35 if (volume <= 0) { 36 if (volume <= 0) {
@@ -61,7 +62,7 @@ void init_PlayerUI(iPlayerUI *d, const iPlayer *player, iRect bounds) {
61 } 62 }
62} 63}
63 64
64static void drawPlayerButton_(iPaint *p, iRect rect, const char *label, int font) { 65static void drawInlineButton_(iPaint *p, iRect rect, const char *label, int font) {
65 const iInt2 mouse = mouseCoord_Window(get_Window(), 0); 66 const iInt2 mouse = mouseCoord_Window(get_Window(), 0);
66 const iBool isHover = contains_Rect(rect, mouse); 67 const iBool isHover = contains_Rect(rect, mouse);
67 const iBool isPressed = isHover && (SDL_GetMouseState(NULL, NULL) & SDL_BUTTON_LEFT) != 0; 68 const iBool isPressed = isHover && (SDL_GetMouseState(NULL, NULL) & SDL_BUTTON_LEFT) != 0;
@@ -113,14 +114,14 @@ void draw_PlayerUI(iPlayerUI *d, iPaint *p) {
113 const iBool isAdjusting = (flags_Player(d->player) & adjustingVolume_PlayerFlag) != 0; 114 const iBool isAdjusting = (flags_Player(d->player) & adjustingVolume_PlayerFlag) != 0;
114 fillRect_Paint(p, d->bounds, playerBackground_ColorId); 115 fillRect_Paint(p, d->bounds, playerBackground_ColorId);
115 drawRect_Paint(p, d->bounds, playerFrame_ColorId); 116 drawRect_Paint(p, d->bounds, playerFrame_ColorId);
116 drawPlayerButton_(p, 117 drawInlineButton_(p,
117 d->playPauseRect, 118 d->playPauseRect,
118 isPaused_Player(d->player) ? "\U0001f782" : "\u23f8", 119 isPaused_Player(d->player) ? "\U0001f782" : "\u23f8",
119 uiContent_FontId); 120 uiContent_FontId);
120 drawPlayerButton_(p, d->rewindRect, "\u23ee", uiContent_FontId); 121 drawInlineButton_(p, d->rewindRect, "\u23ee", uiContent_FontId);
121 drawPlayerButton_(p, d->menuRect, menu_Icon, uiContent_FontId); 122 drawInlineButton_(p, d->menuRect, menu_Icon, uiContent_FontId);
122 if (!isAdjusting) { 123 if (!isAdjusting) {
123 drawPlayerButton_( 124 drawInlineButton_(
124 p, d->volumeRect, volumeChar_(volume_Player(d->player)), uiContentSymbols_FontId); 125 p, d->volumeRect, volumeChar_(volume_Player(d->player)), uiContentSymbols_FontId);
125 } 126 }
126 const int hgt = lineHeight_Text(uiLabelBig_FontId); 127 const int hgt = lineHeight_Text(uiLabelBig_FontId);
@@ -228,24 +229,26 @@ static void drawSevenSegmentBytes_(iInt2 pos, int color, size_t numBytes) {
228 deinit_String(&digits); 229 deinit_String(&digits);
229} 230}
230 231
231void init_DownloadUI(iDownloadUI *d, const iDocumentWidget *doc, uint16_t mediaId, iRect bounds) { 232void init_DownloadUI(iDownloadUI *d, const iMedia *media, uint16_t mediaId, iRect bounds) {
232 d->doc = doc; 233 d->media = media;
233 d->mediaId = mediaId; 234 d->mediaId = mediaId;
234 d->bounds = bounds; 235 d->bounds = bounds;
235} 236}
236 237
238/*----------------------------------------------------------------------------------------------*/
239
237iBool processEvent_DownloadUI(iDownloadUI *d, const SDL_Event *ev) { 240iBool processEvent_DownloadUI(iDownloadUI *d, const SDL_Event *ev) {
238 return iFalse; 241 return iFalse;
239} 242}
240 243
241void draw_DownloadUI(const iDownloadUI *d, iPaint *p) { 244void draw_DownloadUI(const iDownloadUI *d, iPaint *p) {
242 const iMedia *media = constMedia_GmDocument(document_DocumentWidget(d->doc));
243 iGmMediaInfo info; 245 iGmMediaInfo info;
244 float bytesPerSecond; 246 float bytesPerSecond;
245 const iString *path; 247 const iString *path;
246 iBool isFinished; 248 iBool isFinished;
247 downloadInfo_Media(media, d->mediaId, &info); 249 downloadInfo_Media(d->media, d->mediaId, &info);
248 downloadStats_Media(media, d->mediaId, &path, &bytesPerSecond, &isFinished); 250 downloadStats_Media(d->media, (iMediaId){ download_MediaType, d->mediaId },
251 &path, &bytesPerSecond, &isFinished);
249 fillRect_Paint(p, d->bounds, uiBackground_ColorId); 252 fillRect_Paint(p, d->bounds, uiBackground_ColorId);
250 drawRect_Paint(p, d->bounds, uiSeparator_ColorId); 253 drawRect_Paint(p, d->bounds, uiSeparator_ColorId);
251 iRect rect = d->bounds; 254 iRect rect = d->bounds;
@@ -275,3 +278,68 @@ void draw_DownloadUI(const iDownloadUI *d, iPaint *p) {
275 translateCStr_Lang("\u2014 ${mb.per.sec}")); 278 translateCStr_Lang("\u2014 ${mb.per.sec}"));
276 } 279 }
277} 280}
281
282/*----------------------------------------------------------------------------------------------*/
283
284void init_FontpackUI(iFontpackUI *d, const iMedia *media, uint16_t mediaId, iRect bounds) {
285 d->media = media;
286 d->mediaId = mediaId;
287 d->bounds = bounds;
288 d->installRect.size = add_I2(measure_Text(uiLabel_FontId, "${media.fontpack.install}").bounds.size,
289 muli_I2(gap2_UI, 3));
290 d->installRect.pos.x = right_Rect(d->bounds) - gap_UI - d->installRect.size.x;
291 d->installRect.pos.y = mid_Rect(d->bounds).y - d->installRect.size.y / 2;
292}
293
294iBool processEvent_FontpackUI(iFontpackUI *d, const SDL_Event *ev) {
295 switch (ev->type) {
296 case SDL_MOUSEBUTTONDOWN:
297 case SDL_MOUSEBUTTONUP: {
298 const iInt2 pos = init_I2(ev->button.x, ev->button.y);
299 if (contains_Rect(d->installRect, pos)) {
300 return iTrue;
301 }
302 break;
303 }
304 case SDL_MOUSEMOTION:
305 if (contains_Rect(d->bounds, init_I2(ev->motion.x, ev->motion.y))) {
306 return iTrue;
307 }
308 break;
309 }
310 return iFalse;
311}
312
313int height_FontpackUI(const iMedia *media, uint16_t mediaId, int width) {
314 const iStringList *names;
315 iFontpackMediaInfo info;
316 fontpackInfo_Media(media, (iMediaId){ fontpack_MediaType, mediaId }, &info);
317 return lineHeight_Text(uiContent_FontId) +
318 lineHeight_Text(uiLabel_FontId) * (1 + size_StringList(info.names));
319}
320
321void draw_FontpackUI(const iFontpackUI *d, iPaint *p) {
322 /* Draw a background box. */
323 fillRect_Paint(p, d->bounds, uiBackground_ColorId);
324 drawRect_Paint(p, d->bounds, uiSeparator_ColorId);
325 iFontpackMediaInfo info;
326 fontpackInfo_Media(d->media, (iMediaId){ fontpack_MediaType, d->mediaId }, &info);
327 iInt2 pos = topLeft_Rect(d->bounds);
328 const char *checks[] = { "\u2610", "\u2611" };
329 draw_Text(uiContentBold_FontId, pos, uiHeading_ColorId, "\"%s\" v%d",
330 cstr_String(info.packId.id), info.packId.version);
331 pos.y += lineHeight_Text(uiContentBold_FontId);
332 draw_Text(uiLabelBold_FontId, pos, uiText_ColorId, "%.1f MB, %d fonts %s %s %s",
333 info.sizeInBytes / 1.0e6, size_StringList(info.names),
334// checks[info.isValid], info.isValid ? "No errors" : "Errors detected",
335 checks[info.isInstalled], info.isInstalled ? "Installed" : "Not installed",
336 info.isReadOnly ? "Read-Only" : "");
337 pos.y += lineHeight_Text(uiLabelBold_FontId);
338 iConstForEach(StringList, i, info.names) {
339 drawRange_Text(uiLabel_FontId, pos, uiText_ColorId, range_String(i.value));
340 pos.y += lineHeight_Text(uiLabel_FontId);
341 }
342 /* Buttons. */
343 drawInlineButton_(p, d->installRect,
344 "${media.fontpack.install}", uiLabel_FontId);
345}