CInfoClock: rework infocklock

Origin commit data
------------------
Commit: b8b61684df
Author: Thilo Graf <dbt@novatux.de>
Date: 2013-11-12 (Tue, 12 Nov 2013)
This commit is contained in:
2013-11-12 12:19:41 +01:00
committed by Michael Liebmann
parent d30ce8b0e5
commit a2967e2488
6 changed files with 92 additions and 105 deletions

View File

@@ -60,12 +60,11 @@ CComponentsFrmClock::CComponentsFrmClock( const int x_pos, const int y_pos, cons
col_body = color_body; col_body = color_body;
col_shadow = color_shadow; col_shadow = color_shadow;
cl_format_str = format_str;
paintClock = false; paintClock = false;
activeClock = activ; activeClock = activ;
if (activeClock) if (activeClock)
startThread(); startThread();
cl_format_str = format_str;
} }
void CComponentsFrmClock::initVarClock() void CComponentsFrmClock::initVarClock()

View File

@@ -1,41 +1,45 @@
/*
Based up Neutrino-GUI - Tuxbox-Project
Copyright (C) 2001 by Steffen Hehn 'McClean'
Info Clock Window
based up CComponentsFrmClock
Copyright (C) 2013, Thilo Graf 'dbt'
Copyright (C) 2013, Michael Liebmann 'micha-bbg'
License: GPL
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public
License as published by the Free Software Foundation; either
version 2 of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
General Public License for more details.
You should have received a copy of the GNU General Public
License along with this program; if not, write to the
Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
Boston, MA 02110-1301, USA.
*/
#ifdef HAVE_CONFIG_H #ifdef HAVE_CONFIG_H
#include <config.h> #include <config.h>
#endif #endif
#include <global.h> #include <global.h>
#include <neutrino.h> #include <neutrino.h>
#include <pthread.h> // #include <driver/volume.h>
#include <string>
#include <sys/timeb.h>
#include <time.h>
#include <unistd.h>
#include <sys/param.h>
#include <driver/volume.h>
#include <gui/volumebar.h> #include <gui/volumebar.h>
#include <gui/infoclock.h> #include <gui/infoclock.h>
#define YOFF 0
CInfoClock::CInfoClock()
{
frameBuffer = CFrameBuffer::getInstance();
x = y = clock_x = 0;
time_height = time_width = thrTimer = 0;
Init();
}
CInfoClock::~CInfoClock() CInfoClock::CInfoClock():CComponentsFrmClock( 0, 0, 0, 50, "%H:%M:%S", true, CC_SHADOW_OFF, COL_LIGHT_GRAY, COL_MENUCONTENT_PLUS_0,COL_MENUCONTENTDARK_PLUS_0)
{ {
if(thrTimer) initVarInfoClock();
pthread_cancel(thrTimer);
thrTimer = 0;
}
void CInfoClock::Init()
{
CVolumeHelper::getInstance()->refresh();
CVolumeHelper::getInstance()->getInfoClockDimensions(&clock_x, &y, &time_width, &time_height, &digit_h, &digit_offset);
} }
CInfoClock* CInfoClock::getInstance() CInfoClock* CInfoClock::getInstance()
@@ -46,64 +50,35 @@ CInfoClock* CInfoClock::getInstance()
return InfoClock; return InfoClock;
} }
void CInfoClock::paintTime( bool show_dot) void CInfoClock::initVarInfoClock()
{ {
char timestr[20]; cl_font = g_Font[SNeutrinoSettings::FONT_TYPE_MENU_TITLE];
int dummy, mute_dx, h_spacer; Init();
time_t tm = time(0);
strftime((char*) &timestr, sizeof(timestr), "%H:%M:%S", localtime(&tm));
timestr[2] = show_dot ? ':':'.';
CVolumeHelper *cvh = CVolumeHelper::getInstance();
cvh->getInfoClockDimensions(&clock_x, &y, &time_width, &time_height, &digit_h, &digit_offset);
cvh->getMuteIconDimensions(&dummy, &dummy, &mute_dx, &dummy);
cvh->getSpacer(&h_spacer, &dummy);
if (CNeutrinoApp::getInstance()->isMuted())
clock_x -= (mute_dx + h_spacer);
int x_diff = (time_width - g_Font[SNeutrinoSettings::FONT_TYPE_INFOBAR_CHANNAME]->getRenderWidth(timestr)) / 2;
frameBuffer->paintBoxRel(clock_x, y, time_width, time_height, COL_MENUCONTENT_PLUS_0, RADIUS_SMALL);
g_Font[SNeutrinoSettings::FONT_TYPE_INFOBAR_CHANNAME]->RenderString(clock_x + x_diff, y + digit_h + digit_offset + ((time_height - digit_h) / 2), time_width, timestr, COL_MENUCONTENT_TEXT);
} }
void* CInfoClock::TimerProc(void *arg) void CInfoClock::Init()
{ {
CVolumeHelper::getInstance()->refresh();
bool show_dot = false; CVolumeHelper::getInstance()->getInfoClockDimensions(&x, &y, &width, &height);
pthread_setcancelstate(PTHREAD_CANCEL_ENABLE,0); initCCLockItems();
pthread_setcanceltype (PTHREAD_CANCEL_ASYNCHRONOUS,0);
CInfoClock *InfoClock = static_cast<CInfoClock*>(arg);
InfoClock->paintTime(show_dot);
while(1) {
sleep(1);
show_dot = !show_dot;
InfoClock->paintTime(show_dot);
}
return 0;
} }
void CInfoClock::ClearDisplay() void CInfoClock::ClearDisplay()
{ {
frameBuffer->paintBackgroundBoxRel(clock_x, y, time_width, time_height); kill();
Init(); Init();
} }
void CInfoClock::StartClock() bool CInfoClock::StartClock()
{ {
Init(); Init();
return Start();
if(!thrTimer) {
pthread_create (&thrTimer, NULL, TimerProc, (void*) this) ;
pthread_detach(thrTimer);
}
} }
void CInfoClock::StopClock() bool CInfoClock::StopClock()
{ {
if(thrTimer) { bool ret = Stop();
pthread_cancel(thrTimer); kill();
thrTimer = 0;
frameBuffer->paintBackgroundBoxRel(clock_x, y, time_width, time_height); return ret;
}
} }

