forked from TheSaw/win7shell
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrenderer.cpp
1127 lines (982 loc) · 32.9 KB
/
renderer.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
#include <Windows.h>
#include <string>
#include <strsafe.h>
#include <vector>
#include <gdiplus.h>
#include "renderer.h"
#include "gen_win7shell.h"
#include "api.h"
#include "lines.h"
#include <dwmapi.h>
#include <loader/loader/paths.h>
#include <loader/loader/ini.h>
#include <loader/loader/utils.h>
WA_UTILS_API HBITMAP GetMainWindowBmp(void);
bool renderer::getAlbumArt(const std::wstring &fname, const bool skip_lock)
{
if (running && !albumart && (WASABI_API_ALBUMART != NULL))
{
// this is always going to be called from it's own thread
// so the use of GetAlbumArtAsyncResize(..) only makes it
// seem a bit glitchy or can allow multiple actions to be
// triggered which makes the preview seem to then flicker
ARGB32* cur_image = 0;
int cur_w = 0, cur_h = 0;
if (WASABI_API_ALBUMART->GetAlbumArtResize(fname.c_str(), L"cover", &cur_w, &cur_h,
&cur_image, 600, 600, 0, NULL) == ALBUMART_SUCCESS)
{
BITMAPINFO bmi = { 0 };
InitBitmapForARGB32(&bmi, cur_w, cur_h);
Gdiplus::Bitmap tmpbmp(&bmi, cur_image);
float new_height = 0.f, new_width = 0.f, anchor = (m_height * 1.f);
if (!m_settings.AsIcon)
{
if (m_width < m_height)
{
anchor = (m_width * 1.f);
}
}
else
{
anchor = (_iconheight * 1.f);
}
if (cur_w > cur_h)
{
new_height = (float)cur_h / (float)cur_w * (float)anchor;
new_height -= 2;
new_width = anchor;
if (new_height > m_height)
{
new_width = (float)cur_w / (float)cur_h * (float)anchor;
new_width -= 2;
new_height = anchor;
}
}
else
{
new_width = (float)cur_w / (float)cur_h * (float)anchor;
new_width -= 2;
new_height = anchor;
if (new_width > m_width)
{
new_height = (float)cur_h / (float)cur_w * (float)anchor;
new_height -= 2;
new_width = anchor;
}
}
m_iconheight = _iconheight = (int)new_height;
m_iconwidth = _iconwidth = (int)new_width;
// we don't want to keep doing this as it is going
// to be very slow especially with >600x600 images
// so we cache a re-sized image and then draw that
if (cur_image != NULL)
{
const float ratio = (cur_h * 1.f) / (cur_h * 1.f);
if (cur_w > cur_h)
{
new_height = (new_width / ratio);
}
else
{
new_width = (new_height * ratio);
}
albumart = new Gdiplus::Bitmap(static_cast<int>(new_width),
static_cast<int>(new_height),
tmpbmp.GetPixelFormat());
if (albumart)
{
Gdiplus::Graphics graphics(albumart);
graphics.DrawImage(&tmpbmp, static_cast<Gdiplus::REAL>(0),
static_cast<Gdiplus::REAL>(0),
static_cast<Gdiplus::REAL>(new_width),
static_cast<Gdiplus::REAL>(new_height));
}
plugin.memmgr->sysFree(cur_image);
}
else
{
albumart = NULL;
}
}
else
{
return false;
}
}
if (albumart != NULL)
{
Gdiplus::Graphics gfx(background);
gfx.SetInterpolationMode(Gdiplus::InterpolationModeHighQuality);
gfx.SetPixelOffsetMode(Gdiplus::PixelOffsetModeNone);
gfx.SetCompositingQuality(Gdiplus::CompositingQualityHighSpeed);
int iconleft = 0, icontop = 0;
switch (m_settings.IconPosition)
{
case IP_LOWERLEFT:
{
icontop = m_height - m_iconheight - 2;
break;
}
case IP_UPPERRIGHT:
{
iconleft = m_width - m_iconwidth - 2;
break;
}
case IP_LOWERRIGHT:
{
iconleft = m_width - m_iconwidth - 2;
icontop = m_height - m_iconheight - 2;
break;
}
}
if (!m_settings.AsIcon)
{
// TODO need to get this accounting for irregular
// images so they're centered in the window!
iconleft = (m_width / 2) - (m_iconwidth / 2);
}
/*else
{
// Draw icon shadow
// note: have dropped this with the irregular image
// handling as it was introducing a slight
// performance penalty on older / slower h/w
// and it's almost impossible to see its there
gfx.SetSmoothingMode(Gdiplus::SmoothingModeAntiAlias);
gfx.FillRectangle(&Gdiplus::SolidBrush(Gdiplus::Color::MakeARGB((BYTE)(110 - m_settings.BG_Transparency), 0, 0, 0)),
static_cast<Gdiplus::REAL>(iconleft + 1), static_cast<Gdiplus::REAL>(icontop + 1),
static_cast<Gdiplus::REAL>(m_iconwidth + 1), static_cast<Gdiplus::REAL>(m_iconheight + 1));
}*/
gfx.SetSmoothingMode(Gdiplus::SmoothingModeNone);
//Calculate Alpha blend based on Transparency
const float fBlend = (100.0f - m_settings.BG_Transparency) / 100.0f;
// this will draw the image whether it needs
// transparency or not as it will reliably
// maintain the aspect ratio of the artwork
const Gdiplus::ColorMatrix BitmapMatrix =
{
1.0f, 0.0f, 0.0f, 0.0f, 0.0f,
0.0f, 1.0f, 0.0f, 0.0f, 0.0f,
0.0f, 0.0f, 1.0f, 0.0f, 0.0f,
0.0f, 0.0f, 0.0f, fBlend, 0.0f,
0.0f, 0.0f, 0.0f, 0.0f, 1.0f
};
Gdiplus::ImageAttributes ImgAttr;
ImgAttr.SetColorMatrix(&BitmapMatrix, Gdiplus::ColorMatrixFlagsDefault, Gdiplus::ColorAdjustTypeBitmap);
return (gfx.DrawImage(albumart, Gdiplus::RectF(static_cast<Gdiplus::REAL>(iconleft),
static_cast<Gdiplus::REAL>(icontop), static_cast<Gdiplus::REAL>(m_iconwidth),
static_cast<Gdiplus::REAL>(m_iconheight)), 0, 0, static_cast<Gdiplus::REAL>(m_iconwidth),
static_cast<Gdiplus::REAL>(m_iconheight), Gdiplus::UnitPixel, &ImgAttr) == Gdiplus::Ok);
}
// try to get the custom/fallback to
// be shown to avoid a blank preview
fail = true;
GetThumbnail(true, skip_lock);
return false;
}
HBITMAP renderer::GetThumbnail(const bool clear, const bool skip_lock)
{
// not everyone is going to even cause the
// preview to be generated so we will wait
// until its needed to load gdiplus as its
// a relatively slow to close down on exit
if (!running || !SetupGDIplus())
{
return NULL;
}
if (clear)
{
ClearBackground(skip_lock);
}
//Calculate icon size
_iconwidth = m_iconwidth;
if (m_settings.AsIcon)
{
_iconheight = (m_settings.IconSize * m_height) / 100;
_iconheight -= 2;
}
else
{
_iconheight = m_iconheight;
}
//Calculate Alpha blend based on Transparency
const float fBlend = (100.f - m_settings.BG_Transparency) / 100.0f;
const Gdiplus::ColorMatrix BitmapMatrix =
{
1.0f, 0.0f, 0.0f, 0.0f, 0.0f,
0.0f, 1.0f, 0.0f, 0.0f, 0.0f,
0.0f, 0.0f, 1.0f, 0.0f, 0.0f,
0.0f, 0.0f, 0.0f, fBlend, 0.0f,
0.0f, 0.0f, 0.0f, 0.0f, 1.0f
};
bool tempfail = fail;
int iconposition = m_settings.IconPosition;
if (!skip_lock)
{
EnterCriticalSection(&background_cs);
}
// Draw background if not valid
if (!background)
{
__try
{
background = new Gdiplus::Bitmap(m_width, m_height, PixelFormat32bppPARGB);
}
__except (EXCEPTION_EXECUTE_HANDLER)
{
background = NULL;
}
if (m_settings.Shrinkframe)
{
if (iconposition == IP_LOWERLEFT)
{
iconposition = IP_UPPERLEFT;
}
else if (m_settings.IconPosition == IP_LOWERRIGHT)
{
iconposition = IP_UPPERRIGHT;
}
}
no_icon = no_text = fail = false;
if (!background)
{
if (!skip_lock)
{
LeaveCriticalSection(&background_cs);
}
return NULL;
}
Gdiplus::Graphics graphics(background);
// so we've got something irrespective of the mode being used
// it's simpler to ensure that the background has been filled
// in with something that'll act like it's transparent to not
// have it showing as a black rectangle if something fails...
const Gdiplus::SolidBrush solid_brush(Gdiplus::Color::MakeARGB(2, 0, 0, 0));
graphics.FillRectangle(&solid_brush, static_cast<Gdiplus::REAL>(0), static_cast<Gdiplus::REAL>(0),
static_cast<Gdiplus::REAL>(m_width), static_cast<Gdiplus::REAL>(m_height));
switch (tempfail ? m_settings.Revertto : m_settings.Thumbnailbackground)
{
case BG_TRANSPARENT:
{
no_icon = true;
break;
}
case BG_WINAMP:
{
no_text = true;
RECT r = { 0 };
GetClientRect(dialogParent, &r);
// because winamp modern is just weird due to it's drawers
// it's simpler to force a half-height to make it look ok
const INT height = (!modernFix ? (r.bottom - r.top) :
(INT)((r.bottom - r.top) / 1.74f)),
width = (r.right - r.left);
Gdiplus::Bitmap bmp(width, height, PixelFormat32bppPARGB);
Gdiplus::Graphics gfx(&bmp);
HDC hdc = gfx.GetHDC();
gfx.SetCompositingMode(Gdiplus::CompositingModeSourceOver);
gfx.SetCompositingQuality(Gdiplus::CompositingQualityGammaCorrected);
gfx.SetInterpolationMode(Gdiplus::InterpolationModeHighQualityBicubic);
// for most cases just grabbing the window directly
// is all that's needed and uses less resources but
// for some (e.g. winamp modern) then we've got to
// use WM_PRINTCLIENT to better support alpha levels
// the main downside of WM_PRINTCLIENT is it's slow
// when used as part of a SUI based modern skin :(
// note: winamp modern is treated as a special case
// due to the weirdness due to it's drawer :(
if (modernSUI || modernFix)
{
const HDC hdcWindow = GetDCEx(dialogParent, NULL, DCX_CACHE | DCX_WINDOW);
BitBlt(hdc, 0, 0, width, height, hdcWindow, 0, 0, SRCCOPY);
ReleaseDC(dialogParent, hdcWindow);
}
else
{
SendMessageSafe(dialogParent, WM_PRINTCLIENT, (WPARAM)hdc,
PRF_CHILDREN | PRF_NONCLIENT | PRF_CLIENT, 1000);
}
gfx.ReleaseHDC(hdc);
graphics.SetCompositingMode(Gdiplus::CompositingModeSourceOver);
graphics.SetCompositingQuality(Gdiplus::CompositingQualityGammaCorrected);
graphics.SetInterpolationMode(Gdiplus::InterpolationModeHighQualityBicubic);
// find the colour of the almost bottom-right pixel
// and see if it matches out expected colour from
// gen_ff for what should be a non-visible section
// of the skin (but it gets reset / not drawn onto
// the hdc nicely to make use of the existing alpha)
const bool doReplace = (modernFix || (/*!classicSkin &&*/ !modernSUI));
Gdiplus::ImageAttributes ImgAtt;
Gdiplus::Color queried(255, 0, 0, 0), replace(255, 0, 0, 0);
if (doReplace)
{
bmp.GetPixel((width - 1), (height - 1), &queried);
ImgAtt.SetColorKey(queried, queried, Gdiplus::ColorAdjustTypeBitmap);
}
// we draw a re-sized version of the captured window
// whilst resetting certain pixels to have alpha so
// that for some modern skins the preview is better
// than it would otherwise be (due to gen_ff loosing
// that information when it's put into the hdc *ugg*)
if (!IsIconic(plugin.hwndParent))
{
RECT rt = { 0 };
ScaleArtworkToArea(&rt, m_width, m_height, width, height);
Gdiplus::Rect dest(rt.left, rt.top, (rt.right - rt.left), (rt.bottom - rt.top));
graphics.DrawImage(&bmp, dest, 0, 0, width, height, Gdiplus::UnitPixel, (doReplace ?
(replace.ToCOLORREF() == queried.ToCOLORREF() ? &ImgAtt : 0) : 0));
}
else
{
bool use_icon = true;
if (classicSkin)
{
const HBITMAP main_window_bmp = GetMainWindowBmp();
if (main_window_bmp != NULL)
{
Gdiplus::Bitmap image(main_window_bmp, NULL);
DeleteObject(main_window_bmp);
const int image_width = image.GetWidth(), image_height = image.GetHeight();
RECT adjust = { 0 };
ScaleArtworkToArea(&adjust, m_width, m_height, image_width, image_height);
Gdiplus::Rect dest(adjust.left, adjust.top,
adjust.right - adjust.left,
adjust.bottom - adjust.top);
graphics.DrawImage(&image, dest, 0, 0, image_width,
image_height, Gdiplus::UnitPixel);
use_icon = false;
}
}
if (use_icon)
{
// this will either use the custom icon if specified
// or the icon related to the loader currently used.
// there is a disconnect if using wacup.exe loader &
// having set the process icon to be the winamp.exe
// but for what's only used if minimised I just cba!
HICON win32_icon = NULL;
if (GetWinampIniInt(L"tb_icon", 1) == 2)
{
wchar_t taskbar_tmp[MAX_PATH] = { 0 };
win32_icon = (HICON)LoadImage(NULL, CombinePath(taskbar_tmp,
GetPaths()->settings_dir, L"taskbar.ico"), IMAGE_ICON,
256, 256, LR_LOADTRANSPARENT | LR_LOADFROMFILE);
}
bool from_core = false;
if (win32_icon == NULL)
{
// due to how WACUP works a wacup.exe or
// winamp.exe or might have been used as
// the loader along with running as the
// non-legacy or legacy modes so we will
// let the core manage working out a big
// icon for us to use based on the loader
win32_icon = GetLoaderIcon(FALSE);
from_core = true;
}
if (win32_icon != NULL)
{
Gdiplus::Bitmap icon(win32_icon);
const int icon_width = icon.GetWidth(), icon_height = icon.GetHeight();
Gdiplus::Rect dest((m_width / 2) - (icon_width / 2), (m_height / 2) -
(icon_height / 2), icon_width, icon_height);
dest.Inflate(-(icon_width / 4), -(icon_height / 4));
graphics.DrawImage(&icon, dest, 0, 0, icon_width,
icon_height, Gdiplus::UnitPixel,
(doReplace ? (replace.ToCOLORREF() ==
queried.ToCOLORREF() ? &ImgAtt : 0) : 0));
if (!from_core)
{
DestroyIcon(win32_icon);
}
}
}
}
break;
}
case BG_ALBUMART:
{
// get album art
if (!getAlbumArt(m_metadata.getFileName(), skip_lock) &&
(m_settings.Revertto != BG_ALBUMART))
{
// so it can be handled quicker
// we are going to fall through
// to the custom handling which
// will then gets what's needed
if (m_settings.Revertto != BG_CUSTOM)
{
break;
}
}
else
{
break;
}
[[fallthrough]];
}
case BG_CUSTOM:
{
if (m_settings.BGPath[0])
{
if (custom_img == NULL)
{
custom_img = new Gdiplus::Bitmap(m_width, m_height, PixelFormat32bppPARGB);
Gdiplus::Image img(m_settings.BGPath, true);
if ((custom_img != NULL) && (img.GetType() != 0))
{
Gdiplus::Graphics gfx(custom_img);
gfx.SetInterpolationMode(Gdiplus::InterpolationModeBicubic);
const float img_width = img.GetWidth() * 1.f,
img_height = img.GetHeight() * 1.f;
if (m_settings.AsIcon)
{
float new_height = 0.f, new_width = 0.f;
if (img_width > img_height)
{
new_height = img_height / img_width * (float)_iconheight;
new_height -= 2.f;
new_width = _iconwidth * 1.f;
}
else
{
new_width = img_width / img_height * (float)_iconwidth;
new_width -= 2.f;
new_height = _iconheight * 1.f;
}
int iconleft = 0, icontop = 0;
switch (iconposition)
{
case IP_LOWERLEFT:
{
icontop = m_height - _iconheight - 2;
break;
}
case IP_UPPERRIGHT:
{
iconleft = m_width - _iconheight - 2;
break;
}
case IP_LOWERRIGHT:
{
iconleft = m_width - _iconheight - 2;
icontop = m_height - _iconheight - 2;
break;
}
}
if (m_settings.BG_Transparency == 0)
{
// Draw icon shadow
gfx.SetSmoothingMode(Gdiplus::SmoothingModeAntiAlias);
const Gdiplus::SolidBrush shadow_solid_brush(Gdiplus::Color::MakeARGB(110, 0, 0, 0));
gfx.FillRectangle(&shadow_solid_brush,
static_cast<Gdiplus::REAL>(iconleft + 1),
static_cast<Gdiplus::REAL>(icontop + 1),
static_cast<Gdiplus::REAL>(new_width + 1),
static_cast<Gdiplus::REAL>(new_height + 1));
// Draw icon
gfx.SetSmoothingMode(Gdiplus::SmoothingModeNone);
gfx.DrawImage(&img, Gdiplus::RectF(static_cast<Gdiplus::REAL>(iconleft),
static_cast<Gdiplus::REAL>(icontop),
static_cast<Gdiplus::REAL>(new_width),
static_cast<Gdiplus::REAL>(new_height)));
}
else
{
Gdiplus::ImageAttributes ImgAttr;
ImgAttr.SetColorMatrix(&BitmapMatrix, Gdiplus::ColorMatrixFlagsDefault,
Gdiplus::ColorAdjustTypeBitmap);
// Draw icon shadow
gfx.SetSmoothingMode(Gdiplus::SmoothingModeAntiAlias);
const Gdiplus::SolidBrush icon_shadow_solid_brush(Gdiplus::Color::MakeARGB((BYTE)(110 -
m_settings.BG_Transparency), 0, 0, 0));
gfx.FillRectangle(&icon_shadow_solid_brush,
static_cast<Gdiplus::REAL>(iconleft + 1),
static_cast<Gdiplus::REAL>(icontop + 1),
static_cast<Gdiplus::REAL>(new_width + 1),
static_cast<Gdiplus::REAL>(new_height + 1));
// Draw icon
gfx.SetSmoothingMode(Gdiplus::SmoothingModeNone);
gfx.DrawImage(&img, Gdiplus::RectF(static_cast<Gdiplus::REAL>(iconleft),
static_cast<Gdiplus::REAL>(icontop),
static_cast<Gdiplus::REAL>(new_width),
static_cast<Gdiplus::REAL>(new_height)),
0, 0, img_width, img_height, Gdiplus::UnitPixel, &ImgAttr);
}
m_iconwidth = (int)new_width;
m_iconheight = (int)new_height;
}
else
{
float new_height = 0.f, new_width = 0.f;
if (m_width > m_height)
{
new_height = img_height / img_width * (float)m_width;
new_width = m_width * 1.f;
if (new_height > m_height)
{
new_width = img_width / img_height * (float)m_height;
new_height = m_height * 1.f;
}
}
else
{
new_width = img_width / img_height * (float)m_height;
new_height = m_height * 1.f;
if (new_width > m_width)
{
new_height = img_height / img_width * (float)m_width;
new_width = m_width * 1.f;
}
}
gfx.SetSmoothingMode(Gdiplus::SmoothingModeNone);
if (m_settings.BG_Transparency == 0)
{
gfx.DrawImage(&img, Gdiplus::RectF((m_width / 2) - (new_width / 2), 0,
static_cast<Gdiplus::REAL>(new_width),
static_cast<Gdiplus::REAL>(new_height)));
}
else
{
Gdiplus::ImageAttributes ImgAttr;
ImgAttr.SetColorMatrix(&BitmapMatrix, Gdiplus::ColorMatrixFlagsDefault,
Gdiplus::ColorAdjustTypeBitmap);
gfx.SetSmoothingMode(Gdiplus::SmoothingModeNone);
gfx.DrawImage(&img, Gdiplus::RectF((m_width / 2) - (new_width / 2), 0,
static_cast<Gdiplus::REAL>(new_width),
static_cast<Gdiplus::REAL>(new_height)),
0, 0, img_width, img_height,
Gdiplus::UnitPixel, &ImgAttr);
}
}
if (background != NULL)
{
delete background;
}
if (custom_img != NULL)
{
background = (Gdiplus::Bitmap*)custom_img->Clone();
}
else
{
background = NULL;
}
fail = (background == NULL);
// so we can attempt to do something
// we'll clear this so either what's
// been found will show or it'll set
// it to the generic background/text
tempfail = false;
break;
}
else if (m_settings.Revertto != BG_CUSTOM)
{
fail = true;
GetThumbnail(true, true);
break;
}
}
}
else if (m_settings.Revertto != BG_CUSTOM)
{
fail = true;
GetThumbnail(true, true);
}
break;
}
default:
{
fail = true;
GetThumbnail(true, true);
break;
}
}
}
HBITMAP retbmp = NULL;
if (!tempfail)
{
Gdiplus::Bitmap* canvas = NULL;
__try
{
canvas = (background ? background->Clone(0, 0, m_width, m_height,
PixelFormat32bppPARGB) : NULL);
}
__except (EXCEPTION_EXECUTE_HANDLER)
{
}
if (canvas)
{
Gdiplus::REAL textheight = 0;
Gdiplus::Graphics gfx(canvas);
if (!no_text)
{
if (m_settings.Text[0])
{
// Draw text
static lines text_parser(m_settings, m_metadata);
text_parser.Parse();
if (m_textpositions.empty())
{
m_textpositions.resize(text_parser.GetNumberOfLines(), 0);
}
else
{
for (std::vector<int>::size_type i = 0; i != m_textpositions.size(); ++i)
{
if (m_textpositions[i] != 0)
{
m_textpositions[i] -= (m_settings.LowFrameRate ? 3 : 2);
}
else
{
if (scroll_block)
{
bool unblock = true;
for (std::vector<int>::size_type j = 0; j != m_textpositions.size(); ++j)
{
if (m_textpositions[j] < 0)
{
unblock = false;
break;
}
}
scroll_block = !unblock;
m_textpause = (m_settings.LowFrameRate ? 4 : 1);
}
if (!scroll_block && m_textpause == 0)
{
m_textpositions[i] -= (m_settings.LowFrameRate ? 3 : 2);
}
}
}
}
// Setup fonts
if (!normal_font || !large_font)
{
HDC h_gfx = gfx.GetHDC();
if (h_gfx)
{
if (!normal_font)
{
normal_font = new Gdiplus::Font(h_gfx, &m_settings.font);
}
if (!large_font)
{
const int dpi_y = GetDeviceCaps(h_gfx, LOGPIXELSY);
LOGFONT _large_font = m_settings.font;
LONG large_size = -((m_settings.font.lfHeight * 72) / dpi_y);
large_size += 4;
_large_font.lfHeight = -MulDiv(large_size, dpi_y, 72);
large_font = new Gdiplus::Font(h_gfx, &_large_font);
}
gfx.ReleaseHDC(h_gfx);
}
}
// since its possible for the fonts on the machine
// to not be valid then it's better to bail asap &
// reduce the hit - gdi+ only likes true type font
if ((normal_font && normal_font->IsAvailable()) &&
(large_font && large_font->IsAvailable()))
{
Gdiplus::SolidBrush bgcolor(Gdiplus::Color(GetRValue(m_settings.bgcolor),
GetGValue(m_settings.bgcolor),
GetBValue(m_settings.bgcolor))),
fgcolor(Gdiplus::Color(GetRValue(m_settings.text_color),
GetGValue(m_settings.text_color),
GetBValue(m_settings.text_color)));
Gdiplus::StringFormat sf(Gdiplus::StringFormatFlagsNoWrap);
const int text_space = 28;
for (std::size_t text_index = 0; text_index != text_parser.GetNumberOfLines(); ++text_index)
{
Gdiplus::RectF ret_rect;
const std::wstring current_text = text_parser.GetLineText(text_index);
linesettings current_settings = text_parser.GetLineSettings(text_index);
// Measure size
gfx.SetTextRenderingHint(Gdiplus::TextRenderingHintAntiAlias);
const Gdiplus::PointF origin(0, 0);
// this used to apply a parent_rect set to the size of the area
// to be drawn into by the OS but that then messed up the check
// for how long the string actually is which is needed when the
// line is going to be scrolled to prevent being clipped short!
gfx.MeasureString(current_text.c_str(), (INT)current_text.size(),
(current_settings.largefont ? large_font :
normal_font), origin, &sf, &ret_rect);
if (ret_rect.GetBottom() == 0)
{
gfx.MeasureString(L"QWEXCyjM", -1, normal_font, origin, &sf, &ret_rect);
}
Gdiplus::Bitmap text_bitmap(static_cast<INT>(ret_rect.GetRight()),
static_cast<INT>(ret_rect.GetBottom() - 1),
PixelFormat32bppPARGB);
const int bmp_width = (int)text_bitmap.GetWidth(),
bmp_height = (int)text_bitmap.GetHeight();
Gdiplus::Graphics text_gfx(&text_bitmap);
// Graphics setup
text_gfx.SetSmoothingMode(Gdiplus::SmoothingModeNone);
text_gfx.SetInterpolationMode(Gdiplus::InterpolationModeNearestNeighbor);
text_gfx.SetPixelOffsetMode(Gdiplus::PixelOffsetModeNone);
text_gfx.SetCompositingQuality(Gdiplus::CompositingQualityHighSpeed);
(m_settings.Antialias) ? text_gfx.SetTextRenderingHint(Gdiplus::TextRenderingHintAntiAlias) :
text_gfx.SetTextRenderingHint(Gdiplus::TextRenderingHintSingleBitPerPixelGridFit);
// Draw box if needed
const bool empty_text = current_text.empty();
if (current_settings.darkbox && !empty_text)
{
Gdiplus::SolidBrush boxbrush(Gdiplus::Color::MakeARGB(120, GetRValue(m_settings.bgcolor),
GetGValue(m_settings.bgcolor), GetBValue(m_settings.bgcolor)));
ret_rect.Height += 2;
text_gfx.FillRectangle(&boxbrush, ret_rect);
}
// Draw text to offscreen surface
if (!empty_text)
{
const INT text_len = (INT)current_text.size();
LPCWSTR text = current_text.c_str();
const auto& font = (current_settings.largefont ? large_font : normal_font);
text_gfx.SetTextContrast(120);
//shadow
if (current_settings.shadow)
{
text_gfx.DrawString(text, text_len, font, Gdiplus::PointF(1, -1), &sf, &bgcolor);
}
//text
text_gfx.DrawString(text, text_len, font, Gdiplus::PointF(0, -2), &sf, &fgcolor);
}
// Calculate text position
int X = 0, CX = m_width;
if (m_iconwidth == 0)
{
m_iconwidth = _iconwidth;
}
if (m_iconheight == 0)
{
m_iconheight = _iconheight;
}
if (m_settings.AsIcon && !no_icon && !current_settings.forceleft)
{
if ((iconposition == IP_UPPERLEFT) ||
(iconposition == IP_LOWERLEFT))
{
X += m_iconwidth + 5;
CX = m_width - X;
}
else if ((iconposition == IP_UPPERRIGHT) ||
(iconposition == IP_LOWERRIGHT))
{
CX = m_width - m_iconwidth - 5;
}
}
else
{
CX = (int)(CX * 0.96f);
}
gfx.SetClip(Gdiplus::RectF(static_cast<Gdiplus::REAL>(X),
static_cast<Gdiplus::REAL>(0),
static_cast<Gdiplus::REAL>(CX),
static_cast<Gdiplus::REAL>(m_width)),
Gdiplus::CombineModeReplace);
// Draw text bitmap to final bitmap with scrolling as needed
// based on the icon vs background image mode where the area
// can vary depending on the size of things vs overall image
if ((bmp_width > (CX + 2)) && !current_settings.dontscroll)
{
// Draw scrolling text
int left = m_textpositions[text_index];
if (left + bmp_width < 0)
{
// reset text
m_textpositions[text_index] = text_space;
left = text_space;
scroll_block = true;
}
if (left == 0 && m_textpause == 0)
{
m_textpause = (m_settings.LowFrameRate ? 4 : 1); // delay; in steps
}
if (left + bmp_width >= CX)
{
gfx.DrawImage(&text_bitmap, X, (int)textheight, -left,
0, CX, bmp_height, Gdiplus::UnitPixel);
}
else
{
gfx.DrawImage(&text_bitmap, X, (int)textheight, -left, 0,
bmp_width + left, bmp_height, Gdiplus::UnitPixel);
gfx.DrawImage(&text_bitmap, X + text_space + 2 + bmp_width + left,
(int)textheight, 0, 0, -left, bmp_height, Gdiplus::UnitPixel);
}
}
else
{
// Draw non-scrolling text
if (current_settings.center)
{
// Center text
const int newleft = X + ((CX / 2) - (bmp_width / 2));
gfx.DrawImage(&text_bitmap, newleft, (int)textheight, 0, 0,
bmp_width, bmp_height, Gdiplus::UnitPixel);
}
else
{
gfx.DrawImage(&text_bitmap, X, (int)textheight, 0, 0,
bmp_width, bmp_height, Gdiplus::UnitPixel);
}
// Nr. pixels text jumps on each step when scrolling
m_textpositions[text_index] = (m_settings.LowFrameRate ? 3 : 2);
}
gfx.ResetClip();
textheight += bmp_height;
}
if (m_textpause > 0)
{
--m_textpause;
}
if (!m_settings.Shrinkframe)
{
textheight = (Gdiplus::REAL)(m_height - 2);
}
if (m_settings.Thumbnailpb)
{
textheight += 25;
}
if (textheight > m_height - 2)
{
textheight = (Gdiplus::REAL)(m_height - 2);
}
}
}
else
{
// so we've got something irrespective of the mode being used
// it's simpler to ensure that the background has been filled
// in with something that'll act like it's transparent to not
// have it showing as a black rectangle if something fails...
const Gdiplus::SolidBrush solid_brush(Gdiplus::Color::MakeARGB(2, 0, 0, 0));
gfx.FillRectangle(&solid_brush, static_cast<Gdiplus::REAL>(0), static_cast<Gdiplus::REAL>(0),
static_cast<Gdiplus::REAL>(m_width), static_cast<Gdiplus::REAL>(m_height));
}
// Draw progressbar (only if there's a need to do so)
if (m_settings.Thumbnailpb &&
(m_settings.play_total > 0) &&
(m_settings.play_current > 0))
{
gfx.SetSmoothingMode(Gdiplus::SmoothingModeAntiAlias);
const int Y = (!m_settings.Shrinkframe ? (canvas->GetHeight() - 10) : (int)(textheight - 10));
Gdiplus::Pen p1(Gdiplus::Color::MakeARGB(0xFF, 0xFF, 0xFF, 0xFF), 1);
Gdiplus::Pen p2(Gdiplus::Color::MakeARGB(80, 0, 0, 0), 1);
Gdiplus::SolidBrush b1(Gdiplus::Color::MakeARGB(50, 0, 0, 0));
Gdiplus::SolidBrush b2(Gdiplus::Color::MakeARGB(220, 255, 255, 255));
Gdiplus::RectF R1(44, (Gdiplus::REAL)Y, 10, 9);
Gdiplus::RectF R2((Gdiplus::REAL)m_width - 56, (Gdiplus::REAL)Y, 10, 9);
gfx.FillRectangle(&b1, 46, Y, m_width - 94, 9);
gfx.DrawLine(&p2, 46, Y + 2, 46, Y + 6);
gfx.DrawLine(&p2, m_width - 48, Y + 2, m_width - 48, Y + 6);