diff options
author | Andreas Kling <kling@serenityos.org> | 2021-01-12 12:00:09 +0100 |
---|---|---|
committer | Andreas Kling <kling@serenityos.org> | 2021-01-12 12:04:17 +0100 |
commit | 7fc079bd86e066ec65ff7b9aed278a45a017baec (patch) | |
tree | c5fc6549d629c08dc6abf7b954336f4300ff964e /Demos | |
parent | ececac65c23ef06243814725c49553ca94f676a2 (diff) | |
download | serenity-7fc079bd86e066ec65ff7b9aed278a45a017baec.zip |
Demos: Move to Userland/Demos/
Diffstat (limited to 'Demos')
-rw-r--r-- | Demos/CMakeLists.txt | 9 | ||||
-rw-r--r-- | Demos/CatDog/CMakeLists.txt | 6 | ||||
-rw-r--r-- | Demos/CatDog/main.cpp | 245 | ||||
-rw-r--r-- | Demos/Cube/CMakeLists.txt | 6 | ||||
-rw-r--r-- | Demos/Cube/Cube.cpp | 230 | ||||
-rw-r--r-- | Demos/Eyes/CMakeLists.txt | 7 | ||||
-rw-r--r-- | Demos/Eyes/EyesWidget.cpp | 137 | ||||
-rw-r--r-- | Demos/Eyes/EyesWidget.h | 59 | ||||
-rw-r--r-- | Demos/Eyes/main.cpp | 113 | ||||
-rw-r--r-- | Demos/Fire/CMakeLists.txt | 6 | ||||
-rw-r--r-- | Demos/Fire/Fire.cpp | 253 | ||||
-rw-r--r-- | Demos/HelloWorld/CMakeLists.txt | 6 | ||||
-rw-r--r-- | Demos/HelloWorld/main.cpp | 77 | ||||
-rw-r--r-- | Demos/LibGfxDemo/CMakeLists.txt | 6 | ||||
-rw-r--r-- | Demos/LibGfxDemo/main.cpp | 230 | ||||
-rw-r--r-- | Demos/Mouse/CMakeLists.txt | 6 | ||||
-rw-r--r-- | Demos/Mouse/main.cpp | 211 | ||||
-rw-r--r-- | Demos/Screensaver/CMakeLists.txt | 6 | ||||
-rw-r--r-- | Demos/Screensaver/Screensaver.cpp | 170 | ||||
-rw-r--r-- | Demos/WidgetGallery/CMakeLists.txt | 6 | ||||
-rw-r--r-- | Demos/WidgetGallery/main.cpp | 557 |
21 files changed, 0 insertions, 2346 deletions
diff --git a/Demos/CMakeLists.txt b/Demos/CMakeLists.txt deleted file mode 100644 index dbb31e2e1a..0000000000 --- a/Demos/CMakeLists.txt +++ /dev/null @@ -1,9 +0,0 @@ -add_subdirectory(CatDog) -add_subdirectory(Cube) -add_subdirectory(Eyes) -add_subdirectory(Fire) -add_subdirectory(HelloWorld) -add_subdirectory(LibGfxDemo) -add_subdirectory(Mouse) -add_subdirectory(Screensaver) -add_subdirectory(WidgetGallery) diff --git a/Demos/CatDog/CMakeLists.txt b/Demos/CatDog/CMakeLists.txt deleted file mode 100644 index d03747eb57..0000000000 --- a/Demos/CatDog/CMakeLists.txt +++ /dev/null @@ -1,6 +0,0 @@ -set(SOURCES - main.cpp -) - -serenity_app(CatDog ICON app-catdog) -target_link_libraries(CatDog LibGUI LibGfx) diff --git a/Demos/CatDog/main.cpp b/Demos/CatDog/main.cpp deleted file mode 100644 index bf7e691615..0000000000 --- a/Demos/CatDog/main.cpp +++ /dev/null @@ -1,245 +0,0 @@ -/* - * Copyright (c) 2021, Richard Gráčik <r.gracik@gmail.com> - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are met: - * - * 1. Redistributions of source code must retain the above copyright notice, - * this list of conditions and the following disclaimer. - * - * 2. Redistributions in binary form must reproduce the above copyright notice, - * this list of conditions and the following disclaimer in the documentation - * and/or other materials provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" - * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE - * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR - * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF - * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS - * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN - * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) - * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE - * POSSIBILITY OF SUCH DAMAGE. - */ - -#include <LibCore/ElapsedTimer.h> -#include <LibGUI/BoxLayout.h> -#include <LibGUI/Icon.h> -#include <LibGUI/Menu.h> -#include <LibGUI/MenuBar.h> -#include <LibGUI/Painter.h> -#include <LibGUI/Widget.h> -#include <LibGUI/Window.h> -#include <LibGUI/WindowServerConnection.h> -#include <LibGfx/Bitmap.h> - -class MainFrame final : public GUI::Widget { - C_OBJECT(MainFrame); - -public: - virtual void timer_event(Core::TimerEvent&) override - { - if (m_temp_pos.x() > 48) { - m_left = false; - m_right = true; - m_moveX = 16; - - m_curr_bmp = m_erun1; - if (m_curr_frame == 2) - m_curr_bmp = m_erun2; - } else if (m_temp_pos.x() < -16) { - m_left = true; - m_right = false; - m_moveX = -16; - - m_curr_bmp = m_wrun1; - if (m_curr_frame == 2) - m_curr_bmp = m_wrun2; - } else { - m_left = false; - m_right = false; - m_moveX = 0; - } - - if (m_temp_pos.y() > 48) { - m_up = false; - m_down = true; - m_moveY = 10; - - m_curr_bmp = m_srun1; - if (m_curr_frame == 2) - m_curr_bmp = m_srun2; - } else if (m_temp_pos.y() < -16) { - m_up = true; - m_down = false; - m_moveY = -10; - - m_curr_bmp = m_nrun1; - if (m_curr_frame == 2) - m_curr_bmp = m_nrun2; - } else { - m_up = false; - m_down = false; - m_moveY = 0; - } - - if (m_up && m_left) { - m_curr_bmp = m_nwrun1; - if (m_curr_frame == 2) - m_curr_bmp = m_nwrun2; - } else if (m_up && m_right) { - m_curr_bmp = m_nerun1; - if (m_curr_frame == 2) - m_curr_bmp = m_nerun2; - } else if (m_down && m_left) { - m_curr_bmp = m_swrun1; - if (m_curr_frame == 2) - m_curr_bmp = m_swrun2; - } else if (m_down && m_right) { - m_curr_bmp = m_serun1; - if (m_curr_frame == 2) - m_curr_bmp = m_serun2; - } - - window()->move_to(window()->position().x() + m_moveX, window()->position().y() + m_moveY); - m_temp_pos.set_x(m_temp_pos.x() + (-m_moveX)); - m_temp_pos.set_y(m_temp_pos.y() + (-m_moveY)); - - if (m_curr_frame == 1) { - m_curr_frame = 2; - } else { - m_curr_frame = 1; - } - - if (!m_up && !m_down && !m_left && !m_right) { - m_curr_bmp = m_still; - if (m_timer.elapsed() > 5000) { - m_curr_bmp = m_sleep1; - if (m_curr_frame == 2) - m_curr_bmp = m_sleep2; - m_sleeping = true; - } - } - - update(); - } - - void paint_event(GUI::PaintEvent& event) override - { - GUI::Painter painter(*this); - painter.clear_rect(event.rect(), Gfx::Color()); - painter.blit(Gfx::IntPoint(0, 0), *m_curr_bmp, m_curr_bmp->rect()); - } - - void mousemove_event(GUI::MouseEvent& event) override - { - m_temp_pos = event.position(); - m_timer.start(); - if (m_sleeping) { - m_curr_bmp = m_alert; - update(); - } - m_sleeping = false; - } - - void track_cursor_globally() - { - ASSERT(window()); - auto window_id = window()->window_id(); - ASSERT(window_id >= 0); - - set_global_cursor_tracking(true); - GUI::WindowServerConnection::the().send_sync<Messages::WindowServer::SetGlobalCursorTracking>(window_id, true); - } - - void start_the_timer() { m_timer.start(); } - -private: - Gfx::IntPoint m_temp_pos; - Core::ElapsedTimer m_timer; - int m_curr_frame = 1; - int m_moveX, m_moveY = 0; - bool m_up, m_down, m_left, m_right, m_sleeping = false; - - NonnullRefPtr<Gfx::Bitmap> m_alert = *Gfx::Bitmap::load_from_file("/res/icons/catdog/alert.png"); - NonnullRefPtr<Gfx::Bitmap> m_erun1 = *Gfx::Bitmap::load_from_file("/res/icons/catdog/erun1.png"); - NonnullRefPtr<Gfx::Bitmap> m_erun2 = *Gfx::Bitmap::load_from_file("/res/icons/catdog/erun2.png"); - NonnullRefPtr<Gfx::Bitmap> m_nerun1 = *Gfx::Bitmap::load_from_file("/res/icons/catdog/nerun1.png"); - NonnullRefPtr<Gfx::Bitmap> m_nerun2 = *Gfx::Bitmap::load_from_file("/res/icons/catdog/nerun2.png"); - NonnullRefPtr<Gfx::Bitmap> m_nrun1 = *Gfx::Bitmap::load_from_file("/res/icons/catdog/nrun1.png"); - NonnullRefPtr<Gfx::Bitmap> m_nrun2 = *Gfx::Bitmap::load_from_file("/res/icons/catdog/nrun2.png"); - NonnullRefPtr<Gfx::Bitmap> m_nwrun1 = *Gfx::Bitmap::load_from_file("/res/icons/catdog/nwrun1.png"); - NonnullRefPtr<Gfx::Bitmap> m_nwrun2 = *Gfx::Bitmap::load_from_file("/res/icons/catdog/nwrun2.png"); - NonnullRefPtr<Gfx::Bitmap> m_serun1 = *Gfx::Bitmap::load_from_file("/res/icons/catdog/serun1.png"); - NonnullRefPtr<Gfx::Bitmap> m_serun2 = *Gfx::Bitmap::load_from_file("/res/icons/catdog/serun2.png"); - NonnullRefPtr<Gfx::Bitmap> m_sleep1 = *Gfx::Bitmap::load_from_file("/res/icons/catdog/sleep1.png"); - NonnullRefPtr<Gfx::Bitmap> m_sleep2 = *Gfx::Bitmap::load_from_file("/res/icons/catdog/sleep2.png"); - NonnullRefPtr<Gfx::Bitmap> m_srun1 = *Gfx::Bitmap::load_from_file("/res/icons/catdog/srun1.png"); - NonnullRefPtr<Gfx::Bitmap> m_srun2 = *Gfx::Bitmap::load_from_file("/res/icons/catdog/srun2.png"); - NonnullRefPtr<Gfx::Bitmap> m_still = *Gfx::Bitmap::load_from_file("/res/icons/catdog/still.png"); - NonnullRefPtr<Gfx::Bitmap> m_swrun1 = *Gfx::Bitmap::load_from_file("/res/icons/catdog/swrun1.png"); - NonnullRefPtr<Gfx::Bitmap> m_swrun2 = *Gfx::Bitmap::load_from_file("/res/icons/catdog/swrun2.png"); - NonnullRefPtr<Gfx::Bitmap> m_wrun1 = *Gfx::Bitmap::load_from_file("/res/icons/catdog/wrun1.png"); - NonnullRefPtr<Gfx::Bitmap> m_wrun2 = *Gfx::Bitmap::load_from_file("/res/icons/catdog/wrun2.png"); - - NonnullRefPtr<Gfx::Bitmap> m_curr_bmp = m_alert; - MainFrame() - : m_temp_pos { 0, 0 } - { - } -}; - -int main(int argc, char** argv) -{ - if (pledge("stdio rpath wpath cpath shared_buffer accept unix fattr", nullptr) < 0) { - perror("pledge"); - return 1; - } - - auto app = GUI::Application::construct(argc, argv); - auto app_icon = GUI::Icon::default_icon("app-catdog"); - - if (pledge("stdio rpath shared_buffer", nullptr) < 0) { - perror("pledge"); - return 1; - } - - if (unveil("/res", "r") < 0) { - perror("unveil"); - return 1; - } - - if (unveil(nullptr, nullptr) < 0) { - perror("unveil"); - return 1; - } - - auto window = GUI::Window::construct(); - window->set_title("CatDog Demo"); - window->resize(32, 32); - window->set_frameless(true); - window->set_resizable(false); - window->set_has_alpha_channel(true); - window->set_icon(app_icon.bitmap_for_size(16)); - - auto& root_widget = window->set_main_widget<MainFrame>(); - root_widget.set_layout<GUI::VerticalBoxLayout>(); - root_widget.layout()->set_spacing(0); - - auto menubar = GUI::MenuBar::construct(); - auto& app_menu = menubar->add_menu("CatDog Demo"); - app_menu.add_action(GUI::CommonActions::make_quit_action([&](auto&) { app->quit(); })); - auto& help_menu = menubar->add_menu("Help"); - help_menu.add_action(GUI::CommonActions::make_about_action("CatDog Demo", app_icon, window)); - app->set_menubar(move(menubar)); - - window->show(); - root_widget.track_cursor_globally(); - root_widget.start_timer(250, Core::TimerShouldFireWhenNotVisible::Yes); - root_widget.start_the_timer(); // timer for "mouse sleep detection" - - return app->exec(); -} diff --git a/Demos/Cube/CMakeLists.txt b/Demos/Cube/CMakeLists.txt deleted file mode 100644 index ee06d91d3f..0000000000 --- a/Demos/Cube/CMakeLists.txt +++ /dev/null @@ -1,6 +0,0 @@ -set(SOURCES - Cube.cpp -) - -serenity_app(Cube ICON app-cube) -target_link_libraries(Cube LibGUI) diff --git a/Demos/Cube/Cube.cpp b/Demos/Cube/Cube.cpp deleted file mode 100644 index f7273c7d79..0000000000 --- a/Demos/Cube/Cube.cpp +++ /dev/null @@ -1,230 +0,0 @@ -/* - * Copyright (c) 2020, Stephan Unverwerth <s.unverwerth@gmx.de> - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are met: - * - * 1. Redistributions of source code must retain the above copyright notice, this - * list of conditions and the following disclaimer. - * - * 2. Redistributions in binary form must reproduce the above copyright notice, - * this list of conditions and the following disclaimer in the documentation - * and/or other materials provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" - * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE - * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR - * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER - * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, - * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE - * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ - -#include <LibCore/ElapsedTimer.h> -#include <LibGUI/Application.h> -#include <LibGUI/Icon.h> -#include <LibGUI/Label.h> -#include <LibGUI/Painter.h> -#include <LibGUI/Widget.h> -#include <LibGUI/Window.h> -#include <LibGfx/Bitmap.h> -#include <LibGfx/Matrix4x4.h> -#include <LibGfx/Vector3.h> -#include <math.h> -#include <stdio.h> -#include <stdlib.h> -#include <time.h> - -const int WIDTH = 200; -const int HEIGHT = 200; - -class Cube final : public GUI::Widget { - C_OBJECT(Cube) -public: - virtual ~Cube() override; - void set_stat_label(RefPtr<GUI::Label> l) { m_stats = l; }; - -private: - Cube(); - RefPtr<Gfx::Bitmap> m_bitmap; - RefPtr<GUI::Label> m_stats; - - virtual void paint_event(GUI::PaintEvent&) override; - virtual void timer_event(Core::TimerEvent&) override; - - int m_accumulated_time; - int m_cycles; - int m_phase; -}; - -Cube::Cube() -{ - m_bitmap = Gfx::Bitmap::create(Gfx::BitmapFormat::RGB32, { WIDTH, HEIGHT }); - - m_accumulated_time = 0; - m_cycles = 0; - m_phase = 0; - - stop_timer(); - start_timer(20); -} - -Cube::~Cube() -{ -} - -void Cube::paint_event(GUI::PaintEvent& event) -{ - GUI::Painter painter(*this); - painter.add_clip_rect(event.rect()); - - /* Blit it! */ - painter.draw_scaled_bitmap(event.rect(), *m_bitmap, m_bitmap->rect()); -} - -void Cube::timer_event(Core::TimerEvent&) -{ - Core::ElapsedTimer timer; - timer.start(); - - const FloatVector3 vertices[8] { - { -1, -1, -1 }, - { -1, 1, -1 }, - { 1, 1, -1 }, - { 1, -1, -1 }, - { -1, -1, 1 }, - { -1, 1, 1 }, - { 1, 1, 1 }, - { 1, -1, 1 }, - }; - -#define QUAD(a, b, c, d) a, b, c, c, d, a - - const int indices[] { - QUAD(0, 1, 2, 3), - QUAD(7, 6, 5, 4), - QUAD(4, 5, 1, 0), - QUAD(3, 2, 6, 7), - QUAD(1, 5, 6, 2), - QUAD(0, 3, 7, 4), - }; - - const Color colors[] { - Color::Red, - Color::Red, - Color::Green, - Color::Green, - Color::Blue, - Color::Blue, - Color::Magenta, - Color::Magenta, - Color::White, - Color::White, - Color::Yellow, - Color::Yellow, - }; - - FloatVector3 transformed_vertices[8]; - - static float angle = 0; - angle += 0.02f; - - auto matrix = FloatMatrix4x4::translate(FloatVector3(0, 0, 1.5f)) - * FloatMatrix4x4::rotate(FloatVector3(1, 0, 0), angle * 1.17356641f) - * FloatMatrix4x4::rotate(FloatVector3(0, 1, 0), angle * 0.90533273f) - * FloatMatrix4x4::rotate(FloatVector3(0, 0, 1), angle); - - for (int i = 0; i < 8; i++) { - transformed_vertices[i] = matrix.transform_point(vertices[i]); - } - - GUI::Painter painter(*m_bitmap); - painter.fill_rect_with_gradient(Gfx::Orientation::Vertical, m_bitmap->rect(), Gfx::Color::White, Gfx::Color::Blue); - - auto to_point = [](const FloatVector3& v) { - return Gfx::IntPoint(v.x(), v.y()); - }; - - for (size_t i = 0; i < sizeof(indices) / sizeof(indices[0]) / 3; i++) { - auto a = transformed_vertices[indices[i * 3]]; - auto b = transformed_vertices[indices[i * 3 + 1]]; - auto c = transformed_vertices[indices[i * 3 + 2]]; - auto normal = (b - a).cross(c - a); - normal.normalize(); - - // Perspective projection - a.set_x(WIDTH / 2 + a.x() / (1 + a.z() * 0.35) * WIDTH / 3); - a.set_y(HEIGHT / 2 - a.y() / (1 + a.z() * 0.35) * WIDTH / 3); - b.set_x(WIDTH / 2 + b.x() / (1 + b.z() * 0.35) * WIDTH / 3); - b.set_y(HEIGHT / 2 - b.y() / (1 + b.z() * 0.35) * WIDTH / 3); - c.set_x(WIDTH / 2 + c.x() / (1 + c.z() * 0.35) * WIDTH / 3); - c.set_y(HEIGHT / 2 - c.y() / (1 + c.z() * 0.35) * WIDTH / 3); - - float winding = (b.x() - a.x()) * (c.y() - a.y()) - (b.y() - a.y()) * (c.x() - a.x()); - if (winding < 0) - continue; - - float shade = 0.5f + normal.y() * 0.5f; - auto color = colors[i]; - color.set_red(color.red() * shade); - color.set_green(color.green() * shade); - color.set_blue(color.blue() * shade); - - painter.draw_triangle(to_point(a), to_point(b), to_point(c), color); - } - - if ((m_cycles % 50) == 0) { - dbgln("{} total cycles. finished 50 in {} ms, avg {} ms", m_cycles, m_accumulated_time, m_accumulated_time / 50); - m_stats->set_text(String::formatted("{} ms", m_accumulated_time / 50)); - m_accumulated_time = 0; - } - - update(); - - m_accumulated_time += timer.elapsed(); - m_cycles++; -} - -int main(int argc, char** argv) -{ - auto app = GUI::Application::construct(argc, argv); - - if (pledge("stdio rpath shared_buffer", nullptr) < 0) { - perror("pledge"); - return 1; - } - - if (unveil("/res", "r") < 0) { - perror("unveil"); - return 1; - } - - if (unveil(nullptr, nullptr) < 0) { - perror("unveil"); - return 1; - } - - auto window = GUI::Window::construct(); - window->set_double_buffering_enabled(true); - window->set_title("Cube"); - window->set_resizable(false); - window->resize(WIDTH, HEIGHT); - - auto& cube = window->set_main_widget<Cube>(); - - auto& time = cube.add<GUI::Label>(); - time.set_relative_rect({ 0, 4, 40, 10 }); - time.move_by({ window->width() - time.width(), 0 }); - cube.set_stat_label(time); - - window->show(); - - auto app_icon = GUI::Icon::default_icon("app-cube"); - window->set_icon(app_icon.bitmap_for_size(16)); - - return app->exec(); -} diff --git a/Demos/Eyes/CMakeLists.txt b/Demos/Eyes/CMakeLists.txt deleted file mode 100644 index aa0e948d6a..0000000000 --- a/Demos/Eyes/CMakeLists.txt +++ /dev/null @@ -1,7 +0,0 @@ -set(SOURCES - main.cpp - EyesWidget.cpp -) - -serenity_app(Eyes ICON app-eyes) -target_link_libraries(Eyes LibGUI LibGfx) diff --git a/Demos/Eyes/EyesWidget.cpp b/Demos/Eyes/EyesWidget.cpp deleted file mode 100644 index c31d4782e1..0000000000 --- a/Demos/Eyes/EyesWidget.cpp +++ /dev/null @@ -1,137 +0,0 @@ -/* - * Copyright (c) 2020, Sergey Bugaev <bugaevc@serenityos.org> - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are met: - * - * 1. Redistributions of source code must retain the above copyright notice, this - * list of conditions and the following disclaimer. - * - * 2. Redistributions in binary form must reproduce the above copyright notice, - * this list of conditions and the following disclaimer in the documentation - * and/or other materials provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" - * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE - * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR - * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER - * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, - * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE - * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ - -#include "EyesWidget.h" -#include <LibGUI/Painter.h> -#include <LibGUI/Window.h> -#include <LibGUI/WindowServerConnection.h> -#include <LibGfx/Palette.h> -#include <math.h> - -EyesWidget::~EyesWidget() -{ -} - -void EyesWidget::track_cursor_globally() -{ - ASSERT(window()); - auto window_id = window()->window_id(); - ASSERT(window_id >= 0); - - set_global_cursor_tracking(true); - GUI::WindowServerConnection::the().send_sync<Messages::WindowServer::SetGlobalCursorTracking>(window_id, true); -} - -void EyesWidget::mousemove_event(GUI::MouseEvent& event) -{ - m_mouse_position = event.position(); - update(); -} - -void EyesWidget::paint_event(GUI::PaintEvent& event) -{ - GUI::Painter painter(*this); - - painter.clear_rect(event.rect(), Gfx::Color()); - - for (int i = 0; i < m_full_rows; i++) { - for (int j = 0; j < m_eyes_in_row; j++) - render_eyeball(i, j, painter); - } - for (int i = 0; i < m_extra_columns; ++i) - render_eyeball(m_full_rows, i, painter); -} - -void EyesWidget::render_eyeball(int row, int column, GUI::Painter& painter) const -{ - auto eye_width = width() / m_eyes_in_row; - auto eye_height = height() / m_num_rows; - Gfx::IntRect bounds { column * eye_width, row * eye_height, eye_width, eye_height }; - auto width_thickness = max(int(eye_width / 5.5), 1); - auto height_thickness = max(int(eye_height / 5.5), 1); - - bounds.shrink(int(eye_width / 12.5), 0); - painter.fill_ellipse(bounds, palette().base_text()); - bounds.shrink(width_thickness, height_thickness); - painter.fill_ellipse(bounds, palette().base()); - - Gfx::IntPoint pupil_center = this->pupil_center(bounds); - Gfx::IntSize pupil_size { - bounds.width() / 5, - bounds.height() / 5 - }; - Gfx::IntRect pupil { - pupil_center.x() - pupil_size.width() / 2, - pupil_center.y() - pupil_size.height() / 2, - pupil_size.width(), - pupil_size.height() - }; - - painter.fill_ellipse(pupil, palette().base_text()); -} - -Gfx::IntPoint EyesWidget::pupil_center(Gfx::IntRect& eyeball_bounds) const -{ - auto mouse_vector = m_mouse_position - eyeball_bounds.center(); - double dx = mouse_vector.x(); - double dy = mouse_vector.y(); - double mouse_distance = sqrt(dx * dx + dy * dy); - - if (mouse_distance == 0.0) - return eyeball_bounds.center(); - - double width_squared = eyeball_bounds.width() * eyeball_bounds.width(); - double height_squared = eyeball_bounds.height() * eyeball_bounds.height(); - - double max_distance_along_this_direction; - - // clang-format off - if (dx != 0 && abs(dx) >= abs(dy)) { - double slope = dy / dx; - double slope_squared = slope * slope; - max_distance_along_this_direction = 0.25 * sqrt( - (slope_squared + 1) / - (1 / width_squared + slope_squared / height_squared) - ); - } else if (dy != 0 && abs(dy) >= abs(dx)) { - double slope = dx / dy; - double slope_squared = slope * slope; - max_distance_along_this_direction = 0.25 * sqrt( - (slope_squared + 1) / - (slope_squared / width_squared + 1 / height_squared) - ); - } else { - ASSERT_NOT_REACHED(); - } - // clang-format on - - double scale = min(1.0, max_distance_along_this_direction / mouse_distance); - - return { - eyeball_bounds.center().x() + int(dx * scale), - eyeball_bounds.center().y() + int(dy * scale) - }; -} diff --git a/Demos/Eyes/EyesWidget.h b/Demos/Eyes/EyesWidget.h deleted file mode 100644 index fb01e27a45..0000000000 --- a/Demos/Eyes/EyesWidget.h +++ /dev/null @@ -1,59 +0,0 @@ -/* - * Copyright (c) 2020, Sergey Bugaev <bugaevc@serenityos.org> - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are met: - * - * 1. Redistributions of source code must retain the above copyright notice, this - * list of conditions and the following disclaimer. - * - * 2. Redistributions in binary form must reproduce the above copyright notice, - * this list of conditions and the following disclaimer in the documentation - * and/or other materials provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" - * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE - * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR - * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER - * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, - * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE - * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ - -#pragma once - -#include <LibGUI/Widget.h> -#include <LibGfx/Point.h> - -class EyesWidget final : public GUI::Widget { - C_OBJECT(EyesWidget) - -public: - virtual ~EyesWidget(); - void track_cursor_globally(); - -private: - EyesWidget(int num_eyes, int full_rows, int extra) - : m_full_rows(full_rows) - , m_extra_columns(extra) - { - m_num_rows = m_extra_columns > 0 ? m_full_rows + 1 : m_full_rows; - m_eyes_in_row = m_full_rows > 0 ? (num_eyes - m_extra_columns) / m_full_rows : m_extra_columns; - } - - virtual void mousemove_event(GUI::MouseEvent&) override; - virtual void paint_event(GUI::PaintEvent&) override; - - void render_eyeball(int row, int column, GUI::Painter&) const; - Gfx::IntPoint pupil_center(Gfx::IntRect& eyeball_bounds) const; - - Gfx::IntPoint m_mouse_position; - int m_eyes_in_row { -1 }; - int m_full_rows { -1 }; - int m_extra_columns { -1 }; - int m_num_rows { -1 }; -}; diff --git a/Demos/Eyes/main.cpp b/Demos/Eyes/main.cpp deleted file mode 100644 index 0b2fe4ad86..0000000000 --- a/Demos/Eyes/main.cpp +++ /dev/null @@ -1,113 +0,0 @@ -/* - * Copyright (c) 2020, Sergey Bugaev <bugaevc@serenityos.org> - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are met: - * - * 1. Redistributions of source code must retain the above copyright notice, this - * list of conditions and the following disclaimer. - * - * 2. Redistributions in binary form must reproduce the above copyright notice, - * this list of conditions and the following disclaimer in the documentation - * and/or other materials provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" - * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE - * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR - * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER - * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, - * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE - * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ - -#include "EyesWidget.h" -#include <LibCore/ArgsParser.h> -#include <LibGUI/Application.h> -#include <LibGUI/Icon.h> -#include <LibGUI/Menu.h> -#include <LibGUI/MenuBar.h> -#include <LibGUI/Window.h> -#include <LibGfx/Bitmap.h> - -int main(int argc, char* argv[]) -{ - int num_eyes = 2; - int max_in_row = 13; - - // Alternatively, allow the user to ask for a grid. - int grid_rows = -1; - int grid_columns = -1; - - Core::ArgsParser args_parser; - args_parser.add_option(num_eyes, "Number of eyes", "num-eyes", 'n', "number"); - args_parser.add_option(max_in_row, "Maximum number of eyes in a row", "max-in-row", 'm', "number"); - args_parser.add_option(grid_rows, "Number of rows in grid (incompatible with --number)", "grid-rows", 'r', "number"); - args_parser.add_option(grid_columns, "Number of columns in grid (incompatible with --number)", "grid-cols", 'c', "number"); - args_parser.parse(argc, argv); - - if (pledge("stdio shared_buffer accept rpath unix cpath wpath fattr thread", nullptr) < 0) { - perror("pledge"); - return 1; - } - - auto app = GUI::Application::construct(argc, argv); - - if (pledge("stdio shared_buffer accept rpath cpath wpath thread", nullptr) < 0) { - perror("pledge"); - return 1; - } - - if (unveil("/res", "r") < 0) { - perror("unveil"); - return 1; - } - - if (unveil(nullptr, nullptr) < 0) { - perror("unveil"); - return 1; - } - - if ((grid_rows > 0) ^ (grid_columns > 0)) { - warnln("Expected either both or none of 'grid-rows' and 'grid-cols' to be passed."); - return 1; - } - - int full_rows, extra_columns; - - if (grid_rows > 0) { - full_rows = grid_rows; - extra_columns = 0; - num_eyes = grid_rows * grid_columns; - max_in_row = grid_columns; - } else { - full_rows = num_eyes / max_in_row; - extra_columns = num_eyes % max_in_row; - } - - auto app_icon = GUI::Icon::default_icon("app-eyes"); - - auto window = GUI::Window::construct(); - window->set_title("Eyes"); - window->set_icon(app_icon.bitmap_for_size(16)); - window->resize(75 * (full_rows > 0 ? max_in_row : extra_columns), 100 * (full_rows + (extra_columns > 0 ? 1 : 0))); - window->set_has_alpha_channel(true); - - auto& eyes = window->set_main_widget<EyesWidget>(num_eyes, full_rows, extra_columns); - - auto menubar = GUI::MenuBar::construct(); - auto& app_menu = menubar->add_menu("Eyes Demo"); - app_menu.add_action(GUI::CommonActions::make_quit_action([&](auto&) { app->quit(); })); - - auto& help_menu = menubar->add_menu("Help"); - help_menu.add_action(GUI::CommonActions::make_about_action("Eyes Demo", app_icon, window)); - - app->set_menubar(move(menubar)); - window->show(); - eyes.track_cursor_globally(); - - return app->exec(); -} diff --git a/Demos/Fire/CMakeLists.txt b/Demos/Fire/CMakeLists.txt deleted file mode 100644 index 10342de600..0000000000 --- a/Demos/Fire/CMakeLists.txt +++ /dev/null @@ -1,6 +0,0 @@ -set(SOURCES - Fire.cpp -) - -serenity_app(Fire ICON app-fire) -target_link_libraries(Fire LibGUI LibCore LibGfx) diff --git a/Demos/Fire/Fire.cpp b/Demos/Fire/Fire.cpp deleted file mode 100644 index 2e91c78333..0000000000 --- a/Demos/Fire/Fire.cpp +++ /dev/null @@ -1,253 +0,0 @@ -/* - * Copyright (c) 2018-2020, Andreas Kling <kling@serenityos.org> - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are met: - * - * 1. Redistributions of source code must retain the above copyright notice, this - * list of conditions and the following disclaimer. - * - * 2. Redistributions in binary form must reproduce the above copyright notice, - * this list of conditions and the following disclaimer in the documentation - * and/or other materials provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" - * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE - * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR - * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER - * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, - * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE - * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ - -/* Fire.cpp - a (classic) graphics demo for Serenity, by pd. - * heavily based on the Fabien Sanglard's article: - * http://fabiensanglard.net/doom_fire_psx/index.html - * - * Future directions: - * [X] This does suggest the need for a palletized graphics surface. Thanks kling! - * [X] alternate column updates, or vertical interlacing. this would certainly alter - * the effect, but the update load would be halved. - * [/] scaled blit - * [ ] dithering? - * [X] inlining rand() - * [/] precalculating and recycling random data - * [ ] rework/expand palette - * [ ] switch to use tsc values for perf check - * [ ] handle mouse events differently for smoother painting (queue) - * [ ] handle fire bitmap edges better -*/ - -#include <LibCore/ElapsedTimer.h> -#include <LibGUI/Application.h> -#include <LibGUI/Icon.h> -#include <LibGUI/Label.h> -#include <LibGUI/Painter.h> -#include <LibGUI/Widget.h> -#include <LibGUI/Window.h> -#include <LibGfx/Bitmap.h> -#include <stdio.h> -#include <stdlib.h> -#include <time.h> - -#define FIRE_WIDTH 320 -#define FIRE_HEIGHT 168 -#define FIRE_MAX 29 - -static const Color s_palette[] = { - Color(0x07, 0x07, 0x07), Color(0x1F, 0x07, 0x07), Color(0x2F, 0x0F, 0x07), - Color(0x47, 0x0F, 0x07), Color(0x57, 0x17, 0x07), Color(0x67, 0x1F, 0x07), - Color(0x77, 0x1F, 0x07), Color(0x9F, 0x2F, 0x07), Color(0xAF, 0x3F, 0x07), - Color(0xBF, 0x47, 0x07), Color(0xC7, 0x47, 0x07), Color(0xDF, 0x4F, 0x07), - Color(0xDF, 0x57, 0x07), Color(0xD7, 0x5F, 0x07), Color(0xD7, 0x5F, 0x07), - Color(0xD7, 0x67, 0x0F), Color(0xCF, 0x6F, 0x0F), Color(0xCF, 0x7F, 0x0F), - Color(0xCF, 0x87, 0x17), Color(0xC7, 0x87, 0x17), Color(0xC7, 0x8F, 0x17), - Color(0xC7, 0x97, 0x1F), Color(0xBF, 0x9F, 0x1F), Color(0xBF, 0xA7, 0x27), - Color(0xBF, 0xAF, 0x2F), Color(0xB7, 0xAF, 0x2F), Color(0xB7, 0xB7, 0x37), - Color(0xCF, 0xCF, 0x6F), Color(0xEF, 0xEF, 0xC7), Color(0xFF, 0xFF, 0xFF) -}; - -class Fire : public GUI::Widget { - C_OBJECT(Fire) -public: - virtual ~Fire() override; - void set_stat_label(RefPtr<GUI::Label> l) { stats = l; }; - -private: - Fire(); - RefPtr<Gfx::Bitmap> bitmap; - RefPtr<GUI::Label> stats; - - virtual void paint_event(GUI::PaintEvent&) override; - virtual void timer_event(Core::TimerEvent&) override; - virtual void mousedown_event(GUI::MouseEvent& event) override; - virtual void mousemove_event(GUI::MouseEvent& event) override; - virtual void mouseup_event(GUI::MouseEvent& event) override; - - bool dragging; - int timeAvg; - int cycles; - int phase; -}; - -Fire::Fire() -{ - bitmap = Gfx::Bitmap::create(Gfx::BitmapFormat::Indexed8, { 320, 200 }); - - /* Initialize fire palette */ - for (int i = 0; i < 30; i++) - bitmap->set_palette_color(i, s_palette[i]); - - /* Set remaining entries to white */ - for (int i = 30; i < 256; i++) - bitmap->set_palette_color(i, Color::White); - - dragging = false; - timeAvg = 0; - cycles = 0; - phase = 0; - - srand(time(nullptr)); - stop_timer(); - start_timer(20); - - /* Draw fire "source" on bottom row of pixels */ - for (int i = 0; i < FIRE_WIDTH; i++) - bitmap->scanline_u8(bitmap->height() - 1)[i] = FIRE_MAX; - - /* Set off initital paint event */ - //update(); -} - -Fire::~Fire() -{ -} - -void Fire::paint_event(GUI::PaintEvent& event) -{ - Core::ElapsedTimer timer; - timer.start(); - - GUI::Painter painter(*this); - painter.add_clip_rect(event.rect()); - - /* Blit it! */ - painter.draw_scaled_bitmap(event.rect(), *bitmap, bitmap->rect()); - - timeAvg += timer.elapsed(); - cycles++; -} - -void Fire::timer_event(Core::TimerEvent&) -{ - /* Update only even or odd columns per frame... */ - phase++; - if (phase > 1) - phase = 0; - - /* Paint our palettized buffer to screen */ - for (int px = 0 + phase; px < FIRE_WIDTH; px += 2) { - for (int py = 1; py < 200; py++) { - int rnd = rand() % 3; - - /* Calculate new pixel value, don't go below 0 */ - u8 nv = bitmap->scanline_u8(py)[px]; - if (nv > 0) - nv -= (rnd & 1); - - /* ...sigh... */ - int epx = px + (1 - rnd); - if (epx < 0) - epx = 0; - else if (epx > FIRE_WIDTH) - epx = FIRE_WIDTH; - - bitmap->scanline_u8(py - 1)[epx] = nv; - } - } - - if ((cycles % 50) == 0) { - dbgln("{} total cycles. finished 50 in {} ms, avg {} ms", cycles, timeAvg, timeAvg / 50); - stats->set_text(String::format("%d ms", timeAvg / 50)); - timeAvg = 0; - } - - update(); -} - -void Fire::mousedown_event(GUI::MouseEvent& event) -{ - if (event.button() == GUI::MouseButton::Left) - dragging = true; - - return GUI::Widget::mousedown_event(event); -} - -/* FIXME: needs to account for the size of the window rect */ -void Fire::mousemove_event(GUI::MouseEvent& event) -{ - if (dragging) { - if (event.y() >= 2 && event.y() < 398 && event.x() <= 638) { - int ypos = event.y() / 2; - int xpos = event.x() / 2; - bitmap->scanline_u8(ypos - 1)[xpos] = FIRE_MAX + 5; - bitmap->scanline_u8(ypos - 1)[xpos + 1] = FIRE_MAX + 5; - bitmap->scanline_u8(ypos)[xpos] = FIRE_MAX + 5; - bitmap->scanline_u8(ypos)[xpos + 1] = FIRE_MAX + 5; - } - } - - return GUI::Widget::mousemove_event(event); -} - -void Fire::mouseup_event(GUI::MouseEvent& event) -{ - if (event.button() == GUI::MouseButton::Left) - dragging = false; - - return GUI::Widget::mouseup_event(event); -} - -int main(int argc, char** argv) -{ - auto app = GUI::Application::construct(argc, argv); - - if (pledge("stdio rpath shared_buffer", nullptr) < 0) { - perror("pledge"); - return 1; - } - - if (unveil("/res", "r") < 0) { - perror("unveil"); - return 1; - } - - if (unveil(nullptr, nullptr) < 0) { - perror("unveil"); - return 1; - } - - auto window = GUI::Window::construct(); - window->set_double_buffering_enabled(false); - window->set_title("Fire"); - window->set_resizable(false); - window->resize(640, 400); - - auto& fire = window->set_main_widget<Fire>(); - - auto& time = fire.add<GUI::Label>(); - time.set_relative_rect({ 0, 4, 40, 10 }); - time.move_by({ window->width() - time.width(), 0 }); - fire.set_stat_label(time); - - window->show(); - - auto app_icon = GUI::Icon::default_icon("app-fire"); - window->set_icon(app_icon.bitmap_for_size(16)); - - return app->exec(); -} diff --git a/Demos/HelloWorld/CMakeLists.txt b/Demos/HelloWorld/CMakeLists.txt deleted file mode 100644 index a210b1aa77..0000000000 --- a/Demos/HelloWorld/CMakeLists.txt +++ /dev/null @@ -1,6 +0,0 @@ -set(SOURCES - main.cpp -) - -serenity_app(HelloWorld ICON app-hello-world) -target_link_libraries(HelloWorld LibGUI) diff --git a/Demos/HelloWorld/main.cpp b/Demos/HelloWorld/main.cpp deleted file mode 100644 index 4c39b30b66..0000000000 --- a/Demos/HelloWorld/main.cpp +++ /dev/null @@ -1,77 +0,0 @@ -/* - * Copyright (c) 2018-2020, Andreas Kling <kling@serenityos.org> - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are met: - * - * 1. Redistributions of source code must retain the above copyright notice, this - * list of conditions and the following disclaimer. - * - * 2. Redistributions in binary form must reproduce the above copyright notice, - * this list of conditions and the following disclaimer in the documentation - * and/or other materials provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" - * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE - * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR - * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER - * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, - * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE - * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ - -#include <LibGUI/Application.h> -#include <LibGUI/BoxLayout.h> -#include <LibGUI/Button.h> -#include <LibGUI/Icon.h> -#include <LibGUI/Label.h> -#include <LibGUI/Widget.h> -#include <LibGUI/Window.h> - -int main(int argc, char** argv) -{ - auto app = GUI::Application::construct(argc, argv); - auto app_icon = GUI::Icon::default_icon("app-hello-world"); - - if (pledge("stdio rpath shared_buffer", nullptr) < 0) { - perror("pledge"); - return 1; - } - - if (unveil("/res", "r") < 0) { - perror("unveil"); - return 1; - } - - if (unveil(nullptr, nullptr) < 0) { - perror("unveil"); - return 1; - } - - auto window = GUI::Window::construct(); - window->resize(240, 160); - window->set_title("Hello World!"); - window->set_icon(app_icon.bitmap_for_size(16)); - - auto& main_widget = window->set_main_widget<GUI::Widget>(); - main_widget.set_fill_with_background_color(true); - auto& layout = main_widget.set_layout<GUI::VerticalBoxLayout>(); - layout.set_margins({ 4, 4, 4, 4 }); - - auto& label = main_widget.add<GUI::Label>(); - label.set_text("Hello\nWorld!"); - - auto& button = main_widget.add<GUI::Button>(); - button.set_text("Good-bye"); - button.on_click = [&](auto) { - app->quit(); - }; - - window->show(); - - return app->exec(); -} diff --git a/Demos/LibGfxDemo/CMakeLists.txt b/Demos/LibGfxDemo/CMakeLists.txt deleted file mode 100644 index 5f2d4bca8f..0000000000 --- a/Demos/LibGfxDemo/CMakeLists.txt +++ /dev/null @@ -1,6 +0,0 @@ -set(SOURCES - main.cpp -) - -serenity_app(LibGfxDemo ICON app-libgfx-demo) -target_link_libraries(LibGfxDemo LibGUI LibIPC LibGfx LibCore) diff --git a/Demos/LibGfxDemo/main.cpp b/Demos/LibGfxDemo/main.cpp deleted file mode 100644 index c60c0e56d6..0000000000 --- a/Demos/LibGfxDemo/main.cpp +++ /dev/null @@ -1,230 +0,0 @@ -/* - * Copyright (c) 2020, Linus Groh <mail@linusgroh.de> - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are met: - * - * 1. Redistributions of source code must retain the above copyright notice, this - * list of conditions and the following disclaimer. - * - * 2. Redistributions in binary form must reproduce the above copyright notice, - * this list of conditions and the following disclaimer in the documentation - * and/or other materials provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" - * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE - * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR - * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER - * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, - * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE - * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ - -#include <LibGUI/Application.h> -#include <LibGUI/Icon.h> -#include <LibGUI/Painter.h> -#include <LibGUI/Widget.h> -#include <LibGUI/Window.h> -#include <LibGfx/Bitmap.h> -#include <LibGfx/Font.h> -#include <LibGfx/FontDatabase.h> -#include <LibGfx/Painter.h> -#include <LibGfx/Path.h> - -const int WIDTH = 780; -const int HEIGHT = 600; - -class Canvas final : public GUI::Widget { - C_OBJECT(Canvas) -public: - virtual ~Canvas() override; - -private: - Canvas(); - RefPtr<Gfx::Bitmap> m_bitmap; - - void draw(); - virtual void paint_event(GUI::PaintEvent&) override; -}; - -Canvas::Canvas() -{ - m_bitmap = Gfx::Bitmap::create(Gfx::BitmapFormat::RGB32, { WIDTH, HEIGHT }); - draw(); -} - -Canvas::~Canvas() -{ -} - -void Canvas::paint_event(GUI::PaintEvent& event) -{ - GUI::Painter painter(*this); - painter.draw_scaled_bitmap(event.rect(), *m_bitmap, m_bitmap->rect()); -} - -void Canvas::draw() -{ - GUI::Painter painter(*m_bitmap); - - painter.fill_rect({ 20, 20, 100, 100 }, Color::Magenta); - painter.draw_rect({ 20, 140, 100, 100 }, Color::Yellow); - - painter.fill_rect_with_gradient(Gfx::Orientation::Horizontal, { 140, 20, 100, 100 }, Color::Yellow, Color::DarkGreen); - painter.fill_rect_with_gradient(Gfx::Orientation::Vertical, { 140, 140, 100, 100 }, Color::Red, Color::Blue); - - painter.fill_rect_with_dither_pattern({ 260, 20, 100, 100 }, Color::MidGray, Color::Black); - painter.fill_rect_with_checkerboard({ 260, 140, 100, 100 }, { 10, 10 }, Color::LightGray, Color::White); - - painter.draw_line({ 430, 35 }, { 465, 70 }, Color::Green); - painter.draw_line({ 465, 70 }, { 430, 105 }, Color::Green); - painter.draw_line({ 430, 105 }, { 395, 70 }, Color::Green); - painter.draw_line({ 395, 70 }, { 430, 35 }, Color::Green); - painter.draw_rect({ 395, 35, 70, 70 }, Color::Blue); - painter.draw_ellipse_intersecting({ 395, 35, 70, 70 }, Color::Red); - painter.draw_rect({ 380, 20, 100, 100 }, Color::Yellow); - - painter.fill_rect({ 380, 140, 100, 100 }, Color::Blue); - painter.draw_triangle({ 430, 140 }, { 380, 140 }, { 380, 240 }, Color::Green); - painter.draw_triangle({ 430, 240 }, { 480, 140 }, { 480, 240 }, Color::Red); - painter.draw_rect({ 380, 140, 100, 100 }, Color::Yellow); - - painter.draw_line({ 500, 20 }, { 750, 20 }, Color::Green, 1, Gfx::Painter::LineStyle::Solid); - painter.draw_line({ 500, 30 }, { 750, 30 }, Color::Red, 5, Gfx::Painter::LineStyle::Solid); - painter.draw_line({ 500, 45 }, { 750, 45 }, Color::Blue, 10, Gfx::Painter::LineStyle::Solid); - - painter.draw_line({ 500, 60 }, { 750, 60 }, Color::Green, 1, Gfx::Painter::LineStyle::Dotted); - painter.draw_line({ 500, 70 }, { 750, 70 }, Color::Red, 5, Gfx::Painter::LineStyle::Dotted); - painter.draw_line({ 500, 85 }, { 750, 85 }, Color::Blue, 10, Gfx::Painter::LineStyle::Dotted); - - painter.draw_line({ 500, 100 }, { 750, 100 }, Color::Green, 1, Gfx::Painter::LineStyle::Dashed); - painter.draw_line({ 500, 110 }, { 750, 110 }, Color::Red, 5, Gfx::Painter::LineStyle::Dashed); - painter.draw_line({ 500, 125 }, { 750, 125 }, Color::Blue, 10, Gfx::Painter::LineStyle::Dashed); - - painter.draw_line({ 500, 140 }, { 500, 240 }, Color::Green, 1, Gfx::Painter::LineStyle::Solid); - painter.draw_line({ 510, 140 }, { 510, 240 }, Color::Red, 5, Gfx::Painter::LineStyle::Solid); - painter.draw_line({ 525, 140 }, { 525, 240 }, Color::Blue, 10, Gfx::Painter::LineStyle::Solid); - - painter.draw_line({ 540, 140 }, { 540, 240 }, Color::Green, 1, Gfx::Painter::LineStyle::Dotted); - painter.draw_line({ 550, 140 }, { 550, 240 }, Color::Red, 5, Gfx::Painter::LineStyle::Dotted); - painter.draw_line({ 565, 140 }, { 565, 240 }, Color::Blue, 10, Gfx::Painter::LineStyle::Dotted); - - painter.draw_line({ 580, 140 }, { 580, 240 }, Color::Green, 1, Gfx::Painter::LineStyle::Dashed); - painter.draw_line({ 590, 140 }, { 590, 240 }, Color::Red, 5, Gfx::Painter::LineStyle::Dashed); - painter.draw_line({ 605, 140 }, { 605, 240 }, Color::Blue, 10, Gfx::Painter::LineStyle::Dashed); - - painter.draw_line({ 640, 190 }, { 740, 240 }, Color::Green, 1, Gfx::Painter::LineStyle::Solid); - painter.draw_line({ 640, 140 }, { 740, 240 }, Color::Red, 5, Gfx::Painter::LineStyle::Solid); - painter.draw_line({ 690, 140 }, { 740, 240 }, Color::Blue, 10, Gfx::Painter::LineStyle::Solid); - painter.draw_line({ 740, 190 }, { 640, 240 }, Color::Green, 1, Gfx::Painter::LineStyle::Solid); - painter.draw_line({ 740, 140 }, { 640, 240 }, Color::Red, 5, Gfx::Painter::LineStyle::Solid); - painter.draw_line({ 690, 140 }, { 640, 240 }, Color::Blue, 10, Gfx::Painter::LineStyle::Solid); - - auto bg = Gfx::Bitmap::load_from_file("/res/html/misc/90s-bg.png"); - painter.draw_tiled_bitmap({ 20, 260, 480, 320 }, *bg); - - painter.draw_line({ 40, 480 }, { 20, 260 }, Color::Red); - painter.draw_line({ 40, 480 }, { 120, 300 }, Color::Red); - painter.draw_quadratic_bezier_curve({ 40, 480 }, { 20, 260 }, { 120, 300 }, Color::Blue); - - painter.draw_line({ 240, 280 }, { 80, 420 }, Color::Red, 3); - painter.draw_line({ 240, 280 }, { 260, 360 }, Color::Red, 3); - painter.draw_quadratic_bezier_curve({ 240, 280 }, { 80, 420 }, { 260, 360 }, Color::Blue, 3); - - auto path = Gfx::Path(); - path.move_to({ 60, 500 }); - path.line_to({ 90, 540 }); - path.quadratic_bezier_curve_to({ 320, 500 }, { 220, 400 }); - path.line_to({ 300, 440 }); - path.line_to({ 90, 460 }); - path.quadratic_bezier_curve_to({ 260, 500 }, { 200, 540 }); - path.close(); - painter.fill_path(path, Color::Yellow, Gfx::Painter::WindingRule::EvenOdd); - - auto buggie = Gfx::Bitmap::load_from_file("/res/graphics/buggie.png"); - painter.blit({ 280, 280 }, *buggie, buggie->rect(), 0.5); - painter.blit_scaled({ 360, 280, buggie->rect().width() * 2, buggie->rect().height() * 2 }, *buggie, buggie->rect(), 0.5, 0.5); - - painter.draw_rect({ 20, 260, 480, 320 }, Color::DarkGray); - - painter.draw_rect({ 520, 260, 240, 80 }, Color::DarkGray); - painter.draw_text({ 520, 260, 240, 80 }, "CenterLeft", Gfx::TextAlignment::CenterLeft, Color::White); - painter.draw_text({ 520, 260, 240, 80 }, "Center", Gfx::TextAlignment::Center, Color::White); - painter.draw_text({ 520, 260, 240, 80 }, "CenterRight", Gfx::TextAlignment::CenterRight, Color::White); - painter.draw_text({ 520, 260, 240, 80 }, "TopLeft", Gfx::TextAlignment::TopLeft, Color::White); - painter.draw_text({ 520, 260, 240, 80 }, "TopRight", Gfx::TextAlignment::TopRight, Color::White); - - painter.draw_rect({ 520, 360, 240, 30 }, Color::DarkGray); - painter.draw_text({ 520, 360, 240, 30 }, "Emojis! 🙂😂🐞🦄", Gfx::TextAlignment::Center, Color::White); - - painter.draw_rect({ 520, 410, 240, 80 }, Color::DarkGray); - painter.draw_text({ 520, 415, 240, 20 }, "Normal text", Gfx::FontDatabase::default_font(), Gfx::TextAlignment::CenterLeft, Color::Red); - painter.draw_text({ 520, 430, 240, 20 }, "Bold text", Gfx::FontDatabase::default_bold_font(), Gfx::TextAlignment::CenterLeft, Color::Green); - painter.draw_text({ 520, 450, 240, 20 }, "Normal text (fixed width)", Gfx::FontDatabase::default_fixed_width_font(), Gfx::TextAlignment::CenterLeft, Color::Blue); - painter.draw_text({ 520, 465, 240, 20 }, "Bold text (fixed width)", Gfx::FontDatabase::default_bold_fixed_width_font(), Gfx::TextAlignment::CenterLeft, Color::Yellow); - - auto font = Gfx::Font::load_from_file("/res/fonts/PebbletonBold14.font"); - painter.draw_rect({ 520, 510, 240, 30 }, Color::DarkGray); - painter.draw_text({ 520, 510, 240, 30 }, "Hello friends! :^)", *font, Gfx::TextAlignment::Center, Color::White); - - painter.fill_rect({ 520, 560, 10, 20 }, Color::White); - painter.fill_rect({ 530, 560, 10, 20 }, Color::WarmGray); - painter.fill_rect({ 540, 560, 10, 20 }, Color::LightGray); - painter.fill_rect({ 550, 560, 10, 20 }, Color::MidGray); - painter.fill_rect({ 560, 560, 10, 20 }, Color::DarkGray); - painter.fill_rect({ 570, 560, 10, 20 }, Color::Black); - painter.fill_rect({ 580, 560, 10, 20 }, Color::Blue); - painter.fill_rect({ 590, 560, 10, 20 }, Color::MidBlue); - painter.fill_rect({ 600, 560, 10, 20 }, Color::DarkBlue); - painter.fill_rect({ 610, 560, 10, 20 }, Color::Cyan); - painter.fill_rect({ 620, 560, 10, 20 }, Color::MidCyan); - painter.fill_rect({ 630, 560, 10, 20 }, Color::DarkCyan); - painter.fill_rect({ 640, 560, 10, 20 }, Color::Green); - painter.fill_rect({ 650, 560, 10, 20 }, Color::MidGreen); - painter.fill_rect({ 660, 560, 10, 20 }, Color::DarkGreen); - painter.fill_rect({ 670, 560, 10, 20 }, Color::Yellow); - painter.fill_rect({ 680, 560, 10, 20 }, Color::Red); - painter.fill_rect({ 690, 560, 10, 20 }, Color::MidRed); - painter.fill_rect({ 700, 560, 10, 20 }, Color::DarkRed); - painter.fill_rect({ 710, 560, 10, 20 }, Color::Magenta); - painter.fill_rect({ 720, 560, 10, 20 }, Color::MidMagenta); - - update(); -} - -int main(int argc, char** argv) -{ - auto app = GUI::Application::construct(argc, argv); - - if (pledge("stdio rpath shared_buffer", nullptr) < 0) { - perror("pledge"); - return 1; - } - - if (unveil("/res", "r") < 0) { - perror("unveil"); - return 1; - } - - if (unveil(nullptr, nullptr) < 0) { - perror("unveil"); - return 1; - } - - auto window = GUI::Window::construct(); - window->set_double_buffering_enabled(true); - window->set_title("LibGfx Demo"); - window->set_resizable(false); - window->resize(WIDTH, HEIGHT); - - auto app_icon = GUI::Icon::default_icon("app-libgfx-demo"); - window->set_icon(app_icon.bitmap_for_size(16)); - window->set_main_widget<Canvas>(); - window->show(); - - return app->exec(); -} diff --git a/Demos/Mouse/CMakeLists.txt b/Demos/Mouse/CMakeLists.txt deleted file mode 100644 index bc90a5e308..0000000000 --- a/Demos/Mouse/CMakeLists.txt +++ /dev/null @@ -1,6 +0,0 @@ -set(SOURCES - main.cpp -) - -serenity_app(Mouse ICON app-mouse) -target_link_libraries(Mouse LibGUI LibGfx) diff --git a/Demos/Mouse/main.cpp b/Demos/Mouse/main.cpp deleted file mode 100644 index 80960610a8..0000000000 --- a/Demos/Mouse/main.cpp +++ /dev/null @@ -1,211 +0,0 @@ -/* - * Copyright (c) 2020, Andreas Kling <kling@serenityos.org> - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are met: - * - * 1. Redistributions of source code must retain the above copyright notice, this - * list of conditions and the following disclaimer. - * - * 2. Redistributions in binary form must reproduce the above copyright notice, - * this list of conditions and the following disclaimer in the documentation - * and/or other materials provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" - * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE - * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR - * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER - * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, - * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE - * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ - -#include <LibGUI/Action.h> -#include <LibGUI/Application.h> -#include <LibGUI/BoxLayout.h> -#include <LibGUI/Frame.h> -#include <LibGUI/Icon.h> -#include <LibGUI/Menu.h> -#include <LibGUI/MenuBar.h> -#include <LibGUI/Painter.h> -#include <LibGUI/Widget.h> -#include <LibGUI/Window.h> -#include <LibGfx/Bitmap.h> -#include <LibGfx/Path.h> - -#include <math.h> - -class MainFrame final : public GUI::Frame { - C_OBJECT(MainFrame); - -public: - virtual void timer_event(Core::TimerEvent&) override - { - - m_show_scroll_wheel = false; - stop_timer(); - update(); - } - - virtual void paint_event(GUI::PaintEvent& event) override - { - GUI::Painter painter(*this); - painter.add_clip_rect(event.rect()); - painter.fill_rect(frame_inner_rect(), Color::White); - - Gfx::Path path; - // draw mouse outline - path.move_to({ 30, 140 }); - path.line_to({ 30, 20 }); - path.line_to({ 65, 12 }); - path.line_to({ 95, 12 }); - path.line_to({ 130, 20 }); - path.line_to({ 130, 140 }); - path.line_to({ 30, 140 }); - - // draw button separator - path.move_to({ 30, 65 }); - path.line_to({ 130, 65 }); - - path.move_to({ 65, 65 }); - path.line_to({ 65, 13 }); - - path.move_to({ 95, 65 }); - path.line_to({ 95, 13 }); - - // draw fw and back button outlines - path.move_to({ 30, 43 }); - path.line_to({ 25, 43 }); - path.line_to({ 25, 60 }); - path.line_to({ 30, 60 }); - - path.move_to({ 30, 70 }); - path.line_to({ 25, 70 }); - path.line_to({ 25, 87 }); - path.line_to({ 30, 87 }); - - painter.stroke_path(path, Color::Black, 1); - - if (m_buttons & GUI::MouseButton::Left) { - painter.fill_rect({ 31, 21, 34, 44 }, Color::Blue); - painter.draw_triangle({ 30, 21 }, { 65, 21 }, { 65, 12 }, Color::Blue); - } - - if (m_buttons & GUI::MouseButton::Right) { - painter.fill_rect({ 96, 21, 34, 44 }, Color::Blue); - painter.draw_triangle({ 96, 12 }, { 96, 21 }, { 132, 21 }, Color::Blue); - } - - if (m_buttons & GUI::MouseButton::Middle) - painter.fill_rect({ 66, 13, 29, 52 }, Color::Blue); - - if (m_buttons & GUI::MouseButton::Forward) - painter.fill_rect({ 26, 44, 4, 16 }, Color::Blue); - - if (m_buttons & GUI::MouseButton::Back) - painter.fill_rect({ 26, 71, 4, 16 }, Color::Blue); - - if (m_show_scroll_wheel) { - auto radius = 10; - auto off_x = 80; - auto off_y = 38; - - Gfx::IntPoint p1; - Gfx::IntPoint p2; - Gfx::IntPoint p3; - Gfx::IntPoint p4; - - p1.set_x(radius * cos(M_PI * m_wheel_delta_acc / 18) + off_x); - p1.set_y(radius * sin(M_PI * m_wheel_delta_acc / 18) + off_y); - - p2.set_x(radius * cos(M_PI * (m_wheel_delta_acc + 18) / 18) + off_x); - p2.set_y(radius * sin(M_PI * (m_wheel_delta_acc + 18) / 18) + off_y); - - p3.set_x(radius * cos(M_PI * (m_wheel_delta_acc + 9) / 18) + off_x); - p3.set_y(radius * sin(M_PI * (m_wheel_delta_acc + 9) / 18) + off_y); - - p4.set_x(radius * cos(M_PI * (m_wheel_delta_acc + 27) / 18) + off_x); - p4.set_y(radius * sin(M_PI * (m_wheel_delta_acc + 27) / 18) + off_y); - - painter.draw_line(p1, p2, Color::Red, 2); - painter.draw_line(p3, p4, Color::Red, 2); - } - } - - void mousedown_event(GUI::MouseEvent& event) override - { - m_buttons = event.buttons(); - update(); - } - - void mouseup_event(GUI::MouseEvent& event) override - { - m_buttons = event.buttons(); - update(); - } - - void mousewheel_event(GUI::MouseEvent& event) override - { - m_wheel_delta_acc = (m_wheel_delta_acc + event.wheel_delta() + 36) % 36; - m_show_scroll_wheel = true; - update(); - if (!has_timer()) - start_timer(500); - } - -private: - unsigned m_buttons; - unsigned m_wheel_delta_acc; - bool m_show_scroll_wheel; - MainFrame() - : m_buttons { 0 } - , m_wheel_delta_acc { 0 } - , m_show_scroll_wheel { false } - { - } -}; - -int main(int argc, char** argv) -{ - auto app = GUI::Application::construct(argc, argv); - auto app_icon = GUI::Icon::default_icon("app-mouse"); - - if (pledge("stdio rpath shared_buffer", nullptr) < 0) { - perror("pledge"); - return 1; - } - - if (unveil("/res", "r") < 0) { - perror("unveil"); - return 1; - } - - if (unveil(nullptr, nullptr) < 0) { - perror("unveil"); - return 1; - } - - auto window = GUI::Window::construct(); - window->set_title("Mouse button demo"); - window->set_icon(app_icon.bitmap_for_size(16)); - window->resize(160, 155); - - auto& main_widget = window->set_main_widget<MainFrame>(); - main_widget.set_fill_with_background_color(true); - - auto menubar = GUI::MenuBar::construct(); - auto& app_menu = menubar->add_menu("Mouse Demo"); - app_menu.add_action(GUI::CommonActions::make_quit_action([&](auto&) { app->quit(); })); - - auto& help_menu = menubar->add_menu("Help"); - help_menu.add_action(GUI::CommonActions::make_about_action("Mouse Demo", app_icon, window)); - - app->set_menubar(move(menubar)); - window->set_resizable(false); - window->show(); - return app->exec(); -} diff --git a/Demos/Screensaver/CMakeLists.txt b/Demos/Screensaver/CMakeLists.txt deleted file mode 100644 index 6f8acee97c..0000000000 --- a/Demos/Screensaver/CMakeLists.txt +++ /dev/null @@ -1,6 +0,0 @@ -set(SOURCES - Screensaver.cpp -) - -serenity_app(Screensaver ICON app-screensaver) -target_link_libraries(Screensaver LibGUI LibCore LibGfx) diff --git a/Demos/Screensaver/Screensaver.cpp b/Demos/Screensaver/Screensaver.cpp deleted file mode 100644 index f1d25553a7..0000000000 --- a/Demos/Screensaver/Screensaver.cpp +++ /dev/null @@ -1,170 +0,0 @@ -/* - * Copyright (c) 2020, the SerenityOS developers. - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are met: - * - * 1. Redistributions of source code must retain the above copyright notice, this - * list of conditions and the following disclaimer. - * - * 2. Redistributions in binary form must reproduce the above copyright notice, - * this list of conditions and the following disclaimer in the documentation - * and/or other materials provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" - * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE - * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR - * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER - * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, - * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE - * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ - -#include <LibGUI/Application.h> -#include <LibGUI/Event.h> -#include <LibGUI/Icon.h> -#include <LibGUI/Painter.h> -#include <LibGUI/Widget.h> -#include <LibGUI/Window.h> -#include <LibGfx/Bitmap.h> -#include <stdio.h> -#include <time.h> - -class Screensaver final : public GUI::Widget { - C_OBJECT(Screensaver) -public: - virtual ~Screensaver() override; - -private: - Screensaver(int width = 64, int height = 48, int interval = 10000); - RefPtr<Gfx::Bitmap> m_bitmap; - - void draw(); - virtual void paint_event(GUI::PaintEvent&) override; - virtual void timer_event(Core::TimerEvent&) override; - virtual void keydown_event(GUI::KeyEvent&) override; - virtual void mousedown_event(GUI::MouseEvent& event) override; - virtual void mousemove_event(GUI::MouseEvent& event) override; -}; - -Screensaver::Screensaver(int width, int height, int interval) -{ - m_bitmap = Gfx::Bitmap::create(Gfx::BitmapFormat::RGB32, { width, height }); - srand(time(nullptr)); - stop_timer(); - start_timer(interval); - draw(); -} - -Screensaver::~Screensaver() -{ -} - -void Screensaver::mousemove_event(GUI::MouseEvent&) -{ - ::exit(0); -} - -void Screensaver::mousedown_event(GUI::MouseEvent&) -{ - ::exit(0); -} - -void Screensaver::keydown_event(GUI::KeyEvent&) -{ - ::exit(0); -} - -void Screensaver::paint_event(GUI::PaintEvent& event) -{ - GUI::Painter painter(*this); - painter.draw_scaled_bitmap(event.rect(), *m_bitmap, m_bitmap->rect()); -} - -void Screensaver::timer_event(Core::TimerEvent&) -{ - draw(); - update(); -} - -void Screensaver::draw() -{ - const Color colors[] { - Color::Blue, - Color::Cyan, - Color::Green, - Color::Magenta, - Color::Red, - Color::Yellow, - }; - - const Orientation orientations[] { - Gfx::Orientation::Horizontal, - Gfx::Orientation::Vertical - }; - - int start_color_index = 0; - int end_color_index = 0; - while (start_color_index == end_color_index) { - start_color_index = rand() % (sizeof(colors) / sizeof(colors[0])); - end_color_index = rand() % (sizeof(colors) / sizeof(colors[0])); - } - - GUI::Painter painter(*m_bitmap); - painter.fill_rect_with_gradient( - orientations[rand() % (sizeof(orientations) / sizeof(orientations[0]))], - m_bitmap->rect(), - colors[start_color_index], - colors[end_color_index]); -} - -int main(int argc, char** argv) -{ - if (pledge("stdio rpath wpath cpath shared_buffer cpath unix fattr", nullptr) < 0) { - perror("pledge"); - return 1; - } - - auto app = GUI::Application::construct(argc, argv); - - if (pledge("stdio rpath shared_buffer", nullptr) < 0) { - perror("pledge"); - return 1; - } - - if (unveil("/res", "r") < 0) { - perror("unveil"); - return 1; - } - - if (unveil(nullptr, nullptr) < 0) { - perror("unveil"); - return 1; - } - - auto app_icon = GUI::Icon::default_icon("app-screensaver"); - auto window = GUI::Window::construct(); - window->set_double_buffering_enabled(false); - window->set_title("Screensaver"); - window->set_resizable(false); - window->set_frameless(true); - window->set_fullscreen(true); - window->set_minimizable(false); - window->set_icon(app_icon.bitmap_for_size(16)); - - auto& screensaver_window = window->set_main_widget<Screensaver>(64, 48, 10000); - screensaver_window.set_fill_with_background_color(false); - screensaver_window.set_override_cursor(Gfx::StandardCursor::Hidden); - screensaver_window.update(); - - window->show(); - window->move_to_front(); - window->set_cursor(Gfx::StandardCursor::Hidden); - window->update(); - - return app->exec(); -} diff --git a/Demos/WidgetGallery/CMakeLists.txt b/Demos/WidgetGallery/CMakeLists.txt deleted file mode 100644 index 2c4e42046d..0000000000 --- a/Demos/WidgetGallery/CMakeLists.txt +++ /dev/null @@ -1,6 +0,0 @@ -set(SOURCES - main.cpp -) - -serenity_app(WidgetGallery ICON app-widget-gallery) -target_link_libraries(WidgetGallery LibGUI) diff --git a/Demos/WidgetGallery/main.cpp b/Demos/WidgetGallery/main.cpp deleted file mode 100644 index 37e5c4efa2..0000000000 --- a/Demos/WidgetGallery/main.cpp +++ /dev/null @@ -1,557 +0,0 @@ -/* - * Copyright (c) 2018-2020, Andreas Kling <kling@serenityos.org> - * Copyright (c) 2020, Linus Groh <mail@linusgroh.de> - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are met: - * - * 1. Redistributions of source code must retain the above copyright notice, this - * list of conditions and the following disclaimer. - * - * 2. Redistributions in binary form must reproduce the above copyright notice, - * this list of conditions and the following disclaimer in the documentation - * and/or other materials provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" - * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE - * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR - * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER - * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, - * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE - * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ - -#include <AK/NonnullRefPtr.h> -#include <AK/Vector.h> -#include <LibGUI/Action.h> -#include <LibGUI/Application.h> -#include <LibGUI/BoxLayout.h> -#include <LibGUI/Button.h> -#include <LibGUI/CheckBox.h> -#include <LibGUI/ColorInput.h> -#include <LibGUI/ComboBox.h> -#include <LibGUI/GroupBox.h> -#include <LibGUI/Icon.h> -#include <LibGUI/ImageWidget.h> -#include <LibGUI/InputBox.h> -#include <LibGUI/Label.h> -#include <LibGUI/ListView.h> -#include <LibGUI/Menu.h> -#include <LibGUI/MenuBar.h> -#include <LibGUI/MessageBox.h> -#include <LibGUI/Model.h> -#include <LibGUI/OpacitySlider.h> -#include <LibGUI/ProgressBar.h> -#include <LibGUI/RadioButton.h> -#include <LibGUI/ScrollBar.h> -#include <LibGUI/Slider.h> -#include <LibGUI/SpinBox.h> -#include <LibGUI/TabWidget.h> -#include <LibGUI/TextBox.h> -#include <LibGUI/Variant.h> -#include <LibGUI/Widget.h> -#include <LibGUI/Window.h> -#include <LibGfx/FontDatabase.h> - -template<typename T> -class ListViewModel final : public GUI::Model { -public: - static NonnullRefPtr<ListViewModel> create(Vector<T>& model_items) { return adopt(*new ListViewModel(model_items)); } - virtual ~ListViewModel() override { } - virtual int row_count(const GUI::ModelIndex&) const override { return m_model_items.size(); } - virtual int column_count(const GUI::ModelIndex&) const override { return 1; } - virtual GUI::Variant data(const GUI::ModelIndex& index, GUI::ModelRole role) const override - { - ASSERT(index.is_valid()); - ASSERT(index.column() == 0); - if (role == GUI::ModelRole::Display) - return m_model_items.at(index.row()); - return {}; - } - virtual void update() override { did_update(); } - -private: - explicit ListViewModel(Vector<String>& model_items) - : m_model_items(model_items) - { - } - Vector<T>& m_model_items; -}; - -int main(int argc, char** argv) -{ - auto app = GUI::Application::construct(argc, argv); - - if (pledge("stdio rpath shared_buffer", nullptr) < 0) { - perror("pledge"); - return 1; - } - - if (unveil("/res", "r") < 0) { - perror("unveil"); - return 1; - } - - if (unveil(nullptr, nullptr) < 0) { - perror("unveil"); - return 1; - } - - auto app_icon = GUI::Icon::default_icon("app-widget-gallery"); - - auto window = GUI::Window::construct(); - window->resize(430, 480); - window->set_title("Widget Gallery"); - window->set_icon(app_icon.bitmap_for_size(16)); - - auto menubar = GUI::MenuBar::construct(); - - auto& app_menu = menubar->add_menu("Widget Gallery"); - app_menu.add_action(GUI::CommonActions::make_quit_action([&](auto&) { app->quit(); })); - - auto& help_menu = menubar->add_menu("Help"); - help_menu.add_action(GUI::CommonActions::make_about_action("Widget Gallery", app_icon, window)); - - auto& root_widget = window->set_main_widget<GUI::Widget>(); - root_widget.set_fill_with_background_color(true); - root_widget.set_layout<GUI::VerticalBoxLayout>(); - root_widget.layout()->set_margins({ 4, 4, 4, 4 }); - - auto& tab_widget = root_widget.add<GUI::TabWidget>(); - - auto& tab_basic = tab_widget.add_tab<GUI::Widget>("Basic"); - tab_basic.set_layout<GUI::VerticalBoxLayout>(); - tab_basic.layout()->set_margins({ 8, 8, 8, 8 }); - tab_basic.layout()->set_spacing(8); - - auto& radio_group_box = tab_basic.add<GUI::GroupBox>(); - radio_group_box.set_layout<GUI::HorizontalBoxLayout>(); - radio_group_box.layout()->set_margins({ 4, 4, 4, 4 }); - - auto& radio_button_vert_container = radio_group_box.add<GUI::Widget>(); - radio_button_vert_container.set_layout<GUI::VerticalBoxLayout>(); - radio_button_vert_container.layout()->set_margins({ 4, 9, 4, 4 }); - - auto& radio_button_container = radio_button_vert_container.add<GUI::Widget>(); - radio_button_container.set_layout<GUI::HorizontalBoxLayout>(); - - auto& radio1 = radio_button_container.add<GUI::RadioButton>("RadioButton 1"); - radio1.set_checked(true); - [[maybe_unused]] auto& radio2 = radio_button_container.add<GUI::RadioButton>("RadioButton 2"); - auto& radio3 = radio_button_container.add<GUI::RadioButton>("RadioButton 3"); - radio3.set_enabled(false); - - auto& checklabelspin_container = tab_basic.add<GUI::Widget>(); - checklabelspin_container.set_layout<GUI::HorizontalBoxLayout>(); - - auto& check_group_box = checklabelspin_container.add<GUI::GroupBox>(); - check_group_box.set_layout<GUI::HorizontalBoxLayout>(); - check_group_box.layout()->set_margins({ 4, 12, 4, 4 }); - - auto& checkbox_container = check_group_box.add<GUI::Widget>(); - checkbox_container.set_layout<GUI::VerticalBoxLayout>(); - checkbox_container.layout()->set_margins({ 4, 4, 4, 4 }); - - auto& label_container = check_group_box.add<GUI::Widget>(); - label_container.set_layout<GUI::VerticalBoxLayout>(); - label_container.layout()->set_margins({ 4, 4, 4, 4 }); - - auto& spin_group_box = checklabelspin_container.add<GUI::GroupBox>(); - spin_group_box.set_layout<GUI::HorizontalBoxLayout>(); - spin_group_box.layout()->set_margins({ 4, 4, 4, 4 }); - spin_group_box.set_title("Spin boxes"); - - auto& spin_container = spin_group_box.add<GUI::Widget>(); - spin_container.set_layout<GUI::VerticalBoxLayout>(); - spin_container.layout()->set_margins({ 4, 12, 4, 4 }); - - auto& checkbox1 = checkbox_container.add<GUI::CheckBox>("CheckBox 1"); - checkbox1.set_checked(true); - auto& checkbox2 = checkbox_container.add<GUI::CheckBox>("CheckBox 2"); - checkbox2.set_enabled(false); - - auto& label1 = label_container.add<GUI::Label>("Label 1"); - label1.set_fixed_height(22); - auto& label2 = label_container.add<GUI::Label>("Label 2"); - label2.set_enabled(false); - label2.set_fixed_height(22); - - [[maybe_unused]] auto& spinbox1 = spin_container.add<GUI::SpinBox>(); - auto& spinbox2 = spin_container.add<GUI::SpinBox>(); - spinbox2.set_enabled(false); - - auto& button_container = tab_basic.add<GUI::Widget>(); - button_container.set_layout<GUI::HorizontalBoxLayout>(); - - auto& button_vert1_container = button_container.add<GUI::Widget>(); - button_vert1_container.set_layout<GUI::VerticalBoxLayout>(); - - auto& button_vert2_container = button_container.add<GUI::Widget>(); - button_vert2_container.set_layout<GUI::VerticalBoxLayout>(); - - auto& button1 = button_vert1_container.add<GUI::Button>("Button 1"); - button1.set_icon(Gfx::Bitmap::load_from_file("/res/icons/16x16/kill.png")); - auto& button2 = button_vert1_container.add<GUI::Button>("Button 2"); - button2.set_icon(Gfx::Bitmap::load_from_file("/res/icons/16x16/kill.png")); - button2.set_enabled(false); - [[maybe_unused]] auto& button3 = button_vert2_container.add<GUI::Button>("\xF0\x9F\x98\x88 Button 3"); - auto& button4 = button_vert2_container.add<GUI::Button>("\xF0\x9F\x8D\x86 Button 4"); - button4.set_enabled(false); - - auto& text_group_box = tab_basic.add<GUI::GroupBox>(); - text_group_box.set_layout<GUI::HorizontalBoxLayout>(); - text_group_box.set_title("Text boxes"); - text_group_box.layout()->set_margins({ 8, 4, 8, 4 }); - - auto& textbox_vert1_container = text_group_box.add<GUI::Widget>(); - textbox_vert1_container.set_layout<GUI::VerticalBoxLayout>(); - textbox_vert1_container.layout()->set_margins({ 1, 12, 1, 4 }); - - auto& textbox_vert2_container = text_group_box.add<GUI::Widget>(); - textbox_vert2_container.set_layout<GUI::VerticalBoxLayout>(); - textbox_vert2_container.layout()->set_margins({ 1, 12, 1, 4 }); - - auto& textbox1 = textbox_vert1_container.add<GUI::TextBox>(); - textbox1.set_placeholder("Editable"); - auto& textbox2 = textbox_vert1_container.add<GUI::TextBox>(); - textbox2.set_text("Disabled"); - textbox2.set_enabled(false); - auto& textbox3 = textbox_vert2_container.add<GUI::TextBox>(); - textbox3.set_text("Read only"); - textbox3.set_mode(GUI::TextEditor::ReadOnly); - auto& textbox4 = textbox_vert2_container.add<GUI::TextBox>(); - textbox4.set_text("Display only"); - textbox4.set_mode(GUI::TextEditor::DisplayOnly); - - auto& combocolor_container = tab_basic.add<GUI::Widget>(); - combocolor_container.set_layout<GUI::HorizontalBoxLayout>(); - - auto& combo_group_box = combocolor_container.add<GUI::GroupBox>(); - combo_group_box.set_layout<GUI::HorizontalBoxLayout>(); - combo_group_box.layout()->set_margins({ 4, 4, 4, 4 }); - combo_group_box.set_title("Combo boxes"); - - auto& color_group_box = combocolor_container.add<GUI::GroupBox>(); - color_group_box.set_layout<GUI::HorizontalBoxLayout>(); - color_group_box.layout()->set_margins({ 4, 4, 4, 4 }); - color_group_box.set_title("Color pickers"); - - auto& combo_container = combo_group_box.add<GUI::Widget>(); - combo_container.set_layout<GUI::VerticalBoxLayout>(); - combo_container.layout()->set_margins({ 4, 12, 4, 4 }); - - auto& color_container = color_group_box.add<GUI::Widget>(); - color_container.set_layout<GUI::VerticalBoxLayout>(); - color_container.layout()->set_margins({ 4, 12, 4, 4 }); - - Vector<String> model_items; - model_items.append("Yes"); - model_items.append("No"); - model_items.append("Maybe"); - model_items.append("I don't know"); - model_items.append("Can you repeat the question?"); - - auto& combobox1 = combo_container.add<GUI::ComboBox>(); - combobox1.set_only_allow_values_from_model(true); - combobox1.set_model(*ListViewModel<AK::String>::create(model_items)); - - auto& combobox2 = combo_container.add<GUI::ComboBox>(); - combobox2.set_enabled(false); - - auto& color_input_enabled = color_container.add<GUI::ColorInput>(); - color_input_enabled.set_color(Color::from_string("#961605ff").value()); - color_input_enabled.set_color_picker_title("Select color for desktop"); - - auto& color_input_disabled = color_container.add<GUI::ColorInput>(); - color_input_disabled.set_color(Color::from_string("#961605ff").value()); - color_input_disabled.set_enabled(false); - - auto& tab_others = tab_widget.add_tab<GUI::Widget>("Sliders"); - tab_others.set_layout<GUI::VerticalBoxLayout>(); - tab_others.layout()->set_margins({ 8, 8, 8, 8 }); - tab_others.layout()->set_spacing(8); - - auto& vert_slider_group_box = tab_others.add<GUI::GroupBox>(); - vert_slider_group_box.set_layout<GUI::HorizontalBoxLayout>(); - vert_slider_group_box.layout()->set_margins({ 4, 28, 4, 4 }); - vert_slider_group_box.set_title("Vertical sliders"); - - auto& vslider1 = vert_slider_group_box.add<GUI::VerticalSlider>(); - vslider1.set_max(100); - vslider1.set_tooltip("Fixed"); - auto& vslider2 = vert_slider_group_box.add<GUI::VerticalSlider>(); - vslider1.set_max(100); - vslider2.set_enabled(false); - vslider2.set_tooltip("Disabled"); - auto& vslider3 = vert_slider_group_box.add<GUI::VerticalSlider>(); - vslider3.set_max(5); - vslider3.set_knob_size_mode(GUI::Slider::KnobSizeMode::Proportional); - vslider3.set_tooltip("Proportional"); - - auto& horizontal_slider_group_box = tab_others.add<GUI::GroupBox>(); - horizontal_slider_group_box.set_layout<GUI::VerticalBoxLayout>(); - horizontal_slider_group_box.layout()->set_margins({ 4, 12, 4, 4 }); - horizontal_slider_group_box.set_title("Horizontal sliders"); - - auto& horizontal_slider_container = horizontal_slider_group_box.add<GUI::Widget>(); - horizontal_slider_container.set_layout<GUI::HorizontalBoxLayout>(); - horizontal_slider_container.layout()->set_margins({ 4, 4, 4, 4 }); - - auto& horizontal_slider_container2 = horizontal_slider_group_box.add<GUI::Widget>(); - horizontal_slider_container2.set_layout<GUI::HorizontalBoxLayout>(); - horizontal_slider_container2.layout()->set_margins({ 4, 4, 4, 4 }); - - auto& slider1 = horizontal_slider_container.add<GUI::HorizontalSlider>(); - slider1.set_max(100); - auto& slider2 = horizontal_slider_container.add<GUI::HorizontalSlider>(); - slider2.set_enabled(false); - slider2.set_max(100); - slider2.set_value(50); - auto& slider3 = horizontal_slider_container.add<GUI::HorizontalSlider>(); - slider3.set_max(5); - slider3.set_knob_size_mode(GUI::Slider::KnobSizeMode::Proportional); - - auto& progress1 = horizontal_slider_container2.add<GUI::ProgressBar>(); - progress1.set_fixed_height(28); - - slider1.on_change = [&](int value) { - progress1.set_value(value); - if (!(value % (100 / slider3.max()))) - slider3.set_value(value / (100 / slider3.max())); - }; - - slider3.on_change = [&](int value) { - progress1.set_value((value * 100) / slider3.max()); - slider1.set_value((value * 100) / slider3.max()); - }; - - auto& opacity_slider_group_box = tab_others.add<GUI::GroupBox>(); - opacity_slider_group_box.set_fixed_height(48); - opacity_slider_group_box.set_layout<GUI::VerticalBoxLayout>(); - opacity_slider_group_box.layout()->set_margins({ 8, 16, 8, 8 }); - opacity_slider_group_box.set_title("Opacity sliders"); - - auto& opacity_slider = opacity_slider_group_box.add<GUI::OpacitySlider>(); - opacity_slider.set_range(0, 100); - opacity_slider.set_value(75); - - auto& scroll_group_box = tab_others.add<GUI::GroupBox>(); - scroll_group_box.set_layout<GUI::VerticalBoxLayout>(); - scroll_group_box.layout()->set_margins({ 12, 12, 12, 12 }); - scroll_group_box.set_title("Scrollbars"); - - scroll_group_box.layout()->add_spacer(); - - auto& scrollbar1 = scroll_group_box.add<GUI::ScrollBar>(Orientation::Horizontal); - scrollbar1.set_fixed_height(16); - scrollbar1.set_min(0); - scrollbar1.set_max(100); - scrollbar1.set_value(50); - - scroll_group_box.layout()->add_spacer(); - - auto& scrollbar2 = scroll_group_box.add<GUI::ScrollBar>(Orientation::Horizontal); - scrollbar2.set_fixed_height(16); - scrollbar2.set_enabled(false); - - scroll_group_box.layout()->add_spacer(); - - auto& tab_modals = tab_widget.add_tab<GUI::Widget>("Modals"); - tab_modals.set_layout<GUI::VerticalBoxLayout>(); - tab_modals.layout()->set_margins({ 8, 8, 8, 8 }); - tab_modals.layout()->set_spacing(8); - - GUI::MessageBox::Type msg_box_type = GUI::MessageBox::Type::Error; - - auto& msgbox_group_container = tab_modals.add<GUI::GroupBox>("Message boxes"); - msgbox_group_container.set_layout<GUI::VerticalBoxLayout>(); - msgbox_group_container.layout()->set_margins({ 4, 12, 4, 2 }); - - auto& msgbox_radio_container = msgbox_group_container.add<GUI::Widget>(); - msgbox_radio_container.set_layout<GUI::HorizontalBoxLayout>(); - msgbox_radio_container.layout()->set_margins({ 4, 12, 4, 4 }); - - auto& icon_group_box = msgbox_radio_container.add<GUI::GroupBox>("Icon"); - icon_group_box.set_layout<GUI::VerticalBoxLayout>(); - icon_group_box.layout()->set_margins({ 4, 16, 4, 4 }); - - auto& radio_none = icon_group_box.add<GUI::RadioButton>("None"); - radio_none.on_checked = [&](bool) { - msg_box_type = GUI::MessageBox::Type::None; - }; - auto& radio_information = icon_group_box.add<GUI::RadioButton>("\xE2\x84\xB9 Information"); - radio_information.on_checked = [&](bool) { - msg_box_type = GUI::MessageBox::Type::Information; - }; - auto& question_information = icon_group_box.add<GUI::RadioButton>("\xF0\x9F\xA4\x94 Question"); - question_information.on_checked = [&](bool) { - msg_box_type = GUI::MessageBox::Type::Question; - }; - auto& radio_warning = icon_group_box.add<GUI::RadioButton>("\xE2\x9A\xA0 Warning"); - radio_warning.on_checked = [&](bool) { - msg_box_type = GUI::MessageBox::Type::Warning; - }; - auto& radio_error = icon_group_box.add<GUI::RadioButton>("\xE2\x9D\x8C Error"); - radio_error.set_checked(true); - radio_error.on_checked = [&](bool) { - msg_box_type = GUI::MessageBox::Type::Error; - }; - - auto& button_group_box = msgbox_radio_container.add<GUI::GroupBox>("Buttons"); - button_group_box.set_layout<GUI::VerticalBoxLayout>(); - button_group_box.layout()->set_margins({ 4, 16, 4, 4 }); - - GUI::MessageBox::InputType msg_box_input_type = GUI::MessageBox::InputType::OKCancel; - - auto& radio_ok = button_group_box.add<GUI::RadioButton>("OK"); - radio_ok.on_checked = [&](bool) { - msg_box_input_type = GUI::MessageBox::InputType::OK; - }; - auto& radio_ok_cancel = button_group_box.add<GUI::RadioButton>("OK & Cancel"); - radio_ok_cancel.set_checked(true); - radio_ok_cancel.on_checked = [&](bool) { - msg_box_input_type = GUI::MessageBox::InputType::OKCancel; - }; - auto& radio_yes_no = button_group_box.add<GUI::RadioButton>("Yes & No"); - radio_yes_no.on_checked = [&](bool) { - msg_box_input_type = GUI::MessageBox::InputType::YesNo; - }; - auto& radio_yes_no_cancel = button_group_box.add<GUI::RadioButton>("Yes & No & Cancel"); - radio_yes_no_cancel.on_checked = [&](bool) { - msg_box_input_type = GUI::MessageBox::InputType::YesNoCancel; - }; - - auto& msgbox_text_container = msgbox_group_container.add<GUI::Widget>(); - msgbox_text_container.set_layout<GUI::VerticalBoxLayout>(); - msgbox_text_container.set_fixed_height(100); - msgbox_text_container.layout()->set_margins({ 4, 8, 4, 8 }); - - auto& title_textbox = msgbox_text_container.add<GUI::TextBox>(); - title_textbox.set_fixed_height(24); - title_textbox.set_text("Demo Title"); - - auto& content_textbox = msgbox_text_container.add<GUI::TextBox>(); - content_textbox.set_fixed_height(24); - content_textbox.set_text("Demo text for message box."); - - auto& msgbox_button = msgbox_text_container.add<GUI::Button>("Create"); - msgbox_button.on_click = [&](auto) { - GUI::MessageBox::show(window, content_textbox.text(), title_textbox.text(), msg_box_type, msg_box_input_type); - }; - - auto& input_group_box = tab_modals.add<GUI::GroupBox>("Input boxes"); - input_group_box.set_layout<GUI::VerticalBoxLayout>(); - input_group_box.layout()->set_margins({ 4, 12, 4, 4 }); - input_group_box.set_fixed_height(140); - - input_group_box.layout()->add_spacer(); - - auto& input_label = input_group_box.add<GUI::Label>("Valued user input goes here."); - input_label.set_font(Gfx::FontDatabase::default_bold_font()); - - input_group_box.layout()->add_spacer(); - - auto& input_button_container = input_group_box.add<GUI::Widget>(); - input_button_container.set_layout<GUI::VerticalBoxLayout>(); - input_button_container.layout()->set_margins({ 4, 0, 4, 0 }); - - auto& input_button = input_button_container.add<GUI::Button>("Input..."); - String value; - input_button.on_click = [&](auto) { - if (GUI::InputBox::show(value, window, "Enter input:", "Input Box") == GUI::InputBox::ExecOK && !value.is_empty()) - input_label.set_text(value); - }; - - auto& tab_image = tab_widget.add_tab<GUI::Widget>("Images"); - tab_image.set_layout<GUI::VerticalBoxLayout>(); - tab_image.layout()->set_margins({ 8, 8, 8, 8 }); - tab_image.layout()->set_spacing(8); - - auto& banner_image = tab_image.add<GUI::ImageWidget>(); - banner_image.set_frame_thickness(2); - banner_image.load_from_file("/res/graphics/brand-banner.png"); - - auto& gif_animation_image = tab_image.add<GUI::ImageWidget>(); - gif_animation_image.load_from_file("/res/graphics/download-animation.gif"); - - auto& tab_cursors = tab_widget.add_tab<GUI::Widget>("Cursors"); - tab_cursors.set_layout<GUI::VerticalBoxLayout>(); - tab_cursors.layout()->set_margins({ 8, 8, 8, 8 }); - tab_cursors.layout()->set_spacing(8); - - auto& cursor_group_box = tab_cursors.add<GUI::GroupBox>("Cursor"); - cursor_group_box.set_layout<GUI::VerticalBoxLayout>(); - cursor_group_box.layout()->set_margins({ 4, 12, 4, 4 }); - - auto& radio_cursor_none = cursor_group_box.add<GUI::RadioButton>("None"); - radio_cursor_none.set_checked(true); - radio_cursor_none.on_checked = [&](bool) { - window->set_cursor(Gfx::StandardCursor::None); - }; - auto& radio_cursor_arrow = cursor_group_box.add<GUI::RadioButton>("Arrow"); - radio_cursor_arrow.on_checked = [&](bool) { - window->set_cursor(Gfx::StandardCursor::Arrow); - }; - auto& radio_crosshair_arrow = cursor_group_box.add<GUI::RadioButton>("Crosshair"); - radio_crosshair_arrow.on_checked = [&](bool) { - window->set_cursor(Gfx::StandardCursor::Crosshair); - }; - auto& radio_cursor_i_beam = cursor_group_box.add<GUI::RadioButton>("IBeam"); - radio_cursor_i_beam.on_checked = [&](bool) { - window->set_cursor(Gfx::StandardCursor::IBeam); - }; - auto& radio_cursor_resize_horizontal = cursor_group_box.add<GUI::RadioButton>("ResizeHorizontal"); - radio_cursor_resize_horizontal.on_checked = [&](bool) { - window->set_cursor(Gfx::StandardCursor::ResizeHorizontal); - }; - auto& radio_cursor_resize_vertical = cursor_group_box.add<GUI::RadioButton>("ResizeVertical"); - radio_cursor_resize_vertical.on_checked = [&](bool) { - window->set_cursor(Gfx::StandardCursor::ResizeVertical); - }; - auto& radio_cursor_resize_diagonal_tlbr = cursor_group_box.add<GUI::RadioButton>("ResizeDiagonalTLBR"); - radio_cursor_resize_diagonal_tlbr.on_checked = [&](bool) { - window->set_cursor(Gfx::StandardCursor::ResizeDiagonalTLBR); - }; - auto& radio_cursor_resize_diagonal_bltr = cursor_group_box.add<GUI::RadioButton>("ResizeDiagonalBLTR"); - radio_cursor_resize_diagonal_bltr.on_checked = [&](bool) { - window->set_cursor(Gfx::StandardCursor::ResizeDiagonalBLTR); - }; - auto& radio_cursor_resize_column = cursor_group_box.add<GUI::RadioButton>("ResizeColumn"); - radio_cursor_resize_column.on_checked = [&](bool) { - window->set_cursor(Gfx::StandardCursor::ResizeColumn); - }; - auto& radio_cursor_resize_row = cursor_group_box.add<GUI::RadioButton>("ResizeRow"); - radio_cursor_resize_row.on_checked = [&](bool) { - window->set_cursor(Gfx::StandardCursor::ResizeRow); - }; - auto& radio_cursor_hand = cursor_group_box.add<GUI::RadioButton>("Hand"); - radio_cursor_hand.on_checked = [&](bool) { - window->set_cursor(Gfx::StandardCursor::Hand); - }; - auto& radio_cursor_help = cursor_group_box.add<GUI::RadioButton>("Help"); - radio_cursor_help.on_checked = [&](bool) { - window->set_cursor(Gfx::StandardCursor::Help); - }; - auto& radio_cursor_drag = cursor_group_box.add<GUI::RadioButton>("Drag"); - radio_cursor_drag.on_checked = [&](bool) { - window->set_cursor(Gfx::StandardCursor::Drag); - }; - auto& radio_cursor_move = cursor_group_box.add<GUI::RadioButton>("Move"); - radio_cursor_move.on_checked = [&](bool) { - window->set_cursor(Gfx::StandardCursor::Move); - }; - auto& radio_cursor_wait = cursor_group_box.add<GUI::RadioButton>("Wait"); - radio_cursor_wait.on_checked = [&](bool) { - window->set_cursor(Gfx::StandardCursor::Wait); - }; - - app->set_menubar(move(menubar)); - - window->show(); - - return app->exec(); -} |