demo: avoid implicit conversions

Issue #23
This commit is contained in:
Norman Feske 2021-12-02 11:24:09 +01:00
parent 04cf6ea3ab
commit 1aa4f29300
30 changed files with 108 additions and 79 deletions

View File

@ -1082,7 +1082,7 @@
* want to have unsigned int for png_uint_32 instead of unsigned long.
*/
typedef unsigned long png_uint_32;
typedef unsigned int png_uint_32;
typedef long png_int_32;
typedef unsigned short png_uint_16;
typedef short png_int_16;

View File

@ -52,7 +52,7 @@ struct Scout::Canvas_base : Texture_allocator
virtual void draw_box(int x, int y, int w, int h, Color c) = 0;
virtual void draw_string(int x, int y, Font *font, Color color,
char const *str, int len) = 0;
char const *str, size_t len) = 0;
virtual void draw_horizontal_shadow(Rect rect, int intensity) = 0;
@ -99,7 +99,7 @@ class Scout::Canvas : public Canvas_base
void clip(Rect rect) override { _surface.clip(rect); }
void draw_string(int x, int y, Font *font, Color color, char const *str, int len) override
void draw_string(int x, int y, Font *font, Color color, char const *str, size_t len) override
{
char buf[len + 1];
Genode::copy_cstring(buf, str, len + 1);
@ -181,7 +181,7 @@ class Scout::Canvas : public Canvas_base
void set_rgba_texture(Texture_base *texture_base,
unsigned char const *rgba,
unsigned len, int y) override
size_t len, int y) override
{
Texture<PT> *texture = static_cast<Texture<PT> *>(texture_base);

View File

@ -41,12 +41,12 @@ class Scout::Element
Parent_element *_parent; /* parent in element hierarchy */
Event_handler *_evh; /* event handler object */
struct {
int mfocus : 1; /* element has mouse focus */
int selected : 1; /* element has selected state */
int takes_focus : 1; /* element highlights mouse focus */
int chapter : 1; /* display element as single page */
int findable : 1; /* regard element in find function */
int bottom : 1; /* place element to the bottom */
unsigned mfocus : 1; /* element has mouse focus */
unsigned selected : 1; /* element has selected state */
unsigned takes_focus : 1; /* element highlights mouse focus */
unsigned chapter : 1; /* display element as single page */
unsigned findable : 1; /* regard element in find function */
unsigned bottom : 1; /* place element to the bottom */
} _flags { };
public:
@ -78,7 +78,7 @@ class Scout::Element
Area min_size() const { return _min_size; }
bool bottom() const { return _flags.bottom; }
void findable(int flag) { _flags.findable = flag; }
void findable(bool flag) { _flags.findable = flag; }
/**
* Set geometry of the element
@ -95,7 +95,7 @@ class Scout::Element
/**
* Set/reset the mouse focus
*/
virtual void mfocus(int flag)
virtual void mfocus(bool flag)
{
if ((_flags.mfocus == flag) || !_flags.takes_focus) return;
_flags.mfocus = flag;

View File

@ -142,8 +142,9 @@ class Scout::Graphics_backend_impl : public Graphics_backend
src += offset;
dst += offset;
blit(src, sizeof(PT)*_max_size.w(),
dst, sizeof(PT)*_max_size.w(), sizeof(PT)*rect.w(), rect.h());
blit(src, (unsigned)sizeof(PT)*_max_size.w(), dst,
(int)sizeof(PT)*_max_size.w(),
(int)sizeof(PT)*rect.w(), rect.h());
_refresh_view(rect);
}

View File

@ -36,7 +36,7 @@ struct Scout::Texture_allocator : Genode::Interface
virtual void set_rgba_texture(Texture_base *texture,
unsigned char const *rgba,
unsigned len, int y) = 0;
size_t len, int y) = 0;
};
#endif /* _INCLUDE__SCOUT__TEXTURE_ALLOCATOR_H_ */

View File

@ -17,9 +17,13 @@
#include <util/geometry.h>
namespace Scout {
typedef Genode::Point<> Point;
typedef Genode::Area<> Area;
typedef Genode::Rect<> Rect;
using size_t = Genode::size_t;
using uint8_t = Genode::uint8_t;
}
#endif /* _INCLUDE__SCOUT__TYPES_H_ */

View File

