2019-01-20 05:48:43 +01:00
|
|
|
#include <stdio.h>
|
|
|
|
#include <unistd.h>
|
|
|
|
#include <errno.h>
|
|
|
|
#include <string.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <fcntl.h>
|
|
|
|
#include <assert.h>
|
2019-01-31 16:37:43 +01:00
|
|
|
#include <time.h>
|
2019-01-20 05:48:43 +01:00
|
|
|
#include <Kernel/Syscall.h>
|
|
|
|
#include <SharedGraphics/GraphicsBitmap.h>
|
|
|
|
#include <SharedGraphics/Painter.h>
|
|
|
|
#include <LibGUI/GWindow.h>
|
|
|
|
#include <LibGUI/GWidget.h>
|
|
|
|
#include <LibGUI/GLabel.h>
|
2019-01-21 00:31:11 +01:00
|
|
|
#include <LibGUI/GButton.h>
|
2019-01-20 05:48:43 +01:00
|
|
|
#include <LibGUI/GEventLoop.h>
|
2019-01-26 06:39:13 +01:00
|
|
|
#include <LibGUI/GTextBox.h>
|
2019-01-27 20:22:06 +01:00
|
|
|
#include <LibGUI/GCheckBox.h>
|
2019-02-04 13:30:03 +01:00
|
|
|
#include <signal.h>
|
2019-01-20 05:48:43 +01:00
|
|
|
|
2019-01-31 16:37:43 +01:00
|
|
|
class ClockWidget final : public GWidget {
|
|
|
|
public:
|
|
|
|
explicit ClockWidget(GWidget* parent = nullptr);
|
|
|
|
virtual ~ClockWidget() override { }
|
|
|
|
|
|
|
|
private:
|
|
|
|
virtual void paint_event(GPaintEvent&) override;
|
|
|
|
virtual void timer_event(GTimerEvent&) override;
|
|
|
|
virtual void mousedown_event(GMouseEvent&) override;
|
|
|
|
|
|
|
|
dword m_last_time { 0 };
|
|
|
|
};
|
|
|
|
|
|
|
|
ClockWidget::ClockWidget(GWidget* parent)
|
|
|
|
: GWidget(parent)
|
|
|
|
{
|
2019-02-04 11:51:42 +01:00
|
|
|
set_font(Font::default_bold_font());
|
2019-01-31 16:37:43 +01:00
|
|
|
set_relative_rect({ 0, 0, 100, 40 });
|
2019-01-31 17:31:23 +01:00
|
|
|
start_timer(250);
|
2019-01-31 16:37:43 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void ClockWidget::paint_event(GPaintEvent&)
|
|
|
|
{
|
|
|
|
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);
|
2019-02-04 11:51:42 +01:00
|
|
|
painter.fill_rect(rect(), Color::LightGray);
|
2019-01-31 16:37:43 +01:00
|
|
|
painter.draw_text(rect(), timeBuf, Painter::TextAlignment::Center, Color::Black);
|
|
|
|
}
|
|
|
|
|
|
|
|
void ClockWidget::timer_event(GTimerEvent&)
|
|
|
|
{
|
|
|
|
auto now = time(nullptr);
|
|
|
|
if (now == m_last_time)
|
|
|
|
return;
|
|
|
|
m_last_time = now;
|
|
|
|
update();
|
|
|
|
}
|
|
|
|
|
|
|
|
void ClockWidget::mousedown_event(GMouseEvent&)
|
|
|
|
{
|
|
|
|
update();
|
|
|
|
}
|
|
|
|
|
2019-01-20 05:48:43 +01:00
|
|
|
static GWindow* make_font_test_window();
|
2019-01-21 00:31:11 +01:00
|
|
|
static GWindow* make_launcher_window();
|
2019-01-31 16:37:43 +01:00
|
|
|
static GWindow* make_clock_window();
|
2019-01-20 05:48:43 +01:00
|
|
|
|
2019-02-04 13:30:03 +01:00
|
|
|
void handle_sigchld(int)
|
|
|
|
{
|
|
|
|
dbgprintf("Got SIGCHLD\n");
|
|
|
|
}
|
|
|
|
|
2019-01-20 05:48:43 +01:00
|
|
|
int main(int argc, char** argv)
|
|
|
|
{
|
2019-02-04 13:30:03 +01:00
|
|
|
signal(SIGCHLD, handle_sigchld);
|
|
|
|
|
2019-01-20 07:03:38 +01:00
|
|
|
GEventLoop loop;
|
2019-02-03 03:36:10 +01:00
|
|
|
#if 0
|
2019-01-21 00:31:11 +01:00
|
|
|
auto* font_test_window = make_font_test_window();
|
|
|
|
font_test_window->show();
|
2019-02-03 03:36:10 +01:00
|
|
|
#endif
|
2019-01-21 00:31:11 +01:00
|
|
|
|
|
|
|
auto* launcher_window = make_launcher_window();
|
|
|
|
launcher_window->show();
|
2019-01-31 16:37:43 +01:00
|
|
|
|
|
|
|
auto* clock_window = make_clock_window();
|
|
|
|
clock_window->show();
|
|
|
|
|
2019-01-20 05:48:43 +01:00
|
|
|
return loop.exec();
|
|
|
|
}
|
|
|
|
|
|
|
|
GWindow* make_font_test_window()
|
|
|
|
{
|
|
|
|
auto* window = new GWindow;
|
|
|
|
window->set_title("Font test");
|
2019-02-02 08:05:14 +01:00
|
|
|
window->set_rect({ 480, 100, 300, 80 });
|
2019-01-20 05:48:43 +01:00
|
|
|
|
|
|
|
auto* widget = new GWidget;
|
|
|
|
window->set_main_widget(widget);
|
2019-01-21 00:46:08 +01:00
|
|
|
widget->set_relative_rect({ 0, 0, 300, 80 });
|
2019-01-20 05:48:43 +01:00
|
|
|
|
|
|
|
auto* l1 = new GLabel(widget);
|
2019-01-21 00:46:08 +01:00
|
|
|
l1->set_relative_rect({ 0, 0, 300, 20 });
|
|
|
|
l1->set_text("0123456789");
|
2019-01-20 05:48:43 +01:00
|
|
|
|
|
|
|
auto* l2 = new GLabel(widget);
|
2019-01-21 00:46:08 +01:00
|
|
|
l2->set_relative_rect({ 0, 20, 300, 20 });
|
|
|
|
l2->set_text("ABCDEFGHIJKLMNOPQRSTUVWXYZ");
|
2019-01-20 05:48:43 +01:00
|
|
|
|
|
|
|
auto* l3 = new GLabel(widget);
|
2019-01-21 00:46:08 +01:00
|
|
|
l3->set_relative_rect({ 0, 40, 300, 20 });
|
|
|
|
l3->set_text("abcdefghijklmnopqrstuvwxyz");
|
2019-01-20 05:48:43 +01:00
|
|
|
|
|
|
|
auto* l4 = new GLabel(widget);
|
2019-01-21 00:46:08 +01:00
|
|
|
l4->set_relative_rect({ 0, 60, 300, 20 });
|
|
|
|
l4->set_text("!\"#$%&'()*+,-./:;<=>?@[\\]^_{|}~");
|
2019-01-20 05:48:43 +01:00
|
|
|
|
|
|
|
return window;
|
|
|
|
}
|
2019-01-21 00:31:11 +01:00
|
|
|
|
|
|
|
GWindow* make_launcher_window()
|
|
|
|
{
|
|
|
|
auto* window = new GWindow;
|
|
|
|
window->set_title("Launcher");
|
2019-01-30 20:03:52 +01:00
|
|
|
window->set_rect({ 100, 400, 100, 230 });
|
2019-01-21 00:31:11 +01:00
|
|
|
|
|
|
|
auto* widget = new GWidget;
|
|
|
|
window->set_main_widget(widget);
|
2019-01-30 20:03:52 +01:00
|
|
|
widget->set_relative_rect({ 0, 0, 100, 230 });
|
2019-01-21 00:31:11 +01:00
|
|
|
|
|
|
|
auto* label = new GLabel(widget);
|
2019-01-25 15:52:55 +01:00
|
|
|
label->set_relative_rect({ 0, 0, 100, 20 });
|
2019-01-21 00:46:08 +01:00
|
|
|
label->set_text("Apps");
|
2019-01-21 00:31:11 +01:00
|
|
|
|
2019-01-21 02:56:25 +01:00
|
|
|
auto* terminal_button = new GButton(widget);
|
2019-01-25 15:52:55 +01:00
|
|
|
terminal_button->set_relative_rect({ 5, 20, 90, 20 });
|
2019-01-21 02:56:25 +01:00
|
|
|
terminal_button->set_caption("Terminal");
|
2019-01-21 00:31:11 +01:00
|
|
|
|
2019-01-21 02:56:25 +01:00
|
|
|
terminal_button->on_click = [label] (GButton&) {
|
|
|
|
pid_t child_pid = fork();
|
|
|
|
if (!child_pid) {
|
2019-01-21 00:31:11 +01:00
|
|
|
execve("/bin/Terminal", nullptr, nullptr);
|
|
|
|
ASSERT_NOT_REACHED();
|
2019-01-21 02:56:25 +01:00
|
|
|
} else {
|
|
|
|
char buffer[32];
|
|
|
|
sprintf(buffer, "PID: %d", child_pid);
|
|
|
|
label->set_text(buffer);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
auto* guitest_button = new GButton(widget);
|
2019-01-25 15:52:55 +01:00
|
|
|
guitest_button->set_relative_rect({ 5, 50, 90, 20 });
|
2019-01-21 02:56:25 +01:00
|
|
|
guitest_button->set_caption("guitest");
|
|
|
|
|
|
|
|
guitest_button->on_click = [label] (GButton&) {
|
|
|
|
pid_t child_pid = fork();
|
|
|
|
if (!child_pid) {
|
|
|
|
execve("/bin/guitest", nullptr, nullptr);
|
|
|
|
ASSERT_NOT_REACHED();
|
|
|
|
} else {
|
|
|
|
char buffer[32];
|
|
|
|
sprintf(buffer, "PID: %d", child_pid);
|
|
|
|
label->set_text(buffer);
|
2019-01-21 00:31:11 +01:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2019-01-21 02:18:16 +01:00
|
|
|
auto* dummy_button = new GButton(widget);
|
2019-01-25 15:52:55 +01:00
|
|
|
dummy_button->set_relative_rect({ 5, 80, 90, 20 });
|
2019-01-21 02:18:16 +01:00
|
|
|
dummy_button->set_caption("Dummy");
|
|
|
|
|
2019-01-26 06:39:13 +01:00
|
|
|
auto* textbox = new GTextBox(widget);
|
|
|
|
textbox->set_relative_rect({ 5, 110, 90, 20 });
|
2019-01-26 11:24:16 +01:00
|
|
|
textbox->on_return_pressed = [window] (GTextBox& textbox) {
|
|
|
|
window->set_title(textbox.text());
|
|
|
|
};
|
|
|
|
|
|
|
|
auto* other_textbox = new GTextBox(widget);
|
|
|
|
other_textbox->set_relative_rect({ 5, 140, 90, 20 });
|
2019-01-26 06:39:13 +01:00
|
|
|
|
2019-01-27 20:22:06 +01:00
|
|
|
auto* checkbox = new GCheckBox(widget);
|
|
|
|
checkbox->set_relative_rect({ 5, 170, 90, 20 });
|
|
|
|
checkbox->set_caption("CheckBox");
|
|
|
|
|
2019-01-26 06:39:13 +01:00
|
|
|
window->set_focused_widget(textbox);
|
|
|
|
|
2019-01-30 20:03:52 +01:00
|
|
|
auto* close_button = new GButton(widget);
|
|
|
|
close_button->set_relative_rect({ 5, 200, 90, 20 });
|
|
|
|
close_button->set_caption("Close");
|
|
|
|
close_button->on_click = [window] (GButton&) {
|
|
|
|
window->close();
|
|
|
|
};
|
|
|
|
|
2019-01-21 00:31:11 +01:00
|
|
|
return window;
|
|
|
|
}
|
2019-01-31 16:37:43 +01:00
|
|
|
|
|
|
|
GWindow* make_clock_window()
|
|
|
|
{
|
|
|
|
auto* window = new GWindow;
|
|
|
|
window->set_title("Clock");
|
2019-02-02 08:05:14 +01:00
|
|
|
window->set_rect({ 900, 700, 100, 40 });
|
2019-01-31 16:37:43 +01:00
|
|
|
|
|
|
|
auto* clock_widget = new ClockWidget;
|
|
|
|
clock_widget->set_relative_rect({ 0, 0, 100, 40 });
|
|
|
|
window->set_main_widget(clock_widget);
|
|
|
|
|
|
|
|
return window;
|
|
|
|
}
|