opuntiaOS - an operating system targeting x86 and ARMv7
at master 72 lines 2.8 kB view raw
1#include "IconView.h" 2#include "AppListView.h" 3#include <libui/App.h> 4#include <libui/Context.h> 5#include <libui/Label.h> 6#include <libui/Screen.h> 7#include <libui/Window.h> 8 9IconView::IconView(View* superview, const LG::Rect& frame) 10 : View(superview, frame) 11{ 12} 13 14void IconView::display(const LG::Rect& rect) 15{ 16 const int padding = 4; 17 const int offset_x = (AppListView::icon_view_size() - AppListView::icon_size()) / 2; 18 const int offset_y = (AppListView::icon_view_size() - AppListView::icon_size()) / 2; 19 LG::Context ctx = UI::graphics_current_context(); 20 ctx.add_clip(rect); 21 22 if (is_hovered()) { 23 auto rect = LG::Rect(padding, padding, AppListView::icon_view_size() - 2 * padding, AppListView::icon_view_size() - 2 * padding); 24 ctx.set_fill_color(LG::Color::White); 25 ctx.fill_rounded(rect, LG::CornerMask(6)); 26 ctx.set_fill_color(LG::Color(120, 129, 133, 60)); 27 ctx.draw_box_shading(rect, LG::Shading(LG::Shading::Type::Box, 0, 2), LG::CornerMask(6)); 28 } 29 30 ctx.draw({ offset_x, offset_y }, m_launch_entity.icon()); 31 32 ctx.set_fill_color(LG::Color(120, 129, 133)); 33 const int underline_y = AppListView::icon_view_size() - underline_height() - padding; 34 if (entity().windows().size() > 1) { 35 const int len = 10; 36 ctx.fill({ (AppListView::icon_view_size() - len) / 2, underline_y, len - underline_height(), underline_height() }); 37 ctx.fill({ (AppListView::icon_view_size() - len) / 2 + len, underline_y, underline_height(), underline_height() }); 38 } else if (entity().windows().size() > 0) { 39 const int len = 10; 40 ctx.fill({ (AppListView::icon_view_size() - len) / 2, underline_y, len, underline_height() }); 41 } 42} 43 44void IconView::on_click() 45{ 46 if (entity().windows().empty()) { 47 launch(); 48 return; 49 } else { 50 auto demo_menu = UI::Menu(); 51 for (auto& win : entity().windows()) { 52 auto title = win.title(); 53 int this_window_id = window()->id(); 54 int target_window_id = win.window_id(); 55 56 if (win.is_minimized()) { 57 title += " - minimized"; 58 } 59 60 demo_menu.add_item(UI::MenuItem(title, [this, this_window_id, target_window_id] { 61 auto& app = UI::App::the(); 62 AskBringToFrontMessage msg(app.connection().key(), this_window_id, target_window_id); 63 // this->entity().set_minimized(false); 64 app.connection().send_async_message(msg); 65 })); 66 } 67 demo_menu.add_item(UI::MenuItem("New window", [this] { 68 launch(); 69 })); 70 window()->popup_manager().show({ frame().min_x(), (int)UI::Screen::main().bounds().height() - (int)AppListView::dock_view_height() - 4 }, demo_menu); 71 } 72}