1 /***************************************************************************
2 * Copyright (C) 2008-2010 by Andrzej Rybczak *
3 * electricityispower@gmail.com *
5 * This program is free software; you can redistribute it and/or modify *
6 * it under the terms of the GNU General Public License as published by *
7 * the Free Software Foundation; either version 2 of the License, or *
8 * (at your option) any later version. *
10 * This program is distributed in the hope that it will be useful, *
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
13 * GNU General Public License for more details. *
15 * You should have received a copy of the GNU General Public License *
16 * along with this program; if not, write to the *
17 * Free Software Foundation, Inc., *
18 * 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA. *
19 ***************************************************************************/
21 /// NOTICE: Major part of this code is ported from ncmpc's clock screen
35 using Global::MainHeight
;
36 using Global::MainStartY
;
37 using Global::myScreen
;
39 Clock
*myClock
= new Clock
;
41 short Clock::disp
[11] =
43 075557, 011111, 071747, 071717,
44 055711, 074717, 074757, 071111,
45 075757, 075717, 002020
48 long Clock::older
[6], Clock::next
[6], Clock::newer
[6], Clock::mask
;
51 const size_t Clock::Height
= 8;
55 Width
= Config
.clock_display_seconds
? 60 : 40;
57 w
= new Window((COLS
-Width
)/2, (MainHeight
-Height
)/2+MainStartY
, Width
, Height
-1, "", Config
.main_color
, Border(Config
.main_color
));
63 if (Width
<= size_t(COLS
) && Height
<= MainHeight
)
65 w
->MoveTo((COLS
-Width
)/2, (MainHeight
-Height
)/2+MainStartY
);
68 if (myPlaylist
->hasToBeResized
)
70 myPlaylist
->Items
->Hide();
76 void Clock::SwitchTo()
78 if (Width
> size_t(COLS
) || Height
> MainHeight
)
80 ShowMessage("Screen is too small to display clock!");
92 if (myScreen
!= this && myScreen
->isTabbable())
93 Global::myPrevScreen
= myScreen
;
95 myPlaylist
->Items
->Hide();
96 Global::RedrawHeader
= 1;
98 // clearing screen apparently fixes the problem with last digits being misrendered
103 std::basic_string
<my_char_t
> Clock::Title()
110 if (Width
> size_t(COLS
) || Height
> MainHeight
)
111 myPlaylist
->SwitchTo();
113 static timeval past
= { 0, 0 };
114 if (Global::Timer
.tv_sec
<= past
.tv_sec
)
116 gettimeofday(&past
, 0);
118 tm
*time
= localtime(&past
.tv_sec
);
121 Set(time
->tm_sec
% 10, 0);
122 Set(time
->tm_sec
/ 10, 4);
123 Set(time
->tm_min
% 10, 10);
124 Set(time
->tm_min
/ 10, 14);
125 Set(time
->tm_hour
% 10, 20);
126 Set(time
->tm_hour
/ 10, 24);
131 strftime(buf
, 64, "%x", time
);
132 attron(COLOR_PAIR(Config
.main_color
));
133 mvprintw(w
->GetStartY()+w
->GetHeight(), w
->GetStartX()+(w
->GetWidth()-strlen(buf
))/2, "%s", buf
);
134 attroff(COLOR_PAIR(Config
.main_color
));
137 for (int k
= 0; k
< 6; ++k
)
139 newer
[k
] = (newer
[k
] & ~mask
) | (next
[k
] & mask
);
141 for (int s
= 1; s
>= 0; --s
)
143 *w
<< (s
? fmtReverse
: fmtReverseEnd
);
144 for (int i
= 0; i
< 6; ++i
)
146 long a
= (newer
[i
] ^ older
[i
]) & (s
? newer
: older
)[i
];
150 for (int j
= 0; t
; t
>>= 1, ++j
)
158 if (Config
.clock_display_seconds
|| j
< 18)
173 void Clock::Prepare()
175 for (int i
= 0; i
< 5; ++i
)
176 older
[i
] = newer
[i
] = next
[i
] = 0;
179 void Clock::Set(int t
, int n
)
182 for (int i
= 0; i
< 5; ++i
)
184 next
[i
] |= ((disp
[t
] >> ((4 - i
) * 3)) & 07) << n
;
185 mask
|= (next
[i
] ^ older
[i
]) & m
;
191 #endif // ENABLE_CLOCK