@ -67,7 +67,7 @@ struct Sky_texture_painter
static void _multiply_buf(short dst[], int len, int factor)
{
for (int i = 0; i < len; i++)
dst[i] = (dst[i]*factor)>>8;
dst[i] = (short)((dst[i]*factor)>>8);
}
static inline int _mix_channel(int value1, int value2, int alpha)

View File

@ -50,8 +50,8 @@ class Launch_entry : public Scout::Parent_element, public Loadbar_listener
{
_block.append_launchertext(_prg_name.string(), &Scout::link_style, &_launcher);
_loadbar.max_value(max_quota);
_loadbar.value(initial_quota);
_loadbar.max_value((int)max_quota);
_loadbar.value((int)initial_quota);
append(&_loadbar);
append(&_block);

View File

@ -59,7 +59,7 @@ Launchpad_window<PT>::Launchpad_window(Genode::Env &env,
_min_size = Scout::Area(200, 200);
_status_entry.max_value(initial_quota / 1024);
_status_entry.max_value((int)(initial_quota / 1024));
/* adopt widgets as child elements */
_info_section.append(&_status_entry);

View File

@ -127,8 +127,8 @@ class Launchpad_window : public Scout::Scrollbar_listener,
*/
void quota(unsigned long quota) override
{
_status_entry.max_value(initial_quota() / 1024);
_status_entry.value(quota / 1024);
_status_entry.max_value((int)(initial_quota() / 1024));
_status_entry.value((int)(quota / 1024));
_status_entry.refresh();
}
@ -150,8 +150,8 @@ class Launchpad_window : public Scout::Scrollbar_listener,
Genode::Allocator &alloc) override
{
Child_entry<PT> *ce;
ce = new (alloc) Child_entry<PT>(name, quota / 1024,
initial_quota() / 1024,
ce = new (alloc) Child_entry<PT>(name, (int)(quota / 1024),
(int)(initial_quota() / 1024),
*this, launchpad_child);
_child_entry_list.insert(ce);
_kiddy_section.append(ce);

View File

@ -96,7 +96,11 @@ class Loadbar : public Scout::Parent_element
int _max_value;
const char *_txt;
int _txt_w, _txt_h, _txt_len;
int _txt_w, _txt_h;
Scout::size_t _txt_len;
Scout::Font *_font;
void _update_bar_geometry(int w)
@ -188,8 +192,11 @@ class Loadbar : public Scout::Parent_element
using namespace Scout;
int txt_x = abs_position.x() + _position.x() + max((_size.w() - _txt_w)/2, 8UL);
int txt_y = abs_position.y() + _position.y() + max((_size.h() - _txt_h)/2, 0UL) - 1;
int txt_x = abs_position.x() + _position.x()
+ (int)max((_size.w() - (size_t)_txt_w)/2, 8UL);
int txt_y = abs_position.y() + _position.y()
+ (int)max((_size.h() - (size_t)_txt_h)/2, 0UL) - 1;
/* shrink clipping area to text area (limit too long label) */
int cx1 = canvas.clip().x1(), cy1 = canvas.clip().y1();
@ -207,7 +214,7 @@ class Loadbar : public Scout::Parent_element
canvas.clip(Rect(Point(cx1, cy1), Area(cx2 - cx1 + 1, cy2 - cy1 + 1)));
}
void mfocus(int flag) override
void mfocus(bool flag) override
{
if (!_active) return;

View File

@ -144,7 +144,7 @@ struct Main : Scout::Event_handler
_user_state.handle_event(ev);
if (ev.type == Event::TIMER)
Tick::handle(_platform.timer_ticks());
Tick::handle((Scout::Tick::time)_platform.timer_ticks());
/* perform periodic redraw */
Genode::uint64_t const curr_time = _platform.timer_ticks();

View File

@ -22,6 +22,8 @@ class Section : public Scout::Parent_element
{
private:
typedef Scout::size_t size_t;
/*
* Noncopyable
*/
@ -38,7 +40,7 @@ class Section : public Scout::Parent_element
Scout::Font *_font;
int _txt_w = _font->string_width(_txt, Scout::strlen(_txt)).decimal();
int _txt_h = _font->bounding_box().h();
int _txt_len = Scout::strlen(_txt);
size_t _txt_len = Scout::strlen(_txt);
int _r_add;
public:
@ -76,8 +78,11 @@ class Section : public Scout::Parent_element
abs_position.y() + _position.y() + 1,
_size.w() + _r_add, _txt_h - 1, Color(240,240,240,130));
int _txt_x = abs_position.x() + _position.x() + max((_size.w() - _txt_w)/2, 8UL);
int _txt_y = abs_position.y() + _position.y() + max((_STH - _SH - _txt_h)/2, 0) - 1;
int _txt_x = abs_position.x() + _position.x()
+ (int)max((_size.w() - (size_t)_txt_w)/2, 8UL);
int _txt_y = abs_position.y() + _position.y()
+ max((_STH - _SH - (int)_txt_h)/2, 0) - 1;
Parent_element::draw(canvas, abs_position);

View File

@ -92,15 +92,15 @@ static void extract_rgba(const unsigned char *src, int w, int h,
{
for (int i = 0; i < w*h; i++, src += 4) {
int r = src[0];
int g = src[1];
int b = src[2];
int a = src[3];
int r = src[0];
int g = src[1];
int b = src[2];
uint8_t a = src[3];
if (dst_alpha[i]) {
PT s(r, g, b);
dst_pixel[i] = PT::mix(dst_pixel[i], s, a);
dst_alpha[i] = max((int)dst_alpha[i], a);
dst_alpha[i] = (uint8_t)max((int)dst_alpha[i], a);
} else {
dst_pixel[i].rgba(r, g, b);
dst_alpha[i] = a;
@ -298,8 +298,8 @@ Browser_window<PT>::Browser_window(Document *initial_content,
using Scout::random;
for (int j = 0; j < _PANEL_H; j++)
for (int i = 0; i < _PANEL_W; i++) {
_panel_fg [j][i] = _icon_fg [ICON_INDEX][j][i&0x1];
_panel_fg_alpha [j][i] = _icon_fg_alpha [ICON_INDEX][j][i&0x1] + random()%3;
_panel_fg [j][i] = _icon_fg [ICON_INDEX][j][i&0x1];
_panel_fg_alpha [j][i] = (uint8_t)(_icon_fg_alpha [ICON_INDEX][j][i&0x1] + random()%3);
}
/* init panel background */

View File

@ -221,7 +221,7 @@ void Parent_element::flush_cache(Canvas_base &canvas)
** Token **
***********/
Token::Token(Style *style, const char *str, int len)
Token::Token(Style *style, const char *str, size_t len)
:
_str(str),
_len(len),
@ -343,8 +343,8 @@ void Block::format_fixed_width(int w)
/* indent elements of the line according to the alignment */
int dx = 0;
if (_align == CENTER) dx = max(0UL, (max_w - max_x)/2);
if (_align == RIGHT) dx = max(0UL, max_w - max_x);
if (_align == CENTER) dx = (int)max(0UL, (max_w - max_x)/2);
if (_align == RIGHT) dx = (int)max(0UL, max_w - max_x);
for (e = line; e && (e->position().y() == cy); e = e->next)
e->geometry(Rect(Point(e->position().x() + dx, e->position().y()),
e->size()));

View File

@ -89,7 +89,7 @@ class Scout::Token : public Element
protected:
const char *_str; /* start of string */
int _len; /* length of string */
size_t _len; /* length of string */
Style *_style; /* textual style */
Color _col; /* current text color */
Color _outline; /* outline color */
@ -99,7 +99,7 @@ class Scout::Token : public Element
/**
* Constructor
*/
Token(Style *style, const char *str, int len);
Token(Style *style, const char *str, size_t len);
/**
* Element interface
@ -178,7 +178,7 @@ class Scout::Link_token : public Token, private Link, public Event_handler,
_size.w(), 1, Color(0,0,255));
}
void mfocus(int flag) override
void mfocus(bool flag) override
{
/*
* highlight link of all siblings that point to the same link.

View File

@ -83,7 +83,7 @@ class Scout::Fade_icon : public Fader, public Icon<PT, W, H>
/**
* Element interface
*/
void mfocus(int flag) override
void mfocus(bool flag) override
{
Icon<PT, W, H>::mfocus(flag);
int step = _focus_alpha - _default_alpha;

View File

@ -153,7 +153,7 @@ struct Scout::Main : Scout::Event_handler
_user_state.handle_event(ev);
if (event.type == Event::TIMER)
Tick::handle(_platform.timer_ticks());
Tick::handle((Scout::Tick::time)_platform.timer_ticks());
/* perform periodic redraw */
Genode::uint64_t curr_time = _platform.timer_ticks();

View File

@ -63,7 +63,7 @@ static void user_read_data(png_structp png_ptr, png_bytep data, png_size_t len)
{
Png_stream *stream = (Png_stream *)png_get_io_ptr(png_ptr);
stream->read((char *)data, len);
stream->read((char *)data, (int)len);
}

View File

@ -83,7 +83,9 @@ class Scout::Refracted_icon : public Element
} while ((dx < -i) || (dx > _distmap_w - 2 - i)
|| (dy < -j) || (dy > _distmap_h - 2 - j));
_distmap[j*_distmap_w + i] += dy*_distmap_w + dx;
DT &entry = _distmap[j*_distmap_w + i];
entry = (DT)(entry + dy*_distmap_w + dx);
}
}

View File

@ -32,8 +32,13 @@ class Scout::Titlebar : public Parent_element
Titlebar &operator = (Titlebar const &);
Icon<PT, 32, 32> _fg { };
const char *_txt = nullptr;
int _txt_w = 0, _txt_h = 0, _txt_len = 0;
int _txt_w = 0,
_txt_h = 0;
Scout::size_t _txt_len = 0;
public:
@ -82,8 +87,12 @@ class Scout::Titlebar : public Parent_element
abs_position.y() + _position.y(),
_size.w(), _size.h(), Color(b, b, b, a));
int _txt_x = abs_position.x() + _position.x() + max((_size.w() - _txt_w)/2, 8UL);
int _txt_y = abs_position.y() + _position.y() + max((_size.h() - _txt_h)/2, 0UL) - 1;
int _txt_x = abs_position.x() + _position.x()
+ (int)max((_size.w() - _txt_w)/2, 8U);
int _txt_y = abs_position.y() + _position.y()
+ (int)max((_size.h() - _txt_h)/2, 0U) - 1;
canvas.draw_string(_txt_x , _txt_y, &title_font, Color(0,0,0,200), _txt, strlen(_txt));
Parent_element::draw(canvas, abs_position);
}

View File

@ -106,7 +106,7 @@ void Icon<PT, W, H>::rgba(unsigned char *src, int vshift, int shadow)
for (int l = -1; l <=1; l++)
v += _alpha[(j + k + H)%H][(i + l + W)%W];
_shadow[j + 3][i] = v>>shadow;
_shadow[j + 3][i] = (unsigned char)(v>>shadow);
}
/* shift vertically */
@ -122,7 +122,7 @@ void Icon<PT, W, H>::rgba(unsigned char *src, int vshift, int shadow)
for (int j = 0; j < H; j++)
for (int i = 0; i < W; i++) {
_pixel[j][i] = PT::mix(shcol, _pixel[j][i], _alpha[j][i]);
_alpha[j][i] = min(255, _alpha[j][i] + _shadow[j][i]);
_alpha[j][i] = (unsigned char)min(255, _alpha[j][i] + _shadow[j][i]);
}
}
@ -140,7 +140,7 @@ static inline void blur(unsigned char *src, unsigned char *dst, int w, int h)
for (int l = -kernel; l <= kernel; l++)
v += src[w*(j + k) + (i + l)];
dst[w*j + i] = min(v/scale, 255);
dst[w*j + i] = (unsigned char)min(v/scale, 255);
}
}

