summaryrefslogtreecommitdiff
path: root/src/ui
diff options
context:
space:
mode:
authorJaakko Keränen <jaakko.keranen@iki.fi>2021-02-24 12:41:46 +0200
committerJaakko Keränen <jaakko.keranen@iki.fi>2021-02-24 12:41:46 +0200
commit83e936f53d3129433edfdb229a2faf78e48687b1 (patch)
tree4af84e84b7ba5faccac71522fd665bfb63491acf /src/ui
parent740c95a2b0eda0297865b739d780474cea13e75c (diff)
GmDocument: Media type flexibility
Allow defining new inline media types.
Diffstat (limited to 'src/ui')
-rw-r--r--src/ui/documentwidget.c32
1 files changed, 17 insertions, 15 deletions
diff --git a/src/ui/documentwidget.c b/src/ui/documentwidget.c
index 92966538..6b023349 100644
--- a/src/ui/documentwidget.c
+++ b/src/ui/documentwidget.c
@@ -414,7 +414,7 @@ static iRangei visibleRange_DocumentWidget_(const iDocumentWidget *d) {
414 414
415static void addVisible_DocumentWidget_(void *context, const iGmRun *run) { 415static void addVisible_DocumentWidget_(void *context, const iGmRun *run) {
416 iDocumentWidget *d = context; 416 iDocumentWidget *d = context;
417 if (~run->flags & decoration_GmRunFlag && !run->imageId) { 417 if (~run->flags & decoration_GmRunFlag && !run->mediaId) {
418 if (!d->firstVisibleRun) { 418 if (!d->firstVisibleRun) {
419 d->firstVisibleRun = run; 419 d->firstVisibleRun = run;
420 } 420 }
@@ -423,7 +423,8 @@ static void addVisible_DocumentWidget_(void *context, const iGmRun *run) {
423 if (run->preId && run->flags & wide_GmRunFlag) { 423 if (run->preId && run->flags & wide_GmRunFlag) {
424 pushBack_PtrArray(&d->visibleWideRuns, run); 424 pushBack_PtrArray(&d->visibleWideRuns, run);
425 } 425 }
426 if (run->audioId) { 426 if (run->mediaType == audio_GmRunMediaType) {
427 iAssert(run->mediaId);
427 pushBack_PtrArray(&d->visiblePlayers, run); 428 pushBack_PtrArray(&d->visiblePlayers, run);
428 } 429 }
429 if (run->linkId) { 430 if (run->linkId) {
@@ -568,7 +569,7 @@ static uint32_t playerUpdateInterval_DocumentWidget_(const iDocumentWidget *d) {
568 uint32_t interval = 0; 569 uint32_t interval = 0;
569 iConstForEach(PtrArray, i, &d->visiblePlayers) { 570 iConstForEach(PtrArray, i, &d->visiblePlayers) {
570 const iGmRun *run = i.ptr; 571 const iGmRun *run = i.ptr;
571 iPlayer * plr = audioPlayer_Media(media_GmDocument(d->doc), run->audioId); 572 iPlayer * plr = audioPlayer_Media(media_GmDocument(d->doc), run->mediaId);
572 if (flags_Player(plr) & adjustingVolume_PlayerFlag || 573 if (flags_Player(plr) & adjustingVolume_PlayerFlag ||
573 (isStarted_Player(plr) && !isPaused_Player(plr))) { 574 (isStarted_Player(plr) && !isPaused_Player(plr))) {
574 interval = 1000 / 15; 575 interval = 1000 / 15;
@@ -589,7 +590,7 @@ static void updatePlayers_DocumentWidget_(iDocumentWidget *d) {
589 refresh_Widget(d); 590 refresh_Widget(d);
590 iConstForEach(PtrArray, i, &d->visiblePlayers) { 591 iConstForEach(PtrArray, i, &d->visiblePlayers) {
591 const iGmRun *run = i.ptr; 592 const iGmRun *run = i.ptr;
592 iPlayer * plr = audioPlayer_Media(media_GmDocument(d->doc), run->audioId); 593 iPlayer * plr = audioPlayer_Media(media_GmDocument(d->doc), run->mediaId);
593 if (idleTimeMs_Player(plr) > 3000 && ~flags_Player(plr) & volumeGrabbed_PlayerFlag && 594 if (idleTimeMs_Player(plr) > 3000 && ~flags_Player(plr) & volumeGrabbed_PlayerFlag &&
594 flags_Player(plr) & adjustingVolume_PlayerFlag) { 595 flags_Player(plr) & adjustingVolume_PlayerFlag) {
595 setFlags_Player(plr, adjustingVolume_PlayerFlag, iFalse); 596 setFlags_Player(plr, adjustingVolume_PlayerFlag, iFalse);
@@ -1464,7 +1465,8 @@ static void allocVisBuffer_DocumentWidget_(const iDocumentWidget *d) {
1464static iBool fetchNextUnfetchedImage_DocumentWidget_(iDocumentWidget *d) { 1465static iBool fetchNextUnfetchedImage_DocumentWidget_(iDocumentWidget *d) {
1465 iConstForEach(PtrArray, i, &d->visibleLinks) { 1466 iConstForEach(PtrArray, i, &d->visibleLinks) {
1466 const iGmRun *run = i.ptr; 1467 const iGmRun *run = i.ptr;
1467 if (run->linkId && !run->imageId && ~run->flags & decoration_GmRunFlag) { 1468 if (run->linkId && run->mediaType == none_GmRunMediaType &&
1469 ~run->flags & decoration_GmRunFlag) {
1468 const int linkFlags = linkFlags_GmDocument(d->doc, run->linkId); 1470 const int linkFlags = linkFlags_GmDocument(d->doc, run->linkId);
1469 if (isMediaLink_GmDocument(d->doc, run->linkId) && 1471 if (isMediaLink_GmDocument(d->doc, run->linkId) &&
1470 linkFlags & imageFileExtension_GmLinkFlag && 1472 linkFlags & imageFileExtension_GmLinkFlag &&
@@ -2174,8 +2176,8 @@ static iRect playerRect_DocumentWidget_(const iDocumentWidget *d, const iGmRun *
2174} 2176}
2175 2177
2176static void setGrabbedPlayer_DocumentWidget_(iDocumentWidget *d, const iGmRun *run) { 2178static void setGrabbedPlayer_DocumentWidget_(iDocumentWidget *d, const iGmRun *run) {
2177 if (run) { 2179 if (run && run->mediaType == audio_GmRunMediaType) {
2178 iPlayer *plr = audioPlayer_Media(media_GmDocument(d->doc), run->audioId); 2180 iPlayer *plr = audioPlayer_Media(media_GmDocument(d->doc), run->mediaId);
2179 setFlags_Player(plr, volumeGrabbed_PlayerFlag, iTrue); 2181 setFlags_Player(plr, volumeGrabbed_PlayerFlag, iTrue);
2180 d->grabbedStartVolume = volume_Player(plr); 2182 d->grabbedStartVolume = volume_Player(plr);
2181 d->grabbedPlayer = run; 2183 d->grabbedPlayer = run;
@@ -2183,7 +2185,7 @@ static void setGrabbedPlayer_DocumentWidget_(iDocumentWidget *d, const iGmRun *r
2183 } 2185 }
2184 else if (d->grabbedPlayer) { 2186 else if (d->grabbedPlayer) {
2185 setFlags_Player( 2187 setFlags_Player(
2186 audioPlayer_Media(media_GmDocument(d->doc), d->grabbedPlayer->audioId), 2188 audioPlayer_Media(media_GmDocument(d->doc), d->grabbedPlayer->mediaId),
2187 volumeGrabbed_PlayerFlag, 2189 volumeGrabbed_PlayerFlag,
2188 iFalse); 2190 iFalse);
2189 d->grabbedPlayer = NULL; 2191 d->grabbedPlayer = NULL;
@@ -2212,7 +2214,7 @@ static iBool processPlayerEvents_DocumentWidget_(iDocumentWidget *d, const SDL_E
2212 iConstForEach(PtrArray, i, &d->visiblePlayers) { 2214 iConstForEach(PtrArray, i, &d->visiblePlayers) {
2213 const iGmRun *run = i.ptr; 2215 const iGmRun *run = i.ptr;
2214 const iRect rect = playerRect_DocumentWidget_(d, run); 2216 const iRect rect = playerRect_DocumentWidget_(d, run);
2215 iPlayer * plr = audioPlayer_Media(media_GmDocument(d->doc), run->audioId); 2217 iPlayer * plr = audioPlayer_Media(media_GmDocument(d->doc), run->mediaId);
2216 if (contains_Rect(rect, mouse)) { 2218 if (contains_Rect(rect, mouse)) {
2217 iPlayerUI ui; 2219 iPlayerUI ui;
2218 init_PlayerUI(&ui, plr, rect); 2220 init_PlayerUI(&ui, plr, rect);
@@ -2619,7 +2621,7 @@ static iBool processEvent_DocumentWidget_(iDocumentWidget *d, const SDL_Event *e
2619 case drag_ClickResult: { 2621 case drag_ClickResult: {
2620 if (d->grabbedPlayer) { 2622 if (d->grabbedPlayer) {
2621 iPlayer *plr = 2623 iPlayer *plr =
2622 audioPlayer_Media(media_GmDocument(d->doc), d->grabbedPlayer->audioId); 2624 audioPlayer_Media(media_GmDocument(d->doc), d->grabbedPlayer->mediaId);
2623 iPlayerUI ui; 2625 iPlayerUI ui;
2624 init_PlayerUI(&ui, plr, playerRect_DocumentWidget_(d, d->grabbedPlayer)); 2626 init_PlayerUI(&ui, plr, playerRect_DocumentWidget_(d, d->grabbedPlayer));
2625 float off = (float) delta_Click(&d->click).x / (float) width_Rect(ui.volumeSlider); 2627 float off = (float) delta_Click(&d->click).x / (float) width_Rect(ui.volumeSlider);
@@ -2826,7 +2828,7 @@ static void fillRange_DrawContext_(iDrawContext *d, const iGmRun *run, enum iCol
2826 2828
2827static void drawMark_DrawContext_(void *context, const iGmRun *run) { 2829static void drawMark_DrawContext_(void *context, const iGmRun *run) {
2828 iDrawContext *d = context; 2830 iDrawContext *d = context;
2829 if (!run->imageId) { 2831 if (run->mediaType == none_GmRunMediaType) {
2830 fillRange_DrawContext_(d, run, uiMatching_ColorId, d->widget->foundMark, &d->inFoundMark); 2832 fillRange_DrawContext_(d, run, uiMatching_ColorId, d->widget->foundMark, &d->inFoundMark);
2831 fillRange_DrawContext_(d, run, uiMarked_ColorId, d->widget->selectMark, &d->inSelectMark); 2833 fillRange_DrawContext_(d, run, uiMarked_ColorId, d->widget->selectMark, &d->inSelectMark);
2832 } 2834 }
@@ -2925,8 +2927,8 @@ static void drawBannerRun_DrawContext_(iDrawContext *d, const iGmRun *run, iInt2
2925static void drawRun_DrawContext_(void *context, const iGmRun *run) { 2927static void drawRun_DrawContext_(void *context, const iGmRun *run) {
2926 iDrawContext *d = context; 2928 iDrawContext *d = context;
2927 const iInt2 origin = d->viewPos; 2929 const iInt2 origin = d->viewPos;
2928 if (run->imageId) { 2930 if (run->mediaType == image_GmRunMediaType) {
2929 SDL_Texture *tex = imageTexture_Media(media_GmDocument(d->widget->doc), run->imageId); 2931 SDL_Texture *tex = imageTexture_Media(media_GmDocument(d->widget->doc), run->mediaId);
2930 if (tex) { 2932 if (tex) {
2931 const iRect dst = moved_Rect(run->visBounds, origin); 2933 const iRect dst = moved_Rect(run->visBounds, origin);
2932 fillRect_Paint(&d->paint, dst, tmBackground_ColorId); /* in case the image has alpha */ 2934 fillRect_Paint(&d->paint, dst, tmBackground_ColorId); /* in case the image has alpha */
@@ -2935,7 +2937,7 @@ static void drawRun_DrawContext_(void *context, const iGmRun *run) {
2935 } 2937 }
2936 return; 2938 return;
2937 } 2939 }
2938 else if (run->audioId) { 2940 else if (run->mediaType == audio_GmRunMediaType) {
2939 /* Audio player UI is drawn afterwards as a dynamic overlay. */ 2941 /* Audio player UI is drawn afterwards as a dynamic overlay. */
2940 return; 2942 return;
2941 } 2943 }
@@ -3283,7 +3285,7 @@ static void drawSideElements_DocumentWidget_(const iDocumentWidget *d) {
3283static void drawPlayers_DocumentWidget_(const iDocumentWidget *d, iPaint *p) { 3285static void drawPlayers_DocumentWidget_(const iDocumentWidget *d, iPaint *p) {
3284 iConstForEach(PtrArray, i, &d->visiblePlayers) { 3286 iConstForEach(PtrArray, i, &d->visiblePlayers) {
3285 const iGmRun * run = i.ptr; 3287 const iGmRun * run = i.ptr;
3286 const iPlayer *plr = audioPlayer_Media(media_GmDocument(d->doc), run->audioId); 3288 const iPlayer *plr = audioPlayer_Media(media_GmDocument(d->doc), run->mediaId);
3287 const iRect rect = playerRect_DocumentWidget_(d, run); 3289 const iRect rect = playerRect_DocumentWidget_(d, run);
3288 iPlayerUI ui; 3290 iPlayerUI ui;
3289 init_PlayerUI(&ui, plr, rect); 3291 init_PlayerUI(&ui, plr, rect);