summaryrefslogtreecommitdiff
path: root/src/ui/mediaui.c
diff options
context:
space:
mode:
authorJaakko Keränen <jaakko.keranen@iki.fi>2021-10-17 11:15:14 +0300
committerJaakko Keränen <jaakko.keranen@iki.fi>2021-10-17 11:15:14 +0300
commit2e2b823bfb5d34d42c6b6c1b289193c854459b45 (patch)
tree345f37aa1b84d8dedb98ff260265b41495e10878 /src/ui/mediaui.c
parent2f3987f5e54d95658f95c6991b0644bc15eedabf (diff)
Media and FontPacks (work in progress)
Saving this as the last point of progress. This direction is too complicated: Media needs to be a lot more sophisticated to allow dynamic and interactive media at the level of FontPacks. (A bit like Player handles audio playback.) This will be reverted. FontPack management will happen using an another method.
Diffstat (limited to 'src/ui/mediaui.c')
-rw-r--r--src/ui/mediaui.c48
1 files changed, 33 insertions, 15 deletions
diff --git a/src/ui/mediaui.c b/src/ui/mediaui.c
index aa45d73a..ac9475dd 100644
--- a/src/ui/mediaui.c
+++ b/src/ui/mediaui.c
@@ -28,6 +28,7 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */
28#include "paint.h" 28#include "paint.h"
29#include "util.h" 29#include "util.h"
30#include "lang.h" 30#include "lang.h"
31#include "app.h"
31 32
32#include <the_Foundation/path.h> 33#include <the_Foundation/path.h>
33#include <the_Foundation/stringlist.h> 34#include <the_Foundation/stringlist.h>
@@ -281,14 +282,28 @@ void draw_DownloadUI(const iDownloadUI *d, iPaint *p) {
281 282
282/*----------------------------------------------------------------------------------------------*/ 283/*----------------------------------------------------------------------------------------------*/
283 284
285static iMenuItem action_FontpackUI_(const iFontpackUI *d) {
286 if (d->info.isInstalled) {
287 return (iMenuItem){ d->info.isDisabled ? "${media.fontpack.enable}"
288 : close_Icon " ${media.fontpack.disable}",
289 0, 0, format_CStr("media.fontpack.enable arg:%d", d->info.isDisabled) };
290 }
291 return (iMenuItem){ d->info.isInstalled ? close_Icon " ${media.fontpack.disable}"
292 : "${media.fontpack.install}",
293 0, 0,
294 d->info.isInstalled ? "media.fontpack.enable arg:0" : "media.fontpack.install" };
295}
296
284void init_FontpackUI(iFontpackUI *d, const iMedia *media, uint16_t mediaId, iRect bounds) { 297void init_FontpackUI(iFontpackUI *d, const iMedia *media, uint16_t mediaId, iRect bounds) {
285 d->media = media; 298 d->media = media;
286 d->mediaId = mediaId; 299 d->mediaId = mediaId;
300 fontpackInfo_Media(d->media, (iMediaId){ fontpack_MediaType, d->mediaId }, &d->info);
287 d->bounds = bounds; 301 d->bounds = bounds;
288 d->installRect.size = add_I2(measure_Text(uiLabel_FontId, "${media.fontpack.install}").bounds.size, 302 iMenuItem action = action_FontpackUI_(d);
289 muli_I2(gap2_UI, 3)); 303 d->buttonRect.size = add_I2(measure_Text(uiLabel_FontId, action.label).bounds.size,
290 d->installRect.pos.x = right_Rect(d->bounds) - gap_UI - d->installRect.size.x; 304 muli_I2(gap2_UI, 3));
291 d->installRect.pos.y = mid_Rect(d->bounds).y - d->installRect.size.y / 2; 305 d->buttonRect.pos.x = right_Rect(d->bounds) - gap_UI - d->buttonRect.size.x;
306 d->buttonRect.pos.y = mid_Rect(d->bounds).y - d->buttonRect.size.y / 2;
292} 307}
293 308
294iBool processEvent_FontpackUI(iFontpackUI *d, const SDL_Event *ev) { 309iBool processEvent_FontpackUI(iFontpackUI *d, const SDL_Event *ev) {
@@ -296,7 +311,12 @@ iBool processEvent_FontpackUI(iFontpackUI *d, const SDL_Event *ev) {
296 case SDL_MOUSEBUTTONDOWN: 311 case SDL_MOUSEBUTTONDOWN:
297 case SDL_MOUSEBUTTONUP: { 312 case SDL_MOUSEBUTTONUP: {
298 const iInt2 pos = init_I2(ev->button.x, ev->button.y); 313 const iInt2 pos = init_I2(ev->button.x, ev->button.y);
299 if (contains_Rect(d->installRect, pos)) { 314 if (contains_Rect(d->buttonRect, pos)) {
315 if (ev->type == SDL_MOUSEBUTTONUP) {
316 postCommandf_App("%s media:%p mediaid:%u packid:%s",
317 action_FontpackUI_(d).command,
318 d->media, d->mediaId, cstr_String(d->info.packId.id));
319 }
300 return iTrue; 320 return iTrue;
301 } 321 }
302 break; 322 break;
@@ -322,24 +342,22 @@ void draw_FontpackUI(const iFontpackUI *d, iPaint *p) {
322 /* Draw a background box. */ 342 /* Draw a background box. */
323 fillRect_Paint(p, d->bounds, uiBackground_ColorId); 343 fillRect_Paint(p, d->bounds, uiBackground_ColorId);
324 drawRect_Paint(p, d->bounds, uiSeparator_ColorId); 344 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); 345 iInt2 pos = topLeft_Rect(d->bounds);
328 const char *checks[] = { "\u2610", "\u2611" }; 346 const char *checks[] = { "\u2610", "\u2611" };
329 draw_Text(uiContentBold_FontId, pos, uiHeading_ColorId, "\"%s\" v%d", 347 draw_Text(uiContentBold_FontId, pos,
330 cstr_String(info.packId.id), info.packId.version); 348 d->info.isDisabled ? uiText_ColorId : uiHeading_ColorId, "\"%s\" v%d",
349 cstr_String(d->info.packId.id), d->info.packId.version);
331 pos.y += lineHeight_Text(uiContentBold_FontId); 350 pos.y += lineHeight_Text(uiContentBold_FontId);
332 draw_Text(uiLabelBold_FontId, pos, uiText_ColorId, "%.1f MB, %d fonts %s %s %s", 351 draw_Text(uiLabelBold_FontId, pos, uiText_ColorId, "%.1f MB, %d fonts %s %s %s",
333 info.sizeInBytes / 1.0e6, size_StringList(info.names), 352 d->info.sizeInBytes / 1.0e6, size_StringList(d->info.names),
334// checks[info.isValid], info.isValid ? "No errors" : "Errors detected", 353// checks[info.isValid], info.isValid ? "No errors" : "Errors detected",
335 checks[info.isInstalled], info.isInstalled ? "Installed" : "Not installed", 354 checks[d->info.isInstalled], d->info.isInstalled ? "Installed" : "Not installed",
336 info.isReadOnly ? "Read-Only" : ""); 355 d->info.isReadOnly ? "Read-Only" : "");
337 pos.y += lineHeight_Text(uiLabelBold_FontId); 356 pos.y += lineHeight_Text(uiLabelBold_FontId);
338 iConstForEach(StringList, i, info.names) { 357 iConstForEach(StringList, i, d->info.names) {
339 drawRange_Text(uiLabel_FontId, pos, uiText_ColorId, range_String(i.value)); 358 drawRange_Text(uiLabel_FontId, pos, uiText_ColorId, range_String(i.value));
340 pos.y += lineHeight_Text(uiLabel_FontId); 359 pos.y += lineHeight_Text(uiLabel_FontId);
341 } 360 }
342 /* Buttons. */ 361 /* Buttons. */
343 drawInlineButton_(p, d->installRect, 362 drawInlineButton_(p, d->buttonRect, action_FontpackUI_(d).label, uiLabel_FontId);
344 "${media.fontpack.install}", uiLabel_FontId);
345} 363}