1 /***************************************************************************
2 * Copyright (C) 2008-2012 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
34 #include "statusbar.h"
37 using Global::MainHeight
;
38 using Global::MainStartY
;
39 using Global::myScreen
;
41 Clock
*myClock
= new Clock
;
43 short Clock::disp
[11] =
45 075557, 011111, 071747, 071717,
46 055711, 074717, 074757, 071111,
47 075757, 075717, 002020
50 long Clock::older
[6], Clock::next
[6], Clock::newer
[6], Clock::mask
;
53 const size_t Clock::Height
= 8;
57 Width
= Config
.clock_display_seconds
? 60 : 40;
59 itsPane
= new NC::Window(0, MainStartY
, COLS
, MainHeight
, "", Config
.main_color
, NC::brNone
);
60 w
= new NC::Window((COLS
-Width
)/2, (MainHeight
-Height
)/2+MainStartY
, Width
, Height
-1, "", Config
.main_color
, NC::Border(Config
.main_color
));
66 size_t x_offset
, width
;
67 GetWindowResizeParams(x_offset
, width
);
69 // used for clearing area out of clock window while resizing terminal
70 itsPane
->resize(width
, MainHeight
);
71 itsPane
->moveTo(x_offset
, MainStartY
);
74 if (Width
<= width
&& Height
<= MainHeight
)
75 w
->moveTo(x_offset
+(width
-Width
)/2, MainStartY
+(MainHeight
-Height
)/2);
78 void Clock::SwitchTo()
80 using Global::myLockedScreen
;
89 UpdateInactiveScreen(this);
91 size_t x_offset
, width
;
92 GetWindowResizeParams(x_offset
, width
, false);
93 if (Width
> width
|| Height
> MainHeight
)
95 Statusbar::msg("Screen is too small to display clock");
97 UpdateInactiveScreen(myLockedScreen
);
101 if (hasToBeResized
|| myLockedScreen
)
104 if (myScreen
!= this && myScreen
->isTabbable())
105 Global::myPrevScreen
= myScreen
;
110 // clearing screen apparently fixes the problem with last digits being misrendered
115 std::wstring
Clock::Title()
122 if (Width
> itsPane
->getWidth() || Height
> MainHeight
)
124 using Global::myLockedScreen
;
125 using Global::myInactiveScreen
;
129 if (myInactiveScreen
!= myLockedScreen
)
130 myScreen
= myInactiveScreen
;
131 myLockedScreen
->SwitchTo();
134 myPlaylist
->SwitchTo();
137 tm
*time
= localtime(&Global::Timer
.tv_sec
);
140 Set(time
->tm_sec
% 10, 0);
141 Set(time
->tm_sec
/ 10, 4);
142 Set(time
->tm_min
% 10, 10);
143 Set(time
->tm_min
/ 10, 14);
144 Set(time
->tm_hour
% 10, 20);
145 Set(time
->tm_hour
/ 10, 24);
150 strftime(buf
, 64, "%x", time
);
151 attron(COLOR_PAIR(Config
.main_color
));
152 mvprintw(w
->getStarty()+w
->getHeight(), w
->getStartX()+(w
->getWidth()-strlen(buf
))/2, "%s", buf
);
153 attroff(COLOR_PAIR(Config
.main_color
));
156 for (int k
= 0; k
< 6; ++k
)
158 newer
[k
] = (newer
[k
] & ~mask
) | (next
[k
] & mask
);
160 for (int s
= 1; s
>= 0; --s
)
162 *w
<< (s
? NC::fmtReverse
: NC::fmtReverseEnd
);
163 for (int i
= 0; i
< 6; ++i
)
165 long a
= (newer
[i
] ^ older
[i
]) & (s
? newer
: older
)[i
];
169 for (int j
= 0; t
; t
>>= 1, ++j
)
177 if (Config
.clock_display_seconds
|| j
< 18)
192 void Clock::Prepare()
194 for (int i
= 0; i
< 5; ++i
)
195 older
[i
] = newer
[i
] = next
[i
] = 0;
198 void Clock::Set(int t
, int n
)
201 for (int i
= 0; i
< 5; ++i
)
203 next
[i
] |= ((disp
[t
] >> ((4 - i
) * 3)) & 07) << n
;
204 mask
|= (next
[i
] ^ older
[i
]) & m
;
210 #endif // ENABLE_CLOCK