Userland: Allow the Analog Clock window border to be hidden
Introduce the ability to hide the Analog Clock window borde. With this feature enabled it looks like the clock is floating and integrated into the desktop. The "Cube Demo" has the same feature, and was used as inspiration when implementing the feature in the Analog Clock.
This commit is contained in:
parent
3be9af7695
commit
1674d06f78
Notes:
sideshowbarker
2024-07-18 18:22:55 +09:00
Author: https://github.com/bgianfo Commit: https://github.com/SerenityOS/serenity/commit/1674d06f78b Pull-request: https://github.com/SerenityOS/serenity/pull/6998 Reviewed-by: https://github.com/awesomekling
3 changed files with 39 additions and 3 deletions
|
@ -110,7 +110,7 @@ void AnalogClock::draw_seconds_hand(GUI::Painter& painter, double angle)
|
|||
void AnalogClock::paint_event(GUI::PaintEvent& event)
|
||||
{
|
||||
GUI::Painter painter(*this);
|
||||
painter.clear_rect(event.rect(), palette().window());
|
||||
painter.clear_rect(event.rect(), m_show_window_frame ? palette().window() : Gfx::Color::Transparent);
|
||||
|
||||
draw_face(painter);
|
||||
|
||||
|
@ -132,3 +132,20 @@ void AnalogClock::update_title_date()
|
|||
{
|
||||
window()->set_title(Core::DateTime::now().to_string("Clock %d-%m-%Y"));
|
||||
}
|
||||
|
||||
void AnalogClock::context_menu_event(GUI::ContextMenuEvent& event)
|
||||
{
|
||||
if (on_context_menu_request)
|
||||
on_context_menu_request(event);
|
||||
}
|
||||
|
||||
void AnalogClock::set_show_window_frame(bool show)
|
||||
{
|
||||
if (show == m_show_window_frame)
|
||||
return;
|
||||
m_show_window_frame = show;
|
||||
auto& w = *window();
|
||||
w.set_frameless(!m_show_window_frame);
|
||||
w.set_has_alpha_channel(!m_show_window_frame);
|
||||
w.set_alpha_hit_threshold(m_show_window_frame ? 0 : 1);
|
||||
}
|
||||
|
|
|
@ -13,6 +13,10 @@ class AnalogClock : public GUI::Widget {
|
|||
C_OBJECT(AnalogClock)
|
||||
public:
|
||||
~AnalogClock() override = default;
|
||||
void set_show_window_frame(bool);
|
||||
bool show_window_frame() const { return m_show_window_frame; }
|
||||
|
||||
Function<void(GUI::ContextMenuEvent&)> on_context_menu_request;
|
||||
|
||||
private:
|
||||
AnalogClock()
|
||||
|
@ -32,7 +36,10 @@ private:
|
|||
double m_hand_tail_length { 22 };
|
||||
double m_hand_wing_span { 5 };
|
||||
|
||||
bool m_show_window_frame { true };
|
||||
|
||||
protected:
|
||||
void context_menu_event(GUI::ContextMenuEvent& event) override;
|
||||
void paint_event(GUI::PaintEvent&) override;
|
||||
void draw_face(GUI::Painter&);
|
||||
void draw_mirrored_graduations(GUI::Painter&, Gfx::IntRect&, int x, int y, int rect_center_offset);
|
||||
|
|
|
@ -8,6 +8,8 @@
|
|||
#include <LibCore/DateTime.h>
|
||||
#include <LibGUI/Application.h>
|
||||
#include <LibGUI/Icon.h>
|
||||
#include <LibGUI/Menu.h>
|
||||
#include <LibGUI/Menubar.h>
|
||||
#include <LibGUI/Window.h>
|
||||
#include <unistd.h>
|
||||
|
||||
|
@ -32,12 +34,22 @@ int main(int argc, char** argv)
|
|||
|
||||
auto app_icon = GUI::Icon::default_icon("app-analog-clock");
|
||||
auto window = GUI::Window::construct();
|
||||
|
||||
window->set_main_widget<AnalogClock>();
|
||||
window->set_title(Core::DateTime::now().to_string("Clock %d-%m-%Y"));
|
||||
window->set_icon(app_icon.bitmap_for_size(16));
|
||||
window->resize(170, 170);
|
||||
window->set_resizable(false);
|
||||
auto& clock = window->set_main_widget<AnalogClock>();
|
||||
|
||||
auto show_window_frame_action = GUI::Action::create_checkable(
|
||||
"Show Window &Frame", { Mod_Alt, KeyCode::Key_F }, [&](auto& action) {
|
||||
clock.set_show_window_frame(action.is_checked());
|
||||
});
|
||||
show_window_frame_action->set_checked(clock.show_window_frame());
|
||||
auto menu = GUI::Menu::construct();
|
||||
menu->add_action(move(show_window_frame_action));
|
||||
clock.on_context_menu_request = [&](auto& event) {
|
||||
menu->popup(event.screen_position());
|
||||
};
|
||||
|
||||
window->show();
|
||||
return app->exec();
|
||||
|
|
Loading…
Add table
Reference in a new issue