Create Point, Area, Rect via 'from_xml' functions

By using the new functions provided by the base API, this patch removes
the dependency of several components from include/decorator/xml_utils.h.

Issue #4584
This commit is contained in:
Norman Feske 2022-08-17 13:33:58 +02:00 committed by Christian Helmuth
parent f64d1bbc30
commit 08279e6288
17 changed files with 32 additions and 100 deletions

View File

@ -1,8 +1,2 @@
SRC_DIR := src/app/backdrop
include $(GENODE_DIR)/repos/base/recipes/src/content.inc
content: include/decorator
include/decorator:
mkdir -p $@
cp $(GENODE_DIR)/repos/os/include/decorator/* $@

View File

@ -1,11 +1,7 @@
SRC_DIR := src/app/menu_view
include $(GENODE_DIR)/repos/base/recipes/src/content.inc
content: include/decorator include/polygon_gfx
include/decorator:
mkdir -p $@
cp $(GENODE_DIR)/repos/os/include/decorator/* $@
content: include/polygon_gfx
include/polygon_gfx:
mkdir -p $@

View File

@ -1,10 +1,2 @@
SRC_DIR := src/app/window_layouter
include $(GENODE_DIR)/repos/base/recipes/src/content.inc
DECORATOR_INCLUDES := $(addprefix include/decorator/,xml_utils.h types.h)
content: $(DECORATOR_INCLUDES)
$(DECORATOR_INCLUDES):
mkdir -p $(dir $@)
cp $(GENODE_DIR)/repos/os/$@ $@

View File

@ -17,7 +17,6 @@
#include <base/attached_rom_dataspace.h>
#include <gui_session/connection.h>
#include <util/misc_math.h>
#include <decorator/xml_utils.h>
#include <nitpicker_gfx/box_painter.h>
#include <nitpicker_gfx/texture_painter.h>
#include <base/attached_dataspace.h>
@ -262,7 +261,7 @@ void Backdrop::Main::_apply_image(Xml_node operation)
: anchor.vertical == Anchor::HIGH ? v_gap
: 0;
Point const offset = Decorator::point_attribute(operation);
Point const offset = Point::from_xml(operation);
Point const pos = Point(anchored_xpos, anchored_ypos) + offset;

View File

@ -232,7 +232,7 @@ find_hover(Genode::Xml_node pointer_node, Decorator::Window_stack &window_stack)
|| !pointer_node.has_attribute("ypos"))
return Decorator::Window_base::Hover();
return window_stack.hover(Decorator::point_attribute(pointer_node));
return window_stack.hover(Decorator::Point::from_xml(pointer_node));
}

View File

@ -202,7 +202,7 @@ bool Decorator::Window::update(Genode::Xml_node window_node)
/*
* Detect geometry changes
*/
Rect new_geometry = rect_attribute(window_node);
Rect new_geometry = Rect::from_xml(window_node);
if (new_geometry.p1() != geometry().p1()
|| new_geometry.p2() != geometry().p2()) {

View File

@ -255,14 +255,10 @@ void Menu_view::Main::_handle_dialog_update()
{
_styles.flush_outdated_styles();
try {
Xml_node const config = _config.xml();
Xml_node const config = _config.xml();
_position = Decorator::point_attribute(config);
_configured_size = Area(config.attribute_value("width", 0U),
config.attribute_value("height", 0U));
} catch (...) { }
_position = Point::from_xml(config);
_configured_size = Area ::from_xml(config);
_dialog_rom.update();

View File

@ -17,7 +17,6 @@
/* Genode includes */
#include <gui_session/connection.h>
#include <util/misc_math.h>
#include <decorator/xml_utils.h>
#include <nitpicker_gfx/box_painter.h>
#include <nitpicker_gfx/texture_painter.h>
#include <base/attached_rom_dataspace.h>

View File

@ -302,25 +302,22 @@ Dialog::Hover_result Graph::hover(Xml_node hover)
/* update anchor geometry of popup menu */
auto hovered_rect = [] (Xml_node const dialog)
{
if (!dialog.has_type("dialog")) return Rect();
if (!dialog.has_type("dialog"))
return Rect();
auto point_from_xml = [] (Xml_node node) {
return Point((int)node.attribute_value("xpos", 0L),
(int)node.attribute_value("ypos", 0L)); };
if (!dialog.has_sub_node("depgraph"))
return Rect();
auto area_from_xml = [] (Xml_node node) {
return Area(node.attribute_value("width", 0U),
node.attribute_value("height", 0U)); };
if (!dialog.has_sub_node("depgraph")) return Rect();
Xml_node const depgraph = dialog.sub_node("depgraph");
if (!depgraph.has_sub_node("button")) return Rect();
if (!depgraph.has_sub_node("button"))
return Rect();
Xml_node const button = depgraph.sub_node("button");
return Rect(point_from_xml(dialog) + point_from_xml(depgraph) +
point_from_xml(button),
area_from_xml(button));
return Rect(Point::from_xml(dialog) + Point::from_xml(depgraph) +
Point::from_xml(button),
Area::from_xml(button));
};
_popup_anchor = hovered_rect(hover);

View File

@ -1289,9 +1289,7 @@ void Sculpt::Main::_handle_window_layout()
_window_list.update();
Xml_node const window_list = _window_list.xml();
auto win_size = [&] (Xml_node win) {
return Area(win.attribute_value("width", 0U),
win.attribute_value("height", 0U)); };
auto win_size = [&] (Xml_node win) { return Area::from_xml(win); };
unsigned panel_height = 0;
_with_window(window_list, panel_view_label, [&] (Xml_node win) {

View File

@ -217,7 +217,7 @@ find_hover(Genode::Xml_node pointer_node, Decorator::Window_stack &window_stack)
|| !pointer_node.has_attribute("ypos"))
return Decorator::Window_base::Hover();
return window_stack.hover(Decorator::point_attribute(pointer_node));
return window_stack.hover(Decorator::Point::from_xml(pointer_node));
}

View File

@ -149,8 +149,8 @@ Decorator::Theme::Margins Decorator::Theme::decor_margins() const
Decorator::Rect Decorator::Theme::title_geometry() const
{
static Genode::Xml_node node = metadata(_alloc);
static Rect rect = node.has_sub_node("title")
? rect_attribute(node.sub_node("title"))
static Rect rect = node.has_sub_node("title")
? Rect::from_xml(node.sub_node("title"))
: Rect(Point(0, 0), Area(0, 0));
return rect;
}
@ -168,7 +168,7 @@ element_geometry(Genode::Ram_allocator &ram, Genode::Region_map &rm,
if (!node.has_sub_node(sub_node_type))
return Rect(Point(0, 0), Area(0, 0));
return Rect(point_attribute(node.sub_node(sub_node_type)),
return Rect(Point::from_xml(node.sub_node(sub_node_type)),
texture_by_id(ram, rm, alloc, texture_id).size());
}

View File

@ -511,7 +511,7 @@ class Decorator::Window : public Window_base, public Animator::Item
_motion = _config.motion(_title);
Rect const old_geometry = geometry();
Rect const new_geometry = rect_attribute(window_node);
Rect const new_geometry = Rect::from_xml(window_node);
geometry(new_geometry);

View File

@ -81,8 +81,8 @@ class Window_layouter::Assign : public List_model<Assign>::Element
_maximized = assign.attribute_value("maximized", false);
_xpos_any = assign.attribute_value("xpos", String<20>()) == "any";
_ypos_any = assign.attribute_value("ypos", String<20>()) == "any";
_pos = point_attribute(assign);
_size = area_attribute(assign);
_pos = Point::from_xml(assign);
_size = Area::from_xml(assign);
}
/*

View File

@ -15,19 +15,15 @@
#define _TYPES_H_
/* Genode includes */
#include <decorator/types.h>
#include <decorator/xml_utils.h>
#include <os/surface.h>
namespace Window_layouter {
using namespace Genode;
typedef Decorator::Point Point;
typedef Decorator::Area Area;
typedef Decorator::Rect Rect;
using Decorator::area_attribute;
using Decorator::point_attribute;
typedef Surface_base::Point Point;
typedef Surface_base::Area Area;
typedef Surface_base::Rect Rect;
struct Window_id
{

View File

@ -72,7 +72,7 @@ class Window_layouter::Window_list
Window &create_element(Xml_node node)
{
unsigned const id = node.attribute_value("id", 0U);
Area const initial_size = area_attribute(node);
Area const initial_size = Area::from_xml(node);
Window::Label const label =
node.attribute_value("label",Window::Label());
@ -85,7 +85,7 @@ class Window_layouter::Window_list
void update_element(Window &win, Xml_node node)
{
win.client_size(area_attribute(node));
win.client_size(Area::from_xml(node));
win.title (node.attribute_value("title", Window::Title("")));
win.has_alpha (node.attribute_value("has_alpha", false));
win.hidden (node.attribute_value("hidden", false));

View File

@ -16,42 +16,7 @@
#include <decorator/types.h>
namespace Decorator {
static Point point_attribute(Xml_node const &);
static Area area_attribute(Xml_node const &);
static Rect rect_attribute(Xml_node const &);
static Color color(Xml_node const &);
}
/**
* Read point position from XML node
*/
static inline Decorator::Point Decorator::point_attribute(Genode::Xml_node const &point)
{
return Point((int)point.attribute_value("xpos", 0L),
(int)point.attribute_value("ypos", 0L)); }
/**
* Read area size from XML node
*/
static inline Decorator::Area Decorator::area_attribute(Genode::Xml_node const &area)
{
return Area(area.attribute_value("width", 0U),
area.attribute_value("height", 0U));
}
/**
* Read rectangle coordinates from XML node
*/
static inline Decorator::Rect Decorator::rect_attribute(Genode::Xml_node const &rect)
{
return Rect(point_attribute(rect), area_attribute(rect));
}
namespace Decorator { static Color color(Xml_node const &); }
/**