change namespace Clock into class
This commit is contained in:
121
src/clock.cpp
121
src/clock.cpp
@@ -32,67 +32,71 @@
|
|||||||
|
|
||||||
using namespace Global;
|
using namespace Global;
|
||||||
|
|
||||||
Scrollpad *Global::wClock;
|
Clock *myClock = new Clock;
|
||||||
|
|
||||||
namespace
|
short Clock::disp[11] =
|
||||||
{
|
|
||||||
short disp[11] =
|
|
||||||
{
|
{
|
||||||
075557, 011111, 071747, 071717,
|
075557, 011111, 071747, 071717,
|
||||||
055711, 074717, 074757, 071111,
|
055711, 074717, 074757, 071111,
|
||||||
075757, 075717, 002020
|
075757, 075717, 002020
|
||||||
};
|
};
|
||||||
|
|
||||||
long older[6], next[6], newer[6], mask;
|
long Clock::older[6], Clock::next[6], Clock::newer[6], Clock::mask;
|
||||||
|
|
||||||
void set(int t, int n)
|
const size_t Clock::Width = Config.clock_display_seconds ? 60 : 40;
|
||||||
{
|
const size_t Clock::Height = 8;
|
||||||
int m = 7 << n;
|
|
||||||
for (int i = 0; i < 5; i++)
|
|
||||||
{
|
|
||||||
next[i] |= ((disp[t] >> ((4 - i) * 3)) & 07) << n;
|
|
||||||
mask |= (next[i] ^ older[i]) & m;
|
|
||||||
}
|
|
||||||
if (mask & m)
|
|
||||||
mask |= m;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
namespace Clock
|
|
||||||
{
|
|
||||||
const size_t width = Config.clock_display_seconds ? 60 : 40;
|
|
||||||
const size_t height = 8;
|
|
||||||
}
|
|
||||||
|
|
||||||
void Clock::Init()
|
void Clock::Init()
|
||||||
{
|
{
|
||||||
wClock = new Scrollpad((COLS-width)/2, (LINES-height)/2, width, height-1, "", Config.main_color, Border(Config.main_color));
|
w = new Scrollpad((COLS-Width)/2, (LINES-Height)/2, Width, Height-1, "", Config.main_color, Border(Config.main_color));
|
||||||
wClock->SetTimeout(ncmpcpp_window_timeout);
|
w->SetTimeout(ncmpcpp_window_timeout);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Clock::Resize()
|
void Clock::Resize()
|
||||||
{
|
{
|
||||||
if (width <= size_t(COLS) && height <= main_height)
|
if (Width <= size_t(COLS) && Height <= main_height)
|
||||||
{
|
{
|
||||||
wClock->MoveTo((COLS-width)/2, (LINES-height)/2);
|
w->MoveTo((COLS-Width)/2, (LINES-Height)/2);
|
||||||
if (current_screen == csClock)
|
if (current_screen == csClock)
|
||||||
{
|
{
|
||||||
myPlaylist->Main()->Hide();
|
myPlaylist->Main()->Hide();
|
||||||
Prepare();
|
Prepare();
|
||||||
wClock->Display();
|
w->Display();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void Clock::Prepare()
|
void Clock::SwitchTo()
|
||||||
{
|
{
|
||||||
for (int i = 0; i < 5; i++)
|
if (Width > size_t(COLS) || Height > main_height)
|
||||||
older[i] = newer[i] = next[i] = 0;
|
{
|
||||||
|
ShowMessage("Screen is too small to display clock!");
|
||||||
|
}
|
||||||
|
else if (
|
||||||
|
current_screen != csClock
|
||||||
|
# ifdef HAVE_TAGLIB_H
|
||||||
|
&& current_screen != csTinyTagEditor
|
||||||
|
# endif // HAVE_TAGLIB_H
|
||||||
|
)
|
||||||
|
{
|
||||||
|
CLEAR_FIND_HISTORY;
|
||||||
|
wCurrent = w;
|
||||||
|
myPlaylist->Main()->Hide();
|
||||||
|
current_screen = csClock;
|
||||||
|
redraw_header = 1;
|
||||||
|
Clock::Prepare();
|
||||||
|
w->Display();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
std::string Clock::Title()
|
||||||
|
{
|
||||||
|
return "Clock";
|
||||||
}
|
}
|
||||||
|
|
||||||
void Clock::Update()
|
void Clock::Update()
|
||||||
{
|
{
|
||||||
if (width > size_t(COLS) || height > main_height)
|
if (Width > size_t(COLS) || Height > main_height)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
time_t rawtime;
|
time_t rawtime;
|
||||||
@@ -100,19 +104,19 @@ void Clock::Update()
|
|||||||
tm *time = localtime(&rawtime);
|
tm *time = localtime(&rawtime);
|
||||||
|
|
||||||
mask = 0;
|
mask = 0;
|
||||||
set(time->tm_sec % 10, 0);
|
Set(time->tm_sec % 10, 0);
|
||||||
set(time->tm_sec / 10, 4);
|
Set(time->tm_sec / 10, 4);
|
||||||
set(time->tm_min % 10, 10);
|
Set(time->tm_min % 10, 10);
|
||||||
set(time->tm_min / 10, 14);
|
Set(time->tm_min / 10, 14);
|
||||||
set(time->tm_hour % 10, 20);
|
Set(time->tm_hour % 10, 20);
|
||||||
set(time->tm_hour / 10, 24);
|
Set(time->tm_hour / 10, 24);
|
||||||
set(10, 7);
|
Set(10, 7);
|
||||||
set(10, 17);
|
Set(10, 17);
|
||||||
|
|
||||||
char buf[54];
|
char buf[54];
|
||||||
strftime(buf, 64, "%x", time);
|
strftime(buf, 64, "%x", time);
|
||||||
attron(COLOR_PAIR(Config.main_color));
|
attron(COLOR_PAIR(Config.main_color));
|
||||||
mvprintw(wCurrent->GetStartY()+wCurrent->GetHeight(), wCurrent->GetStartX()+(wCurrent->GetWidth()-strlen(buf))/2, "%s", buf);
|
mvprintw(w->GetStartY()+w->GetHeight(), w->GetStartX()+(w->GetWidth()-strlen(buf))/2, "%s", buf);
|
||||||
attroff(COLOR_PAIR(Config.main_color));
|
attroff(COLOR_PAIR(Config.main_color));
|
||||||
refresh();
|
refresh();
|
||||||
|
|
||||||
@@ -122,7 +126,7 @@ void Clock::Update()
|
|||||||
next[k] = 0;
|
next[k] = 0;
|
||||||
for (int s = 1; s >= 0; s--)
|
for (int s = 1; s >= 0; s--)
|
||||||
{
|
{
|
||||||
wCurrent->Reverse(s);
|
w->Reverse(s);
|
||||||
for (int i = 0; i < 6; i++)
|
for (int i = 0; i < 6; i++)
|
||||||
{
|
{
|
||||||
long a = (newer[i] ^ older[i]) & (s ? newer : older)[i];
|
long a = (newer[i] ^ older[i]) & (s ? newer : older)[i];
|
||||||
@@ -135,10 +139,10 @@ void Clock::Update()
|
|||||||
{
|
{
|
||||||
if (!(a & (t << 1)))
|
if (!(a & (t << 1)))
|
||||||
{
|
{
|
||||||
wCurrent->GotoXY(2*j+2, i);
|
w->GotoXY(2*j+2, i);
|
||||||
}
|
}
|
||||||
if (Global::Config.clock_display_seconds || j < 18)
|
if (Global::Config.clock_display_seconds || j < 18)
|
||||||
*wCurrent << " ";
|
*w << " ";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -151,27 +155,22 @@ void Clock::Update()
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void Clock::SwitchTo()
|
void Clock::Prepare()
|
||||||
{
|
{
|
||||||
if (width > size_t(COLS) || height > main_height)
|
for (int i = 0; i < 5; i++)
|
||||||
{
|
older[i] = newer[i] = next[i] = 0;
|
||||||
ShowMessage("Screen is too small to display clock!");
|
|
||||||
}
|
}
|
||||||
else if (
|
|
||||||
current_screen != csClock
|
void Clock::Set(int t, int n)
|
||||||
# ifdef HAVE_TAGLIB_H
|
|
||||||
&& current_screen != csTinyTagEditor
|
|
||||||
# endif // HAVE_TAGLIB_H
|
|
||||||
)
|
|
||||||
{
|
{
|
||||||
CLEAR_FIND_HISTORY;
|
int m = 7 << n;
|
||||||
wCurrent = wClock;
|
for (int i = 0; i < 5; i++)
|
||||||
myPlaylist->Main()->Hide();
|
{
|
||||||
current_screen = csClock;
|
next[i] |= ((disp[t] >> ((4 - i) * 3)) & 07) << n;
|
||||||
redraw_header = 1;
|
mask |= (next[i] ^ older[i]) & m;
|
||||||
Clock::Prepare();
|
|
||||||
wCurrent->Display();
|
|
||||||
}
|
}
|
||||||
|
if (mask & m)
|
||||||
|
mask |= m;
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif // ENABLE_CLOCK
|
#endif // ENABLE_CLOCK
|
||||||
|
|||||||
29
src/clock.h
29
src/clock.h
@@ -28,18 +28,31 @@
|
|||||||
#ifdef ENABLE_CLOCK
|
#ifdef ENABLE_CLOCK
|
||||||
|
|
||||||
#include "window.h"
|
#include "window.h"
|
||||||
|
#include "screen.h"
|
||||||
|
|
||||||
namespace Clock
|
class Clock : public Screen<Window>
|
||||||
{
|
{
|
||||||
void Init();
|
public:
|
||||||
void Resize();
|
virtual void Init();
|
||||||
void SwitchTo();
|
virtual void Resize();
|
||||||
|
virtual void SwitchTo();
|
||||||
|
|
||||||
void Update();
|
virtual std::string Title();
|
||||||
void Prepare();
|
|
||||||
}
|
|
||||||
|
|
||||||
#include <ctime>
|
virtual void Update();
|
||||||
|
|
||||||
|
protected:
|
||||||
|
static void Prepare();
|
||||||
|
static void Set(int, int);
|
||||||
|
|
||||||
|
static short disp[11];
|
||||||
|
static long older[6], next[6], newer[6], mask;
|
||||||
|
|
||||||
|
static const size_t Width;
|
||||||
|
static const size_t Height;
|
||||||
|
};
|
||||||
|
|
||||||
|
extern Clock *myClock;
|
||||||
|
|
||||||
#endif // ENABLE_CLOCK
|
#endif // ENABLE_CLOCK
|
||||||
|
|
||||||
|
|||||||
@@ -64,9 +64,9 @@ namespace Global
|
|||||||
|
|
||||||
extern Window *wHeader;
|
extern Window *wHeader;
|
||||||
extern Window *wFooter;
|
extern Window *wFooter;
|
||||||
# ifdef ENABLE_CLOCK
|
//# ifdef ENABLE_CLOCK
|
||||||
extern Scrollpad *wClock;
|
// extern Scrollpad *wClock;
|
||||||
# endif
|
//# endif
|
||||||
|
|
||||||
extern MPD::Connection *Mpd;
|
extern MPD::Connection *Mpd;
|
||||||
|
|
||||||
@@ -109,8 +109,6 @@ namespace Global
|
|||||||
// extern bool search_case_sensitive;
|
// extern bool search_case_sensitive;
|
||||||
// extern bool search_match_to_pattern;
|
// extern bool search_match_to_pattern;
|
||||||
|
|
||||||
extern std::string volume_state;
|
|
||||||
|
|
||||||
// extern const char *search_mode_normal;
|
// extern const char *search_mode_normal;
|
||||||
// extern const char *search_mode_strict;
|
// extern const char *search_mode_strict;
|
||||||
|
|
||||||
|
|||||||
@@ -157,7 +157,7 @@ int main(int argc, char *argv[])
|
|||||||
# endif // HAVE_TAGLIB_H
|
# endif // HAVE_TAGLIB_H
|
||||||
|
|
||||||
# ifdef ENABLE_CLOCK
|
# ifdef ENABLE_CLOCK
|
||||||
Clock::Init();
|
myClock->Init();
|
||||||
# endif // ENABLE_CLOCK
|
# endif // ENABLE_CLOCK
|
||||||
|
|
||||||
myHelp->Init();
|
myHelp->Init();
|
||||||
@@ -264,7 +264,7 @@ int main(int argc, char *argv[])
|
|||||||
break;
|
break;
|
||||||
# ifdef ENABLE_CLOCK
|
# ifdef ENABLE_CLOCK
|
||||||
case csClock:
|
case csClock:
|
||||||
screen_title = "Clock";
|
screen_title = myClock->Title();
|
||||||
break;
|
break;
|
||||||
# endif // ENABLE_CLOCK
|
# endif // ENABLE_CLOCK
|
||||||
default:
|
default:
|
||||||
@@ -324,7 +324,7 @@ int main(int argc, char *argv[])
|
|||||||
# ifdef ENABLE_CLOCK
|
# ifdef ENABLE_CLOCK
|
||||||
if (current_screen == csClock)
|
if (current_screen == csClock)
|
||||||
{
|
{
|
||||||
Clock::Update();
|
myClock->Update();
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
# endif
|
# endif
|
||||||
@@ -508,7 +508,7 @@ int main(int argc, char *argv[])
|
|||||||
# endif // HAVE_TAGLIB_H
|
# endif // HAVE_TAGLIB_H
|
||||||
|
|
||||||
# ifdef ENABLE_CLOCK
|
# ifdef ENABLE_CLOCK
|
||||||
Clock::Resize();
|
myClock->Resize();
|
||||||
# endif // ENABLE_CLOCK
|
# endif // ENABLE_CLOCK
|
||||||
|
|
||||||
if (Config.header_visibility)
|
if (Config.header_visibility)
|
||||||
@@ -2049,7 +2049,7 @@ int main(int argc, char *argv[])
|
|||||||
# ifdef ENABLE_CLOCK
|
# ifdef ENABLE_CLOCK
|
||||||
else if (Keypressed(input, Key.Clock))
|
else if (Keypressed(input, Key.Clock))
|
||||||
{
|
{
|
||||||
Clock::SwitchTo();
|
myClock->SwitchTo();
|
||||||
}
|
}
|
||||||
# endif // ENABLE_CLOCK
|
# endif // ENABLE_CLOCK
|
||||||
else if (Keypressed(input, Key.Quit))
|
else if (Keypressed(input, Key.Quit))
|
||||||
|
|||||||
Reference in New Issue
Block a user