nitpicker: Add const qualifiers

This commit is contained in:
Norman Feske 2013-09-07 02:02:26 +02:00
parent 7e35388336
commit fa34b79b2c
21 changed files with 521 additions and 477 deletions

View File

@ -103,7 +103,7 @@ class Log_entry
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);
canvas->draw_string(Point(1, y - 1), default_font, label_fgcol, _label);
canvas->draw_box(Rect(Point(1, y + label_h - 1), Area(label_w + 2, 1)), Color(0, 0, 0));
canvas->draw_box(Rect(Point(label_w + 2, y), Area(1, label_h - 1)), _color);
canvas->draw_box(Rect(Point(label_w + 3, y), Area(1, label_h - 1)), Color(0, 0, 0));
@ -113,7 +113,7 @@ class Log_entry
canvas->draw_box(Rect(Point(1, y), Area(1000, label_h)), text_bgcol);
/* draw log text */
canvas->draw_string(Point(label_w + 6, y), &default_font, text_fgcol, _text);
canvas->draw_string(Point(label_w + 6, y), default_font, text_fgcol, _text);
}
/**

View File

@ -31,7 +31,7 @@ class Texture : public Area
/**
* Return pointer to alpha values, or 0 if no alpha channel exists
*/
virtual unsigned char *alpha() { return 0; }
virtual unsigned char const *alpha() const { return 0; }
};
@ -87,13 +87,14 @@ class Canvas
* Define/request clipping rectangle
*/
void clip(Rect clip) { _clip = Rect::intersect(Rect(Point(0, 0), _size), clip); }
Rect clip() { return _clip; }
bool clip_valid() { return _clip.valid(); }
Rect clip() const { return _clip; }
bool clip_valid() const { return _clip.valid(); }
/**
* Return dimension of canvas in pixels
*/
Area size() { return _size; }
Area size() const { return _size; }
/**
* Draw filled box
@ -106,13 +107,13 @@ class Canvas
/**
* Draw string
*/
virtual void draw_string(Point position, Font *font, Color color,
virtual void draw_string(Point position, Font const &font, Color color,
const char *str) = 0;
/**
* Draw texture
*/
virtual void draw_texture(Texture *src, Color mix_color, Point position,
virtual void draw_texture(Texture const &src, Color mix_color, Point position,
Mode mode, bool allow_alpha = true) = 0;
};

View File

@ -23,17 +23,17 @@ class Chunky_texture : public Texture
{
private:
PT *_pixels;
unsigned char *_alpha;
PT const *_pixels;
unsigned char const *_alpha;
public:
Chunky_texture(PT *pixels, unsigned char *alpha, Area size) :
Texture(size), _pixels(pixels), _alpha(alpha) { }
Chunky_texture(PT const *pixels, unsigned char const *alpha, Area size)
: Texture(size), _pixels(pixels), _alpha(alpha) { }
PT *pixels() { return _pixels; }
PT const *pixels() const { return _pixels; }
unsigned char *alpha() { return _alpha; }
unsigned char const *alpha() const { return _alpha; }
};
@ -75,19 +75,17 @@ class Chunky_canvas : public Canvas
_flush_pixels(clipped);
}
void draw_string(Point p, Font *font, Color color, const char *sstr)
void draw_string(Point p, Font const &font, Color color, char const *sstr)
{
const unsigned char *str = (const unsigned char *)sstr;
unsigned char const *str = (unsigned char const *)sstr;
int x = p.x(), y = p.y();
if (!str || !font) return;
unsigned char const *src = font->img;
int d, h = font->img_h;
unsigned char const *src = font.img;
int d, h = font.img_h;
/* check top clipping */
if ((d = _clip.y1() - y) > 0) {
src += d*font->img_w;
src += d*font.img_w;
y += d;
h -= d;
}
@ -99,8 +97,8 @@ class Chunky_canvas : public Canvas
if (h < 1) return;
/* skip hidden glyphs */
for ( ; *str && (x + font->wtab[*str] < _clip.x1()); )
x += font->wtab[*str++];
for ( ; *str && (x + font.wtab[*str] < _clip.x1()); )
x += font.wtab[*str++];
int x_start = x;
@ -110,13 +108,13 @@ class Chunky_canvas : public Canvas
/* draw glyphs */
for ( ; *str && (x <= _clip.x2()); str++) {
int w = font->wtab[*str];
int w = font.wtab[*str];
int start = max(0, _clip.x1() - x);
int end = min(w - 1, _clip.x2() - x);
PT *d = dst + x;
unsigned char const *s = src + font->otab[*str];
unsigned char const *s = src + font.otab[*str];
for (int j = 0; j < h; j++, s += font->img_w, d += _size.w())
for (int j = 0; j < h; j++, s += font.img_w, d += _size.w())
for (int i = start; i <= end; i++)
if (s[i]) d[i] = pix;
@ -126,27 +124,27 @@ class Chunky_canvas : public Canvas
_flush_pixels(Rect(Point(x_start, y), Area(x - x_start + 1, h)));
}
void draw_texture(Texture *texture, Color mix_color, Point position,
void draw_texture(Texture const &texture, Color mix_color, Point position,
Mode mode, bool allow_alpha)
{
Rect clipped = Rect::intersect(Rect(position, *texture), _clip);
Rect clipped = Rect::intersect(Rect(position, texture), _clip);
if (!clipped.valid()) return;
int src_w = texture->w();
int dst_w = _size.w();
int const src_w = texture.w();
int const dst_w = _size.w();
Chunky_texture<PT> *tex = static_cast<Chunky_texture<PT> *>(texture);
Chunky_texture<PT> const &tex = static_cast<Chunky_texture<PT> const &>(texture);
/* calculate offset of first texture pixel to copy */
unsigned long tex_start_offset = (clipped.y1() - position.y())*src_w
+ clipped.x1() - position.x();
/* start address of source pixels */
PT *src = tex->pixels() + tex_start_offset;
PT const *src = tex.pixels() + tex_start_offset;
/* start address of source alpha values */
unsigned char *alpha = tex->alpha() + tex_start_offset;
unsigned char const *alpha = tex.alpha() + tex_start_offset;
/* start address of destination pixels */
PT *dst = _addr + clipped.y1()*dst_w + clipped.x1();
@ -154,8 +152,9 @@ class Chunky_canvas : public Canvas
PT mix_pixel(mix_color.r, mix_color.g, mix_color.b);
int i, j;
PT *s, *d;
unsigned char *a;
PT const *s;
PT *d;
unsigned char const *a;
switch (mode) {
@ -165,7 +164,7 @@ class Chunky_canvas : public Canvas
* If the texture has no alpha channel, we can use
* a plain pixel blit.
*/
if (tex->alpha() == 0 || !allow_alpha) {
if (tex.alpha() == 0 || !allow_alpha) {
blit(src, src_w*sizeof(PT),
dst, dst_w*sizeof(PT),
clipped.w()*sizeof(PT), clipped.h());

View File

@ -33,17 +33,17 @@ class Point
/**
* Operator for adding points
*/
Point operator + (Point p) { return Point(_x + p.x(), _y + p.y()); }
Point operator + (Point const &p) const { return Point(_x + p.x(), _y + p.y()); }
/**
* Operator for subtracting points
*/
Point operator - (Point p) { return Point(_x - p.x(), _y - p.y()); }
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 p) { return p.x() != _x || p.y() != _y; }
bool operator != (Point const &p) const { return p.x() != _x || p.y() != _y; }
};
@ -51,7 +51,7 @@ class Area
{
private:
int _w, _h;
int const _w, _h;
public:
@ -90,11 +90,6 @@ class Rect
Rect() { }
/**
* Assign new coordinates
*/
void rect(Rect r) { _p1 = r.p1(); _p2 = r.p2(); }
/**
* Accessors
*/
@ -140,7 +135,7 @@ class Rect
* 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)
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);
@ -154,7 +149,7 @@ class Rect
/**
* Return position of an area when centered within the rectangle
*/
Point center(Area area) {
Point center(Area area) const {
return Point((w() - area.w())/2, (h() - area.h())/2) + p1(); }
};

View File

@ -35,9 +35,9 @@ static inline bool _mouse_button(Keycode keycode) {
** User state interface **
**************************/
User_state::User_state(Global_keys &global_keys, Canvas *canvas, Menubar *menubar)
User_state::User_state(Global_keys &global_keys, Canvas &canvas, Menubar &menubar)
:
View_stack(canvas, this), _global_keys(global_keys), _key_cnt(0),
View_stack(canvas, *this), _global_keys(global_keys), _key_cnt(0),
_menubar(menubar), _pointed_view(0), _input_receiver(0),
_global_key_sequence(false)
{ }
@ -52,7 +52,7 @@ void User_state::handle_event(Input::Event ev)
* Mangle incoming events
*/
int ax = _mouse_pos.x(), ay = _mouse_pos.y();
int rx = 0, ry = 0; /* skip info about relative motion per default */
int rx = 0, ry = 0; /* skip info about relative motion by default */
/* transparently handle absolute and relative motion events */
if (type == Event::MOTION) {
@ -76,22 +76,27 @@ void User_state::handle_event(Input::Event ev)
_mouse_pos = Point(ax, ay);
View * pointed_view = find_view(_mouse_pos);
/* count keys */
if (type == Event::PRESS) _key_cnt++;
if (type == Event::RELEASE && _key_cnt > 0) _key_cnt--;
View const * const pointed_view = find_view(_mouse_pos);
/*
* Deliver a leave event if pointed-to session changed
*/
if (pointed_view && _pointed_view &&
pointed_view->session() != _pointed_view->session()) {
!pointed_view->same_session_as(*_pointed_view)) {
Input::Event leave_ev(Input::Event::LEAVE, 0, ax, ay, 0, 0);
_pointed_view->session()->submit_input_event(&leave_ev);
_pointed_view->session().submit_input_event(leave_ev);
}
/* remember currently pointed-at view */
_pointed_view = pointed_view;
/**
* Guard that performs a whole-screen update when leaving the scope
* Guard that, when 'enabled' is set to true, performs a whole-screen
* update when leaving the scope
*/
struct Update_all_guard
{
@ -108,40 +113,42 @@ void User_state::handle_event(Input::Event ev)
return;
if (user_state._input_receiver)
user_state._menubar->state(user_state, user_state._input_receiver->label(),
menu_title, user_state._input_receiver->color());
user_state._menubar.state(user_state,
user_state._input_receiver->label(),
menu_title,
user_state._input_receiver->color());
else
user_state._menubar->state(user_state, "", "", BLACK);
user_state._menubar.state(user_state, "", "", BLACK);
user_state.update_all_views();
}
} update_all_guard(*this);
/*
* Detect mouse press event in kill mode, used to select the session
* to lock out.
*/
if (kill() && type == Event::PRESS && keycode == Input::BTN_LEFT) {
if (pointed_view && pointed_view->session())
lock_out_session(pointed_view->session());
/* leave kill mode */
pointed_view = 0;
Mode::_mode &= ~KILL;
update_all_guard.enabled = true;
}
/*
* Handle start of a key sequence
*/
if (type == Event::PRESS && _key_cnt == 0) {
if (type == Event::PRESS && _key_cnt == 1) {
/*
* Detect mouse press event in kill mode, used to select the session
* to lock out.
*/
if (kill() && keycode == Input::BTN_LEFT) {
if (pointed_view)
lock_out_session(pointed_view->session());
/* leave kill mode */
update_all_guard.enabled = true;
Mode::leave_kill();
return;
}
/* update focused view */
if (pointed_view != focused_view() && _mouse_button(keycode)) {
bool const focus_stays_in_session =
(_focused_view && pointed_view &&
_focused_view->session() == pointed_view->session());
focused_view() && pointed_view &&
focused_view()->belongs_to(pointed_view->session());
/*
* Update the whole screen when the focus change results in
@ -155,21 +162,21 @@ void User_state::handle_event(Input::Event ev)
*/
if (!focus_stays_in_session) {
if (_focused_view) {
if (focused_view()) {
Input::Event unfocus_ev(Input::Event::FOCUS, 0, ax, ay, 0, 0);
_focused_view->session()->submit_input_event(&unfocus_ev);
focused_view()->session().submit_input_event(unfocus_ev);
}
if (pointed_view) {
Input::Event focus_ev(Input::Event::FOCUS, 1, ax, ay, 0, 0);
pointed_view->session()->submit_input_event(&focus_ev);
pointed_view->session().submit_input_event(focus_ev);
}
}
if (!flat() || !_focused_view || !pointed_view)
if (!flat() || !focused_view() || !pointed_view)
update_all_guard.enabled = true;
_focused_view = pointed_view;
focused_view(pointed_view);
}
/*
@ -194,9 +201,9 @@ void User_state::handle_event(Input::Event ev)
* No global rule matched, so the input stream gets directed to the
* focused view or refers to a built-in operation.
*/
if (!global_receiver && _focused_view) {
_input_receiver = _focused_view->session();
update_all_guard.menu_title = _focused_view->title();
if (!global_receiver && focused_view()) {
_input_receiver = &focused_view()->session();
update_all_guard.menu_title = focused_view()->title();
}
/*
@ -205,22 +212,17 @@ void User_state::handle_event(Input::Event ev)
*/
if (_global_keys.is_operation_key(keycode)) {
Mode::_mode ^= _global_keys.is_kill_key(keycode) ? KILL : 0
| _global_keys.is_xray_key(keycode) ? XRAY : 0;
if (_global_keys.is_kill_key(keycode)) Mode::toggle_kill();
if (_global_keys.is_xray_key(keycode)) Mode::toggle_xray();
update_all_guard.enabled = true;
_input_receiver = 0;
}
}
/* count keys */
if (type == Event::PRESS) _key_cnt++;
if (type == Event::RELEASE && _key_cnt > 0) _key_cnt--;
/*
* Deliver event to Nitpicker session except when kill mode is activated
* Deliver event to session except when kill mode is activated
*/
if (kill()) return;
if (type == Event::MOTION || type == Event::WHEEL) {
@ -234,23 +236,23 @@ void User_state::handle_event(Input::Event ev)
*/
if (flat() || (xray() && focused_view() == pointed_view))
if (pointed_view)
pointed_view->session()->submit_input_event(&ev);
pointed_view->session().submit_input_event(ev);
} else if (_input_receiver)
_input_receiver->submit_input_event(&ev);
_input_receiver->submit_input_event(ev);
}
/* deliver press/release event to session with focused view */
if (type == Event::PRESS || type == Event::RELEASE)
if (_input_receiver)
_input_receiver->submit_input_event(&ev);
_input_receiver->submit_input_event(ev);
/*
* Detect end of global key sequence
*/
if (ev.type() == Event::RELEASE && _key_cnt == 0 && _global_key_sequence) {
_input_receiver = _focused_view ? _focused_view->session() : 0;
update_all_guard.menu_title = _focused_view ? _focused_view->title() : "";
_input_receiver = focused_view() ? &focused_view()->session() : 0;
update_all_guard.menu_title = focused_view() ? focused_view()->title() : "";
update_all_guard.enabled = true;
_global_key_sequence = false;
}
@ -261,16 +263,17 @@ void User_state::handle_event(Input::Event ev)
** Mode interface **
********************/
void User_state::forget(View *v)
void User_state::forget(View const &view)
{
if (_focused_view == v) {
Mode::forget(v);
_menubar->state(*this, "", "", BLACK);
if (focused_view() == &view) {
Mode::forget(view);
_menubar.state(*this, "", "", BLACK);
update_all_views();
}
if (_input_receiver == v->session())
if (_input_receiver && view.belongs_to(*_input_receiver))
_input_receiver = 0;
if (_pointed_view == v)
if (_pointed_view == &view)
_pointed_view = find_view(_mouse_pos);
}

View File

@ -26,19 +26,19 @@
/**
* Draw rectangle
*/
static void draw_rect(Canvas *canvas, int x, int y, int w, int h, Color color)
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(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);
}
/**
* 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, Rect r, Color color, int frame_size)
{
/* draw frame around the view */
int d = frame_size;
@ -58,35 +58,33 @@ void View::title(const char *title)
Nitpicker::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(), _title));
_label_rect = Rect(Point(0, 0), label_size(_session.label(), _title));
}
void View::frame(Canvas *canvas, Mode *mode)
void View::frame(Canvas &canvas, Mode const &mode) const
{
/* do not draw frame in flat mode */
if (mode->flat()) return;
if (mode.flat()) return;
draw_frame(canvas, *this, _session->color(), frame_size(mode));
draw_frame(canvas, *this, _session.color(), frame_size(mode));
}
void View::draw(Canvas *canvas, Mode *mode)
void View::draw(Canvas &canvas, Mode const &mode) const
{
/* use dimming in x-ray mode */
Canvas::Mode op = mode->flat() ? Canvas::SOLID : Canvas::MIXED;
/* is this the currently focused view? */
Session *focused_session = mode->focused_view()
? mode->focused_view()->session()
: 0;
bool const view_is_focused = mode.focused_view()
&& mode.focused_view()->belongs_to(_session);
bool view_is_focused = (focused_session == _session);
Color frame_color = _session->color();
Color const frame_color = _session.color();
/* do not dim the focused view in x-ray mode */
if (mode->xray() && !mode->kill() && view_is_focused)
op = Canvas::SOLID;
/*
* Use dimming in x-ray and kill mode, but do not dim the focused view in
* x-ray mode.
*/
Canvas::Mode const op = mode.flat() || (mode.xray() && view_is_focused)
? Canvas::SOLID : Canvas::MIXED;
/*
* The view content and label should never overdraw the
@ -97,25 +95,25 @@ void View::draw(Canvas *canvas, Mode *mode)
Clip_guard clip_guard(canvas, *this);
/*
* If the clipping area shrinked to zero,
* we do not process drawing operations.
* If the clipping area shrinked to zero, we do not process drawing
* operations.
*/
if (!canvas->clip_valid() || !_session) return;
if (!canvas.clip_valid() || !&_session) return;
/* allow alpha blending only in flat mode */
bool allow_alpha = mode->flat();
bool allow_alpha = mode.flat();
/* draw view content */
Color mix_color = Color(_session->color().r >> 1,
_session->color().g >> 1,
_session->color().b >> 1);
Color const mix_color = mode.kill() ? KILL_COLOR
: Color(_session.color().r >> 1,
_session.color().g >> 1,
_session.color().b >> 1);
if (mode->kill()) mix_color = KILL_COLOR;
canvas->draw_texture(_session->texture(), mix_color, _buffer_off + p1(),
op, allow_alpha);
canvas.draw_texture(_session.texture(), mix_color, _buffer_off + p1(),
op, allow_alpha);
if (mode->flat()) return;
if (mode.flat()) return;
/* draw label */
draw_label(canvas, _label_rect.p1(), _session->label(), WHITE, _title, frame_color);
draw_label(canvas, _label_rect.p1(), _session.label(), WHITE, _title, frame_color);
}

View File

@ -26,7 +26,7 @@
*
* \param view first view of the view stack
*/
static View *last_stay_top_view(View *view)
static View const *last_stay_top_view(View const *view)
{
for (; view && view->view_stack_next() && view->view_stack_next()->stay_top(); )
view = view->view_stack_next();
@ -52,13 +52,14 @@ static View *last_stay_top_view(View *view)
** View stack interface **
**************************/
View *View_stack::_next_view(View *view)
template <typename VIEW>
VIEW *View_stack::_next_view(VIEW *view) const
{
Session *active_session = _mode->focused_view() ?
_mode->focused_view()->session() : 0;
Session * const active_session = _mode.focused_view() ?
&_mode.focused_view()->session() : 0;
View *active_background = active_session ?
active_session->background() : 0;
View * const active_background = active_session ?
active_session->background() : 0;
for (;;) {
view = view ? view->view_stack_next() : 0;
@ -77,22 +78,22 @@ View *View_stack::_next_view(View *view)
}
Rect View_stack::_outline(View *view)
Rect View_stack::_outline(View const &view) const
{
if (_mode->flat()) return *view;
if (_mode.flat()) return view;
/* request thickness of view frame */
int frame_size = view->frame_size(_mode);
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 Rect(Point(view.x1() - frame_size, view.y1() - frame_size),
Point(view.x2() + frame_size, view.y2() + frame_size));
}
View *View_stack::_target_stack_position(View *neighbor, bool behind)
View const *View_stack::_target_stack_position(View const *neighbor, bool behind)
{
/* find target position in view stack */
View *cv = last_stay_top_view(_first_view());
View const *cv = last_stay_top_view(_first_view());
for ( ; cv; cv = _next_view(cv)) {
@ -117,7 +118,7 @@ View *View_stack::_target_stack_position(View *neighbor, bool behind)
}
void View_stack::_optimize_label_rec(View *cv, View *lv, Rect rect, Rect *optimal)
void View_stack::_optimize_label_rec(View const *cv, View const *lv, Rect rect, Rect *optimal)
{
/* if label already fits in optimized rectangle, we are happy */
if (optimal->fits(lv->label_rect().area()))
@ -125,7 +126,7 @@ void View_stack::_optimize_label_rec(View *cv, View *lv, Rect rect, Rect *optima
/* find next view that intersects with the rectangle or the target view */
Rect clipped;
while (cv && cv != lv && !(clipped = Rect::intersect(_outline(cv), rect)).valid())
while (cv && cv != lv && !(clipped = Rect::intersect(_outline(*cv), rect)).valid())
cv = _next_view(cv);
/* reached end of view stack */
@ -165,11 +166,11 @@ void View_stack::_optimize_label_rec(View *cv, View *lv, Rect rect, Rect *optima
void View_stack::_place_labels(Rect rect)
{
/* do not calculate label positions in flat mode */
if (_mode->flat()) return;
if (_mode.flat()) return;
/* ignore mouse cursor */
View *start = _next_view(_first_view());
View *view = start;
View const *start = _next_view(_first_view());
View *view = _next_view(_first_view());
for (; view && _next_view(view); view = _next_view(view))
if (Rect::intersect(*view, rect).valid()) {
@ -177,7 +178,7 @@ void View_stack::_place_labels(Rect rect)
Rect old = view->label_rect(), best;
/* calculate best visible label position */
Rect rect = Rect::intersect(Rect(Point(), _canvas->size()), *view);
Rect rect = Rect::intersect(Rect(Point(), _canvas.size()), *view);
if (start) _optimize_label_rec(start, view, rect, &best);
/*
@ -191,18 +192,19 @@ void View_stack::_place_labels(Rect rect)
view->label_pos(Point(x, best.y1()));
/* refresh old and new label positions */
refresh_view(view, view, old);
refresh_view(view, view, view->label_rect());
refresh_view(*view, view, old);
refresh_view(*view, view, view->label_rect());
}
}
void View_stack::draw_rec(View *view, View *dst_view, Session *exclude, Rect rect)
void View_stack::draw_rec(View const *view, View const *dst_view,
Session const *exclude, Rect rect) const
{
Rect clipped;
/* find next view that intersects with the current clipping rectangle */
for ( ; view && !(clipped = Rect::intersect(_outline(view), rect)).valid(); )
for ( ; view && !(clipped = Rect::intersect(_outline(*view), rect)).valid(); )
view = _next_view(view);
/* check if we hit the bottom of the view stack */
@ -211,7 +213,7 @@ void View_stack::draw_rec(View *view, View *dst_view, Session *exclude, Rect rec
Rect top, left, right, bottom;
rect.cut(clipped, &top, &left, &right, &bottom);
View *next = _next_view(view);
View const *next = _next_view(view);
/* draw areas at the top/left of the current view */
if (next && top.valid()) draw_rec(next, dst_view, exclude, top);
@ -223,12 +225,12 @@ void View_stack::draw_rec(View *view, View *dst_view, Session *exclude, Rect rec
Clip_guard clip_guard(_canvas, clipped);
/* draw background if view is transparent */
if (view->session()->uses_alpha())
if (view->uses_alpha())
draw_rec(_next_view(view), 0, 0, clipped);
view->frame(_canvas, _mode);
if (view->session() != exclude)
if (!exclude || !view->belongs_to(*exclude))
view->draw(_canvas, _mode);
}
@ -238,10 +240,8 @@ void View_stack::draw_rec(View *view, View *dst_view, Session *exclude, Rect rec
}
void View_stack::refresh_view(View *view, View *dst_view, Rect rect)
void View_stack::refresh_view(View const &view, View const *dst_view, Rect rect)
{
if (!view) return;
/* clip argument agains view outline */
rect = Rect::intersect(rect, _outline(view));
@ -249,43 +249,43 @@ void View_stack::refresh_view(View *view, View *dst_view, Rect rect)
}
void View_stack::viewport(View *view, Rect pos, Point buffer_off, bool do_redraw)
void View_stack::viewport(View &view, Rect pos, Point buffer_off, bool do_redraw)
{
Rect old = _outline(view);
view->rect(pos);
view->buffer_off(buffer_off);
static_cast<Rect &>(view) = Rect(pos);
view.buffer_off(buffer_off);
Rect compound = Rect::compound(old, _outline(view));
/* update labels (except when moving the mouse cursor) */
if (view != _first_view())
if (&view != _first_view())
_place_labels(compound);
if (!_mode->flat())
if (!_mode.flat())
do_redraw = true;
/* update area on screen */
draw_rec(_first_view(), 0, do_redraw ? 0 : view->session(), compound);
draw_rec(_first_view(), 0, do_redraw ? 0 : &view.session(), compound);
}
void View_stack::stack(View *view, View *neighbor, bool behind, bool do_redraw)
void View_stack::stack(View const &view, View const *neighbor, bool behind, bool do_redraw)
{
_views.remove(view);
_views.insert(view, _target_stack_position(neighbor, behind));
_views.remove(&view);
_views.insert(&view, _target_stack_position(neighbor, behind));
_place_labels(*view);
_place_labels(view);
/* refresh affected screen area */
refresh_view(view, 0, _outline(view));
}
void View_stack::title(View *view, const char *title)
void View_stack::title(View &view, const char *title)
{
view->title(title);
_place_labels(*view);
view.title(title);
_place_labels(view);
refresh_view(view, 0, _outline(view));
}
@ -303,13 +303,13 @@ View *View_stack::find_view(Point p)
}
void View_stack::remove_view(View *view)
void View_stack::remove_view(View const &view)
{
/* remember geometry of view to remove */
Rect rect = _outline(view);
/* exclude view from view stack */
_views.remove(view);
_views.remove(&view);
/*
* Reset focused and pointed-at view if necessary
@ -320,7 +320,7 @@ void View_stack::remove_view(View *view)
* the current one, resulting in a dangling pointer right after the view
* gets destructed by the caller of 'removed_view'.
*/
_mode->forget(view);
_mode.forget(view);
/* redraw area where the view was visible */
draw_rec(_first_view(), 0, 0, rect);

View File

@ -289,11 +289,11 @@ namespace Framebuffer {
{
private:
::Buffer *_buffer;
View_stack *_view_stack;
::Session *_session;
Flush_merger *_flush_merger;
Framebuffer::Session *_framebuffer;
::Buffer &_buffer;
View_stack &_view_stack;
::Session &_session;
Flush_merger &_flush_merger;
Framebuffer::Session &_framebuffer;
public:
@ -302,37 +302,37 @@ namespace Framebuffer {
*
* \param session Nitpicker session
*/
Session_component(::Buffer *buffer, View_stack *view_stack,
::Session *session, Flush_merger *flush_merger,
Framebuffer::Session *framebuffer)
Session_component(::Buffer &buffer, View_stack &view_stack,
::Session &session, Flush_merger &flush_merger,
Framebuffer::Session &framebuffer)
:
_buffer(buffer), _view_stack(view_stack), _session(session),
_flush_merger(flush_merger), _framebuffer(framebuffer) { }
Genode::Dataspace_capability dataspace() { return _buffer->ds_cap(); }
Genode::Dataspace_capability dataspace() { return _buffer.ds_cap(); }
void release() { }
Mode mode() const
{
return Mode(_buffer->size().w(), _buffer->size().h(),
_buffer->format());
return Mode(_buffer.size().w(), _buffer.size().h(),
_buffer.format());
}
void mode_sigh(Genode::Signal_context_capability) { }
void refresh(int x, int y, int w, int h)
{
_view_stack->update_session_views(_session,
Rect(Point(x, y), Area(w, h)));
_view_stack.update_session_views(_session,
Rect(Point(x, y), Area(w, h)));
/* flush dirty pixels to physical frame buffer */
if (_flush_merger->defer == false) {
Rect r = _flush_merger->to_be_flushed();
_framebuffer->refresh(r.x1(), r.y1(), r.w(), r.h());
_flush_merger->reset();
if (_flush_merger.defer == false) {
Rect r = _flush_merger.to_be_flushed();
_framebuffer.refresh(r.x1(), r.y1(), r.w(), r.h());
_flush_merger.reset();
}
_flush_merger->defer = true;
_flush_merger.defer = true;
}
};
}
@ -343,25 +343,24 @@ class View_component : public Genode::List<View_component>::Element,
{
private:
View_stack *_view_stack;
View_stack &_view_stack;
::View _view;
Genode::Rpc_entrypoint *_ep;
static unsigned _flags(Session *session)
{
return (session && session->stay_top()) ? ::View::STAY_TOP : 0;
}
Genode::Rpc_entrypoint &_ep;
public:
/**
* Constructor
*/
View_component(::Session *session, View_stack *view_stack,
Genode::Rpc_entrypoint *ep):
_view_stack(view_stack), _view(session, _flags(session)), _ep(ep) { }
View_component(::Session &session, View_stack &view_stack,
Genode::Rpc_entrypoint &ep):
_view_stack(view_stack),
_view(session,
session.stay_top() ? ::View::STAY_TOP : ::View::NOT_STAY_TOP,
::View::NOT_TRANSPARENT, ::View::NOT_BACKGROUND, Rect()),
_ep(ep) { }
::View *view() { return &_view; }
::View &view() { return _view; }
/******************************
@ -372,26 +371,26 @@ class View_component : public Genode::List<View_component>::Element,
int buf_x, int buf_y, bool redraw)
{
/* transpose y position by vertical session offset */
y += _view.session()->v_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, Rect(Point(x, y), Area(w, h)),
Point(buf_x, buf_y), redraw);
return 0;
}
int stack(Nitpicker::View_capability neighbor_cap, bool behind, bool redraw)
{
Genode::Object_pool<View_component>::Guard nvc(_ep->lookup_and_lock(neighbor_cap));
Genode::Object_pool<View_component>::Guard nvc(_ep.lookup_and_lock(neighbor_cap));
::View *neighbor_view = nvc ? nvc->view() : 0;
::View *neighbor_view = nvc ? &nvc->view() : 0;
_view_stack->stack(&_view, neighbor_view, behind, redraw);
_view_stack.stack(_view, neighbor_view, behind, redraw);
return 0;
}
int title(Title const &title)
{
_view_stack->title(&_view, title.string());
_view_stack.title(_view, title.string());
return 0;
}
};
@ -417,9 +416,9 @@ namespace Nitpicker {
* Entrypoint that is used for the views, input session,
* and framebuffer session.
*/
Genode::Rpc_entrypoint *_ep;
Genode::Rpc_entrypoint &_ep;
View_stack *_view_stack;
View_stack &_view_stack;
Genode::List<View_component> _view_list;
@ -434,24 +433,24 @@ namespace Nitpicker {
/**
* Constructor
*/
Session_component(const char *name,
::Buffer *buffer,
Texture *texture,
View_stack *view_stack,
Genode::Rpc_entrypoint *ep,
Flush_merger *flush_merger,
Framebuffer::Session *framebuffer,
Session_component(char const *name,
::Buffer &buffer,
Texture const &texture,
View_stack &view_stack,
Genode::Rpc_entrypoint &ep,
Flush_merger &flush_merger,
Framebuffer::Session &framebuffer,
int v_offset,
unsigned char *input_mask,
unsigned char const *input_mask,
bool provides_default_bg,
Color color,
bool stay_top)
:
::Session(name, texture, v_offset, color, input_mask, stay_top),
_framebuffer_session_component(buffer, view_stack, this, flush_merger, framebuffer),
_framebuffer_session_component(buffer, view_stack, *this, flush_merger, framebuffer),
_ep(ep), _view_stack(view_stack),
_framebuffer_session_cap(_ep->manage(&_framebuffer_session_component)),
_input_session_cap(_ep->manage(&_input_session_component)),
_framebuffer_session_cap(_ep.manage(&_framebuffer_session_component)),
_input_session_cap(_ep.manage(&_input_session_component)),
_provides_default_bg(provides_default_bg)
{ }
@ -460,11 +459,10 @@ namespace Nitpicker {
*/
~Session_component()
{
_ep->dissolve(&_framebuffer_session_component);
_ep->dissolve(&_input_session_component);
_ep.dissolve(&_framebuffer_session_component);
_ep.dissolve(&_input_session_component);
View_component *vc;
while ((vc = _view_list.first()))
while (View_component *vc = _view_list.first())
destroy_view(vc->cap());
}
@ -473,7 +471,7 @@ namespace Nitpicker {
** Nitpicker-internal session interface **
******************************************/
void submit_input_event(Input::Event *ev)
void submit_input_event(Input::Event e)
{
using namespace Input;
@ -481,7 +479,6 @@ namespace Nitpicker {
* Transpose absolute coordinates by session-specific vertical
* offset.
*/
Event e = *ev;
if (e.ax() || e.ay())
e = Event(e.type(), e.code(), e.ax(),
max(0, e.ay() - v_offset()), e.rx(), e.ry());
@ -507,19 +504,19 @@ namespace Nitpicker {
* Use a heap partition!
*/
View_component *view = new (Genode::env()->heap())
View_component(this, _view_stack, _ep);
View_component(*this, _view_stack, _ep);
_view_list.insert(view);
return _ep->manage(view);
return _ep.manage(view);
}
void destroy_view(View_capability view_cap)
{
View_component *vc = dynamic_cast<View_component *>(_ep->lookup_and_lock(view_cap));
View_component *vc = dynamic_cast<View_component *>(_ep.lookup_and_lock(view_cap));
if (!vc) return;
_view_stack->remove_view(vc->view());
_ep->dissolve(vc);
_view_stack.remove_view(vc->view());
_ep.dissolve(vc);
_view_list.remove(vc);
destroy(Genode::env()->heap(), vc);
}
@ -527,9 +524,9 @@ namespace Nitpicker {
int background(View_capability view_cap)
{
if (_provides_default_bg) {
Genode::Object_pool<View_component>::Guard vc(_ep->lookup_and_lock(view_cap));
vc->view()->background(true);
_view_stack->default_background(vc->view());
Genode::Object_pool<View_component>::Guard vc(_ep.lookup_and_lock(view_cap));
vc->view().background(true);
_view_stack.default_background(vc->view());
return 0;
}
@ -537,11 +534,11 @@ namespace Nitpicker {
if (::Session::background()) ::Session::background()->background(false);
/* assign session background */
Genode::Object_pool<View_component>::Guard vc(_ep->lookup_and_lock(view_cap));
::Session::background(vc->view());
Genode::Object_pool<View_component>::Guard vc(_ep.lookup_and_lock(view_cap));
::Session::background(&vc->view());
/* switch background view to background mode */
if (::Session::background()) ::Session::background()->background(true);
if (::Session::background()) vc->view().background(true);
return 0;
}
@ -556,9 +553,9 @@ namespace Nitpicker {
Session_list &_session_list;
Global_keys &_global_keys;
Area _scr_size;
View_stack *_view_stack;
Flush_merger *_flush_merger;
Framebuffer::Session *_framebuffer;
View_stack &_view_stack;
Flush_merger &_flush_merger;
Framebuffer::Session &_framebuffer;
int _default_v_offset;
protected:
@ -598,7 +595,7 @@ namespace Nitpicker {
bool provides_default_bg = (Genode::strcmp(label_buf, "backdrop") == 0);
Session_component *session = new (md_alloc())
Session_component(label_buf, cdt, cdt, _view_stack, ep(),
Session_component(label_buf, *cdt, *cdt, _view_stack, *ep(),
_flush_merger, _framebuffer, v_offset,
cdt->input_mask_buffer(),
provides_default_bg, session_color(args),
@ -612,14 +609,17 @@ namespace Nitpicker {
void _destroy_session(Session_component *session)
{
Chunky_dataspace_texture<PT> *cdt;
cdt = static_cast<Chunky_dataspace_texture<PT> *>(session->texture());
/* retrieve pointer to texture from session */
Chunky_dataspace_texture<PT> const &cdt =
static_cast<Chunky_dataspace_texture<PT> const &>(session->texture());
_session_list.remove(session);
_global_keys.apply_config(_session_list);
destroy(md_alloc(), session);
destroy(md_alloc(), cdt);
/* cast away constness just for destruction of the texture */
destroy(md_alloc(), const_cast<Chunky_dataspace_texture<PT> *>(&cdt));
}
public:
@ -628,12 +628,12 @@ namespace Nitpicker {
* Constructor
*/
Root(Session_list &session_list, Global_keys &global_keys,
Genode::Rpc_entrypoint *session_ep, Area scr_size,
View_stack *view_stack, Genode::Allocator *md_alloc,
Flush_merger *flush_merger,
Framebuffer::Session *framebuffer, int default_v_offset)
Genode::Rpc_entrypoint &session_ep, Area scr_size,
View_stack &view_stack, Genode::Allocator &md_alloc,
Flush_merger &flush_merger,
Framebuffer::Session &framebuffer, int default_v_offset)
:
Genode::Root_component<Session_component>(session_ep, md_alloc),
Genode::Root_component<Session_component>(&session_ep, &md_alloc),
_session_list(session_list), _global_keys(global_keys),
_scr_size(scr_size), _view_stack(view_stack), _flush_merger(flush_merger),
_framebuffer(framebuffer), _default_v_offset(default_v_offset) { }
@ -657,30 +657,30 @@ class Input_handler_component : public Genode::Rpc_object<Input_handler,
{
private:
User_state *_user_state;
View *_mouse_cursor;
Area _mouse_size;
Flush_merger *_flush_merger;
Input::Session *_input;
User_state &_user_state;
View &_mouse_cursor;
Area const _mouse_size;
Flush_merger &_flush_merger;
Input::Session &_input;
Input::Event *_ev_buf;
Framebuffer::Session *_framebuffer;
Timer::Session *_timer;
Framebuffer::Session &_framebuffer;
Timer::Session &_timer;
public:
/**
* Constructor
*/
Input_handler_component(User_state *user_state, View *mouse_cursor,
Area mouse_size, Flush_merger *flush_merger,
Input::Session *input,
Framebuffer::Session *framebuffer,
Timer::Session *timer)
Input_handler_component(User_state &user_state, View &mouse_cursor,
Area mouse_size, Flush_merger &flush_merger,
Input::Session &input,
Framebuffer::Session &framebuffer,
Timer::Session &timer)
:
_user_state(user_state), _mouse_cursor(mouse_cursor),
_mouse_size(mouse_size), _flush_merger(flush_merger),
_input(input),
_ev_buf(Genode::env()->rm_session()->attach(_input->dataspace())),
_ev_buf(Genode::env()->rm_session()->attach(_input.dataspace())),
_framebuffer(framebuffer), _timer(timer)
{ }
@ -691,7 +691,7 @@ class Input_handler_component : public Genode::Rpc_object<Input_handler,
* \param max size of the event array
* \return number of events subjected to merge
*/
unsigned _num_consecutive_events(Input::Event *ev, unsigned max)
unsigned _num_consecutive_events(Input::Event const *ev, unsigned max)
{
if (max < 1) return 0;
if (ev->type() != Input::Event::MOTION) return 1;
@ -714,7 +714,7 @@ class Input_handler_component : public Genode::Rpc_object<Input_handler,
* \param n number of events to merge
* \return merged motion event
*/
Input::Event _merge_motion_events(Input::Event *ev, unsigned n)
static Input::Event _merge_motion_events(Input::Event const *ev, unsigned n)
{
Input::Event res;
for (unsigned i = 0; i < n; i++, ev++)
@ -751,7 +751,7 @@ class Input_handler_component : public Genode::Rpc_object<Input_handler,
continue;
/* pass event to user state */
_user_state->handle_event(curr);
_user_state.handle_event(curr);
}
}
@ -761,28 +761,28 @@ class Input_handler_component : public Genode::Rpc_object<Input_handler,
void do_input_handling()
{
do {
Point old_mouse_pos = _user_state->mouse_pos();
Point old_mouse_pos = _user_state.mouse_pos();
/* handle batch of pending events */
if (_input->is_pending())
_import_input_events(_input->flush());
if (_input.is_pending())
_import_input_events(_input.flush());
Point new_mouse_pos = _user_state->mouse_pos();
Point 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);
_user_state.viewport(_mouse_cursor,
Rect(new_mouse_pos, _mouse_size),
Point(), true);
/* flush dirty pixels to physical frame buffer */
if (_flush_merger->defer == false) {
Rect r = _flush_merger->to_be_flushed();
if (_flush_merger.defer == false) {
Rect r = _flush_merger.to_be_flushed();
if (r.valid())
_framebuffer->refresh(r.x1(), r.y1(), r.w(), r.h());
_flush_merger->reset();
_framebuffer.refresh(r.x1(), r.y1(), r.w(), r.h());
_flush_merger.reset();
}
_flush_merger->defer = false;
_flush_merger.defer = false;
/*
* In kill mode, we never leave the dispatch function to block
@ -790,10 +790,10 @@ class Input_handler_component : public Genode::Rpc_object<Input_handler,
* spinning for the end of the kill mode less painful for all
* non-blocked processes.
*/
if (_user_state->kill())
_timer->msleep(10);
if (_user_state.kill())
_timer.msleep(10);
} while (_user_state->kill());
} while (_user_state.kill());
}
};
@ -930,23 +930,23 @@ int main(int argc, char **argv)
*/
global_keys.apply_config(session_list);
static User_state user_state(global_keys, &screen, &menubar);
static User_state user_state(global_keys, screen, menubar);
/*
* Create view stack with default elements
*/
Area mouse_size(big_mouse.w, big_mouse.h);
Mouse_cursor<PT> mouse_cursor((PT *)&big_mouse.pixels[0][0],
mouse_size, &user_state);
mouse_size, user_state);
menubar.state(user_state, "", "", BLACK);
Background background(screen.size());
user_state.default_background(&background);
user_state.stack(&mouse_cursor);
user_state.stack(&menubar);
user_state.stack(&background);
user_state.default_background(background);
user_state.stack(mouse_cursor);
user_state.stack(menubar);
user_state.stack(background);
/*
* Initialize Nitpicker root interface
@ -955,9 +955,9 @@ int main(int argc, char **argv)
Sliced_heap sliced_heap(env()->ram_session(), env()->rm_session());
static Nitpicker::Root<PT> np_root(session_list, global_keys,
&ep, Area(mode.width(), mode.height()),
&user_state, &sliced_heap,
&screen, &framebuffer,
ep, Area(mode.width(), mode.height()),
user_state, sliced_heap,
screen, framebuffer,
MENUBAR_HEIGHT);
env()->parent()->announce(ep.manage(&np_root));
@ -971,8 +971,8 @@ int main(int argc, char **argv)
* periodic fashion.
*/
static Input_handler_component
input_handler(&user_state, &mouse_cursor, mouse_size,
&screen, &input, &framebuffer, &timer);
input_handler(user_state, mouse_cursor, mouse_size,
screen, input, framebuffer, timer);
Capability<Input_handler> input_handler_cap = ep.manage(&input_handler);
/* start periodic mode of operation */

View File

@ -17,32 +17,40 @@
#include "view.h"
#include "clip_guard.h"
class Background : public Session, public View
struct Background : private Texture, Session, View
{
public:
/*
* The background uses no texture. Therefore
* we can pass a null pointer as texture argument
* to the Session constructor.
*/
Background(Area size) :
Session("", 0, 0, BLACK),
View(this, View::BACKGROUND, Rect(Point(0, 0), size)) { }
/*
* The background uses no texture. Therefore
* we can pass a null pointer as texture argument
* to the Session constructor.
*/
Background(Area size)
:
Texture(Area(0, 0)), Session("", *this, 0, BLACK),
View(*this, View::NOT_STAY_TOP, View::NOT_TRANSPARENT,
View::BACKGROUND, Rect(Point(0, 0), size))
{ }
/********************
** View interface **
********************/
/***********************
** Session interface **
***********************/
int frame_size(Mode *mode) { return 0; }
void frame(Canvas *canvas, Mode *mode) { }
void submit_input_event(Input::Event) { }
void draw(Canvas *canvas, Mode *mode)
{
Clip_guard clip_guard(canvas, *this);
canvas->draw_box(*this, Color(25, 37, 50));
}
/********************
** View interface **
********************/
int frame_size(Mode const &mode) const { return 0; }
void frame(Canvas &canvas, Mode const &mode) { }
void draw(Canvas &canvas, Mode const &mode) const
{
Clip_guard clip_guard(canvas, *this);
canvas.draw_box(*this, Color(25, 37, 50));
}
};
#endif
#endif /* _BACKGROUND_H_ */

View File

@ -27,25 +27,32 @@ class Chunky_menubar : public Chunky_texture<PT>,
public:
Chunky_menubar(PT *pixels, Area size) :
Chunky_texture<PT>(pixels, 0, size),
Session("", this, 0, BLACK),
Menubar(&_chunky_canvas, size, this),
_chunky_canvas(pixels, size) { }
Chunky_menubar(PT *pixels, Area size)
:
Chunky_texture<PT>(pixels, 0, size), Session("", *this, 0, BLACK),
Menubar(_chunky_canvas, size, *this), _chunky_canvas(pixels, size)
{ }
/***********************
** Session interface **
***********************/
void submit_input_event(Input::Event) { }
/********************
** View interface **
********************/
int frame_size(Mode *mode) { return 0; }
void frame(Canvas *canvas, Mode *mode) { }
void draw(Canvas *canvas, Mode *mode)
int frame_size(Mode const &mode) const { return 0; }
void frame(Canvas &canvas, Mode const &mode) { }
void draw(Canvas const &canvas, Mode const &mode)
{
Clip_guard clip_guard(canvas, *this);
/* draw menubar content */
canvas->draw_texture(this, BLACK, p1(), Canvas::SOLID);
canvas.draw_texture(*this, BLACK, p1(), Canvas::SOLID);
}
};

View File

@ -34,17 +34,20 @@ class Clip_guard
{
private:
Canvas *_canvas;
Rect _orig_clip_rect;
Canvas &_canvas;
Rect const _orig_clip_rect;
public:
Clip_guard(Canvas *canvas, Rect new_clip_rect):
Clip_guard(Canvas &canvas, Rect new_clip_rect)
:
_canvas(canvas),
_orig_clip_rect(_canvas->clip()) {
_canvas->clip(Rect::intersect(_orig_clip_rect, new_clip_rect)); }
_orig_clip_rect(_canvas.clip())
{
_canvas.clip(Rect::intersect(_orig_clip_rect, new_clip_rect));
}
~Clip_guard() { _canvas->clip(_orig_clip_rect); }
~Clip_guard() { _canvas.clip(_orig_clip_rect); }
};
#endif
#endif /* _CLIP_GUARD_H_ */

View File

@ -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, 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 + Point(i, j), default_font, BLACK, s);
}
@ -52,19 +52,19 @@ 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, Point pos,
const char *session_label, Color session_label_color,
const char *view_title, Color view_title_color)
{
pos = pos + Point(1, 1);
draw_string_outline(canvas, pos, session_label);
canvas->draw_string(pos, &default_font, session_label_color, 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);
draw_string_outline(canvas, pos, view_title);
canvas->draw_string(pos, &default_font, view_title_color, view_title);
canvas.draw_string(pos, default_font, view_title_color, view_title);
}
#endif /* _DRAW_LABEL_H_ */

View File

@ -32,7 +32,7 @@ class List
friend class List;
LT *_next;
LT mutable *_next;
public:
@ -41,7 +41,7 @@ class List
/**
* Return next element in list
*/
LT *next() { return _next; }
LT *next() const { return _next; }
};
public:
@ -56,7 +56,8 @@ class List
/**
* Return first list element
*/
LT *first() { return _first; }
LT *first() { return _first; }
LT const *first() const { return _first; }
/**
* Insert element into list
@ -65,22 +66,22 @@ class List
* \param at target position (preceding list element) or
* 0 to insert element at the beginning of the list
*/
void insert(LT *le, LT *at = 0)
void insert(LT const *le, LT const *at = 0)
{
/* insert element at the beginning of the list */
if (at == 0) {
le->_next = _first;
_first = le;
_first = const_cast<LT *>(le);
} else {
le->_next = at->_next;
at->_next = le;
at->_next = const_cast<LT *>(le);
}
}
/**
* Remove element from list
*/
void remove(LT *le)
void remove(LT const *le)
{
if (!_first) return;

View File

@ -22,20 +22,24 @@ class Menubar : public View
{
private:
Canvas *_canvas;
Canvas &_canvas;
protected:
Menubar(Canvas *canvas, Area size, Session *session):
View(session, View::STAY_TOP, Rect(Point(0, 0), size)), _canvas(canvas) { }
Menubar(Canvas &canvas, Area size, Session &session)
:
View(session, View::STAY_TOP, View::NOT_TRANSPARENT,
View::NOT_BACKGROUND, Rect(Point(0, 0), size)),
_canvas(canvas)
{ }
public:
/**
* Set state that is displayed in the trusted menubar
*/
void state(Mode mode, const char *session_label, const char *view_title,
Color session_color)
void state(Mode const &mode, const char *session_label,
const char *view_title, Color session_color)
{
/* choose base color dependent on the Nitpicker state */
int r = (mode.kill()) ? 200 : (mode.xray()) ? session_color.r : (session_color.r + 100) >> 1;
@ -43,20 +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)),
Color(r + (r / 2), g + (g / 2), b + (b / 2)));
_canvas.draw_box(Rect(Point(0, 0), 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++) {
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(Rect(Point(0, i), Area(w(), 1)), Color(r, g, b));
}
/* draw last line darker */
_canvas->draw_box(Rect(Point(0, h() - 1), Area(w(), 1)),
Color(r / 4, g / 4, b / 4));
_canvas.draw_box(Rect(Point(0, h() - 1), Area(w(), 1)),
Color(r / 4, g / 4, b / 4));
/* draw label */
draw_label(_canvas, center(label_size(session_label, view_title)),

View File

@ -18,44 +18,43 @@ class View;
class Mode
{
protected:
private:
unsigned _mode;
bool _xray;
bool _kill;
/*
* Last clicked view. This view is receiving
* keyboard input.
* Last clicked view. This view is receiving keyboard input, except
* for global keys.
*/
View *_focused_view;
View const *_focused_view;
public:
/*
* Bitmasks for the different Nitpicker modes
*/
enum {
XRAY = 0x1,
KILL = 0x2,
};
Mode(): _mode(0), _focused_view(0) { }
Mode(): _xray(false), _kill(false), _focused_view(0) { }
virtual ~Mode() { }
/**
* Accessors
*/
bool xray() { return _mode & XRAY; }
bool kill() { return _mode & KILL; }
bool flat() { return _mode == 0; }
bool xray() const { return _xray; }
bool kill() const { return _kill; }
bool flat() const { return !_xray && !_kill; }
View *focused_view() { return _focused_view; }
void leave_kill() { _kill = false; }
void toggle_kill() { _kill = !_kill; }
void toggle_xray() { _xray = !_xray; }
View const *focused_view() const { return _focused_view; }
void focused_view(View const *view) { _focused_view = view; }
/**
* Discard all references to specified view
*/
virtual void forget(View *v) {
if (v == _focused_view) _focused_view = 0; }
virtual void forget(View const &v) {
if (&v == _focused_view) _focused_view = 0; }
};
#endif

View File

@ -27,18 +27,28 @@ class Mouse_cursor : public Chunky_texture<PT>, public Session, public View
{
private:
View_stack *_view_stack;
View_stack const &_view_stack;
public:
/**
* Constructor
*/
Mouse_cursor(PT *pixels, Area size, View_stack *view_stack):
Mouse_cursor(PT const *pixels, Area size, View_stack const &view_stack)
:
Chunky_texture<PT>(pixels, 0, size),
Session("", this, 0, BLACK),
View(this, View::STAY_TOP | View::TRANSPARENT),
_view_stack(view_stack) { }
Session("", *this, 0, BLACK),
View(*this, View::STAY_TOP, View::TRANSPARENT, View::NOT_BACKGROUND,
Rect()),
_view_stack(view_stack)
{ }
/***********************
** Session interface **
***********************/
void submit_input_event(Input::Event) { }
/********************
@ -49,19 +59,19 @@ class Mouse_cursor : public Chunky_texture<PT>, public Session, public View
* The mouse cursor is always displayed without a surrounding frame.
*/
int frame_size(Mode *mode) { return 0; }
int frame_size(Mode const &mode) const { return 0; }
void frame(Canvas *canvas, Mode *mode) { }
void frame(Canvas &canvas, Mode const &mode) const { }
void draw(Canvas *canvas, Mode *mode)
void draw(Canvas &canvas, Mode const &mode) const
{
Clip_guard clip_guard(canvas, *this);
/* draw area behind the mouse cursor */
_view_stack->draw_rec(view_stack_next(), 0, 0, *this);
_view_stack.draw_rec(view_stack_next(), 0, 0, *this);
/* draw mouse cursor */
canvas->draw_texture(this, BLACK, p1(), Canvas::MASKED);
canvas.draw_texture(*this, BLACK, p1(), Canvas::MASKED);
}
};

View File

@ -36,13 +36,13 @@ class Session : public Session_list::Element
private:
char _label[LABEL_LEN];
Color _color;
Texture *_texture;
View *_background;
int _v_offset;
unsigned char *_input_mask;
bool _stay_top;
char _label[LABEL_LEN];
Color _color;
Texture const &_texture;
View *_background;
int _v_offset;
unsigned char const *_input_mask;
bool const _stay_top;
public:
@ -64,8 +64,8 @@ class Session : public Session_list::Element
* 'input_mask' is a null pointer, user input is
* unconditionally consumed by the view.
*/
Session(const char *label, Texture *texture, int v_offset,
Color color, unsigned char *input_mask = 0,
Session(char const *label, Texture const &texture, int v_offset,
Color color, unsigned char const *input_mask = 0,
bool stay_top = false)
:
_color(color), _texture(texture), _background(0),
@ -74,13 +74,13 @@ class Session : public Session_list::Element
virtual ~Session() { }
virtual void submit_input_event(Input::Event *ev) { }
virtual void submit_input_event(Input::Event ev) = 0;
char *label() { return _label; }
char const *label() const { return _label; }
Texture *texture() const { return _texture; }
Texture const &texture() const { return _texture; }
Color color() { return _color; }
Color color() const { return _color; }
View *background() const { return _background; }
@ -91,7 +91,7 @@ class Session : public Session_list::Element
/**
* Return true if session uses an alpha channel
*/
bool uses_alpha() const { return _texture && _texture->alpha(); }
bool uses_alpha() const { return _texture.alpha(); }
/**
* Return vertical offset of session
@ -101,16 +101,16 @@ class Session : public Session_list::Element
/**
* Return input mask value at specified buffer position
*/
unsigned char input_mask_at(Point p)
unsigned char input_mask_at(Point p) const
{
if (!_input_mask) return 0;
/* check boundaries */
if (p.x() < 0 || p.x() >= _texture->w()
|| p.y() < 0 || p.y() >= _texture->h())
if (p.x() < 0 || p.x() >= _texture.w()
|| p.y() < 0 || p.y() >= _texture.h())
return 0;
return _input_mask[p.y()*_texture->w() + p.x()];
return _input_mask[p.y()*_texture.w() + p.x()];
}
};

View File

@ -46,7 +46,7 @@ class User_state : public Mode, public View_stack
* according to the current Mitpicker mode and the
* focused view.
*/
Menubar *_menubar;
Menubar &_menubar;
/*
* Current mouse cursor position
@ -56,7 +56,7 @@ class User_state : public Mode, public View_stack
/*
* Currently pointed-at view
*/
View *_pointed_view;
View const *_pointed_view;
/*
* Session that receives the current stream of input events
@ -73,7 +73,7 @@ class User_state : public Mode, public View_stack
/**
* Constructor
*/
User_state(Global_keys &global_keys, Canvas *canvas, Menubar *menubar);
User_state(Global_keys &global_keys, Canvas &canvas, Menubar &menubar);
/**
* Handle input event
@ -86,12 +86,12 @@ class User_state : public Mode, public View_stack
/**
* Accessors
*/
Point mouse_pos() { return _mouse_pos; }
Point mouse_pos() { return _mouse_pos; }
/**
* Mode interface
*/
void forget(View *);
void forget(View const &);
};
#endif

View File

@ -41,34 +41,39 @@ class View : public Same_buffer_list_elem, public View_stack_elem, public Rect
enum { TITLE_LEN = 32 }; /* max.characters of a title */
enum Stay_top { NOT_STAY_TOP = 0, STAY_TOP = 1 };
enum Transparent { NOT_TRANSPARENT = 0, TRANSPARENT = 1 };
enum Background { NOT_BACKGROUND = 0, BACKGROUND = 1 };
private:
unsigned _flags; /* properties of the view */
Stay_top const _stay_top; /* keep view always on top */
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 */
Session &_session; /* session that created the view */
char _title[TITLE_LEN];
public:
enum {
STAY_TOP = 0x01, /* keep view always on top */
TRANSPARENT = 0x02, /* background is partly visible */
BACKGROUND = 0x20, /* view is a background view */
};
View(Session *session, unsigned flags = 0, Rect rect = Rect()):
Rect(rect), _flags(flags), _session(session) { title(""); }
View(Session &session, Stay_top stay_top, Transparent transparent,
Background background, Rect rect)
:
Rect(rect), _stay_top(stay_top), _transparent(transparent),
_background(background), _session(session)
{ title(""); }
virtual ~View() { }
/**
* Return thickness of frame that surrounds the view
*/
virtual int frame_size(Mode *mode)
virtual int frame_size(Mode const &mode) const
{
if (mode->focused_view()
&& mode->focused_view()->session() == _session)
if (mode.focused_view()
&& mode.focused_view()->belongs_to(_session))
return 5;
return 3;
@ -77,12 +82,12 @@ class View : public Same_buffer_list_elem, public View_stack_elem, public Rect
/**
* Draw view-surrounding frame on canvas
*/
virtual void frame(Canvas *canvas, Mode *mode);
virtual void frame(Canvas &canvas, Mode const &mode) const;
/**
* Draw view on canvas
*/
virtual void draw(Canvas *canvas, Mode *mode);
virtual void draw(Canvas &canvas, Mode const &mode) const;
/**
* Set view title
@ -92,6 +97,9 @@ class View : public Same_buffer_list_elem, public View_stack_elem, public Rect
/**
* Return successor in view stack
*/
View const *view_stack_next() const {
return static_cast<View const *>(View_stack_elem::next()); }
View *view_stack_next() {
return static_cast<View *>(View_stack_elem::next()); }
@ -100,29 +108,34 @@ class View : public Same_buffer_list_elem, public View_stack_elem, public Rect
*
* \param is_bg true if view is background
*/
void background(bool is_bg)
{
if (is_bg) _flags |= BACKGROUND;
else _flags &= ~BACKGROUND;
}
void background(bool is_bg) {
_background = is_bg ? BACKGROUND : NOT_BACKGROUND; }
/**
* Accessors
*/
Session *session() { return _session; }
bool stay_top() { return _flags & STAY_TOP; }
bool transparent() { return _flags & TRANSPARENT || _session->uses_alpha(); }
bool background() { return _flags & BACKGROUND; }
void buffer_off(Point buffer_off) { _buffer_off = buffer_off; }
Point buffer_off() { return _buffer_off; }
Rect label_rect() { return _label_rect; }
void label_pos(Point pos) { _label_rect = Rect(pos, _label_rect.area()); }
char *title() { return _title; }
Session &session() const { return _session; }
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(); }
char const *title() const { return _title; }
void buffer_off(Point buffer_off) { _buffer_off = buffer_off; }
void label_pos(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 *mode)
bool input_response_at(Point p, Mode const &mode) const
{
/* check if point lies outside view geometry */
if ((p.x() < x1()) || (p.x() > x2())
@ -130,12 +143,11 @@ class View : public Same_buffer_list_elem, public View_stack_elem, public Rect
return false;
/* if view uses an alpha channel, check the input mask */
if (mode->flat() && session()->uses_alpha())
return session()->input_mask_at(p - p1() + _buffer_off);
if (mode.flat() && session().uses_alpha())
return session().input_mask_at(p - p1() + _buffer_off);
return true;
}
};
#endif
#endif /* _VIEW_H_ */

View File

@ -22,8 +22,8 @@ class View_stack
{
private:
Canvas *_canvas;
Mode *_mode;
Canvas &_canvas;
Mode &_mode;
List<View_stack_elem> _views;
View *_default_background;
@ -34,7 +34,7 @@ class View_stack
* active Nitpicker mode. In non-flat modes, we incorporate the
* surrounding frame.
*/
Rect _outline(View *view);
Rect _outline(View const &view) const;
/**
* Return top-most view of the view stack
@ -44,12 +44,12 @@ class View_stack
/**
* Find position in view stack for inserting a view
*/
View *_target_stack_position(View *neighbor, bool behind);
View const *_target_stack_position(View const *neighbor, bool behind);
/**
* Find best visible label position
*/
void _optimize_label_rec(View *cv, View *lv, Rect rect, Rect *optimal);
void _optimize_label_rec(View const *cv, View const *lv, Rect rect, Rect *optimal);
/**
* Position labels that are affected by specified area
@ -58,21 +58,25 @@ class View_stack
/**
* Return view following the specified view in the view stack
*
* The function is a template to capture both const and non-const
* usage.
*/
View *_next_view(View *view);
template <typename VIEW>
VIEW *_next_view(VIEW *view) const;
public:
/**
* Constructor
*/
View_stack(Canvas *canvas, Mode *mode) :
View_stack(Canvas &canvas, Mode &mode) :
_canvas(canvas), _mode(mode), _default_background(0) { }
/**
* Return size
*/
Area size() { return _canvas->size(); }
Area size() { return _canvas.size(); }
/**
* Draw views in specified area (recursivly)
@ -82,22 +86,22 @@ class View_stack
* if all views should be drawn
* \param exclude do not draw views of this session
*/
void draw_rec(View *view, View *dst_view, Session *exclude, Rect);
void draw_rec(View const *view, View const *dst_view, Session const *exclude, Rect) const;
/**
* Draw whole view stack
*/
void update_all_views()
{
_place_labels(Rect(Point(), _canvas->size()));
draw_rec(_first_view(), 0, 0, Rect(Point(), _canvas->size()));
_place_labels(Rect(Point(), _canvas.size()));
draw_rec(_first_view(), 0, 0, Rect(Point(), _canvas.size()));
}
/**
* Update all views belonging to the specified session
*
* \param Session * Session that created the view
* \param Rect Buffer area to update
* \param Session Session that created the view
* \param Rect Buffer area to update
*
* Note: For now, we perform an independent view-stack traversal
* for each view when calling 'refresh_view'. This becomes
@ -105,11 +109,11 @@ class View_stack
* a tailored 'draw_rec_session' function would overcome
* this problem.
*/
void update_session_views(Session *session, Rect rect)
void update_session_views(Session const &session, Rect rect)
{
for (View *view = _first_view(); view; view = view->view_stack_next()) {
for (View const *view = _first_view(); view; view = view->view_stack_next()) {
if (view->session() != session)
if (!view->belongs_to(session))
continue;
/*
@ -119,7 +123,7 @@ class View_stack
Point offset = view->p1() + view->buffer_off();
Rect r = Rect::intersect(Rect(rect.p1() + offset,
rect.p2() + offset), *view);
refresh_view(view, view, r);
refresh_view(*view, view, r);
}
}
@ -131,7 +135,7 @@ class View_stack
* refreshed or 'view' if the refresh should be limited to
* the specified view.
*/
void refresh_view(View *view, View *dst, Rect);
void refresh_view(View const &view, View const *dst, Rect);
/**
* Define position and viewport
@ -140,7 +144,7 @@ class View_stack
* \param buffer_off view offset of displayed buffer
* \param do_redraw perform screen update immediately
*/
void viewport(View *view, Rect pos, Point buffer_off, bool do_redraw);
void viewport(View &view, Rect pos, Point buffer_off, bool do_redraw);
/**
* Insert view at specified position in view stack
@ -153,13 +157,13 @@ class View_stack
* bottom of the view stack, specify neighbor = 0 and
* behind = false.
*/
void stack(View *view, View *neighbor = 0, bool behind = true,
bool do_redraw = true);
void stack(View const &view, View const *neighbor = 0,
bool behind = true, bool do_redraw = true);
/**
* Set view title
*/
void title(View *view, const char *title);
void title(View &view, char const *title);
/**
* Find view at specified position
@ -169,17 +173,17 @@ class View_stack
/**
* Remove view from view stack
*/
void remove_view(View *);
void remove_view(View const &);
/**
* Define default background
*/
void default_background(View *view) { _default_background = view; }
void default_background(View &view) { _default_background = &view; }
/**
* Return true if view is the default background
*/
bool is_default_background(View *view) { return view == _default_background; }
bool is_default_background(View const *view) const { return view == _default_background; }
/**
* Remove all views of specified session from view stack
@ -187,11 +191,11 @@ class View_stack
* Rather than removing the views from the view stack, this function moves
* the session views out of the visible screen area.
*/
void lock_out_session(Session *session)
void lock_out_session(Session const &session)
{
View *view = _first_view(), *next_view = view->view_stack_next();
View const *view = _first_view(), *next_view = view->view_stack_next();
while (view) {
if (view->session() == session) remove_view(view);
if (view->belongs_to(session)) remove_view(*view);
view = next_view;
next_view = view ? view->view_stack_next() : 0;
}

View File

@ -255,7 +255,7 @@ void Vancouver_console::entry()
((fg & 0x2) >> 1)*127+lum, /* G+luminosity */
(fg & 0x1)*127+lum /* B+luminosity */);
canvas.draw_string(where, &default_font, color, buffer);
canvas.draw_string(where, default_font, color, buffer);
/* Checksum for comparing */
if (cmp_even) checksum1 += character;