From 35bfc34db55e09865d0b3be3d4a4c392ea8c33b4 Mon Sep 17 00:00:00 2001 From: Norman Feske Date: Sat, 28 Dec 2013 19:01:25 +0100 Subject: [PATCH] Move nitpicker_gfx/geometry.h to util/geometry.h This patch makes nitpicker's geometry utilities available for the use by other programs. Thereby, the 'Point', 'Area', and 'Rect' classes have become templates that take the coordinate type and distance type as arguments. --- demo/src/server/nitlog/main.cc | 8 + os/include/nitpicker_gfx/canvas.h | 19 ++- os/include/nitpicker_gfx/geometry.h | 156 -------------------- os/include/util/geometry.h | 179 +++++++++++++++++++++++ os/src/server/nitpicker/background.h | 4 +- os/src/server/nitpicker/chunky_menubar.h | 2 +- os/src/server/nitpicker/clip_guard.h | 9 +- os/src/server/nitpicker/draw_label.h | 16 +- os/src/server/nitpicker/main.cc | 56 +++---- os/src/server/nitpicker/menubar.h | 13 +- os/src/server/nitpicker/mouse_cursor.h | 4 +- os/src/server/nitpicker/session.h | 7 +- os/src/server/nitpicker/user_state.cc | 6 +- os/src/server/nitpicker/user_state.h | 4 +- os/src/server/nitpicker/view.cc | 12 +- os/src/server/nitpicker/view.h | 33 +++-- os/src/server/nitpicker/view_stack.cc | 6 +- os/src/server/nitpicker/view_stack.h | 6 +- ports/src/vancouver/console.cc | 4 +- 19 files changed, 296 insertions(+), 248 deletions(-) delete mode 100644 os/include/nitpicker_gfx/geometry.h create mode 100644 os/include/util/geometry.h diff --git a/demo/src/server/nitlog/main.cc b/demo/src/server/nitlog/main.cc index 503a10cafe..b9fd9117ee 100644 --- a/demo/src/server/nitlog/main.cc +++ b/demo/src/server/nitlog/main.cc @@ -101,6 +101,10 @@ class Log_entry int label_w = default_font.str_w(_label); int label_h = default_font.str_h(_label); + typedef Canvas::Rect Rect; + typedef Canvas::Area Area; + typedef Canvas::Point Point; + if (new_section) { canvas->draw_box(Rect(Point(1, y), Area(label_w + 2, label_h - 1)), label_bgcol); canvas->draw_string(Point(1, y - 1), default_font, label_fgcol, _label); @@ -359,6 +363,10 @@ int main(int argc, char **argv) */ static Sliced_heap sliced_heap(env()->ram_session(), env()->rm_session()); + typedef Canvas::Point Point; + typedef Canvas::Area Area; + typedef Canvas::Rect Rect; + /* create log window */ void *addr = env()->rm_session()->attach(nitpicker.framebuffer()->dataspace()); static Chunky_canvas canvas((Pixel_rgb565 *)addr, diff --git a/os/include/nitpicker_gfx/canvas.h b/os/include/nitpicker_gfx/canvas.h index 04a3522e79..8797e1252d 100644 --- a/os/include/nitpicker_gfx/canvas.h +++ b/os/include/nitpicker_gfx/canvas.h @@ -14,17 +14,18 @@ #ifndef _INCLUDE__NITPICKER_GFX__CANVAS_H_ #define _INCLUDE__NITPICKER_GFX__CANVAS_H_ +#include + #include #include #include -#include -class Texture : public Area +class Texture : public Genode::Area<> { public: - Texture(Area size): Area(size) { } + Texture(Area<> size): Area<>(size) { } virtual ~Texture() { } @@ -42,6 +43,12 @@ class Texture : public Area */ class Canvas { + public: + + typedef Genode::Point<> Point; + typedef Genode::Area<> Area; + typedef Genode::Rect<> Rect; + protected: Rect _clip; /* clipping area */ @@ -50,8 +57,7 @@ class Canvas /** * Constructor */ - Canvas(Area size): - _clip(Point(0, 0), size), _size(size) { } + Canvas(Area size) : _clip(Point(0, 0), size), _size(size) { } /** * Register canvas area as to be flushed @@ -86,7 +92,8 @@ class Canvas /** * Define/request clipping rectangle */ - void clip(Rect clip) { _clip = Rect::intersect(Rect(Point(0, 0), _size), clip); } + void clip(Rect clip) { + _clip = Rect::intersect(Rect(Point(0, 0), _size), clip); } Rect clip() const { return _clip; } bool clip_valid() const { return _clip.valid(); } diff --git a/os/include/nitpicker_gfx/geometry.h b/os/include/nitpicker_gfx/geometry.h deleted file mode 100644 index 25d27bbaa0..0000000000 --- a/os/include/nitpicker_gfx/geometry.h +++ /dev/null @@ -1,156 +0,0 @@ -/* - * \brief Geometric primitives - * \author Norman Feske - * \date 2006-08-05 - */ - -/* - * Copyright (C) 2006-2013 Genode Labs GmbH - * - * This file is part of the Genode OS framework, which is distributed - * under the terms of the GNU General Public License version 2. - */ - -#ifndef _INCLUDE__NITPICKER_GFX__GEOMETRY_H_ -#define _INCLUDE__NITPICKER_GFX__GEOMETRY_H_ - -#include "miscmath.h" - -class Point -{ - private: - - int _x, _y; - - public: - - Point(int x, int y): _x(x), _y(y) { } - Point(): _x(0), _y(0) { } - - int x() const { return _x; } - int y() const { return _y; } - - /** - * Operator for adding points - */ - Point operator + (Point const &p) const { return Point(_x + p.x(), _y + p.y()); } - - /** - * Operator for subtracting points - */ - Point operator - (Point const &p) const { return Point(_x - p.x(), _y - p.y()); } - - /** - * Operator for testing non-equality of two points - */ - bool operator != (Point const &p) const { return p.x() != _x || p.y() != _y; } -}; - - -class Area -{ - private: - - int const _w, _h; - - public: - - Area(int w, int h): _w(w), _h(h) { } - Area(): _w(0), _h(0) { } - - int w() const { return _w; } - int h() const { return _h; } - - bool valid() const { return _w > 0 && _h > 0; } - - int num_pixels() const { return _w*_h; } -}; - - -/* - * A valid rectangle consists of two points wheras point 2 has - * higher or equal coordinates than point 1. All other cases - * are threated as invalid rectangles. - */ -class Rect -{ - private: - - Point _p1, _p2; - - public: - - /** - * Constructors - */ - Rect(Point p1, Point p2): _p1(p1), _p2(p2) { } - - Rect(Point p, Area a): - _p1(p), _p2(p.x() + a.w() - 1, p.y() + a.h() - 1) { } - - Rect() { } - - /** - * Accessors - */ - int x1() const { return _p1.x(); } - int y1() const { return _p1.y(); } - int x2() const { return _p2.x(); } - int y2() const { return _p2.y(); } - int w() const { return _p2.x() - _p1.x() + 1; } - int h() const { return _p2.y() - _p1.y() + 1; } - Point p1() const { return _p1; } - Point p2() const { return _p2; } - Area area() const { return Area(w(), h()); } - - /** - * Return true if rectangle area is greater than zero - */ - bool valid() const { return _p1.x() <= _p2.x() && _p1.y() <= _p2.y(); } - - /** - * Return true if area fits in rectangle - */ - bool fits(Area area) const { return w() >= area.w() && h() >= area.h(); } - - /** - * Create new rectangle by intersecting two rectangles - */ - static Rect intersect(Rect r1, Rect r2) { - return Rect(Point(max(r1.x1(), r2.x1()), max(r1.y1(), r2.y1())), - Point(min(r1.x2(), r2.x2()), min(r1.y2(), r2.y2()))); } - - /** - * Compute compounding rectangle of two rectangles - */ - static Rect compound(Rect r1, Rect r2) { - return Rect(Point(min(r1.x1(), r2.x1()), min(r1.y1(), r2.y1())), - Point(max(r1.x2(), r2.x2()), max(r1.y2(), r2.y2()))); } - - /** - * Cut out rectangle from rectangle - * - * \param r rectangle to cut out - * - * In the worst case (if we cut a hole into the rectangle) we get - * four valid resulting rectangles. - */ - void cut(Rect r, Rect *top, Rect *left, Rect *right, Rect *bottom) const - { - /* limit the cut-out area to the actual rectangle */ - r = intersect(r, *this); - - *top = Rect(Point(x1(), y1()), Point(x2(), r.y1() - 1)); - *left = Rect(Point(x1(), r.y1()), Point(r.x1() - 1, r.y2())); - *right = Rect(Point(r.x2() + 1, r.y1()), Point(x2(), r.y2())); - *bottom = Rect(Point(x1(), r.y2() + 1), Point(x2(), y2())); - } - - /** - * Return position of an area when centered within the rectangle - */ - Point center(Area area) const { - return Point((w() - area.w())/2, (h() - area.h())/2) + p1(); } -}; - -#endif /* _INCLUDE__NITPICKER_GFX__GEOMETRY_H_ */ diff --git a/os/include/util/geometry.h b/os/include/util/geometry.h new file mode 100644 index 0000000000..e38fd9898d --- /dev/null +++ b/os/include/util/geometry.h @@ -0,0 +1,179 @@ +/* + * \brief Geometric primitives + * \author Norman Feske + * \date 2006-08-05 + */ + +/* + * Copyright (C) 2006-2013 Genode Labs GmbH + * + * This file is part of the Genode OS framework, which is distributed + * under the terms of the GNU General Public License version 2. + */ + +#ifndef _INCLUDE__UTIL__GEOMETRY_H_ +#define _INCLUDE__UTIL__GEOMETRY_H_ + +#include +#include + +namespace Genode { + template class Point; + template class Area; + template class Rect; +} + + +/** + * \param CT coordinate type + */ +template +class Genode::Point +{ + private: + + CT _x, _y; + + public: + + Point(CT x, CT y): _x(x), _y(y) { } + Point(): _x(0), _y(0) { } + + int x() const { return _x; } + int y() const { return _y; } + + /** + * Operator for adding points + */ + Point operator + (Point const &p) const { return Point(_x + p.x(), _y + p.y()); } + + /** + * Operator for subtracting points + */ + Point operator - (Point const &p) const { return Point(_x - p.x(), _y - p.y()); } + + /** + * Operator for testing non-equality of two points + */ + bool operator != (Point const &p) const { return p.x() != _x || p.y() != _y; } +}; + + +/** + * \param DT distance type + */ +template +class Genode::Area +{ + private: + + DT _w, _h; + + public: + + Area(DT w, DT h): _w(w), _h(h) { } + Area(): _w(0), _h(0) { } + + DT w() const { return _w; } + DT h() const { return _h; } + + bool valid() const { return _w > 0 && _h > 0; } + + size_t count() const { return _w*_h; } +}; + + +/** + * Rectangle + * + * A valid rectangle consists of two points wheras point 2 has higher or equal + * coordinates than point 1. All other cases are threated as invalid + * rectangles. + * + * \param CT coordinate type + * \param DT distance type + */ +template +class Genode::Rect +{ + private: + + Point _p1, _p2; + + public: + + /** + * Constructors + */ + Rect(Point p1, Point p2): _p1(p1), _p2(p2) { } + + Rect(Point p, Area
a) + : _p1(p), _p2(p.x() + a.w() - 1, p.y() + a.h() - 1) { } + + Rect() { } + + /** + * Accessors + */ + CT x1() const { return _p1.x(); } + CT y1() const { return _p1.y(); } + CT x2() const { return _p2.x(); } + CT y2() const { return _p2.y(); } + DT w() const { return _p2.x() - _p1.x() + 1; } + DT h() const { return _p2.y() - _p1.y() + 1; } + Point p1() const { return _p1; } + Point p2() const { return _p2; } + Area
area() const { return Area
(w(), h()); } + + /** + * Return true if rectangle area is greater than zero + */ + bool valid() const { return _p1.x() <= _p2.x() && _p1.y() <= _p2.y(); } + + /** + * Return true if area fits in rectangle + */ + bool fits(Area
area) const { return w() >= area.w() && h() >= area.h(); } + + /** + * Create new rectangle by intersecting two rectangles + */ + static Rect intersect(Rect r1, Rect r2) { + return Rect(Point(max(r1.x1(), r2.x1()), max(r1.y1(), r2.y1())), + Point(min(r1.x2(), r2.x2()), min(r1.y2(), r2.y2()))); } + + /** + * Compute compounding rectangle of two rectangles + */ + static Rect compound(Rect r1, Rect r2) { + return Rect(Point(min(r1.x1(), r2.x1()), min(r1.y1(), r2.y1())), + Point(max(r1.x2(), r2.x2()), max(r1.y2(), r2.y2()))); } + + /** + * Cut out rectangle from rectangle + * + * \param r rectangle to cut out + * + * In the worst case (if we cut a hole into the rectangle) we get + * four valid resulting rectangles. + */ + void cut(Rect r, Rect *top, Rect *left, Rect *right, Rect *bottom) const + { + /* limit the cut-out area to the actual rectangle */ + r = intersect(r, *this); + + *top = Rect(Point(x1(), y1()), Point(x2(), r.y1() - 1)); + *left = Rect(Point(x1(), r.y1()), Point(r.x1() - 1, r.y2())); + *right = Rect(Point(r.x2() + 1, r.y1()), Point(x2(), r.y2())); + *bottom = Rect(Point(x1(), r.y2() + 1), Point(x2(), y2())); + } + + /** + * Return position of an area when centered within the rectangle + */ + Point center(Area
area) const { + return Point(((CT)w() - (CT)area.w())/2, + ((CT)h() - (CT)area.h())/2) + p1(); } +}; + +#endif /* _INCLUDE__UTIL__GEOMETRY_H_ */ diff --git a/os/src/server/nitpicker/background.h b/os/src/server/nitpicker/background.h index 4959d2f8ee..28750b840e 100644 --- a/os/src/server/nitpicker/background.h +++ b/os/src/server/nitpicker/background.h @@ -26,11 +26,11 @@ struct Background : private Texture, Session, View * we can pass a null pointer as texture argument * to the Session constructor. */ - Background(Area size) + Background(Canvas::Area size) : Texture(Area(0, 0)), Session(Genode::Session_label(""), 0, false), View(*this, View::NOT_STAY_TOP, View::NOT_TRANSPARENT, - View::BACKGROUND, Rect(Point(0, 0), size)), + View::BACKGROUND, Canvas::Rect(Canvas::Point(0, 0), size)), color(25, 37, 50) { } diff --git a/os/src/server/nitpicker/chunky_menubar.h b/os/src/server/nitpicker/chunky_menubar.h index 638cba97e9..6492adf0fa 100644 --- a/os/src/server/nitpicker/chunky_menubar.h +++ b/os/src/server/nitpicker/chunky_menubar.h @@ -27,7 +27,7 @@ class Chunky_menubar : public Chunky_texture, public: - Chunky_menubar(PT *pixels, Area size) + Chunky_menubar(PT *pixels, Canvas::Area size) : Chunky_texture(pixels, 0, size), Session(Genode::Session_label(""), 0, false), diff --git a/os/src/server/nitpicker/clip_guard.h b/os/src/server/nitpicker/clip_guard.h index 8c28f84982..d1aa30f670 100644 --- a/os/src/server/nitpicker/clip_guard.h +++ b/os/src/server/nitpicker/clip_guard.h @@ -34,17 +34,18 @@ class Clip_guard { private: - Canvas &_canvas; - Rect const _orig_clip_rect; + Canvas &_canvas; + + Canvas::Rect const _orig_clip_rect; public: - Clip_guard(Canvas &canvas, Rect new_clip_rect) + Clip_guard(Canvas &canvas, Canvas::Rect new_clip_rect) : _canvas(canvas), _orig_clip_rect(_canvas.clip()) { - _canvas.clip(Rect::intersect(_orig_clip_rect, new_clip_rect)); + _canvas.clip(Canvas::Rect::intersect(_orig_clip_rect, new_clip_rect)); } ~Clip_guard() { _canvas.clip(_orig_clip_rect); } diff --git a/os/src/server/nitpicker/draw_label.h b/os/src/server/nitpicker/draw_label.h index fd131176d4..af263418ea 100644 --- a/os/src/server/nitpicker/draw_label.h +++ b/os/src/server/nitpicker/draw_label.h @@ -24,12 +24,12 @@ enum { LABEL_GAP = 5 }; /** * Draw black outline of string */ -inline void draw_string_outline(Canvas &canvas, Point pos, const char *s) +inline void draw_string_outline(Canvas &canvas, Canvas::Point pos, const char *s) { for (int j = -1; j <= 1; j++) for (int i = -1; i <= 1; i++) if (i || j) - canvas.draw_string(pos + Point(i, j), default_font, BLACK, s); + canvas.draw_string(pos + Canvas::Point(i, j), default_font, BLACK, s); } @@ -39,9 +39,9 @@ inline void draw_string_outline(Canvas &canvas, Point pos, const char *s) * \param sl session label string * \param vt view title string */ -inline Area label_size(const char *sl, const char *vt) { - return Area(default_font.str_w(sl) + LABEL_GAP + default_font.str_w(vt) + 2, - default_font.str_h(sl) + 2); } +inline Canvas::Area label_size(const char *sl, const char *vt) { + return Canvas::Area(default_font.str_w(sl) + LABEL_GAP + default_font.str_w(vt) + 2, + default_font.str_h(sl) + 2); } /** @@ -52,16 +52,16 @@ inline Area label_size(const char *sl, const char *vt) { * policy. In contrast, the view title can individually be defined by the * application. */ -static void draw_label(Canvas &canvas, Point pos, +static void draw_label(Canvas &canvas, Canvas::Point pos, const char *session_label, Color session_label_color, const char *view_title, Color view_title_color) { - pos = pos + Point(1, 1); + pos = pos + Canvas::Point(1, 1); draw_string_outline(canvas, pos, session_label); canvas.draw_string(pos, default_font, session_label_color, session_label); - pos = pos + Point(default_font.str_w(session_label) + LABEL_GAP, 0); + pos = pos + Canvas::Point(default_font.str_w(session_label) + LABEL_GAP, 0); draw_string_outline(canvas, pos, view_title); canvas.draw_string(pos, default_font, view_title_color, view_title); diff --git a/os/src/server/nitpicker/main.cc b/os/src/server/nitpicker/main.cc index 427ece577f..480df98468 100644 --- a/os/src/server/nitpicker/main.cc +++ b/os/src/server/nitpicker/main.cc @@ -69,23 +69,23 @@ class Flush_merger { private: - Rect _to_be_flushed = { Point(), Area(-1, -1) }; + Canvas::Rect _to_be_flushed = { Canvas::Point(), Canvas::Area() }; public: bool defer = false; - Rect to_be_flushed() const { return _to_be_flushed; } + Canvas::Rect to_be_flushed() const { return _to_be_flushed; } - void merge(Rect rect) + void merge(Canvas::Rect rect) { if (_to_be_flushed.valid()) - _to_be_flushed = Rect::compound(_to_be_flushed, rect); + _to_be_flushed = Canvas::Rect::compound(_to_be_flushed, rect); else _to_be_flushed = rect; } - void reset() { _to_be_flushed = Rect(Point(), Area(-1, -1)); } + void reset() { _to_be_flushed = Canvas::Rect(Canvas::Point(), Canvas::Area()); } }; @@ -94,14 +94,14 @@ class Screen : public Chunky_canvas, public Flush_merger { protected: - virtual void _flush_pixels(Rect rect) { merge(rect); } + virtual void _flush_pixels(Canvas::Rect rect) { merge(rect); } public: /** * Constructor */ - Screen(PT *base, Area size) : Chunky_canvas(base, size) { } + Screen(PT *base, Canvas::Area size) : Chunky_canvas(base, size) { } }; @@ -109,7 +109,7 @@ class Buffer { private: - Area _size; + Canvas::Area _size; Framebuffer::Mode::Format _format; Genode::Attached_ram_dataspace _ram_ds; @@ -121,7 +121,7 @@ class Buffer * \throw Ram_session::Alloc_failed * \throw Rm_session::Attach_failed */ - Buffer(Area size, Framebuffer::Mode::Format format, Genode::size_t bytes) + Buffer(Canvas::Area size, Framebuffer::Mode::Format format, Genode::size_t bytes) : _size(size), _format(format), _ram_ds(Genode::env()->ram_session(), bytes) @@ -131,7 +131,7 @@ class Buffer * Accessors */ Genode::Ram_dataspace_capability ds_cap() const { return _ram_ds.cap(); } - Area size() const { return _size; } + Canvas::Area size() const { return _size; } Framebuffer::Mode::Format format() const { return _format; } void *local_addr() const { return _ram_ds.local_addr(); } }; @@ -160,7 +160,7 @@ class Chunky_dataspace_texture : public Buffer, public Chunky_texture /** * Return base address of alpha channel or 0 if no alpha channel exists */ - unsigned char *_alpha_base(Area size, bool use_alpha) + unsigned char *_alpha_base(Canvas::Area size, bool use_alpha) { if (!use_alpha) return 0; @@ -173,13 +173,13 @@ class Chunky_dataspace_texture : public Buffer, public Chunky_texture /** * Constructor */ - Chunky_dataspace_texture(Area size, bool use_alpha) + Chunky_dataspace_texture(Canvas::Area size, bool use_alpha) : Buffer(size, _format(), calc_num_bytes(size, use_alpha)), Chunky_texture((PT *)local_addr(), _alpha_base(size, use_alpha), size) { } - static Genode::size_t calc_num_bytes(Area size, bool use_alpha) + static Genode::size_t calc_num_bytes(Canvas::Area size, bool use_alpha) { /* * If using an alpha channel, the alpha buffer follows the @@ -353,11 +353,12 @@ class Framebuffer::Session_component : public Genode::Rpc_object void refresh(int x, int y, int w, int h) { _view_stack.update_session_views(_session, - Rect(Point(x, y), Area(w, h))); + Canvas::Rect(Canvas::Point(x, y), + Canvas::Area(w, h))); /* flush dirty pixels to physical frame buffer */ if (_flush_merger.defer == false) { - Rect r = _flush_merger.to_be_flushed(); + Canvas::Rect r = _flush_merger.to_be_flushed(); _framebuffer.refresh(r.x1(), r.y1(), r.w(), r.h()); _flush_merger.reset(); } @@ -387,7 +388,7 @@ class View_component : public Genode::List::Element, _view_stack(view_stack), _view(session, session.stay_top() ? ::View::STAY_TOP : ::View::NOT_STAY_TOP, - ::View::NOT_TRANSPARENT, ::View::NOT_BACKGROUND, Rect()), + ::View::NOT_TRANSPARENT, ::View::NOT_BACKGROUND, Canvas::Rect()), _ep(ep) { } ::View &view() { return _view; } @@ -403,8 +404,9 @@ class View_component : public Genode::List::Element, /* transpose y position by vertical session offset */ y += _view.session().v_offset(); - _view_stack.viewport(_view, Rect(Point(x, y), Area(w, h)), - Point(buf_x, buf_y), redraw); + _view_stack.viewport(_view, Canvas::Rect(Canvas::Point(x, y), + Canvas::Area(w, h)), + Canvas::Point(buf_x, buf_y), redraw); return 0; } @@ -637,7 +639,7 @@ class Nitpicker::Session_component : public Genode::Rpc_object, { _release_buffer(); - Area const size(mode.width(), mode.height()); + Canvas::Area const size(mode.width(), mode.height()); typedef Pixel_rgb565 PT; @@ -767,7 +769,7 @@ struct Nitpicker::Main void *fb_base = env()->rm_session()->attach(fb_ds_cap); - Screen screen = { (PT *)fb_base, Area(mode.width(), mode.height()) }; + Screen screen = { (PT *)fb_base, Canvas::Area(mode.width(), mode.height()) }; /* * Menu bar @@ -776,7 +778,7 @@ struct Nitpicker::Main PT *menubar_pixels = (PT *)env()->heap()->alloc(sizeof(PT)*mode.width()*16); - Chunky_menubar menubar = { menubar_pixels, Area(mode.width(), MENUBAR_HEIGHT) }; + Chunky_menubar menubar = { menubar_pixels, Canvas::Area(mode.width(), MENUBAR_HEIGHT) }; /* * User-input policy @@ -790,7 +792,7 @@ struct Nitpicker::Main /* * Create view stack with default elements */ - Area mouse_size { big_mouse.w, big_mouse.h }; + Canvas::Area mouse_size { big_mouse.w, big_mouse.h }; Mouse_cursor mouse_cursor { (PT *)&big_mouse.pixels[0][0], mouse_size, user_state }; @@ -859,23 +861,23 @@ void Nitpicker::Main::handle_input(unsigned) return; do { - Point const old_mouse_pos = user_state.mouse_pos(); + Canvas::Point const old_mouse_pos = user_state.mouse_pos(); /* handle batch of pending events */ if (input.is_pending()) import_input_events(ev_buf, input.flush(), user_state); - Point const new_mouse_pos = user_state.mouse_pos(); + Canvas::Point const new_mouse_pos = user_state.mouse_pos(); /* update mouse cursor */ if (old_mouse_pos != new_mouse_pos) user_state.viewport(mouse_cursor, - Rect(new_mouse_pos, mouse_size), - Point(), true); + Canvas::Rect(new_mouse_pos, mouse_size), + Canvas::Point(), true); /* flush dirty pixels to physical frame buffer */ if (screen.defer == false) { - Rect const r = screen.to_be_flushed(); + Canvas::Rect const r = screen.to_be_flushed(); if (r.valid()) framebuffer.refresh(r.x1(), r.y1(), r.w(), r.h()); screen.reset(); diff --git a/os/src/server/nitpicker/menubar.h b/os/src/server/nitpicker/menubar.h index 00162be014..533c917303 100644 --- a/os/src/server/nitpicker/menubar.h +++ b/os/src/server/nitpicker/menubar.h @@ -26,10 +26,10 @@ class Menubar : public View protected: - Menubar(Canvas &canvas, Area size, Session &session) + Menubar(Canvas &canvas, Canvas::Area size, Session &session) : View(session, View::STAY_TOP, View::NOT_TRANSPARENT, - View::NOT_BACKGROUND, Rect(Point(0, 0), size)), + View::NOT_BACKGROUND, Canvas::Rect(Canvas::Point(0, 0), size)), _canvas(canvas) { } @@ -47,19 +47,20 @@ class Menubar : public View int b = (mode.kill()) ? 70 : (mode.xray()) ? session_color.b : (session_color.b + 100) >> 1; /* highlight first line with slightly brighter color */ - _canvas.draw_box(Rect(Point(0, 0), Area(w(), 1)), + _canvas.draw_box(Canvas::Rect(Canvas::Point(0, 0), Canvas::Area(w(), 1)), Color(r + (r / 2), g + (g / 2), b + (b / 2))); /* draw slightly shaded background */ - for (int i = 1; i < h() - 1; i++) { + for (unsigned i = 1; i < h() - 1; i++) { r -= r > 3 ? 4 : 0; g -= g > 3 ? 4 : 0; b -= b > 4 ? 4 : 0; - _canvas.draw_box(Rect(Point(0, i), Area(w(), 1)), Color(r, g, b)); + _canvas.draw_box(Canvas::Rect(Canvas::Point(0, i), + Canvas::Area(w(), 1)), Color(r, g, b)); } /* draw last line darker */ - _canvas.draw_box(Rect(Point(0, h() - 1), Area(w(), 1)), + _canvas.draw_box(Canvas::Rect(Canvas::Point(0, h() - 1), Canvas::Area(w(), 1)), Color(r / 4, g / 4, b / 4)); /* draw label */ diff --git a/os/src/server/nitpicker/mouse_cursor.h b/os/src/server/nitpicker/mouse_cursor.h index ea6647e424..327b8cb588 100644 --- a/os/src/server/nitpicker/mouse_cursor.h +++ b/os/src/server/nitpicker/mouse_cursor.h @@ -34,12 +34,12 @@ class Mouse_cursor : public Chunky_texture, public Session, public View /** * Constructor */ - Mouse_cursor(PT const *pixels, Area size, View_stack const &view_stack) + Mouse_cursor(PT const *pixels, Canvas::Area size, View_stack const &view_stack) : Chunky_texture(pixels, 0, size), Session(Genode::Session_label(""), 0, false), View(*this, View::STAY_TOP, View::TRANSPARENT, View::NOT_BACKGROUND, - Rect()), + Canvas::Rect()), _view_stack(view_stack) { } diff --git a/os/src/server/nitpicker/session.h b/os/src/server/nitpicker/session.h index ab470f4d4f..5d9c666a06 100644 --- a/os/src/server/nitpicker/session.h +++ b/os/src/server/nitpicker/session.h @@ -18,7 +18,6 @@ #include #include #include -#include #include #include #include @@ -103,13 +102,13 @@ class Session : public Session_list::Element /** * Return input mask value at specified buffer position */ - unsigned char input_mask_at(Point p) const + unsigned char input_mask_at(Canvas::Point p) const { if (!_input_mask || !_texture) return 0; /* check boundaries */ - if (p.x() < 0 || p.x() >= _texture->w() - || p.y() < 0 || p.y() >= _texture->h()) + if ((unsigned)p.x() >= _texture->w() + || (unsigned)p.y() >= _texture->h()) return 0; return _input_mask[p.y()*_texture->w() + p.x()]; diff --git a/os/src/server/nitpicker/user_state.cc b/os/src/server/nitpicker/user_state.cc index 96bef32b8f..100fb85943 100644 --- a/os/src/server/nitpicker/user_state.cc +++ b/os/src/server/nitpicker/user_state.cc @@ -57,8 +57,8 @@ void User_state::handle_event(Input::Event ev) /* transparently handle absolute and relative motion events */ if (type == Event::MOTION) { if ((ev.rx() || ev.ry()) && ev.ax() == 0 && ev.ay() == 0) { - ax = max(0, min(size().w(), ax + ev.rx())); - ay = max(0, min(size().h(), ay + ev.ry())); + ax = max(0, min((int)size().w(), ax + ev.rx())); + ay = max(0, min((int)size().h(), ay + ev.ry())); } else { ax = ev.ax(); ay = ev.ay(); @@ -74,7 +74,7 @@ void User_state::handle_event(Input::Event ev) /* create the mangled event */ ev = Input::Event(type, keycode, ax, ay, rx, ry); - _mouse_pos = Point(ax, ay); + _mouse_pos = Canvas::Point(ax, ay); /* count keys */ if (type == Event::PRESS) _key_cnt++; diff --git a/os/src/server/nitpicker/user_state.h b/os/src/server/nitpicker/user_state.h index cec44bb349..827e036e2c 100644 --- a/os/src/server/nitpicker/user_state.h +++ b/os/src/server/nitpicker/user_state.h @@ -51,7 +51,7 @@ class User_state : public Mode, public View_stack /* * Current mouse cursor position */ - Point _mouse_pos; + Canvas::Point _mouse_pos; /* * Currently pointed-at view @@ -86,7 +86,7 @@ class User_state : public Mode, public View_stack /** * Accessors */ - Point mouse_pos() { return _mouse_pos; } + Canvas::Point mouse_pos() { return _mouse_pos; } /** * Mode interface diff --git a/os/src/server/nitpicker/view.cc b/os/src/server/nitpicker/view.cc index 8254a2e722..0ae92a79e6 100644 --- a/os/src/server/nitpicker/view.cc +++ b/os/src/server/nitpicker/view.cc @@ -28,17 +28,17 @@ */ static void draw_rect(Canvas &canvas, int x, int y, int w, int h, Color color) { - canvas.draw_box(Rect(Point(x, y), Area(w, 1)), color); - canvas.draw_box(Rect(Point(x, y), Area(1, h)), color); - canvas.draw_box(Rect(Point(x + w - 1, y), Area(1, h)), color); - canvas.draw_box(Rect(Point(x, y + h - 1), Area(w, 1)), color); + canvas.draw_box(Canvas::Rect(Canvas::Point(x, y), Canvas::Area(w, 1)), color); + canvas.draw_box(Canvas::Rect(Canvas::Point(x, y), Canvas::Area(1, h)), color); + canvas.draw_box(Canvas::Rect(Canvas::Point(x + w - 1, y), Canvas::Area(1, h)), color); + canvas.draw_box(Canvas::Rect(Canvas::Point(x, y + h - 1), Canvas::Area(w, 1)), color); } /** * Draw outlined frame with black outline color */ -static void draw_frame(Canvas &canvas, Rect r, Color color, int frame_size) +static void draw_frame(Canvas &canvas, Canvas::Rect r, Color color, int frame_size) { /* draw frame around the view */ int d = frame_size; @@ -58,7 +58,7 @@ void View::title(const char *title) Genode::strncpy(_title, title, TITLE_LEN); /* calculate label size, the position is defined by the view stack */ - _label_rect = Rect(Point(0, 0), label_size(_session.label().string(), _title)); + _label_rect = Canvas::Rect(Canvas::Point(0, 0), label_size(_session.label().string(), _title)); } diff --git a/os/src/server/nitpicker/view.h b/os/src/server/nitpicker/view.h index d2945f3782..dd10707ecc 100644 --- a/os/src/server/nitpicker/view.h +++ b/os/src/server/nitpicker/view.h @@ -16,8 +16,8 @@ #include #include + #include -#include #include "mode.h" #include "session.h" @@ -35,7 +35,9 @@ struct Same_buffer_list_elem : Genode::List::Element { }; struct View_stack_elem : Genode::List::Element { }; -class View : public Same_buffer_list_elem, public View_stack_elem, public Rect +class View : public Same_buffer_list_elem, + public View_stack_elem, + public Canvas::Rect { public: @@ -51,10 +53,10 @@ class View : public Same_buffer_list_elem, public View_stack_elem, public Rect Transparent const _transparent; /* background is partly visible */ Background _background; /* view is a background view */ - Rect _label_rect; /* position and size of label */ - Point _buffer_off; /* offset to the visible buffer area */ - Session &_session; /* session that created the view */ - char _title[TITLE_LEN]; + Canvas::Rect _label_rect; /* position and size of label */ + Canvas::Point _buffer_off; /* offset to the visible buffer area */ + Session &_session; /* session that created the view */ + char _title[TITLE_LEN]; public: @@ -119,23 +121,24 @@ class View : public Same_buffer_list_elem, public View_stack_elem, public Rect bool belongs_to(Session const &session) const { return &session == &_session; } bool same_session_as(View const &other) const { return &_session == &other._session; } - bool stay_top() const { return _stay_top; } - bool transparent() const { return _transparent || _session.uses_alpha(); } - bool background() const { return _background; } - Point buffer_off() const { return _buffer_off; } - Rect label_rect() const { return _label_rect; } - bool uses_alpha() const { return _session.uses_alpha(); } + bool stay_top() const { return _stay_top; } + bool transparent() const { return _transparent || _session.uses_alpha(); } + bool background() const { return _background; } + Rect label_rect() const { return _label_rect; } + bool uses_alpha() const { return _session.uses_alpha(); } + + Canvas::Point buffer_off() const { return _buffer_off; } char const *title() const { return _title; } - void buffer_off(Point buffer_off) { _buffer_off = buffer_off; } + void buffer_off(Canvas::Point buffer_off) { _buffer_off = buffer_off; } - void label_pos(Point pos) { _label_rect = Rect(pos, _label_rect.area()); } + void label_pos(Canvas::Point pos) { _label_rect = Rect(pos, _label_rect.area()); } /** * Return true if input at screen position 'p' refers to the view */ - bool input_response_at(Point p, Mode const &mode) const + bool input_response_at(Canvas::Point p, Mode const &mode) const { /* check if point lies outside view geometry */ if ((p.x() < x1()) || (p.x() > x2()) diff --git a/os/src/server/nitpicker/view_stack.cc b/os/src/server/nitpicker/view_stack.cc index f1da6c409d..27853c58cf 100644 --- a/os/src/server/nitpicker/view_stack.cc +++ b/os/src/server/nitpicker/view_stack.cc @@ -63,15 +63,15 @@ VIEW *View_stack::_next_view(VIEW *view) const } -Rect View_stack::_outline(View const &view) const +Canvas::Rect View_stack::_outline(View const &view) const { if (_mode.flat()) return view; /* request thickness of view frame */ int const frame_size = view.frame_size(_mode); - return Rect(Point(view.x1() - frame_size, view.y1() - frame_size), - Point(view.x2() + frame_size, view.y2() + frame_size)); + return Canvas::Rect(Canvas::Point(view.x1() - frame_size, view.y1() - frame_size), + Canvas::Point(view.x2() + frame_size, view.y2() + frame_size)); } diff --git a/os/src/server/nitpicker/view_stack.h b/os/src/server/nitpicker/view_stack.h index 184e11b38c..80c2f92572 100644 --- a/os/src/server/nitpicker/view_stack.h +++ b/os/src/server/nitpicker/view_stack.h @@ -22,6 +22,10 @@ class View_stack { private: + typedef Canvas::Point Point; + typedef Canvas::Area Area; + typedef Canvas::Rect Rect; + Canvas &_canvas; Mode &_mode; Genode::List _views; @@ -34,7 +38,7 @@ class View_stack * active Nitpicker mode. In non-flat modes, we incorporate the * surrounding frame. */ - Rect _outline(View const &view) const; + Canvas::Rect _outline(View const &view) const; /** * Return top-most view of the view stack diff --git a/ports/src/vancouver/console.cc b/ports/src/vancouver/console.cc index 6361cd67ce..b5f4d42f6e 100644 --- a/ports/src/vancouver/console.cc +++ b/ports/src/vancouver/console.cc @@ -215,7 +215,7 @@ void Vancouver_console::entry() _pixels = env()->rm_session()->attach(framebuffer->dataspace()); Chunky_canvas canvas((Pixel_rgb565 *) _pixels, - Area(_fb_mode.width(), + Canvas::Area(_fb_mode.width(), _fb_mode.height())); /* @@ -244,7 +244,7 @@ void Vancouver_console::entry() else checksum2 = 0; for (int j=0; j<25; j++) { for (int i=0; i<80; i++) { - Point where(i*8, j*15); + Canvas::Point where(i*8, j*15); char character = *((char *) (_guest_fb +(_regs->offset << 1) +j*80*2+i*2)); char colorvalue = *((char *) (_guest_fb+(_regs->offset << 1)+j*80*2+i*2+1)); char buffer[2]; buffer[0] = character; buffer[1] = 0;