View File

@ -15,5 +15,5 @@
extern "C" void *memset(void *s, int c, Genode::size_t n)
{
return Genode::memset(s, c, n);
return Genode::memset(s, (char)c, n);
}

View File

@ -23,5 +23,5 @@ extern "C" int snprintf(char *dst, Genode::size_t dst_len, const char *format, .
sc.vprintf(format, list);
va_end(list);
return sc.len();
return (int)sc.len();
}

View File

@ -17,7 +17,7 @@ extern "C" double strtod(const char *nptr, char **endptr)
{
double value = 0;
int num_chars = Genode::ascii_to(nptr, value);
Genode::size_t num_chars = Genode::ascii_to(nptr, value);
if (endptr)
*endptr = (char *)(nptr + num_chars);

View File

@ -17,5 +17,5 @@ extern "C" int vsnprintf(char *dst, Genode::size_t dst_len, const char *format,
{
Genode::String_console sc(dst, dst_len);
sc.vprintf(format, list);
return sc.len();
return (int)sc.len();
}

View File

@ -53,7 +53,7 @@ static inline int filter(int x0, int x1, int x2, int x3, int u)
cached_u = u;
}
return (x0*k0 + x1*k1 + x2*k2 + x3*k3)>>8;
return (x0*k0 + x1*k1 + x2*k2 + x3*k3) >> 8;
}
@ -74,7 +74,7 @@ static void gen_buf(short tmp[], int noise_w, int noise_h,
{
/* generate noise */
for (int i = 0; i < noise_h; i++) for (int j = 0; j < noise_w; j++)
dst[i*dst_w + j] = Scout::random()%256 - 128;
dst[i*dst_w + j] = (short)(Scout::random()%256 - 128);
/* interpolate horizontally */
for (int j = dst_w - 1; j >= 0; j--) {
@ -92,7 +92,7 @@ static void gen_buf(short tmp[], int noise_w, int noise_h,
int x2 = dst[i*dst_w + x2_idx];
int x3 = dst[i*dst_w + x3_idx];
tmp[i*dst_w + j] = filter(x0, x1, x2, x3, u);
tmp[i*dst_w + j] = (short)filter(x0, x1, x2, x3, u);
}
}
@ -112,7 +112,7 @@ static void gen_buf(short tmp[], int noise_w, int noise_h,
int y2 = tmp[y2_idx + j];
int y3 = tmp[y3_idx + j];
dst[i*dst_w + j] = filter(y0, y1, y2, y3, u);
dst[i*dst_w + j] = (short)filter(y0, y1, y2, y3, u);
}
}
}
@ -131,7 +131,7 @@ static void normalize_buf(short dst[], int len, int amp)
if (max == min) return;
for (int i = 0; i < len; i++)
dst[i] = (amp*(dst[i] - min))/(max - min);
dst[i] = (short)((amp*(dst[i] - min))/(max - min));
}
@ -141,7 +141,7 @@ static void normalize_buf(short dst[], int len, int amp)
static void add_bufs(short src1[], short src2[], short dst[], int len)
{
for (int i = 0; i < len; i++)
dst[i] = src1[i] + src2[i];
dst[i] = (short)(src1[i] + src2[i]);
}
/**

View File

@ -191,7 +191,7 @@ class Liquid_fb::Main : public Scout::Event_handler
void _init_fb_win()
{
_fb_win.parent(&_user_state);
_fb_win.content_geometry(config_fb_x, config_fb_y,
_fb_win.content_geometry((int)config_fb_x, (int)config_fb_y,
config_fb_width, config_fb_height);
}
@ -220,8 +220,8 @@ class Liquid_fb::Main : public Scout::Event_handler
_fb_win.config_decoration(config_decoration);
/* must get called after 'config_decoration()' */
_fb_win.content_geometry(config_fb_x, config_fb_y,
config_fb_width, config_fb_height);
_fb_win.content_geometry((int)config_fb_x, (int)config_fb_y,
config_fb_width, config_fb_height);
_user_state.update_view_offset();
}
@ -247,7 +247,7 @@ class Liquid_fb::Main : public Scout::Event_handler
_user_state.handle_event(ev);
if (ev.type == Event::TIMER) {
Scout::Tick::handle(_platform.timer_ticks());
Scout::Tick::handle((Scout::Tick::time)_platform.timer_ticks());
}
/* perform periodic redraw */

View File

@ -109,7 +109,7 @@ class Window_content : public Scout::Element
a += (Genode::Dither_matrix::value(x, y) - 127) >> 4;
alpha[y*w + x] = Genode::max(alpha_min, Genode::min(a, 255));
alpha[y*w + x] = (unsigned char)Genode::max(alpha_min, Genode::min(a, 255));
}
}

View File

@ -103,15 +103,16 @@ class Log_entry
{
private:
typedef Genode::Color Color;
using Color = Genode::Color;
using size_t = Genode::size_t;
char _label[64];
char _text[LOG_W];
char _attr[LOG_W];
Color _color { };
int _label_len = 0;
int _text_len = 0;
int _id = 0;
char _label[64];
char _text[LOG_W];
char _attr[LOG_W];
Color _color { };
size_t _label_len = 0;
size_t _text_len = 0;
int _id = 0;
public:
@ -176,8 +177,8 @@ class Log_entry
/**
* Accessors
*/
int label_len() { return _label_len; }
int id() { return _id; }
size_t label_len() { return _label_len; }
int id() { return _id; }
};