mirror of
https://github.com/genodelabs/genode.git
synced 2025-04-07 19:34:56 +00:00
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.
This commit is contained in:
parent
6efac7672f
commit
35bfc34db5
@ -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<Pixel_rgb565> canvas((Pixel_rgb565 *)addr,
|
||||
|
@ -14,17 +14,18 @@
|
||||
#ifndef _INCLUDE__NITPICKER_GFX__CANVAS_H_
|
||||
#define _INCLUDE__NITPICKER_GFX__CANVAS_H_
|
||||
|
||||
#include <util/geometry.h>
|
||||
|
||||
#include <nitpicker_gfx/miscmath.h>
|
||||
#include <nitpicker_gfx/color.h>
|
||||
#include <nitpicker_gfx/font.h>
|
||||
#include <nitpicker_gfx/geometry.h>
|
||||
|
||||
|
||||
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(); }
|
||||
|
@ -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_ */
|
179
os/include/util/geometry.h
Normal file
179
os/include/util/geometry.h
Normal file
@ -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 <util/misc_math.h>
|
||||
#include <base/stdint.h>
|
||||
|
||||
namespace Genode {
|
||||
template <typename CT = int> class Point;
|
||||
template <typename DT = unsigned> class Area;
|
||||
template <typename CT = int, typename DT = unsigned> class Rect;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* \param CT coordinate type
|
||||
*/
|
||||
template <typename CT>
|
||||
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 <typename DT>
|
||||
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 <typename CT, typename DT>
|
||||
class Genode::Rect
|
||||
{
|
||||
private:
|
||||
|
||||
Point<CT> _p1, _p2;
|
||||
|
||||
public:
|
||||
|
||||
/**
|
||||
* Constructors
|
||||
*/
|
||||
Rect(Point<CT> p1, Point<CT> p2): _p1(p1), _p2(p2) { }
|
||||
|
||||
Rect(Point<CT> p, Area<DT> 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<CT> p1() const { return _p1; }
|
||||
Point<CT> p2() const { return _p2; }
|
||||
Area<DT> area() const { return Area<DT>(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<DT> 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<CT>(max(r1.x1(), r2.x1()), max(r1.y1(), r2.y1())),
|
||||
Point<CT>(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<CT>(min(r1.x1(), r2.x1()), min(r1.y1(), r2.y1())),
|
||||
Point<CT>(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<CT>(x1(), y1()), Point<CT>(x2(), r.y1() - 1));
|
||||
*left = Rect(Point<CT>(x1(), r.y1()), Point<CT>(r.x1() - 1, r.y2()));
|
||||
*right = Rect(Point<CT>(r.x2() + 1, r.y1()), Point<CT>(x2(), r.y2()));
|
||||
*bottom = Rect(Point<CT>(x1(), r.y2() + 1), Point<CT>(x2(), y2()));
|
||||
}
|
||||
|
||||
/**
|
||||
* Return position of an area when centered within the rectangle
|
||||
*/
|
||||
Point<CT> center(Area<DT> area) const {
|
||||
return Point<CT>(((CT)w() - (CT)area.w())/2,
|
||||
((CT)h() - (CT)area.h())/2) + p1(); }
|
||||
};
|
||||
|
||||
#endif /* _INCLUDE__UTIL__GEOMETRY_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)
|
||||
{ }
|
||||
|
||||
|
@ -27,7 +27,7 @@ class Chunky_menubar : public Chunky_texture<PT>,
|
||||
|
||||
public:
|
||||
|
||||
Chunky_menubar(PT *pixels, Area size)
|
||||
Chunky_menubar(PT *pixels, Canvas::Area size)
|
||||
:
|
||||
Chunky_texture<PT>(pixels, 0, size),
|
||||
Session(Genode::Session_label(""), 0, false),
|
||||
|
@ -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); }
|
||||
|
@ -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);
|
||||
|
@ -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<PT>, 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<PT>(base, size) { }
|
||||
Screen(PT *base, Canvas::Area size) : Chunky_canvas<PT>(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<void>(); }
|
||||
};
|
||||
@ -160,7 +160,7 @@ class Chunky_dataspace_texture : public Buffer, public Chunky_texture<PT>
|
||||
/**
|
||||
* 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<PT>
|
||||
/**
|
||||
* 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>((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<Session>
|
||||
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<View_component>::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<View_component>::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<Session>,
|
||||
{
|
||||
_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<PT> screen = { (PT *)fb_base, Area(mode.width(), mode.height()) };
|
||||
Screen<PT> 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<PT> menubar = { menubar_pixels, Area(mode.width(), MENUBAR_HEIGHT) };
|
||||
Chunky_menubar<PT> 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<PT> 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();
|
||||
|
@ -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 */
|
||||
|
@ -34,12 +34,12 @@ class Mouse_cursor : public Chunky_texture<PT>, 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<PT>(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)
|
||||
{ }
|
||||
|
||||
|
@ -18,7 +18,6 @@
|
||||
#include <util/list.h>
|
||||
#include <util/string.h>
|
||||
#include <nitpicker_gfx/color.h>
|
||||
#include <nitpicker_gfx/geometry.h>
|
||||
#include <nitpicker_gfx/canvas.h>
|
||||
#include <nitpicker_gfx/string.h>
|
||||
#include <os/session_policy.h>
|
||||
@ -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()];
|
||||
|
@ -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++;
|
||||
|
@ -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
|
||||
|
@ -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));
|
||||
}
|
||||
|
||||
|
||||
|
@ -16,8 +16,8 @@
|
||||
|
||||
#include <util/string.h>
|
||||
#include <util/list.h>
|
||||
|
||||
#include <nitpicker_gfx/canvas.h>
|
||||
#include <nitpicker_gfx/geometry.h>
|
||||
|
||||
#include "mode.h"
|
||||
#include "session.h"
|
||||
@ -35,7 +35,9 @@ struct Same_buffer_list_elem : Genode::List<Same_buffer_list_elem>::Element { };
|
||||
struct View_stack_elem : Genode::List<View_stack_elem>::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())
|
||||
|
@ -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));
|
||||
}
|
||||
|
||||
|
||||
|
@ -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<View_stack_elem> _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
|
||||
|
@ -215,7 +215,7 @@ void Vancouver_console::entry()
|
||||
_pixels = env()->rm_session()->attach(framebuffer->dataspace());
|
||||
|
||||
Chunky_canvas<Pixel_rgb565> 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;
|
||||
|
Loading…
x
Reference in New Issue
Block a user