View File

@@ -1,39 +1,51 @@
#ifndef __infoclock__ /*
#define __infoclock__ Based up Neutrino-GUI - Tuxbox-Project
Copyright (C) 2001 by Steffen Hehn 'McClean'
Info Clock Window
based up CComponentsFrmClock
Copyright (C) 2013, Thilo Graf 'dbt'
Copyright (C) 2013, Michael Liebmann 'micha-bbg'
License: GPL
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public
License as published by the Free Software Foundation; either
version 2 of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
General Public License for more details.
You should have received a copy of the GNU General Public
License along with this program; if not, write to the
Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
Boston, MA 02110-1301, USA.
*/
#ifndef __INFOCLOCK__
#define __INFOCLOCK__
#include <driver/framebuffer.h> #include <gui/components/cc.h>
#include <driver/fontrenderer.h>
#include <system/settings.h>
#include <gui/color.h>
#include <string>
class CInfoClock class CInfoClock : public CComponentsFrmClock
{ {
protected:
void initVarInfoClock();
private: private:
CFrameBuffer * frameBuffer;
pthread_t thrTimer;
void paintTime( bool show_dot);
int time_offset, digit_offset, digit_h;
int x, y, clock_x;
void Init(); void Init();
static void CleanUpProc(void* arg);
static void* TimerProc(void *arg);
public: public:
CInfoClock(); CInfoClock();
~CInfoClock(); // ~CInfoClock(); // inherited from CComponentsFrmClock
static CInfoClock* getInstance(); static CInfoClock* getInstance();
void StartClock(); bool StartClock();
void StopClock(); bool StopClock();
void ClearDisplay(); void ClearDisplay();
int time_width, time_height;
}; };
#endif #endif

