mirror of
https://github.com/RGBCube/serenity
synced 2025-05-31 07:58:11 +00:00
Move Widget & friends into LibGUI.
This commit is contained in:
parent
7e5b81fe48
commit
a026da47e7
29 changed files with 73 additions and 551 deletions
37
LibGUI/ClockWidget.cpp
Normal file
37
LibGUI/ClockWidget.cpp
Normal file
|
@ -0,0 +1,37 @@
|
|||
#include "ClockWidget.h"
|
||||
#include "Painter.h"
|
||||
#include <time.h>
|
||||
|
||||
ClockWidget::ClockWidget(Widget* parent)
|
||||
: Widget(parent)
|
||||
{
|
||||
setWindowRelativeRect({ 0, 0, 100, 40 });
|
||||
startTimer(250);
|
||||
}
|
||||
|
||||
ClockWidget::~ClockWidget()
|
||||
{
|
||||
}
|
||||
|
||||
void ClockWidget::paintEvent(PaintEvent&)
|
||||
{
|
||||
auto now = time(nullptr);
|
||||
auto& tm = *localtime(&now);
|
||||
|
||||
char timeBuf[128];
|
||||
sprintf(timeBuf, "%02u:%02u:%02u ", tm.tm_hour, tm.tm_min, tm.tm_sec);
|
||||
|
||||
Painter painter(*this);
|
||||
painter.fill_rect(rect(), Color::MidGray);
|
||||
painter.draw_text(rect(), timeBuf, Painter::TextAlignment::Center, Color::Black);
|
||||
}
|
||||
|
||||
void ClockWidget::timerEvent(TimerEvent&)
|
||||
{
|
||||
auto now = time(nullptr);
|
||||
if (now == m_lastSeenTimestamp)
|
||||
return;
|
||||
m_lastSeenTimestamp = now;
|
||||
update();
|
||||
}
|
||||
|
Loading…
Add table
Add a link
Reference in a new issue