Serenity Operating System
at hosted 111 lines 3.8 kB view raw
1/* 2 * Copyright (c) 2020-2020, Hüseyin Aslıtürk <asliturk@hotmail.com> 3 * All rights reserved. 4 * 5 * Redistribution and use in source and binary forms, with or without 6 * modification, are permitted provided that the following conditions are met: 7 * 8 * 1. Redistributions of source code must retain the above copyright notice, this 9 * list of conditions and the following disclaimer. 10 * 11 * 2. Redistributions in binary form must reproduce the above copyright notice, 12 * this list of conditions and the following disclaimer in the documentation 13 * and/or other materials provided with the distribution. 14 * 15 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 16 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 17 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 18 * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE 19 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 20 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 21 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 22 * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 23 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 24 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 25 */ 26 27#include "MonitorWidget.h" 28#include <LibGUI/Painter.h> 29 30//#define DEBUG_MODE 31 32MonitorWidget::MonitorWidget() 33{ 34 m_monitor_bitmap = Gfx::Bitmap::load_from_file("/res/monitor.png"); 35 m_monitor_rect = { 8, 9, 320, 180 }; 36} 37 38void MonitorWidget::set_wallpaper(String path) 39{ 40 m_desktop_wallpaper_path = path; 41 m_desktop_wallpaper_bitmap = Gfx::Bitmap::load_from_file(path); 42} 43 44String MonitorWidget::wallpaper() 45{ 46 return m_desktop_wallpaper_path; 47} 48 49void MonitorWidget::set_wallpaper_mode(String mode) 50{ 51 m_desktop_wallpaper_mode = mode; 52} 53 54String MonitorWidget::wallpaper_mode() 55{ 56 return m_desktop_wallpaper_mode; 57} 58 59void MonitorWidget::set_desktop_resolution(Gfx::Size resolution) 60{ 61 m_desktop_resolution = resolution; 62} 63 64Gfx::Size MonitorWidget::desktop_resolution() 65{ 66 return m_desktop_resolution; 67} 68 69void MonitorWidget::set_background_color(Gfx::Color color) 70{ 71 m_desktop_color = color; 72} 73 74Gfx::Color MonitorWidget::background_color() 75{ 76 return m_desktop_color; 77} 78 79void MonitorWidget::paint_event(GUI::PaintEvent& event) 80{ 81#ifdef DEBUG_MODE 82 dbg() << "Paint event fired." 83 << " Color:" << m_desktop_color.to_string() << "." 84 << " Resolution:" << m_desktop_resolution.to_string() << "." 85 << " Wallpaper:" << m_desktop_wallpaper_path << "."; 86#endif 87 88 GUI::Painter painter(*this); 89 painter.add_clip_rect(event.rect()); 90 91 painter.blit({ 0, 0 }, *m_monitor_bitmap, m_monitor_bitmap->rect()); 92 93 painter.fill_rect(m_monitor_rect, m_desktop_color); 94 95 if (!m_desktop_wallpaper_bitmap.is_null()) { 96 if (m_desktop_wallpaper_mode == "simple") { 97 painter.blit({ 8, 9 }, *m_desktop_wallpaper_bitmap, { 88, 51, 200, 150 }); 98 } else if (m_desktop_wallpaper_mode == "center") { 99 painter.draw_scaled_bitmap({ 88, 51, 160, 90 }, *m_desktop_wallpaper_bitmap, m_desktop_wallpaper_bitmap->rect()); 100 } else if (m_desktop_wallpaper_mode == "tile") { 101 painter.draw_tiled_bitmap(m_monitor_rect, *m_desktop_wallpaper_bitmap); 102 } else if (m_desktop_wallpaper_mode == "scaled") { 103 painter.draw_scaled_bitmap(m_monitor_rect, *m_desktop_wallpaper_bitmap, m_desktop_wallpaper_bitmap->rect()); 104 } else { 105 ASSERT_NOT_REACHED(); 106 } 107 } 108 109 if (!m_desktop_resolution.is_null()) 110 painter.draw_text(m_monitor_rect, m_desktop_resolution.to_string(), Gfx::TextAlignment::Center); 111}