View File

@@ -101,7 +101,7 @@ void CVolumeBar::initVolumeBarSize()
cvh->getMuteIconDimensions(&mute_ax, &mute_ay, &mute_dx, &mute_dy); cvh->getMuteIconDimensions(&mute_ax, &mute_ay, &mute_dx, &mute_dy);
// info clock // info clock
int dummy; int dummy;
cvh->getInfoClockDimensions(&dummy, &clock_y, &clock_width, &clock_height, &dummy, &dummy); cvh->getInfoClockDimensions(&dummy, &clock_y, &clock_width, &clock_height);
int mute_corrY = 0; int mute_corrY = 0;
if (mute_dy < height) if (mute_dy < height)
mute_corrY = (height - mute_dy) / 2; mute_corrY = (height - mute_dy) / 2;
@@ -111,6 +111,7 @@ void CVolumeBar::initVolumeBarSize()
CInfoClock::getInstance()->ClearDisplay(); CInfoClock::getInstance()->ClearDisplay();
vb_pbh = height-8; vb_pbh = height-8;
vb_pby = height/2-vb_pbh/2; vb_pby = height/2-vb_pbh/2;
} }

View File

@@ -123,7 +123,7 @@ class CVolumeHelper
int getVolIconHeight() {return icon_height;} int getVolIconHeight() {return icon_height;}
void getDimensions(int *_x, int *_y, int *_sw, int *_sh, int *_iw, int *_dw) { *_x = x; *_y = y; *_sw = sw; *_sh = sh; *_iw = icon_width; *_dw = digit_width; } void getDimensions(int *_x, int *_y, int *_sw, int *_sh, int *_iw, int *_dw) { *_x = x; *_y = y; *_sw = sw; *_sh = sh; *_iw = icon_width; *_dw = digit_width; }
void getMuteIconDimensions(int *_x, int *_y, int *w, int *h) { *_x = mute_ax; *_y = mute_ay+mute_corrY; *w = mute_dx; *h = mute_dy; } void getMuteIconDimensions(int *_x, int *_y, int *w, int *h) { *_x = mute_ax; *_y = mute_ay+mute_corrY; *w = mute_dx; *h = mute_dy; }
void getInfoClockDimensions(int *_x, int *_y, int *w, int *h, int *d_h, int *d_o) { *_x = clock_ax; *_y = clock_ay; *w = clock_dx; *h = clock_dy, *d_h = digit_h, *d_o = digit_offset; } void getInfoClockDimensions(int *_x, int *_y, int *w, int *h/*, int *d_h, int *d_o*/) { *_x = clock_ax; *_y = clock_ay; *w = clock_dx; *h = clock_dy/*, *d_h = digit_h, *d_o = digit_offset*/; }
void getVolBarDimensions(int *_y, int *_dy) { *_y = vol_ay; *_dy = vol_height; } void getVolBarDimensions(int *_y, int *_dy) { *_y = vol_ay; *_dy = vol_height; }
void setMuteIconCorrY(int corr) { mute_corrY = corr; } void setMuteIconCorrY(int corr) { mute_corrY = corr; }
void refresh(); void refresh();

View File

@@ -2028,7 +2028,7 @@ void CNeutrinoApp::RealRun(CMenuWidget &mainMenu)
InfoClock = CInfoClock::getInstance(); InfoClock = CInfoClock::getInstance();
if(g_settings.mode_clock) if(g_settings.mode_clock)
InfoClock->StartClock(); g_settings.mode_clock = InfoClock->StartClock();
//cCA::GetInstance()->Ready(true); //cCA::GetInstance()->Ready(true);