Move nitpicker_gfx/color.h to util/color.h

This commit is contained in:
Norman Feske 2013-12-28 20:35:56 +01:00 committed by Christian Helmuth
parent e809192b97
commit 0063f217ca
14 changed files with 131 additions and 119 deletions

View File

@ -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<Genode::Log_session>
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<Genode::Log_session>
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));
}

View File

@ -23,6 +23,7 @@
#include <os/attached_ram_dataspace.h>
#include <input/event.h>
#include <os/config.h>
#include <util/color.h>
/* terminal includes */
#include <terminal/decoder.h>
@ -34,7 +35,6 @@
/* nitpicker graphic back end */
#include <nitpicker_gfx/font.h>
#include <nitpicker_gfx/color.h>
#include <nitpicker_gfx/pixel_rgb565.h>
@ -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];

View File

@ -15,8 +15,8 @@
#define _INCLUDE__NITPICKER_GFX__CANVAS_H_
#include <util/geometry.h>
#include <util/color.h>
#include <nitpicker_gfx/color.h>
#include <nitpicker_gfx/font.h>
@ -47,6 +47,7 @@ class Canvas
typedef Genode::Point<> Point;
typedef Genode::Area<> Area;
typedef Genode::Rect<> Rect;
typedef Genode::Color Color;
protected:

View File

@ -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_ */

View File

@ -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 <util/string.h>
#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<Color>(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_ */

64
os/include/util/color.h Normal file
View File

@ -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 <util/string.h>
namespace Genode {
struct Color;
template <>
inline size_t ascii_to<Color>(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<Genode::Color>(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_ */

View File

@ -19,7 +19,7 @@
struct Background : private Texture, Session, View
{
Color color;
Genode::Color color;
/*
* The background uses no texture. Therefore

View File

@ -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 <util/color.h>
/*
* 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_ */

View File

@ -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);

View File

@ -28,7 +28,7 @@
#include <nitpicker_session/nitpicker_session.h>
#include <framebuffer_session/connection.h>
#include <nitpicker_gfx/pixel_rgb565.h>
#include <nitpicker_gfx/string.h>
#include <util/color.h>
#include <os/session_policy.h>
#include <os/server.h>

View File

@ -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)),

View File

@ -17,11 +17,12 @@
/* Genode includes */
#include <util/list.h>
#include <util/string.h>
#include <nitpicker_gfx/color.h>
#include <nitpicker_gfx/canvas.h>
#include <nitpicker_gfx/string.h>
#include <os/session_policy.h>
/* 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; }

View File

@ -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(),

View File

@ -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);