-
Notifications
You must be signed in to change notification settings - Fork 14
/
fe_present.cpp
1682 lines (1387 loc) · 38.1 KB
/
fe_present.cpp
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
998
999
1000
/*
*
* Attract-Mode frontend
* Copyright (C) 2013-15 Andrew Mickelson
*
* This file is part of Attract-Mode.
*
* Attract-Mode is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Attract-Mode is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with Attract-Mode. If not, see <http://www.gnu.org/licenses/>.
*
*/
#include "fe_present.hpp"
#include "fe_util.hpp"
#include "fe_image.hpp"
#include "fe_text.hpp"
#include "fe_listbox.hpp"
#include "fe_rectangle.hpp"
#include "fe_input.hpp"
#include "fe_file.hpp"
#include "fe_blend.hpp"
#include "zip.hpp"
#include "base64.hpp"
#include "BarlowCJK.ttf.h"
#include <iostream>
#include <cmath>
#include <limits>
#include <cstring>
#ifndef NO_MOVIE
#include <Audio/AudioDevice.hpp>
#endif
#ifdef USE_XLIB
#include <X11/extensions/Xrandr.h>
#endif
#ifdef USE_XINERAMA
#include <X11/extensions/Xinerama.h>
#endif
#ifdef USE_DRM
#include <unistd.h>
#include <fcntl.h>
#include <stdio.h>
#include <xf86drm.h>
#include <xf86drmMode.h>
#endif
#ifdef SFML_SYSTEM_MACOS
#include <CoreVideo/CoreVideo.h>
#endif
#ifdef SFML_SYSTEM_WINDOWS
#include <windows.h>
BOOL CALLBACK my_mon_enum_proc( HMONITOR, HDC, LPRECT mon_rect, LPARAM data )
{
std::vector < FeMonitor > *monitors = (std::vector < FeMonitor > *)data;
FeMonitor mon(
monitors->size(),
mon_rect->right - mon_rect->left,
mon_rect->bottom - mon_rect->top );
mon.transform = sf::Transform().translate( mon_rect->left, mon_rect->top );
FeDebug() << "Multimon: monitor #" << monitors->size()
<< ": " << mon.size.x << "x" << mon.size.y << " @ "
<< mon_rect->left << "," << mon_rect->top << std::endl;
// make sure primary monitor is first in m_mon vector
//
if (( mon_rect->left == 0 ) && ( mon_rect->top == 0 ))
monitors->insert( monitors->begin(), mon );
else
monitors->push_back( mon );
return TRUE;
}
#endif
FeFontContainer::FeFontContainer()
: m_needs_reload( false )
{
}
FeFontContainer::~FeFontContainer()
{
}
void FeFontContainer::set_font( const std::string &n )
{
m_name = n;
if ( !m_font.loadFromFile( n ) )
FeLog() << "Error loading font from file: " << n << std::endl;
}
void FeFontContainer::load_default_font()
{
m_font_binary_data = base64_decode( _binary_resources_fonts_BarlowCJK_ttf );
m_font.loadFromMemory( m_font_binary_data.data(), m_font_binary_data.size() );
}
const sf::Font &FeFontContainer::get_font() const
{
return m_font;
}
void FeFontContainer::clear_font()
{
m_font = sf::Font();
m_needs_reload = true;
}
FeMonitor::FeMonitor( int n, int w, int h )
: num( n )
{
size.x = w;
size.y = h;
}
FeMonitor::FeMonitor( const FeMonitor &o )
: FePresentableParent( o ),
transform( o.transform ),
size( o.size ),
num( o.num )
{
}
FeMonitor &FeMonitor::operator=( const FeMonitor &o )
{
elements = o.elements;
transform = o.transform;
size = o.size;
num = o.num;
return *this;
}
int FeMonitor::get_width()
{
return size.x;
}
int FeMonitor::get_height()
{
return size.y;
}
int FeMonitor::get_num()
{
return num;
}
FePresent::FePresent( FeSettings *fesettings, FeWindow &wnd )
: m_feSettings( fesettings ),
m_window( wnd ),
m_layoutFont( NULL ),
m_defaultFont( NULL ),
m_baseRotation( FeSettings::RotateNone ),
m_toggleRotation( FeSettings::RotateNone ),
m_refresh_rate( 0 ),
m_playMovies( true ),
m_user_page_size( -1 ),
m_preserve_aspect( false ),
m_custom_overlay( false ),
m_listBox( NULL ),
m_emptyShader( NULL ),
m_overlay_caption( NULL ),
m_overlay_lb( NULL ),
m_layout_loaded( false )
{
m_baseRotation = m_feSettings->get_screen_rotation();
m_layoutFontName = "";
init_monitors();
}
void FePresent::init_monitors()
{
m_mon.clear();
//
// Handle multi-monitors
//
// We support multi-monitor setups on MS-Windows when in fullscreen or "fillscreen" mode
// We also determine display's refresh rate here
//
#if defined(SFML_SYSTEM_MACOS)
CGDirectDisplayID display_id = CGMainDisplayID();
CGDisplayModeRef display_mode = CGDisplayCopyDisplayMode( display_id );
size_t refresh_rate = CGDisplayModeGetRefreshRate( display_mode );
if ( refresh_rate == 0 )
{
CVDisplayLinkRef display_link;
CVDisplayLinkCreateWithCGDisplay( display_id, &display_link );
const CVTime time = CVDisplayLinkGetNominalOutputVideoRefreshPeriod( display_link );
if ( !( time.flags & kCVTimeIsIndefinite ))
m_refresh_rate = (int)( (float)time.timeScale / (float)time.timeValue + 0.5f );
}
else
m_refresh_rate = refresh_rate;
#endif
#if defined(USE_DRM)
#define MAX_DRM_DEVICES 64
drmDevicePtr devices[MAX_DRM_DEVICES] = { NULL };
int num_devices, fd = -1;
num_devices = drmGetDevices2( 0, devices, MAX_DRM_DEVICES );
for ( int i = 0; i < num_devices; i++ )
{
drmDevicePtr device = devices[i];
int ret;
if ( !( device->available_nodes & ( 1 << DRM_NODE_PRIMARY )))
continue;
int drm_fd = open( device->nodes[DRM_NODE_PRIMARY], O_RDWR | O_CLOEXEC );
drmModeRes *p_res = drmModeGetResources( drm_fd );
if ( p_res )
for ( int j = 0; j < p_res->count_connectors; j++ )
{
drmModeConnector *p_connector = drmModeGetConnector( drm_fd, p_res->connectors[j] );
drmModeEncoder *encoder;
drmModeCrtc *crtc;
encoder = drmModeGetEncoder( drm_fd, p_connector->encoder_id );
drmModeModeInfo mode_info;
memset( &mode_info, 0, sizeof( drmModeModeInfo ));
if ( encoder != NULL )
{
crtc = drmModeGetCrtc( drm_fd, encoder->crtc_id );
drmModeFreeEncoder( encoder );
if ( crtc != NULL )
{
if ( crtc->mode_valid )
m_refresh_rate = crtc->mode.vrefresh;
drmModeFreeCrtc( crtc );
}
}
}
close( drm_fd );
}
drmFreeDevices( devices, num_devices );
#endif
#if defined(SFML_SYSTEM_WINDOWS)
DEVMODE devMode;
memset( &devMode, 0, sizeof(DEVMODE) );
devMode.dmSize = sizeof(DEVMODE);
devMode.dmDriverExtra = 0;
if ( EnumDisplaySettings( NULL, ENUM_CURRENT_SETTINGS, &devMode ) != 0 )
m_refresh_rate = devMode.dmDisplayFrequency;
if ( m_feSettings->get_info_bool( FeSettings::MultiMon )
&& !is_windowed_mode( m_feSettings->get_window_mode() ) )
{
EnumDisplayMonitors( NULL, NULL, my_mon_enum_proc, (LPARAM)&m_mon );
//
// The Windows virtual screen can have a negative valued top left corner, whereas in SFML we
// always have a 0,0 top left. So we correct the transforms in m_mon to SFML's coordinates now.
//
int translate_x = -GetSystemMetrics( SM_XVIRTUALSCREEN );
int translate_y = -GetSystemMetrics( SM_YVIRTUALSCREEN );
//
// On Windows 'Fill screen' mode our window is offscreen 1 pixel in each direction, so correct
// for that here to align draw area with screen
//
if ( m_feSettings->get_window_mode() == FeSettings::Default )
{
translate_x += 1;
translate_y += 1;
}
sf::Transform correction = sf::Transform().translate( translate_x, translate_y );
for ( std::vector<FeMonitor>::iterator itr=m_mon.begin(); itr!=m_mon.end(); ++itr )
(*itr).transform *= correction;
}
else
#elif defined(USE_XLIB)
Display *xdisp = XOpenDisplay( NULL );
if ( !xdisp )
{
FeLog() << "Unable to open x display" << std::endl;
}
else
{
Window root = RootWindow( xdisp, 0 );
XRRScreenConfiguration *xconf = XRRGetScreenInfo( xdisp, root );
m_refresh_rate = XRRConfigCurrentRate( xconf );
XRRFreeScreenConfigInfo( xconf );
}
#if !defined(USE_XINERAMA)
XCloseDisplay( xdisp );
#else
bool set_first=true;
if ( xdisp && ( m_feSettings->get_info_bool( FeSettings::MultiMon ) )
&& !is_windowed_mode( m_feSettings->get_window_mode() ) )
{
int num = 0;
XineramaScreenInfo *si = XineramaQueryScreens( xdisp, &num );
if ( !si )
{
FeLog() << "Unable to query Xinerama screens" << std::endl;
set_first=true;
}
else
{
for ( int i=0; i<num; i++ )
{
FeMonitor mon(
si[i].screen_number,
si[i].width,
si[i].height );
mon.transform = sf::Transform().translate(
si[i].x_org,
si[i].y_org );
FeDebug() << "Multimon: monitor #" << si[i].screen_number
<< ": " << mon.size.x << "x" << mon.size.y << " @ "
<< si[i].x_org << "," << si[i].y_org << std::endl;
m_mon.push_back( mon );
}
set_first=false;
XFree( si );
}
}
if ( xdisp )
XCloseDisplay( xdisp );
if ( set_first )
#endif
#endif
{
FeMonitor mc( 0, m_window.get_win().getSize().x, m_window.get_win().getSize().y );
#ifdef SFML_SYSTEM_WINDOWS
//
// On Windows 'Fill screen' mode our window is offscreen 1 pixel in each direction, so correct
// for that here to align draw area with screen.
//
if ( m_feSettings->get_window_mode() == FeSettings::Default )
{
mc.size.x -= 2;
mc.size.y -= 2;
mc.transform = sf::Transform().translate( 1, 1 );
}
#endif
m_mon.push_back( mc );
}
ASSERT( m_mon.size() > 0 );
m_layoutSize = m_mon[0].size;
if ( m_refresh_rate == 0 )
{
FeLog() << "Failed to detect the refresh rate. Defaulting to 60 Hz" << std::endl;
m_refresh_rate = 60;
}
else
FeDebug() << "Monitor's Refresh Rate: " << m_refresh_rate << " Hz" << std::endl;
}
FePresent::~FePresent()
{
clear();
}
void FePresent::clear()
{
//
// keep toggle rotation, base rotation and mute state through clear
//
// Activating the screen saver keeps the previous base rotation, while
// mute and toggle rotation are kept whenever the layout is changed
//
m_listBox=NULL; // listbox gets deleted with the m_mon.elements below
m_layout_transform = sf::Transform();
m_ui_transform = sf::Transform();
m_layoutFont = NULL;
m_layoutFontName = "";
m_user_page_size = -1;
m_preserve_aspect = false;
m_custom_overlay = false;
m_overlay_caption = NULL;
m_overlay_lb = NULL;
for ( std::vector<FeMonitor>::iterator itr=m_mon.begin(); itr!=m_mon.end(); ++itr )
{
while ( !(*itr).elements.empty() )
{
FeBasePresentable *p = (*itr).elements.back();
(*itr).elements.pop_back();
delete p;
}
}
while ( !m_texturePool.empty() )
{
FeBaseTextureContainer *t = m_texturePool.back();
m_texturePool.pop_back();
delete t;
}
while ( !m_sounds.empty() )
{
FeSound *s = m_sounds.back();
m_sounds.pop_back();
delete s;
}
while ( !m_scriptShaders.empty() )
{
FeShader *sh = m_scriptShaders.back();
m_scriptShaders.pop_back();
delete sh;
}
if ( m_emptyShader )
{
delete m_emptyShader;
m_emptyShader = NULL;
}
while ( !m_fontPool.empty() )
{
FeFontContainer *f = m_fontPool.back();
m_fontPool.pop_back();
delete f;
}
m_baseRotation = m_feSettings->get_screen_rotation();
FeSettings::RotationState actualRotation = get_actual_rotation();
if (( actualRotation == FeSettings::RotateLeft ) || ( actualRotation == FeSettings::RotateRight ))
{
m_layoutSize.x = m_mon[0].size.y;
m_layoutSize.y = m_mon[0].size.x;
}
else
{
m_layoutSize.x = m_mon[0].size.x;
m_layoutSize.y = m_mon[0].size.y;
}
m_layoutScale.x = 1.0;
m_layoutScale.y = 1.0;
FeBlend::clear_default_shaders();
delete m_blank_texture;
m_blank_texture = NULL;
delete m_defaultFont;
m_defaultFont = NULL;
m_layoutFont = NULL;
}
void FePresent::draw( sf::RenderTarget& target, sf::RenderStates states ) const
{
std::vector<FeBasePresentable *>::const_iterator itl;
//
for ( unsigned int i=0; i<m_mon.size(); i++ )
{
// use m_transform on monitor 0
states.transform = i ? m_mon[i].transform : m_layout_transform;
for ( itl=m_mon[i].elements.begin(); itl != m_mon[i].elements.end(); ++itl )
{
if ( (*itl)->get_visible() )
target.draw( (*itl)->drawable(), states );
}
}
}
FeImage *FePresent::add_image( bool is_artwork,
const std::string &n,
float x,
float y,
float w,
float h,
FePresentableParent &p )
{
FeTextureContainer *new_tex = new FeTextureContainer( is_artwork, n );
new_tex->set_smooth( m_feSettings->get_info_bool( FeSettings::SmoothImages ) );
FeImage *new_image = new FeImage( p, new_tex, x, y, w, h );
new_image->set_scale_factor( m_layoutScale.x, m_layoutScale.y );
// if this is a static image/video then load it now
//
if (( !is_artwork ) && ( n.find_first_of( "[" ) == std::string::npos ))
new_image->setFileName( n.c_str() );
flag_redraw();
m_texturePool.push_back( new_tex );
p.elements.push_back( new_image );
return new_image;
}
FeImage *FePresent::add_clone( FeImage *o,
FePresentableParent &p )
{
FeImage *new_image = new FeImage( o );
flag_redraw();
p.elements.push_back( new_image );
if ( o->get_presentable_parent() != NULL )
o->get_presentable_parent()->set_nesting_level( p.get_nesting_level() + 1 );
return new_image;
}
FeText *FePresent::add_text( const std::string &n, int x, int y, int w, int h,
FePresentableParent &p )
{
FeText *new_text = new FeText( p, n, x, y, w, h );
new_text->setFont( *get_layout_font() );
new_text->set_scale_factor( m_layoutScale.x, m_layoutScale.y );
flag_redraw();
p.elements.push_back( new_text );
return new_text;
}
FeListBox *FePresent::add_listbox( int x, int y, int w, int h,
FePresentableParent &p )
{
FeListBox *new_lb = new FeListBox( p, x, y, w, h );
new_lb->setFont( *get_layout_font() );
new_lb->set_scale_factor( m_layoutScale.x, m_layoutScale.y );
flag_redraw();
m_listBox = new_lb;
p.elements.push_back( new_lb );
return new_lb;
}
FeRectangle *FePresent::add_rectangle( float x, float y, float w, float h,
FePresentableParent &p )
{
FeRectangle *new_rc = new FeRectangle( p, x, y, w, h );
new_rc->set_scale_factor( m_layoutScale.x, m_layoutScale.y );
flag_redraw();
p.elements.push_back( new_rc );
return new_rc;
}
FeImage *FePresent::add_surface( int w, int h, FePresentableParent &p )
{
FeSurfaceTextureContainer *new_surface = new FeSurfaceTextureContainer( w, h );
new_surface->set_smooth( m_feSettings->get_info_bool( FeSettings::SmoothImages ) );
new_surface->set_nesting_level( p.get_nesting_level() + 1 );
//
// Set the default sprite size to the same as the texture itself
//
FeImage *new_image = new FeImage( p, new_surface, 0, 0, w, h );
new_image->set_scale_factor( m_layoutScale.x, m_layoutScale.y );
new_image->set_blend_mode( FeBlend::Premultiplied );
new_image->texture_changed();
flag_redraw();
p.elements.push_back( new_image );
m_texturePool.push_back( new_surface );
return new_image;
}
FeSound *FePresent::add_sound( const char *n, bool reuse )
{
//
// Behaviour:
//
// - if n is empty, return a new (empty) sound object
// - if n is supplied:
// - if n matches an existing sound and reuse is true,
// return that matching sound object
// - otherwise return a new sound object loaded with n
//
std::string path;
std::string name=n;
if ( !name.empty() )
{
if ( is_relative_path( name ) )
{
int script_id = get_script_id();
if ( script_id < 0 )
m_feSettings->get_path( FeSettings::Current, path );
else
m_feSettings->get_plugin_full_path( script_id, path );
}
if ( reuse )
{
std::string test = path + name;
for ( std::vector<FeSound *>::iterator itr=m_sounds.begin();
itr!=m_sounds.end(); ++itr )
{
if ( test.compare( (*itr)->get_file_name() ) == 0 )
return (*itr);
}
}
}
// Sound not found, try loading now
//
FeSound *new_sound = new FeSound();
if ( !name.empty() )
new_sound->load( path + name );
new_sound->set_volume(
m_feSettings->get_play_volume( FeSoundInfo::Sound ) );
m_sounds.push_back( new_sound );
return new_sound;
}
FeShader *FePresent::add_shader( FeShader::Type type, const char *shader1, const char *shader2 )
{
std::string path1;
std::string path2;
m_feSettings->get_path( FeSettings::Current, path1 );
std::string s1;
std::string s2;
if ( shader1 )
s1 = clean_path( shader1 );
m_scriptShaders.push_back( new FeShader() );
FeShader *sh = m_scriptShaders.back();
if ( !is_relative_path( s1 ) )
path1.clear();
switch ( type )
{
case FeShader::VertexAndFragment:
path2 = path1;
if ( shader2 )
s2 = clean_path( shader2 );
if ( !is_relative_path( s2 ) )
path2.clear();
sh->load( path1 + s1, path2 + s2 );
break;
case FeShader::Vertex:
case FeShader::Fragment:
sh->load( path1 + s1, type );
break;
case FeShader::Empty:
default:
break;
}
return sh;
}
float FePresent::get_layout_width() const
{
return (float)m_layoutSize.x;
}
float FePresent::get_layout_height() const
{
return (float)m_layoutSize.y;
}
float FePresent::get_layout_scale_x() const
{
return m_layoutScale.x;
}
float FePresent::get_layout_scale_y() const
{
return m_layoutScale.y;
}
void FePresent::set_layout_width( float w )
{
if ( w != m_layoutSize.x )
{
m_layoutSize.x = w;
set_transforms();
flag_redraw();
}
}
void FePresent::set_layout_height( float h )
{
if ( h != m_layoutSize.y )
{
m_layoutSize.y = h;
set_transforms();
flag_redraw();
}
}
const FeFontContainer *FePresent::get_pooled_font( const std::string &n )
{
std::vector<std::string> my_list;
my_list.push_back( n );
return get_pooled_font( my_list );
}
const FeFontContainer *FePresent::get_pooled_font(
const std::vector < std::string > &l )
{
std::string ffile;
// search list for a font
for ( std::vector<std::string>::const_iterator itr=l.begin();
itr != l.end(); ++itr )
{
if ( m_feSettings->get_font_file( ffile, *itr ) )
break;
}
if ( ffile.empty() )
return get_default_font_container();
// Next check if this font is already loaded in our pool
//
for ( std::vector<FeFontContainer *>::iterator itr=m_fontPool.begin();
itr != m_fontPool.end(); ++itr )
{
if ( ffile.compare( (*itr)->get_name() ) == 0 )
return *itr;
}
// No match, so load this font and add it to the pool
//
m_fontPool.push_back( new FeFontContainer() );
m_fontPool.back()->set_font( ffile );
return m_fontPool.back();
}
void FePresent::set_layout_font_name( const char *n )
{
const FeFontContainer *font = get_pooled_font( n );
if ( font )
{
m_layoutFontName = n;
m_layoutFont = font;
flag_redraw();
}
}
const char *FePresent::get_layout_font_name() const
{
return m_layoutFontName.c_str();
}
void FePresent::set_base_rotation( int r )
{
FeLog() << "! NOTE: Setting base_rotation is deprecated. Use toggle_rotation or Screen Rotation in General Settings." << std::endl;
}
int FePresent::get_base_rotation() const
{
return m_baseRotation;
}
void FePresent::set_toggle_rotation( int r )
{
if ( r != m_toggleRotation )
{
m_toggleRotation = (FeSettings::RotationState)r;
set_transforms();
flag_redraw();
}
}
int FePresent::get_toggle_rotation() const
{
return m_toggleRotation;
}
const char *FePresent::get_display_name() const
{
return m_feSettings->get_current_display_title().c_str();
}
int FePresent::get_display_index() const
{
return m_feSettings->get_current_display_index();
}
const char *FePresent::get_filter_name() const
{
return m_feSettings->get_filter_name( m_feSettings->get_current_filter_index() ).c_str();
}
int FePresent::get_filter_index() const
{
return m_feSettings->get_current_filter_index();
}
void FePresent::set_filter_index( int idx )
{
int new_offset = idx - get_filter_index();
if ( new_offset != 0 )
{
if ( m_feSettings->navigate_filter( new_offset ) )
load_layout();
else
update_to_new_list( new_offset );
}
}
int FePresent::get_current_filter_size() const
{
return m_feSettings->get_filter_size( m_feSettings->get_current_filter_index() );
}
bool FePresent::get_clones_list_showing() const
{
if ( m_feSettings->get_clone_index() > 0 )
return true;
else
return false;
}
int FePresent::get_selection_index() const
{
return m_feSettings->get_rom_index( m_feSettings->get_current_filter_index(), 0 );
}
int FePresent::get_sort_by() const
{
FeRomInfo::Index idx;
bool rev;
int limit;
m_feSettings->get_current_sort( idx, rev, limit );
return idx;
}
bool FePresent::get_reverse_order() const
{
FeRomInfo::Index idx;
bool rev;
int limit;
m_feSettings->get_current_sort( idx, rev, limit );
return rev;
}
int FePresent::get_list_limit() const
{
FeRomInfo::Index idx;
bool rev;
int limit;
m_feSettings->get_current_sort( idx, rev, limit );
return limit;
}
void FePresent::set_selection_index( int index )
{
int new_offset = index - get_selection_index();
if ( new_offset != 0 )
change_selection( new_offset );
}
void FePresent::change_selection( int step, bool end_navigation )
{
on_transition( ToNewSelection, step );
m_feSettings->step_current_selection( step );
update( false );
on_transition( FromOldSelection, -step );
if ( end_navigation )
on_end_navigation();
}
bool FePresent::reset_screen_saver()
{
if ( m_feSettings->get_present_state() == FeSettings::ScreenSaver_Showing )
{
// Reset from screen saver
//
load_layout();
return true;
}
m_lastInput=m_layoutTimer.getElapsedTime();
return false;
}
bool FePresent::handle_event( FeInputMap::Command c )
{
if ( reset_screen_saver() )
return true;
switch( c )
{
case FeInputMap::NextGame:
change_selection( 1, false );
break;
case FeInputMap::PrevGame:
change_selection( -1, false );
break;
case FeInputMap::NextPage:
change_selection( get_page_size(), false );
break;
case FeInputMap::PrevPage:
change_selection( -get_page_size(), false );
break;
case FeInputMap::RandomGame:
{
int ls = m_feSettings->get_filter_size( m_feSettings->get_current_filter_index() );
if ( ls > 0 )
{
int step = rand() % ls;
if ( step != 0 )
change_selection( step );
}
}
break;
case FeInputMap::ToggleRotateRight:
toggle_rotate( FeSettings::RotateRight );
break;
case FeInputMap::ToggleFlip:
toggle_rotate( FeSettings::RotateFlip );
break;
case FeInputMap::ToggleRotateLeft:
toggle_rotate( FeSettings::RotateLeft );
break;
case FeInputMap::ToggleMovie:
toggle_movie();
break;
case FeInputMap::NextDisplay:
case FeInputMap::PrevDisplay:
if ( m_feSettings->navigate_display( ( c == FeInputMap::NextDisplay ) ? 1 : -1 ) )
load_layout();
else
update_to_new_list( 0, true );
break;
case FeInputMap::NextFilter:
case FeInputMap::PrevFilter:
{