diff --git a/demo/src/server/nitlog/main.cc b/demo/src/server/nitlog/main.cc index f8f4d4b5c..8cea22ee5 100644 --- a/demo/src/server/nitlog/main.cc +++ b/demo/src/server/nitlog/main.cc @@ -48,6 +48,8 @@ class Log_entry { private: + typedef Genode::Color Color; + char _label[64]; char _text[LOG_W]; char _attr[LOG_W]; @@ -65,7 +67,7 @@ class Log_entry */ Log_entry() { } - Log_entry(Color color, const char *label, const char *log_text, const char *log_attr, int id): + Log_entry(Genode::Color color, const char *label, const char *log_text, const char *log_attr, int id): _color(color), _id(id) { Genode::strncpy(_label, label, sizeof(_label)); @@ -156,7 +158,8 @@ class Log_window * \param sid unique ID of the log session. This ID is used to * determine section transitions in the log output. */ - void write(Color color, const char *label, const char *log_text, int sid) + void write(Genode::Color color, const char *label, + const char *log_text, int sid) { _entries[_dst_entry] = Log_entry(color, label, log_text, _attr, sid); @@ -210,10 +213,10 @@ class Log_session_component : public Genode::Rpc_object private: - Color _color; - Log_window *_log_window; - char _label[LABEL_LEN]; - int _id; + Genode::Color _color; + Log_window *_log_window; + char _label[LABEL_LEN]; + int _id; static int _bit(int v, int bit_num) { return (v >> bit_num) & 1; } @@ -237,7 +240,7 @@ class Log_session_component : public Genode::Rpc_object int g = (_bit(_id, 4) + 2*_bit(_id, 1))*scale + offset; int b = (_bit(_id, 5) + 2*_bit(_id, 2))*scale + offset; - _color = Color(r, g, b); + _color = Genode::Color(r, g, b); Genode::strncpy(_label, label, sizeof(_label)); } diff --git a/gems/src/server/terminal/main.cc b/gems/src/server/terminal/main.cc index 5999a0ffa..f2b86dd6a 100644 --- a/gems/src/server/terminal/main.cc +++ b/gems/src/server/terminal/main.cc @@ -23,6 +23,7 @@ #include #include #include +#include /* terminal includes */ #include @@ -34,7 +35,6 @@ /* nitpicker graphic back end */ #include -#include #include @@ -65,6 +65,9 @@ inline Pixel_rgb565 mix(Pixel_rgb565 p1, Pixel_rgb565 p2, int alpha) } +using Genode::Color; + + static Color color_palette[2*8]; diff --git a/os/include/nitpicker_gfx/canvas.h b/os/include/nitpicker_gfx/canvas.h index af0b0c29a..5de827557 100644 --- a/os/include/nitpicker_gfx/canvas.h +++ b/os/include/nitpicker_gfx/canvas.h @@ -15,8 +15,8 @@ #define _INCLUDE__NITPICKER_GFX__CANVAS_H_ #include +#include -#include #include @@ -47,6 +47,7 @@ class Canvas typedef Genode::Point<> Point; typedef Genode::Area<> Area; typedef Genode::Rect<> Rect; + typedef Genode::Color Color; protected: diff --git a/os/include/nitpicker_gfx/color.h b/os/include/nitpicker_gfx/color.h deleted file mode 100644 index cf08e8b6f..000000000 --- a/os/include/nitpicker_gfx/color.h +++ /dev/null @@ -1,36 +0,0 @@ -/* - * \brief Color representation - * \date 2006-08-04 - * \author Norman Feske - */ - -/* - * 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__COLOR_H_ -#define _INCLUDE__NITPICKER_GFX__COLOR_H_ - -struct Color -{ - int r, g, b; - - /** - * Constructors - */ - Color(int red, int green, int blue): r(red), g(green), b(blue) { } - Color(): r(0), g(0), b(0) { } -}; - -/* - * Symbolic names for some important colors - */ -static const Color BLACK(0, 0, 0); -static const Color WHITE(255, 255, 255); -static const Color FRAME_COLOR(255, 200, 127); -static const Color KILL_COLOR(255, 0, 0); - -#endif /* _INCLUDE__NITPICKER_GFX__COLOR_H_ */ diff --git a/os/include/nitpicker_gfx/string.h b/os/include/nitpicker_gfx/string.h deleted file mode 100644 index 4b3ed8b84..000000000 --- a/os/include/nitpicker_gfx/string.h +++ /dev/null @@ -1,52 +0,0 @@ -/* - * \brief Convert string to color - * \author Norman Feske - * \date 2013-01-04 - */ - -/* - * Copyright (C) 2012 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__STRING_H_ -#define _INCLUDE__NITPICKER_GFX__STRING_H_ - -/* Genode includes */ -#include - -#include "nitpicker_gfx/color.h" - -namespace Genode { - - /** - * Convert ASCII string to Color - * - * The ASCII string must have the format '#rrggbb' - * - * \return number of consumed characters, or 0 if the string contains - * no valid color - */ - template <> - inline size_t ascii_to(const char *s, Color *result, unsigned) - { - /* validate string */ - if (strlen(s) < 7 || *s != '#') return 0; - - enum { HEX = true }; - - for (unsigned i = 0; i < 6; i++) - if (!is_digit(s[i + 1], HEX)) return 0; - - int red = 16*digit(s[1], HEX) + digit(s[2], HEX), - green = 16*digit(s[3], HEX) + digit(s[4], HEX), - blue = 16*digit(s[5], HEX) + digit(s[6], HEX); - - *result = Color(red, green, blue); - return 7; - } -} - -#endif /* _INCLUDE__NITPICKER_GFX__STRING_H_ */ diff --git a/os/include/util/color.h b/os/include/util/color.h new file mode 100644 index 000000000..691f29594 --- /dev/null +++ b/os/include/util/color.h @@ -0,0 +1,64 @@ +/* + * \brief Color representation + * \date 2006-08-04 + * \author Norman Feske + */ + +/* + * 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__COLOR_H_ +#define _INCLUDE__UTIL__COLOR_H_ + +#include + +namespace Genode { + struct Color; + + template <> + inline size_t ascii_to(const char *, Color *, unsigned); +} + + +struct Genode::Color +{ + int r, g, b; + + Color(int red, int green, int blue): r(red), g(green), b(blue) { } + Color(): r(0), g(0), b(0) { } +}; + + +/** + * Convert ASCII string to Color + * + * The ASCII string must have the format '#rrggbb' + * + * \return number of consumed characters, or 0 if the string contains + * no valid color + */ +template <> +inline Genode::size_t +Genode::ascii_to(const char *s, Genode::Color *result, unsigned) +{ + /* validate string */ + if (strlen(s) < 7 || *s != '#') return 0; + + enum { HEX = true }; + + for (unsigned i = 0; i < 6; i++) + if (!is_digit(s[i + 1], HEX)) return 0; + + int red = 16*digit(s[1], HEX) + digit(s[2], HEX), + green = 16*digit(s[3], HEX) + digit(s[4], HEX), + blue = 16*digit(s[5], HEX) + digit(s[6], HEX); + + *result = Color(red, green, blue); + return 7; +} + +#endif /* _INCLUDE__UTIL__COLOR_H_ */ diff --git a/os/src/server/nitpicker/background.h b/os/src/server/nitpicker/background.h index 28750b840..4884db492 100644 --- a/os/src/server/nitpicker/background.h +++ b/os/src/server/nitpicker/background.h @@ -19,7 +19,7 @@ struct Background : private Texture, Session, View { - Color color; + Genode::Color color; /* * The background uses no texture. Therefore diff --git a/os/src/server/nitpicker/color.h b/os/src/server/nitpicker/color.h new file mode 100644 index 000000000..bcb5f0858 --- /dev/null +++ b/os/src/server/nitpicker/color.h @@ -0,0 +1,27 @@ +/* + * \brief Color definitions used by nitpicker + * \date 2006-08-04 + * \author Norman Feske + */ + +/* + * 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 _COLOR_H_ +#define _COLOR_H_ + +#include + +/* + * Symbolic names for some important colors + */ +static const Genode::Color BLACK(0, 0, 0); +static const Genode::Color WHITE(255, 255, 255); +static const Genode::Color FRAME_COLOR(255, 200, 127); +static const Genode::Color KILL_COLOR(255, 0, 0); + +#endif /* _COLOR_H_ */ diff --git a/os/src/server/nitpicker/draw_label.h b/os/src/server/nitpicker/draw_label.h index af263418e..b18e06bb9 100644 --- a/os/src/server/nitpicker/draw_label.h +++ b/os/src/server/nitpicker/draw_label.h @@ -53,8 +53,8 @@ inline Canvas::Area label_size(const char *sl, const char *vt) { * application. */ 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) + const char *session_label, Genode::Color session_label_color, + const char *view_title, Genode::Color view_title_color) { pos = pos + Canvas::Point(1, 1); diff --git a/os/src/server/nitpicker/main.cc b/os/src/server/nitpicker/main.cc index 480df9846..06c90134f 100644 --- a/os/src/server/nitpicker/main.cc +++ b/os/src/server/nitpicker/main.cc @@ -28,7 +28,7 @@ #include #include #include -#include +#include #include #include diff --git a/os/src/server/nitpicker/menubar.h b/os/src/server/nitpicker/menubar.h index 533c91730..a295f60f8 100644 --- a/os/src/server/nitpicker/menubar.h +++ b/os/src/server/nitpicker/menubar.h @@ -39,7 +39,7 @@ class Menubar : public View * Set state that is displayed in the trusted menubar */ void state(Mode const &mode, const char *session_label, - const char *view_title, Color session_color) + const char *view_title, Genode::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; @@ -48,7 +48,7 @@ class Menubar : public View /* highlight first line with slightly brighter color */ _canvas.draw_box(Canvas::Rect(Canvas::Point(0, 0), Canvas::Area(w(), 1)), - Color(r + (r / 2), g + (g / 2), b + (b / 2))); + Genode::Color(r + (r / 2), g + (g / 2), b + (b / 2))); /* draw slightly shaded background */ for (unsigned i = 1; i < h() - 1; i++) { @@ -56,12 +56,13 @@ class Menubar : public View g -= g > 3 ? 4 : 0; b -= b > 4 ? 4 : 0; _canvas.draw_box(Canvas::Rect(Canvas::Point(0, i), - Canvas::Area(w(), 1)), Color(r, g, b)); + Canvas::Area(w(), 1)), + Genode::Color(r, g, b)); } /* draw last line darker */ _canvas.draw_box(Canvas::Rect(Canvas::Point(0, h() - 1), Canvas::Area(w(), 1)), - Color(r / 4, g / 4, b / 4)); + Genode::Color(r / 4, g / 4, b / 4)); /* draw label */ draw_label(_canvas, center(label_size(session_label, view_title)), diff --git a/os/src/server/nitpicker/session.h b/os/src/server/nitpicker/session.h index 5d9c666a0..41c997386 100644 --- a/os/src/server/nitpicker/session.h +++ b/os/src/server/nitpicker/session.h @@ -17,11 +17,12 @@ /* Genode includes */ #include #include -#include #include -#include #include +/* local includes */ +#include "color.h" + class Texture; class View; class Session; @@ -35,7 +36,7 @@ class Session : public Session_list::Element private: Genode::Session_label const _label; - Color _color; + Genode::Color _color; Texture const *_texture; View *_background = 0; int _v_offset; @@ -81,7 +82,7 @@ class Session : public Session_list::Element */ void input_mask(unsigned char const *mask) { _input_mask = mask; } - Color color() const { return _color; } + Genode::Color color() const { return _color; } View *background() const { return _background; } diff --git a/os/src/server/nitpicker/view.cc b/os/src/server/nitpicker/view.cc index 0ae92a79e..4f97d45a7 100644 --- a/os/src/server/nitpicker/view.cc +++ b/os/src/server/nitpicker/view.cc @@ -26,7 +26,7 @@ /** * 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, Genode::Color 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); @@ -38,7 +38,7 @@ static void draw_rect(Canvas &canvas, int x, int y, int w, int h, Color color) /** * Draw outlined frame with black outline color */ -static void draw_frame(Canvas &canvas, Canvas::Rect r, Color color, int frame_size) +static void draw_frame(Canvas &canvas, Canvas::Rect r, Genode::Color color, int frame_size) { /* draw frame around the view */ int d = frame_size; @@ -77,7 +77,7 @@ void View::draw(Canvas &canvas, Mode const &mode) const bool const view_is_focused = mode.focused_view() && mode.focused_view()->belongs_to(_session); - Color const frame_color = _session.color(); + Genode::Color const frame_color = _session.color(); /* * Use dimming in x-ray and kill mode, but do not dim the focused view in @@ -104,10 +104,10 @@ void View::draw(Canvas &canvas, Mode const &mode) const bool allow_alpha = mode.flat(); /* draw view content */ - Color const mix_color = mode.kill() ? KILL_COLOR - : Color(_session.color().r >> 1, - _session.color().g >> 1, - _session.color().b >> 1); + Genode::Color const mix_color = mode.kill() ? KILL_COLOR + : Genode::Color(_session.color().r >> 1, + _session.color().g >> 1, + _session.color().b >> 1); if (_session.texture()) canvas.draw_texture(*_session.texture(), mix_color, _buffer_off + p1(), diff --git a/ports/src/vancouver/console.cc b/ports/src/vancouver/console.cc index e70c3e4e4..3c9c28d7a 100644 --- a/ports/src/vancouver/console.cc +++ b/ports/src/vancouver/console.cc @@ -251,9 +251,9 @@ void Vancouver_console::entry() char fg = colorvalue & 0xf; if (fg == 0x8) fg = 0x7; unsigned lum = ((fg & 0x8) >> 3)*127; - Color color(((fg & 0x4) >> 2)*127+lum, /* R+luminosity */ - ((fg & 0x2) >> 1)*127+lum, /* G+luminosity */ - (fg & 0x1)*127+lum /* B+luminosity */); + Genode::Color color(((fg & 0x4) >> 2)*127+lum, /* R+luminosity */ + ((fg & 0x2) >> 1)*127+lum, /* G+luminosity */ + (fg & 0x1)*127+lum /* B+luminosity */); canvas.draw_string(where, default_font, color, buffer);