-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdspitems.c
2614 lines (1942 loc) · 66.6 KB
/
dspitems.c
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
/*
* GraphTFT plugin for the Video Disk Recorder
*
* dspitems.c
*
* (c) 2007-2015 Jörg Wendel
*
* This code is distributed under the terms and conditions of the
* GNU GENERAL PUBLIC LICENSE. See the file COPYING for details.
*/
//***************************************************************************
// Includes
//***************************************************************************
#include <sstream>
#include <sysinfo.h>
#include <theme.h>
#include <display.h>
#include <scan.h>
#include <span.h>
#include <setup.h>
#include <libexif/exif-data.h>
const int maxGranularity = 100;
//***************************************************************************
// Init Statics
//***************************************************************************
Renderer* cDisplayItem::render = 0;
cGraphTFTDisplay* cDisplayItem::vdrStatus = 0;
int cDisplayItem::forceDraw = yes;
uint64_t cDisplayItem::nextForce = 0;
cDisplayItem* cDisplayItem::selectedItem = 0;
//***************************************************************************
// cDisplayItem
//***************************************************************************
void cDisplayItem::scheduleForce(uint64_t aTime)
{
if (!nextForce || nextForce > aTime)
{
nextForce = aTime;
tell(1, "schedule force in (%ldms)",
nextForce - msNow());
}
}
void cDisplayItem::scheduleDrawAt(uint64_t aTime)
{
// if (aTime < nextDraw || nextDraw < msNow())
{
nextDraw = aTime;
tell(2, "schedule next draw of '%s'[%s] in (%ldms)",
nameOf(), Debug().c_str(),
nextDraw - msNow());
}
}
void cDisplayItem::scheduleDrawIn(int aTime)
{
uint64_t at = aTime + msNow();
// the maximal redraw granularity is 500ms (maxGranularity), due to this
// adjust to next full step
at = round((double)((double)at / maxGranularity)) * maxGranularity;
scheduleDrawAt(at);
}
void cDisplayItem::scheduleDrawNextFullMinute()
{
uint64_t ms = SECONDS(((time(0)/60 +1) * 60) - time(0));
scheduleDrawAt(ms+msNow());
}
//***************************************************************************
// Object
//***************************************************************************
cDisplayItem::cDisplayItem()
: cThemeItem()
{
changed = no;
nextDraw = 0;
section = 0;
marquee_active = no;
backgroundItem = 0;
visible = yes;
nextAnimationAt = msNow();
actLineCount = na;
lastConditionState = true;
lastX = 0;
lastY = 0;
lastWidth = 0;
lastHeight = 0;
}
cDisplayItem::~cDisplayItem()
{
}
//***************************************************************************
// Evaluate Color
//***************************************************************************
p_rgba cDisplayItem::evaluateColor(const char* var, p_rgba rgba)
{
string p = "";
if (evaluate(p, var) != success)
memset(rgba, 255, sizeof(t_rgba)); // fallback white
else
str2rgba(p.c_str(), rgba);
tell(3, "evaluated color '%s' to %d/%d/%d/%d (%s)",
var, rgba[0], rgba[1], rgba[2], rgba[3], p.c_str());
return rgba;
}
//***************************************************************************
// Evaluate Path
//***************************************************************************
string cDisplayItem::evaluatePath()
{
string p = "";
// iterate over path
for (int i = 0; i < pathCount; i++)
{
if (evaluate(p, pathList[i].configured.c_str()) != success)
continue;
tell(5, "check path '%s'", p.c_str());
if (p == "")
{
tell(1, "path '%s' empty, skipping",
pathList[i].configured.c_str());
continue;
}
// append plugin config path
if (p[0] != '/')
{
p = string(GraphTFTSetup.themesPath)
+ string(Thms::theTheme->getDir())
+ "/" + p;
tell(4, "%d path [%s] converted to '%s'", i,
pathList[i].configured.c_str(), p.c_str());
}
if (fileExists(p.c_str()))
return p;
// time for next image?
// -> else we don't need to check for range
if (nextAnimationAt > msNow())
return pathList[i].last;
// check for range
unsigned int s = p.find_last_of('(');
unsigned int e = p.find_last_of(')');
int rangeSize = e-s-1;
int cur;
if (s != string::npos && e != string::npos && rangeSize >= 3)
{
Scan scan(p.substr(s+1, rangeSize).c_str(), no);
int minNum, maxNum;
string path = "";
scan.eat();
if (!scan.isNum())
continue; // range parsing error
minNum = scan.lastInt();
scan.eat();
if (!scan.isOperator() || *scan.lastIdent() != '-')
continue; // range parsing error
scan.eat();
if (!scan.isNum())
continue; // range parsing error
maxNum = scan.lastInt();
if (scan.eat() == success)
continue; // range parsing error (waste behind second int)
// get actual number
cur = pathList[i].curNum;
// reset ...
if (cur < minNum)
{
pathList[i].curNum = minNum;
cur = minNum-1;
}
do
{
if (++cur > maxNum)
cur = minNum;
path = p.substr(0, s) + Str::toStr(cur) + p.substr(e+1);
tell(2, "Checking for '%s'", path.c_str());
} while (!fileExists(path.c_str()) && cur != pathList[i].curNum);
if (fileExists(path.c_str()))
{
tell(4, "Animated image '%s'", path.c_str());
pathList[i].last = path;
pathList[i].curNum = cur;
nextAnimationAt = msNow() + _delay;
return pathList[i].last;
}
}
}
tell(2, "Image for '%s' with %d elements not found :(", _path.c_str(), pathCount);
return "";
}
//***************************************************************************
// Replay Mode Value
//***************************************************************************
int cDisplayItem::replayModeValue(ReplayMode rm)
{
bool play, forward;
int speed;
if (!vdrStatus->_replay.control
|| !vdrStatus->_replay.control->GetReplayMode(play, forward, speed))
return -1;
switch (rm)
{
case rmSpeed: return speed;
case rmForward: return forward;
case rmPlay: return play;
default: return na;
}
return na;
}
//***************************************************************************
// Evaluate Condition
//***************************************************************************
int cDisplayItem::evaluateCondition(int recurse)
{
static Scan* scan = 0;
int result;
int state;
int rightType = catUnknown;
int leftType = catUnknown;
int leftInt = 0;
int rightInt = 0;
string leftStr = "";
string rightStr = "";
char op[100]; *op = 0;
char logicalOp[100]; *logicalOp = 0;
string expression;
if (!recurse || !scan)
{
if (_condition.size() <= 0)
return yes;
// beim Fehler erst mal 'no' ... ?
if (evaluate(expression, _condition.c_str()) != success)
return no;
tell(3, "evaluating condition '%s' with expression '%s'",
_condition.c_str(), expression.c_str());
// ...
if (scan) delete scan;
scan = new Scan(expression.c_str());
}
// left expression
scan->eat();
if (scan->isNum())
{
leftInt = scan->lastInt();
leftType = catInteger;
}
else if (scan->isString())
{
leftStr = scan->lastString();
leftType = catString;
}
else
{
tell(0, "Error: Invalid left '%s' expression in '%s'",
scan->lastIdent(), expression.c_str());
return no;
}
// operator ?
if ((state = scan->eat()) == success && scan->isOperator() && !scan->isLogical())
{
strcpy(op, scan->lastIdent());
// right expression
scan->eat();
if (scan->isNum())
{
rightInt = scan->lastInt();
rightType = catInteger;
}
else if (scan->isString())
{
rightStr = scan->lastString();
rightType = catString;
}
else
{
tell(0, "Error: Invalid right '%s' expression in '%s'",
scan->lastIdent(), expression.c_str());
return no;
}
// check the condition
if (leftType != rightType)
{
tell(0, "Error: Argument types of left and right "
"agrument don't match in (%d/%d) '%s'",
leftType, rightType, expression.c_str());
return no;
}
if (leftType == catInteger)
result = condition(leftInt, rightInt, op);
else
result = condition(&leftStr, &rightStr, op);
state = scan->eat();
}
else if (leftType == catInteger)
{
result = leftInt ? true : false;
}
else
{
result = leftStr != "" ? true : false;
}
// any more expressions in here?
tell(4, "check for further condition at '%s'", Str::notNull(scan->next()));
if (state == success)
{
tell(4, "further condition found");
if (!scan->isLogical())
{
tell(0, "Error: Invalid logical operator '%s' expression in '%s'",
scan->lastIdent(), expression.c_str());
return no;
}
strcpy(logicalOp, scan->lastIdent());
// start a recursion ...
if (strncmp(logicalOp, "&", 1) == 0)
result = result && evaluateCondition(yes);
else if (strncmp(logicalOp, "|", 1) == 0)
result = result || evaluateCondition(yes);
}
tell(3, "condition is '%s'; evaluated condition is '%s'; result is '%s'",
_condition.c_str(), expression.c_str(), result ? "match" : "don't match");
return result;
}
//***************************************************************************
// evaluate the condition
//***************************************************************************
int cDisplayItem::condition(int left, int right, const char* op)
{
tell(4, "evaluate condition '%d' '%s' '%d'", left, op, right);
if (strcmp(op, ">") == 0)
return left > right;
if (strcmp(op, "<") == 0)
return left < right;
if (strcmp(op, ">=") == 0)
return left >= right;
if (strcmp(op, "<=") == 0)
return left <= right;
if (strcmp(op, "=") == 0 || strcmp(op, "==") == 0)
return left == right;
if (strcmp(op, "!=") == 0 || strcmp(op, "<>") == 0)
return left != right;
tell(0, "Unexpected operator '%s'", op);
return no;
}
int cDisplayItem::condition(string* left, string* right, const char* op)
{
tell(4, "evaluate condition '%s' '%s' '%s'",
left->c_str(), op, right->c_str());
if (strcmp(op, ">") == 0)
return *left > *right;
if (strcmp(op, "<") == 0)
return *left < *right;
if (strcmp(op, ">=") == 0)
return *left >= *right;
if (strcmp(op, "<=") == 0)
return *left <= *right;
if (strcmp(op, "=") == 0 || strcmp(op, "==") == 0)
return *left == *right;
if (strcmp(op, "!=") == 0 || strcmp(op, "<>") == 0)
return *left != *right;
tell(0, "Unexpected operator '%s'", op);
return no;
}
//***************************************************************************
// Interface
//***************************************************************************
int cDisplayItem::reset()
{
if (_scroll)
{
marquee_active = yes;
marquee_left = no;
marquee_idx = na;
marquee_count = 0;
marquee_strip = 0;
// scheduleDrawIn(0);
}
nextAnimationAt = msNow();
lastWidth = 0;
return done;
}
int cDisplayItem::draw()
{
int status = success;
int cond = true;
// check condition
if (!isOfGroup(groupMenu) && !isOfGroup(groupTextList))
{
cond = evaluateCondition();
if (!cond)
{
tell(4, "Ignore drawing of '%s' due to condition '%s'",
nameOf(), _condition.c_str());
status = ignore;
}
}
// schedule due to the configured delay ..
if (cond && _delay > 0 && visible && msNow() > nextDraw && !_scroll)
scheduleDrawIn(_delay);
// condition state changed force immediate redraw !
if (lastConditionState != cond)
{
tell(4, "Condition '%s' of '%s' [%s] changed from (%d) to (%d), force draw",
_condition.c_str(), nameOf(),
Text() != "" ? Text().c_str() : Path().c_str(),
lastConditionState, cond);
lastConditionState = cond;
scheduleForce(msNow() + 10);
}
return status;
}
int cDisplayItem::refresh()
{
tell(6, "timeMs::Now() (%ldms);", msNow());
tell(6, "nextForce at (%ldms)", nextForce);
tell(6, "forceDraw '%s', nextDraw (%ldms), isForegroundItem(%d), Foreground(%d)",
forceDraw ? "yes" : "no", nextDraw, isForegroundItem(), Foreground());
changed = no;
// LogDuration ld("cDisplayItem::refresh()");
// force required ? (volume, animating, osd-message, ...)
if (nextForce && msNow() >= nextForce)
{
forceDraw = yes;
nextForce = 0;
}
// respect the maximal redraw granularity
if ((nextDraw && (msNow() >= nextDraw-(maxGranularity/2-1)))
|| isForegroundItem() || forceDraw || Foreground())
{
nextDraw = 0;
int res = draw() == success ? 1 : 0;
changed = res > 0;
tell(2, "draw '%s', %s", nameOf(), res ? "done" : "skipped due to condition");
if (res > 0 && logLevel >= 3)
{
if (isForegroundItem() || forceDraw || Foreground())
{
tell(3, "forceDraw(%d), isForegroundItem(%d), Foreground(%d)",
forceDraw, isForegroundItem(), Foreground());
tell(3, "'%s' - '%s'", nameOf(),
Text().size() ? Text().c_str() : Path().c_str());
}
}
return res;
}
return 0;
}
//***************************************************************************
// Painters
//***************************************************************************
int cDisplayItem::drawText(const char* text, int y,
int height, int clear, int skipLines)
{
int width;
unsigned int viewLength = clen(text);
unsigned int textLen = clen(text); // character count (real chars)
int lineHeight = 0;
y = y ? y : Y();
width = Width() ? Width() : Thms::theTheme->getWidth() - X();
height = height != na? height : Height();
height = height != na ? height : Thms::theTheme->getHeight() - y;
skipLines = skipLines ? skipLines : StartLine();
if (!height)
return done;
// draw background
if (clear)
drawBackRect(y, _bg_height ? _bg_height : height);
if (!textLen || Str::isEmpty(text))
return done;
// text width in pixel
int textWidth = render->textWidthOf(text, _font.c_str(), _size, lineHeight);
lineHeight = !lineHeight ? 1 :lineHeight;
// respect max height for line count
int lines = height / lineHeight > 0 ? height / lineHeight : 1;
if (_lines > 0)
lines = std::min(lines, _lines);
int visibleWidth = width*lines;
if (textWidth <= 0)
{
textWidth = 22 * textLen;
tell(1, "Info: Can't detect text with of '%s'[%s](%d) witch font %s/%d. Assuming %dpx",
text, _debug.c_str(), textLen, _font.c_str(), _size, textWidth);
}
int charWidth = textWidth / textLen > 0 ? textWidth / textLen : 1; // at least one pixel :p
viewLength = visibleWidth / charWidth; // calc max visible chars
tell(4, "[%s] drawing text '%s' at %d/%d (%d/%d), '%s'(%d) lines (%d)!",
_debug.c_str(), text, X(), y, width, height, _font.c_str(), _size, lines);
tell(3, "[%s] textLen %d, viewLength = %d, textWidth = %dpx, visibleWidth = %dpx, lines = %d, font %s/%d",
_debug.c_str(), textLen, viewLength, textWidth, visibleWidth, lines, _font.c_str(), _size);
tell(5, "[%s] scroll is (%d) and marquee_active is (%d) for text '%s'",
_debug.c_str(), _scroll, marquee_active, text);
// get line count of the actual text
actLineCount = render->lineCount(text, _font.c_str(), _size, width);
// ...
// exclude item fom scrolling if more than one line displayed,
// multiline srcolle is prepared but dont work cause of the word warp featute in ImlibRenderer::text(...)
// -> to hard to calculate this here ...
if (!_scroll || textWidth < visibleWidth || lines > 1)
{
t_rgba rgba;
// normal and 'dots' mode
render->text(text,
_font.c_str(), _size, _align,
X(), y,
evaluateColor(_color.c_str(), rgba),
width, height, lines,
_dots, skipLines);
}
else
{
// marquee and ticker mode
// viewLength -= 3;
if (msNow() > nextAnimationAt)
{
if (_scroll == 1 && marquee_idx + viewLength > textLen)
marquee_left = yes;
else if (_scroll == 2 && marquee_idx + viewLength > textLen)
marquee_idx = na;
if (marquee_left)
marquee_idx--;
else
marquee_idx++;
if (marquee_idx == 0)
{
marquee_left = no;
marquee_count++;
}
if (_scroll_count && marquee_count > _scroll_count)
{
marquee_active = no;
marquee_idx = 0;
}
if (marquee_active)
{
if (_delay < 200)
_delay = 200;
if (marquee_idx == 0 || marquee_idx > (int)(textLen - viewLength))
scheduleDrawIn(_delay*3);
else
scheduleDrawIn(_delay);
nextAnimationAt = nextDraw;
}
}
int blen = strlen(text);
int cs, ps;
int i = 0;
t_rgba rgba;
for (ps = 0; ps < blen; ps += cs)
{
i++;
cs = std::max(mblen(&text[ps], blen-ps), 1);
if (i >= marquee_idx)
break;
}
tell(3, "drawing text in scroll mode '%s' (%d/%d), nextDraw is %ld; idx is %d/%d",
text, textLen, viewLength, nextDraw/1000, marquee_idx, ps);
render->text(text + ps,
_font.c_str(), _size, _align,
X(), y,
evaluateColor(_color.c_str(), rgba),
width, height,
lines, marquee_active ? no : _dots);
}
return done;
}
int cDisplayItem::drawRectangle()
{
t_rgba rgba;
render->rectangle(X(), Y(), Width(), Height(),
evaluateColor(_color.c_str(), rgba));
return done;
}
int cDisplayItem::drawBackRect(int y, int height)
{
int x = _bg_x != na ? _bg_x : X();
int width = _bg_width > 0 ? _bg_width : Width();
y = y ? y : _bg_y != na ? _bg_y : Y();
if (!height)
height = _bg_height > 0 ? _bg_height : Height();
if (!Overlay())
{
t_rgba bg_rgba;
evaluateColor(_bg_color.c_str(), bg_rgba);
if (haveBackgroundItem())
{
string p;
// fill with part of the backround image
evaluate(p, backgroundItem->Path().c_str());
tell(3, "Drawing backround area of '%s' for '%s'",
p.c_str(), _text.c_str());
render->imagePart(p.c_str(), x, y, width, height);
}
if (bg_rgba[rgbA])
{
// fill with solid color, respect alpha channel
render->rectangle(x, y, width, height, bg_rgba);
}
}
return done;
}
//***************************************************************************
// Get Jpeg Orientation
//***************************************************************************
int getJpegOrientation(const char* file)
{
int orientation = 1; // 1 => 'normal'
ExifData* exifData = exif_data_new_from_file(file);
if (exifData)
{
ExifByteOrder byteOrder = exif_data_get_byte_order(exifData);
ExifEntry* exifEntry = exif_data_get_entry(exifData, EXIF_TAG_ORIENTATION);
if (exifEntry)
orientation = exif_get_short(exifEntry->data, byteOrder);
exif_data_free(exifData);
}
return orientation;
}
int cDisplayItem::drawImage(const char* path, int fit, int aspectRatio, int noBack)
{
int orientation = 1; // 1 => 'normal'
if (!path) path = _path.c_str();
if (fit == na) fit = _fit;
if (aspectRatio == na) aspectRatio = _aspect_ratio;
tell(3, "drawing image '%s' at %d/%d (%d/%d); fit = %d; aspectRatio = %d)",
path, X(), Y(), Width(), Height(), _fit, aspectRatio);
if (BgWidth() && !noBack)
drawBackRect();
if (strcasestr(path, "JPEG") || strcasestr(path, "JPG"))
orientation = getJpegOrientation(path);
render->image(path,
X(), Y(),
Width(), Height(),
fit, aspectRatio, orientation);
return done;
}
//***************************************************************************
// Format String
//***************************************************************************
const char* cDisplayItem::formatString(const char* str, const char* fmt,
char* buffer, int len)
{
if (Str::isEmpty(fmt) || Str::isEmpty(str))
return str;
sprintf(buffer, "%.*s", len, str);
if (strcasecmp(fmt, "upper") == 0)
Str::toCase(Str::cUpper, buffer);
if (strcasecmp(fmt, "lower") == 0)
Str::toCase(Str::cLower, buffer);
return buffer;
}
//***************************************************************************
// Format Date Time
//***************************************************************************
const char* cDisplayItem::formatDateTime(time_t theTime, const char* fmt,
char* date, int len, int absolut)
{
struct tm tim = {0};
tm* tmp;
int res;
*date = 0;
string format = fmt && *fmt ? fmt :
(_format.length() ? _format : "%a %d.%m %H:%M");
// %s seems to be absolut as default ...
if (absolut && format.find("%s") == string::npos)
{
localtime_r(&theTime, &tim);
theTime += timezone;
}
tmp = localtime_r(&theTime, &tim);
if (!tmp)
{
tell(0, "Error: Can't get localtime!");
return 0;
}
res = strftime(date, len, format.c_str(), tmp);
if (!res)
{
tell(0, "Error: Can't convert time, maybe "
"invalid format string '%s'!", format.c_str());
return 0;
}
if (format.find("%s") != string::npos
|| format.find("%S") != string::npos
|| format.find("%T") != string::npos)
{
// refresh in 1 second
if (!_delay)
scheduleDrawIn(1000);
}
else
{
// refresh at next full minute
scheduleDrawNextFullMinute();
}
return date;
}
//***************************************************************************
// Draw Image on Background Coordinates
//***************************************************************************
int cDisplayItem::drawImageOnBack(const char* path, int fit, int height)
{
if (!path)
return done;
int x = _bg_x != na ? _bg_x : X();
int width = _bg_width > 0 ? _bg_width : Width();
int y = _bg_y != na ? _bg_y : Y();
if (height == na)
height = _bg_height > 0 ? _bg_height : Height();
tell(0, "drawing image '%s' at %d/%d (%d/%d)", path, x, y, width, height);
render->image(path, x, y, width, height, fit);
return done;
}
int cDisplayItem::drawProgressBar(double current, double total,
string path, int y, int height,
int withFrame, int clear)
{
t_rgba rgba;
int xDone;
char tmp[50];
int bgX = _bg_x != na ? _bg_x : X();
int bgWidth = _bg_width ? _bg_width : Width();
int bgY = y != na ? y : _bg_y != na ? _bg_y : Y();
int bgHeight = height != na ? height : _bg_height ? _bg_height : Height();
int red, green, blue, alpha;
rgba2int(str2rgba(_color.c_str(), rgba), red, green, blue, alpha);
current = current < 0 ? 0 : current ;
bgHeight = bgHeight ? bgHeight : Height();
height = height == na ? Height() : height;
y = y == na ? Y() : y;
if (!total) total = 1;
xDone = (int)((current/total) * (float)Width());
tell(4, "bar, %f/%f xDone=%d", current, total, xDone);
// background
if (clear)
drawBackRect(y, height);
if (_bg_x && withFrame)
render->rectangle(bgX, bgY,
bgWidth, bgHeight,
evaluateColor(_bg_color.c_str(), rgba));
if (path != "")
render->image(path.c_str(),
X(), y,
Width(), height,
true);
else // if (_bg_x <= 0)
render->rectangle(X(), y, Width(), height,
evaluateColor(_bg_color.c_str(), rgba));
// foreground