diff options
Diffstat (limited to 'src/ui/mediaui.c')
-rw-r--r-- | src/ui/mediaui.c | 39 |
1 files changed, 22 insertions, 17 deletions
diff --git a/src/ui/mediaui.c b/src/ui/mediaui.c index b622a554..4f2499b0 100644 --- a/src/ui/mediaui.c +++ b/src/ui/mediaui.c | |||
@@ -28,8 +28,10 @@ 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> |
34 | #include <the_Foundation/stringlist.h> | ||
33 | 35 | ||
34 | static const char *volumeChar_(float volume) { | 36 | static const char *volumeChar_(float volume) { |
35 | if (volume <= 0) { | 37 | if (volume <= 0) { |
@@ -61,7 +63,7 @@ void init_PlayerUI(iPlayerUI *d, const iPlayer *player, iRect bounds) { | |||
61 | } | 63 | } |
62 | } | 64 | } |
63 | 65 | ||
64 | static void drawPlayerButton_(iPaint *p, iRect rect, const char *label, int font) { | 66 | static void drawInlineButton_(iPaint *p, iRect rect, const char *label, int font) { |
65 | const iInt2 mouse = mouseCoord_Window(get_Window(), 0); | 67 | const iInt2 mouse = mouseCoord_Window(get_Window(), 0); |
66 | const iBool isHover = contains_Rect(rect, mouse); | 68 | const iBool isHover = contains_Rect(rect, mouse); |
67 | const iBool isPressed = isHover && (SDL_GetMouseState(NULL, NULL) & SDL_BUTTON_LEFT) != 0; | 69 | const iBool isPressed = isHover && (SDL_GetMouseState(NULL, NULL) & SDL_BUTTON_LEFT) != 0; |
@@ -86,7 +88,7 @@ static int drawSevenSegmentTime_(iInt2 pos, int color, int align, int seconds) { | |||
86 | const int hours = seconds / 3600; | 88 | const int hours = seconds / 3600; |
87 | const int mins = (seconds / 60) % 60; | 89 | const int mins = (seconds / 60) % 60; |
88 | const int secs = seconds % 60; | 90 | const int secs = seconds % 60; |
89 | const int font = defaultBig_FontId; | 91 | const int font = uiLabelBig_FontId; |
90 | iString num; | 92 | iString num; |
91 | init_String(&num); | 93 | init_String(&num); |
92 | if (hours) { | 94 | if (hours) { |
@@ -113,17 +115,17 @@ void draw_PlayerUI(iPlayerUI *d, iPaint *p) { | |||
113 | const iBool isAdjusting = (flags_Player(d->player) & adjustingVolume_PlayerFlag) != 0; | 115 | const iBool isAdjusting = (flags_Player(d->player) & adjustingVolume_PlayerFlag) != 0; |
114 | fillRect_Paint(p, d->bounds, playerBackground_ColorId); | 116 | fillRect_Paint(p, d->bounds, playerBackground_ColorId); |
115 | drawRect_Paint(p, d->bounds, playerFrame_ColorId); | 117 | drawRect_Paint(p, d->bounds, playerFrame_ColorId); |
116 | drawPlayerButton_(p, | 118 | drawInlineButton_(p, |
117 | d->playPauseRect, | 119 | d->playPauseRect, |
118 | isPaused_Player(d->player) ? "\U0001f782" : "\u23f8", | 120 | isPaused_Player(d->player) ? "\U0001f782" : "\u23f8", |
119 | uiContent_FontId); | 121 | uiContent_FontId); |
120 | drawPlayerButton_(p, d->rewindRect, "\u23ee", uiContent_FontId); | 122 | drawInlineButton_(p, d->rewindRect, "\u23ee", uiContent_FontId); |
121 | drawPlayerButton_(p, d->menuRect, menu_Icon, uiContent_FontId); | 123 | drawInlineButton_(p, d->menuRect, menu_Icon, uiContent_FontId); |
122 | if (!isAdjusting) { | 124 | if (!isAdjusting) { |
123 | drawPlayerButton_( | 125 | drawInlineButton_( |
124 | p, d->volumeRect, volumeChar_(volume_Player(d->player)), uiContentSymbols_FontId); | 126 | p, d->volumeRect, volumeChar_(volume_Player(d->player)), uiContentSymbols_FontId); |
125 | } | 127 | } |
126 | const int hgt = lineHeight_Text(defaultBig_FontId); | 128 | const int hgt = lineHeight_Text(uiLabelBig_FontId); |
127 | const int yMid = mid_Rect(d->scrubberRect).y; | 129 | const int yMid = mid_Rect(d->scrubberRect).y; |
128 | const float playTime = time_Player(d->player); | 130 | const float playTime = time_Player(d->player); |
129 | const float totalTime = duration_Player(d->player); | 131 | const float totalTime = duration_Player(d->player); |
@@ -196,7 +198,7 @@ void draw_PlayerUI(iPlayerUI *d, iPaint *p) { | |||
196 | 198 | ||
197 | /*----------------------------------------------------------------------------------------------*/ | 199 | /*----------------------------------------------------------------------------------------------*/ |
198 | 200 | ||
199 | static void drawSevenSegmentBytes_(iInt2 pos, int color, size_t numBytes) { | 201 | void drawSevenSegmentBytes_MediaUI(int font, iInt2 pos, int majorColor, int minorColor, size_t numBytes) { |
200 | iString digits; | 202 | iString digits; |
201 | init_String(&digits); | 203 | init_String(&digits); |
202 | if (numBytes == 0) { | 204 | if (numBytes == 0) { |
@@ -219,33 +221,34 @@ static void drawSevenSegmentBytes_(iInt2 pos, int color, size_t numBytes) { | |||
219 | magnitude++; | 221 | magnitude++; |
220 | } | 222 | } |
221 | if (magnitude > 6) { | 223 | if (magnitude > 6) { |
222 | prependCStr_String(&digits, uiTextStrong_ColorEscape); | 224 | prependCStr_String(&digits, escape_Color(majorColor)); |
223 | } | 225 | } |
224 | } | 226 | } |
225 | const int font = uiLabel_FontId; | ||
226 | const iInt2 dims = measureRange_Text(font, range_String(&digits)).bounds.size; | 227 | const iInt2 dims = measureRange_Text(font, range_String(&digits)).bounds.size; |
227 | drawRange_Text(font, addX_I2(pos, -dims.x), color, range_String(&digits)); | 228 | drawRange_Text(font, addX_I2(pos, -dims.x), minorColor, range_String(&digits)); |
228 | deinit_String(&digits); | 229 | deinit_String(&digits); |
229 | } | 230 | } |
230 | 231 | ||
231 | void init_DownloadUI(iDownloadUI *d, const iDocumentWidget *doc, uint16_t mediaId, iRect bounds) { | 232 | void 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 | |||
237 | iBool processEvent_DownloadUI(iDownloadUI *d, const SDL_Event *ev) { | 240 | iBool processEvent_DownloadUI(iDownloadUI *d, const SDL_Event *ev) { |
238 | return iFalse; | 241 | return iFalse; |
239 | } | 242 | } |
240 | 243 | ||
241 | void draw_DownloadUI(const iDownloadUI *d, iPaint *p) { | 244 | void 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; |
@@ -263,7 +266,9 @@ void draw_DownloadUI(const iDownloadUI *d, iPaint *p) { | |||
263 | isFinished ? uiTextAction_ColorId : uiTextDim_ColorId, | 266 | isFinished ? uiTextAction_ColorId : uiTextDim_ColorId, |
264 | cstr_Lang(isFinished ? "media.download.complete" : "media.download.warnclose")); | 267 | cstr_Lang(isFinished ? "media.download.complete" : "media.download.warnclose")); |
265 | const int x2 = right_Rect(rect); | 268 | const int x2 = right_Rect(rect); |
266 | drawSevenSegmentBytes_(init_I2(x2, y1), uiTextDim_ColorId, info.numBytes); | 269 | drawSevenSegmentBytes_MediaUI(uiLabel_FontId, init_I2(x2, y1), |
270 | uiTextStrong_ColorId, uiTextDim_ColorId, | ||
271 | info.numBytes); | ||
267 | const iInt2 pos = init_I2(x2, y2); | 272 | const iInt2 pos = init_I2(x2, y2); |
268 | if (bytesPerSecond > 0) { | 273 | if (bytesPerSecond > 0) { |
269 | drawAlign_Text(uiLabel_FontId, pos, uiTextDim_ColorId, right_Alignment, | 274 | drawAlign_Text(uiLabel_FontId, pos, uiTextDim_ColorId, right_Alignment, |