Repository navigation
Expand file tree
/
Copy pathmodel_display.h
More file actions
997 lines (854 loc) · 33.4 KB
/
Copy pathmodel_display.h
File metadata and controls
997 lines (854 loc) · 33.4 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
// This file is part of the Diffractor photo and video organizer
// Copyright 2026 Zac Walker
//
// This program is free software; you can redistribute it and / or modify it
// under the terms of the LGPL License either version 2.1 or later.
// License details are available at https://www.gnu.org/licenses/lgpl-2.1.html
// This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY
// Purpose: What one opened display shows: the item or items on screen, their textures and decoders,
// the player session, zoom and panorama views, comparison, and the subtitles and media controls drawn
// over them. Split from model.h so the many files that only need view_state do not compile the audio and
// video headers this depends on.
#pragma once
#include "model.h"
#include "av_format.h"
#include "av_player.h"
#include "av_sid.h"
class document_state;
class sid_monitor_motion;
class display_state_t final : public std::enable_shared_from_this<display_state_t>
{
public:
async_strategy& _async;
common_display_state_t& _common;
bool _comparing = false;
df::comparison_zoom_state _comparison_zoom;
std::shared_ptr<av_session> _session;
// Bumped whenever the session is torn down or superseded. An open that completes after a bump has
// lost the display and must close what it was handed, not publish it. UI thread only.
uint32_t _av_generation = 0;
core::blob _selected_item_data;
// The panel's document of a file with no viewer: _selected_item_data decoded as text, or a dump of
// it. Set with the bytes, and keeps its selection while the panel is rebuilt.
std::shared_ptr<document_state> _document;
std::vector<archive_item> _archive_items;
av_media_info _player_media_info;
// Set once the full-file metadata scan (or player open) has completed for this display item.
// Reading the whole file finishes hydrating a cloud-only placeholder, so this is the point at
// which a previously offline item can be safely re-indexed to pick up its real metadata.
bool _full_metadata_loaded = false;
// The decoder could not make sense of this file, so there is nothing to play or show. The panel
// falls back to a hex dump of the bytes, which at least says what the file really is.
bool _av_open_failed = false;
texture_state_ptr _selected_texture1;
texture_state_ptr _selected_texture2;
df::item_element_ptr _item1;
df::item_element_ptr _item2;
// Painted track width, used only to quantise scrubber redraws to whole pixels.
mutable int _scrubber_width = 0;
int _hover_scrubber_pos = -1;
mutable int _time_width = 0;
int _next_photo_tick = 0;
// Latches the end of the current clip until the queued pause/seek has actually taken effect.
bool _media_end_handled = false;
core::pixel_difference_result _pixel_difference = core::pixel_difference_result::unknown;
int _last_scrubber_pos = -1;
int _last_duration = -1;
int _last_seconds = -1;
std::string _duration;
std::string _time;
core::const_surface_ptr _hover_surface;
mutable render::vertices_ptr _audio_verts;
mutable pointi _audio_element_offset;
mutable recti _audio_element_bounds;
mutable float _audio_element_alpha = 1.0f;
// The SID tune playing here: the session reads its samples through a WAV stream, and the SID monitor
// reads the chip's state beside them. The tune and the voices the user silenced are this display's
// choice, so they survive reopening the session for another tune. UI thread only.
std::shared_ptr<sid_tune_render> _sid;
int _sid_song = 0;
sid_voice_mix _sid_mix;
// What of the SID monitor moves with the music, as the monitor last placed it, so each present can bring
// it up to the session's position without the scene being rebuilt. UI thread only.
mutable std::shared_ptr<sid_monitor_motion> _sid_motion;
// The subtitles the user picked from the menu for this item; empty while the settings choose. Kept
// across a reopen for another track. UI thread only.
std::optional<subtitle_choice> _subtitle_choice;
// The textures of the subtitle bitmaps on show, keyed by the surface each was uploaded from, so a line
// is uploaded once however many frames it stays up. UI thread only.
mutable std::vector<std::pair<core::const_surface_ptr, render::texture_ptr>> _subtitle_textures;
// What draw_subtitles last drew, as subtitle_events::shown_key names it, and the key a repaint has been
// asked for since then - each change is asked for once.
mutable uint64_t _subtitles_drawn_key = 0;
mutable uint64_t _subtitles_requested_key = 0;
// The top of the media controls floating over the picture while the media view draws it, in the
// view's pixels; zero when none float there.
int _overlay_top = 0;
int _compare_hover_loc = 0;
int _compare_video_pos = 0;
bool _temporary_zoom = false;
uint64_t _zoom_activity_generation = 0;
double _zoom_activity_time = 0.0;
float _zoom_overlay_alpha = 1.0f;
recti compare_control_bounds;
recti _compare_bounds;
recti _compare_limits;
recti _compare_video_control_bounds;
recti _compare_video_scrubber_bounds;
// Clickable A and B pane markers. Two entries while both images show; only the first while magnified.
mutable std::array<recti, 2> _pane_marker_bounds;
bool _can_compare = false;
bool _is_compare_video = false;
bool _comparison_eligible = false;
bool _is_one = false;
bool _is_two = false;
bool _is_multi = false;
bool _can_zoom = false;
struct zoom_layout_state
{
sized source_extent;
sized viewport_extent;
pointd viewport_origin;
pointd pending_source_anchor;
pointd pending_client_anchor;
bool pending_reanchor = false;
};
std::array<zoom_layout_state, 2> _zoom_layouts;
// The declaration request this display has already queued. Held here rather than on the session
// because the session outlives every display: a read released with its display publishes nothing,
// and the next display is the thing that should ask again.
core::file_path _panorama_read_path;
sizei _panorama_read_source;
core::date_t _panorama_read_modified;
std::vector<core::const_image_ptr> _images;
std::vector<core::const_surface_ptr> _surfaces;
// UI-owned, index-aligned with _images/_surfaces so a collage cell can name the item it shows.
df::item_elements _collage_source_items;
mutable std::vector<render::texture_ptr> _textures;
std::vector<recti> _surface_bounds;
size_t _selection_item_count = 0;
size_t _collage_image_count = 0;
size_t _selection_overflow_count = 0;
static constexpr size_t max_surfaces = 24;
pointi media_offset;
ui::animate_alpha _loading_alpha_animation;
explicit display_state_t(async_strategy& async, common_display_state_t& common)
: _async(async), _common(common)
{
}
void populate(const view_state& state);
bool is_one() const
{
return _is_one;
}
bool is_two() const
{
return _is_two;
}
// Two selected files is cardinality; comparison is the separate claim that the pair is like with like.
bool is_comparison() const
{
return _is_two && _comparison_eligible;
}
render_valid update_for_present(double time_now) const;
// Draws the subtitles on show over the video frame last drawn, scaled from the video's pixels to the
// picture. Lines at the bottom rise clear of the media controls while those show.
void draw_subtitles(render::draw_context& dc) const;
double media_pos() const
{
return _session ? _session->last_frame_time() : 0.0;
}
double media_start() const
{
return _player_media_info.start;
}
double media_end() const
{
return _player_media_info.end;
}
bool comparing() const
{
return _comparing;
}
static constexpr size_t zoom_pane_index(const df::zoom_pane pane) noexcept
{
return pane == df::zoom_pane::primary ? 0 : 1;
}
df::zoom_pane active_zoom_pane() const noexcept
{
return _is_two ? _comparison_zoom.active() : df::zoom_pane::primary;
}
void active_zoom_pane(const df::zoom_pane pane)
{
if (_is_two && _comparison_zoom.active() != pane)
{
// The pane you switch to always adopts the scale and center you were just looking at.
_comparison_zoom.active(pane);
mark_zoom_activity();
_async.invalidate_view(view_invalid::view_layout | view_invalid::view_redraw |
view_invalid::command_state | view_invalid::controller);
}
}
void flip_zoom_pane()
{
if (!_is_two) return;
active_zoom_pane(df::comparison_zoom_state::other(_comparison_zoom.active()));
}
void active_zoom_pane_at(const pointd location)
{
// Magnified there is no left or right to hit test, so the pointer never chooses the pane.
if (!_is_two || is_zoom_mode()) return;
for (const auto pane : {df::zoom_pane::primary, df::zoom_pane::secondary})
{
const auto& layout = _zoom_layouts[zoom_pane_index(pane)];
const rectd pane_bounds(layout.viewport_origin, layout.viewport_extent);
if (pane_bounds.contains(location))
{
active_zoom_pane(pane);
return;
}
}
}
const df::zoom_view_state& current_zoom_state() const noexcept
{
return _is_two ? _comparison_zoom.active_state() : _common._zoom;
}
zoom_layout_state& current_zoom_layout() noexcept
{
return _zoom_layouts[zoom_pane_index(active_zoom_pane())];
}
const zoom_layout_state& current_zoom_layout() const noexcept
{
return _zoom_layouts[zoom_pane_index(active_zoom_pane())];
}
pointd zoom_anchor_at(const pointd location) const noexcept
{
return location - current_zoom_layout().viewport_origin;
}
template <class Mutator>
void mutate_zoom(Mutator&& mutator)
{
if (_is_two) _comparison_zoom.mutate(std::forward<Mutator>(mutator));
else mutator(_common._zoom);
}
bool zoom() const
{
return _can_zoom && current_zoom_state().is_magnified(zoom_fit_scale());
}
bool is_zoom_mode() const
{
return _can_zoom && (_temporary_zoom || !current_zoom_state().is_fit());
}
uint64_t zoom_activity_generation() const noexcept
{
return _zoom_activity_generation;
}
void mark_zoom_activity() noexcept
{
++_zoom_activity_generation;
_zoom_activity_time = core::now();
}
bool zoom_interactive(const double time_now) const noexcept
{
return time_now - _zoom_activity_time < 0.15;
}
void zoom(const bool zoom)
{
const auto state_changes = zoom ? !this->zoom() : !current_zoom_state().is_fit();
if (state_changes)
{
stop_slideshow();
if (zoom && panorama_projects())
{
enter_panorama_projection();
return;
}
mutate_zoom([zoom](df::zoom_view_state& state)
{
if (zoom) state.set_explicit(1.0);
else state.fit();
});
mark_zoom_activity();
_async.invalidate_view(view_invalid::app_layout | view_invalid::view_layout | view_invalid::tooltip |
view_invalid::controller);
}
}
int zoom_scale_percent() const
{
return core::round(current_zoom_state().effective_scale(zoom_fit_scale()) * 100.0);
}
void adjust_zoom_scale(const int direction, const pointd anchor)
{
if (direction == 0) return;
if (is_panorama_projected())
{
panorama_step_fov(direction);
return;
}
if (direction > 0 && panorama_projects() && current_zoom_state().is_fit())
{
enter_panorama_projection();
return;
}
if (direction > 0 && panorama_enters_at_100())
{
zoom_100(anchor);
return;
}
auto& layout = current_zoom_layout();
const auto source_anchor = current_zoom_state().source_point_at(
layout.source_extent, layout.viewport_extent, zoom_fit_scale(), anchor);
mutate_zoom([&](df::zoom_view_state& state)
{
state.step(direction, zoom_fit_scale(), layout.source_extent, layout.viewport_extent, anchor);
});
mark_zoom_activity();
if (!current_zoom_state().is_fit())
{
layout.pending_source_anchor = source_anchor;
layout.pending_client_anchor = layout.viewport_origin + anchor;
layout.pending_reanchor = true;
}
_async.invalidate_view(view_invalid::app_layout | view_invalid::view_layout | view_invalid::view_redraw |
view_invalid::controller);
}
void adjust_zoom_scale(const int direction)
{
if (direction == 0) return;
const auto& layout = current_zoom_layout();
const pointd anchor{layout.viewport_extent.Width / 2.0, layout.viewport_extent.Height / 2.0};
if (is_panorama_projected())
{
panorama_step_fov(direction);
return;
}
if (direction > 0 && panorama_projects() && current_zoom_state().is_fit())
{
enter_panorama_projection();
return;
}
if (direction > 0 && panorama_enters_at_100())
{
zoom_100(anchor);
return;
}
mutate_zoom([&](df::zoom_view_state& state)
{
state.step(direction, zoom_fit_scale(), layout.source_extent, layout.viewport_extent, anchor);
});
mark_zoom_activity();
_async.invalidate_view(view_invalid::app_layout | view_invalid::view_layout | view_invalid::view_redraw |
view_invalid::controller);
}
void zoom_100()
{
const auto& layout = current_zoom_layout();
zoom_100({layout.viewport_extent.Width / 2.0, layout.viewport_extent.Height / 2.0});
}
void zoom_100(const pointd anchor)
{
// zoom.md: 100% means one source pixel per device pixel, and a sphere has no such pixel. Asking
// for actual size is asking for what the file stores, so it leaves the projection - visibly,
// because the zoom chrome's control says which of the two is in force.
if (declares_equirectangular()) _common._panorama.flat = true;
auto& layout = current_zoom_layout();
const auto source_anchor = current_zoom_state().source_point_at(
layout.source_extent, layout.viewport_extent, zoom_fit_scale(), anchor);
const auto old_scale = current_zoom_state().effective_scale(zoom_fit_scale());
mutate_zoom([&](df::zoom_view_state& state)
{
state.set_anchored(1.0, old_scale, layout.source_extent, layout.viewport_extent, anchor);
});
mark_zoom_activity();
layout.pending_source_anchor = source_anchor;
layout.pending_client_anchor = layout.viewport_origin + anchor;
layout.pending_reanchor = true;
_async.invalidate_view(view_invalid::app_layout | view_invalid::view_layout | view_invalid::view_redraw |
view_invalid::controller);
}
void zoom_fit_variant(const df::zoom_scale_mode mode)
{
const auto& layout = current_zoom_layout();
mutate_zoom([&](df::zoom_view_state& state)
{
if (mode == df::zoom_scale_mode::fit_width)
state.fit_width(layout.source_extent, layout.viewport_extent);
else if (mode == df::zoom_scale_mode::fill)
state.fill(layout.source_extent, layout.viewport_extent);
else
state.fit();
});
mark_zoom_activity();
_async.invalidate_view(view_invalid::app_layout | view_invalid::view_layout | view_invalid::view_redraw |
view_invalid::controller);
}
void zoom_scale(const double scale)
{
const auto& layout = current_zoom_layout();
const pointd anchor{layout.viewport_extent.Width / 2.0, layout.viewport_extent.Height / 2.0};
const auto old_scale = current_zoom_state().effective_scale(zoom_fit_scale());
mutate_zoom([&](df::zoom_view_state& state)
{
state.set_anchored(scale, old_scale, layout.source_extent, layout.viewport_extent, anchor);
});
mark_zoom_activity();
_async.invalidate_view(view_invalid::app_layout | view_invalid::view_layout | view_invalid::view_redraw |
view_invalid::controller);
}
double zoom_fit_scale() const
{
const auto& layout = current_zoom_layout();
return df::zoom_view_state::fit_scale(layout.source_extent, layout.viewport_extent, setting.scale_up);
}
double zoom_fit_scale(const df::zoom_pane pane) const
{
const auto& layout = _zoom_layouts[zoom_pane_index(pane)];
return df::zoom_view_state::fit_scale(layout.source_extent, layout.viewport_extent, setting.scale_up);
}
void zoom_layout(const sized source, const sized viewport, const pointd viewport_origin,
const df::zoom_pane pane = df::zoom_pane::primary)
{
auto& layout = _zoom_layouts[zoom_pane_index(pane)];
layout.source_extent = source;
layout.viewport_extent = viewport;
layout.viewport_origin = viewport_origin;
auto& state = _is_two ? _comparison_zoom.state(pane) : _common._zoom;
state.update_source(source, zoom_fit_scale(pane));
state.update_fit_variant(source, viewport, setting.scale_up);
if (layout.pending_reanchor)
{
state.center_source_point_at(layout.pending_source_anchor, source, viewport, zoom_fit_scale(pane),
layout.pending_client_anchor - viewport_origin);
layout.pending_reanchor = false;
}
}
const df::zoom_view_state& zoom_state() const noexcept
{
return current_zoom_state();
}
const df::zoom_view_state& zoom_state(const df::zoom_pane pane) const noexcept
{
return _is_two ? _comparison_zoom.state(pane) : _common._zoom;
}
void restore_zoom_state(const df::zoom_view_state& state)
{
mutate_zoom([&](df::zoom_view_state& current) { current = state; });
_temporary_zoom = false;
mark_zoom_activity();
_async.invalidate_view(view_invalid::app_layout | view_invalid::view_layout | view_invalid::view_redraw |
view_invalid::controller);
}
void inspect_at_100(const pointd anchor)
{
// zoom.md: one mechanism, two durations. A declared sphere is a sphere under a held button too,
// and the pointer aims it from the moment of the press.
if (panorama_projects())
{
enter_panorama_projection(true);
panorama_look_at(anchor);
return;
}
auto& layout = current_zoom_layout();
const auto source_anchor = current_zoom_state().source_point_at(
layout.source_extent, layout.viewport_extent, zoom_fit_scale(), anchor);
const auto old_scale = current_zoom_state().effective_scale(zoom_fit_scale());
mutate_zoom([&](df::zoom_view_state& state)
{
state.set_anchored(1.0, old_scale, layout.source_extent, layout.viewport_extent, anchor);
});
mark_zoom_activity();
layout.pending_source_anchor = source_anchor;
layout.pending_client_anchor = layout.viewport_origin + anchor;
layout.pending_reanchor = true;
_temporary_zoom = true;
_async.invalidate_view(view_invalid::app_layout | view_invalid::view_layout | view_invalid::view_redraw |
view_invalid::controller);
}
void commit_inspect()
{
if (_temporary_zoom)
{
_temporary_zoom = false;
mark_zoom_activity();
_async.invalidate_view(view_invalid::view_redraw | view_invalid::controller);
}
}
bool is_temporary_zoom() const noexcept
{
return _temporary_zoom;
}
void zoom_center(const pointd center)
{
const auto scale = current_zoom_state().effective_scale(zoom_fit_scale());
mutate_zoom([&](df::zoom_view_state& state) { state.set_explicit(scale, center); });
mark_zoom_activity();
_async.invalidate_view(view_invalid::view_layout | view_invalid::view_redraw);
}
// Moving the centre only. No button was pressed, so the sweep must not decide the scale for the
// user and lose the fit variant they chose. This runs on plain pointer movement, so it asks for a
// redraw and not a layout: nothing set_center touches changes a measured extent, and re-measuring
// the media column on every sample of a sweep is a cost paid for nothing.
void look_around_center(const pointd center)
{
mutate_zoom([&](df::zoom_view_state& state) { state.set_center(center); });
mark_zoom_activity();
_async.invalidate_view(view_invalid::view_redraw);
}
// zoom.md: the display's own question, wider than what the file declares. The shape fallback
// lives on the metadata record beside the declaration.
bool displays_as_panorama() const
{
if (!_is_one || !_item1) return false;
const auto md = _item1->metadata();
return md && md->displays_as_panorama();
}
// zoom.md: the file declares a sphere, so the viewer can put the user inside it. Only
// equirectangular: cylindrical names no vertical mapping the file agrees on, and `unspecified`
// names no projection at all, so both keep the flat treatment.
bool declares_equirectangular() const
{
if (!_is_one || !_item1) return false;
const auto md = _item1->metadata();
// Dimensions are what the coverage is derived from, so an item the scan has not measured yet
// cannot be stood inside - the sidecar merge sets the declaration without ever seeing a pixel.
return md && md->panorama == prop::panorama_projection::equirectangular && !md->dimensions().is_empty();
}
// Whether the next magnified draw is a projection. The flat override is per item and visible in
// the zoom chrome, so this is never a hidden mode.
bool panorama_projects() const
{
if (!declares_equirectangular() || _common._panorama.flat) return false;
// The sphere is described in the file's stored pixel grid, so a file that also asks to be
// rotated for display would be sampled in a space its own metadata does not describe. Shown
// flat rather than shown wrong; vanishingly rare, because a stitcher writes the panorama the
// way up it means it.
return !setting.show_rotated || !_selected_texture1 ||
_selected_texture1->display_orientation() == core::orientation::top_left;
}
// Whether the next magnified draw is a projection. Inspect zoom is included: zoom.md makes it and
// zoom mode two durations of one mechanism sharing one renderer, so press-and-hold on a declared
// sphere shows the sphere. The flat override is per item and visible in the zoom chrome, so this
// is never a hidden mode.
bool is_panorama_projected() const
{
return is_zoom_mode() && panorama_projects();
}
const panorama_session& panorama() const noexcept
{
return _common._panorama;
}
panorama_request panorama_draw_request() const
{
if (!is_panorama_projected()) return {};
return {true, _common._panorama.geometry, _common._panorama.view};
}
// Keyed on the path so a second panorama opens at its own centre. Declaration currency also
// includes source dimensions: replacing a file at the same path must reread its crop geometry,
// while ordinary repopulation must not throw away where the user is looking or the flat/projected
// choice they made.
void panorama_item(const core::file_path path, const sizei source, const core::date_t modified)
{
auto& session = _common._panorama;
if (session.path == path && session.source == source && session.modified == modified) return;
const auto same_path = session.path == path;
session.path = path;
session.source = source;
session.modified = modified;
session.geometry = prop::panorama_geometry::assumed(source);
session.resolved = false;
session.reset_view_on_resolve = !same_path;
if (!same_path)
{
session.flat = false;
session.view.reset(session.geometry);
}
}
// The declared coverage, once the file has answered. Applied only while the item and source size
// it was read for are still on screen. Declaration currency is separate from the user's camera
// and flat/projected choice, so a same-path declaration refresh does not reset either.
void panorama_geometry(const core::file_path path, const prop::panorama_geometry& declared, const sizei source,
const core::date_t modified)
{
auto& session = _common._panorama;
if (session.path != path || session.source != source || session.modified != modified || session.resolved) return;
const auto resolved = prop::panorama_geometry::resolve(declared, source);
if (!resolved.is_valid()) return;
session.geometry = resolved;
session.resolved = true;
if (session.reset_view_on_resolve)
{
session.view.reset(session.geometry);
session.reset_view_on_resolve = false;
}
_async.invalidate_view(view_invalid::view_redraw);
}
// zoom.md L6: the projection is a state the user can change, so it has a control that shows
// which one is on. Leaving the projection lands on the flat picture at 100%, which is the
// answer someone asking for the pixels wanted.
void toggle_panorama_projection()
{
if (!declares_equirectangular()) return;
_common._panorama.flat = !_common._panorama.flat;
if (_common._panorama.flat) zoom_100();
else _common._panorama.view.reset(_common._panorama.geometry);
mark_zoom_activity();
_async.invalidate_view(view_invalid::app_layout | view_invalid::view_layout | view_invalid::view_redraw |
view_invalid::controller);
}
// A drag turns the world under the pointer. The whole gesture is recomputed from its origin
// against the view it started from, for the same reason panning is: coalesced or dropped move
// messages must not change where the drag ends up.
void panorama_drag(const pointd client_delta, const panorama_view& start)
{
const auto& layout = current_zoom_layout();
_common._panorama.view.drag(client_delta, layout.viewport_extent, start);
mark_zoom_activity();
_async.invalidate_view(view_invalid::view_redraw);
}
// An interrupted look puts the camera back where the gesture found it, the same undo a cancelled
// pan gets.
void restore_panorama_view(const panorama_view& view)
{
_common._panorama.view = view;
mark_zoom_activity();
_async.invalidate_view(view_invalid::view_redraw);
}
// The field-of-view ladder replaces the zoom ladder while projected. Stepping out from the widest
// stop leaves magnification entirely, which is the same shape as zoom.md L2 stepping out to Fit.
void panorama_step_fov(const int direction)
{
if (direction == 0) return;
if (!_common._panorama.view.step_fov(direction))
{
zoom(false);
return;
}
mark_zoom_activity();
_async.invalidate_view(view_invalid::view_redraw | view_invalid::controller);
}
// Entering a projection is entering zoom mode: the scale it carries is what makes the mode
// active and what the flat picture returns to, and it is never what the projected draw uses.
void enter_panorama_projection(const bool temporary = false)
{
const auto fit = zoom_fit_scale();
const auto scale = fit < 1.0 ? 1.0 : fit * 1.5;
mutate_zoom([scale](df::zoom_view_state& state) { state.set_explicit(scale); });
_common._panorama.view.reset(_common._panorama.geometry);
_temporary_zoom = temporary;
mark_zoom_activity();
_async.invalidate_view(view_invalid::app_layout | view_invalid::view_layout | view_invalid::view_redraw |
view_invalid::controller);
}
// Where a held pointer is aiming. Positional, like the flat inspect traversal it replaces: the
// viewport maps the whole file, so crossing it looks all the way round.
void panorama_look_at(const pointd local)
{
const auto& layout = current_zoom_layout();
_common._panorama.view.aim(local, layout.viewport_extent, _common._panorama.geometry);
mark_zoom_activity();
_async.invalidate_view(view_invalid::view_redraw);
}
// zoom.md: look around a flat wide picture. No button is held, so press-and-hold inspect zoom is
// untouched. A projected panorama is excluded: it is looked around by dragging, and following a
// resting pointer as well would give one picture two answers to the same movement.
bool is_looking_around() const
{
return is_zoom_mode() && !_temporary_zoom && displays_as_panorama() && !panorama_projects();
}
// zoom.md: a 12000x1000 stitch fitted to a browsing window is a bright line, so the ladder's first
// stop above fit is still nothing to read. Entering zoom on a panorama goes straight to 100%,
// where the strip is legible and the pointer can sweep it. Only when 100% is a step up: a small
// declared panorama scaled up to fill the window is already past it, and the shortcut would answer
// a zoom in by zooming out.
bool panorama_enters_at_100() const
{
return current_zoom_state().is_fit() && displays_as_panorama() && zoom_fit_scale() < 1.0;
}
// The pointer maps onto the source-space centre, so crossing the viewport sweeps the whole
// width. The vertical axis is pinned unless the picture is taller than the viewport at this
// scale: without something to see up there, following the pointer is only jitter.
void look_around_at(const pointd local)
{
const auto& layout = current_zoom_layout();
const auto viewport = layout.viewport_extent;
const auto source = layout.source_extent;
if (viewport.Width <= 0.0 || viewport.Height <= 0.0 || source.Width <= 0.0 || source.Height <= 0.0) return;
const auto scale = current_zoom_state().effective_scale(zoom_fit_scale());
const auto center = df::zoom_view_state::look_around_center(local, source, viewport, scale);
if (current_zoom_state().center() == center) return;
look_around_center(center);
}
void pan_zoom(const pointd client_delta, const df::zoom_view_state& start)
{
const auto& layout = current_zoom_layout();
mutate_zoom([&](df::zoom_view_state& state)
{
state = start;
const auto scale = state.effective_scale(zoom_fit_scale());
state.pan_source({-client_delta.X / scale, -client_delta.Y / scale}, layout.source_extent,
layout.viewport_extent, zoom_fit_scale());
});
mark_zoom_activity();
_async.invalidate_view(view_invalid::view_layout | view_invalid::view_redraw);
}
void pan_zoom_by(const pointd client_delta)
{
const auto& layout = current_zoom_layout();
mutate_zoom([&](df::zoom_view_state& state)
{
const auto scale = state.effective_scale(zoom_fit_scale());
state.pan_source({client_delta.X / scale, client_delta.Y / scale}, layout.source_extent,
layout.viewport_extent, zoom_fit_scale());
});
mark_zoom_activity();
_async.invalidate_view(view_invalid::view_layout | view_invalid::view_redraw);
}
void pan_zoom_to_horizontal_edge(const bool last)
{
auto& layout = current_zoom_layout();
mutate_zoom([&](df::zoom_view_state& state)
{
state.pan_source({last ? layout.source_extent.Width : -layout.source_extent.Width, 0.0},
layout.source_extent, layout.viewport_extent, zoom_fit_scale());
});
mark_zoom_activity();
_async.invalidate_view(view_invalid::view_layout | view_invalid::view_redraw);
}
void zoom_region(const rectd& region)
{
const auto& layout = current_zoom_layout();
mutate_zoom([&](df::zoom_view_state& state)
{
state.zoom_region(region, layout.source_extent, layout.viewport_extent, zoom_fit_scale());
});
mark_zoom_activity();
_async.invalidate_view(view_invalid::app_layout | view_invalid::view_layout | view_invalid::view_redraw |
view_invalid::controller);
}
bool can_zoom() const
{
return _can_zoom;
}
void toggle_zoom()
{
if (current_zoom_state().is_fit()) zoom(true);
else zoom(false);
}
void toggle_zoom_fit()
{
mutate_zoom([](df::zoom_view_state& state) { state.toggle_fit(); });
mark_zoom_activity();
_async.invalidate_view(view_invalid::app_layout | view_invalid::view_layout | view_invalid::view_redraw |
view_invalid::controller);
}
bool player_has_video() const
{
return _player_media_info.has_video;
}
bool can_play_media() const
{
return (_player_media_info.has_video || _player_media_info.has_audio) && _session;
}
bool is_playing_media() const
{
return (_player_media_info.has_video || _player_media_info.has_audio) && _session && _session->is_playing();
}
bool is_playing() const
{
return _common._is_slideshow || is_playing_media();
}
bool is_slideshow() const
{
return _common._is_slideshow;
}
bool is_playing_slideshow() const
{
return _common._is_slideshow && (!_session || !_session->is_playing());
}
void stop_slideshow()
{
if (_common._is_slideshow)
{
_common._is_slideshow = false;
_next_photo_tick = 0;
// command_state too: the slideshow toggle and its related commands read this flag.
// screen_saver because a photo slideshow is the only thing holding sleep off.
_async.invalidate_view(view_invalid::view_redraw | view_invalid::command_state |
view_invalid::screen_saver);
}
}
bool display_item_has_trait(const file_traits t) const
{
return _is_one && _item1 && _item1->file_type()->has_trait(t);
}
int slideshow_pos() const
{
return core::mul_div(_next_photo_tick, 1000,
std::max(1, setting.slideshow_delay) * render::default_ticks_per_second);
}
// Brings the scrubber's position and time text up to the session. Repaints only while the media controls
// are shown: hidden, they draw at alpha 0, and the fade that brings them back repaints them current.
void update_scrubber(const bool controls_shown = true)
{
const auto& info = _player_media_info;
if (info.has_video || info.has_audio)
{
auto invalid = false;
const auto start = info.start;
const auto end = info.end;
const auto len = end - start;
const auto media_pos = _session ? _session->last_frame_time() : 0.0;
const auto pos = static_cast<int>((media_pos - start) * _scrubber_width / std::max(1.0, len));
const auto endi = core::round(end);
if (endi != _last_duration)
{
_duration = core::format_seconds(endi);
}
if (pos != _last_scrubber_pos)
{
_last_scrubber_pos = pos;
invalid = true;
}
const auto position = core::round(media_pos);
if (_last_seconds != position)
{
_last_seconds = position;
_time = core::format_seconds(position);
invalid = true;
}
if (invalid && controls_shown)
{
_async.invalidate_view(view_invalid::view_redraw);
}
}
}
void load_compare_preview(int elapsed_numerator, int elapsed_denominator);
void load_seek_preview(int pos_numerator, int pos_denominator, std::function<void()> callback);
void preview_loaded()
{
update_scrubber();
_async.invalidate_view(view_invalid::view_redraw | view_invalid::tooltip);
}
bool is_multi() const
{
return _is_multi;
}
bool step()
{
bool invalid = false;
invalid |= _loading_alpha_animation.step();
invalid |= _selected_texture1 && _selected_texture1->step();
invalid |= _selected_texture2 && _selected_texture2->step();
return invalid;
}
void update_av_session(const std::shared_ptr<av_session>& ses);
// Reads the head of the display item into _selected_item_data, and decodes it into _document, off
// the UI thread.
void load_selected_item_data();
// False when a teardown or a newer open has taken the display since; the caller then owns closing
// the session it was handed.
bool publish_av_session(const std::shared_ptr<av_session>& ses, uint32_t generation);
// A player session only reads the container, so a sidecar packet is fetched separately.
void load_xmp_sidecar();
void calc_pixel_difference();
};