summaryrefslogtreecommitdiff
path: root/otk
diff options
context:
space:
mode:
Diffstat (limited to 'otk')
-rw-r--r--otk/label.cc14
-rw-r--r--otk/rect.hh6
-rw-r--r--otk/renderstyle.cc4
-rw-r--r--otk/screeninfo.cc4
-rw-r--r--otk/screeninfo.hh6
-rw-r--r--otk/size.hh12
-rw-r--r--otk/surface.cc4
-rw-r--r--otk/truerendercontrol.cc56
-rw-r--r--otk/widget.cc50
-rw-r--r--otk/widget.hh2
10 files changed, 77 insertions, 81 deletions
diff --git a/otk/label.cc b/otk/label.cc
index 16fa25a0..c17e295e 100644
--- a/otk/label.cc
+++ b/otk/label.cc
@@ -71,11 +71,12 @@ void Label::setFont(const Font *f)
void Label::calcDefaultSizes()
{
- unsigned int longest = 0;
+ int longest = 0;
// find the longest line
std::vector<ustring>::iterator it, end = _parsedtext.end();
for (it = _parsedtext.begin(); it != end; ++it) {
- unsigned int length = _font->measureString(*it);
+ int length = _font->measureString(*it);
+ if (length < 0) continue; // lines too long get skipped
if (length > longest) longest = length;
}
setMinSize(Size(longest + borderWidth() * 2 + bevel() * 4,
@@ -101,10 +102,10 @@ void Label::styleChanged(const RenderStyle &style)
void Label::renderForeground(Surface &surface)
{
const RenderControl *control = display->renderControl(screen());
- unsigned int sidemargin = bevel() * 2;
+ int sidemargin = bevel() * 2;
int y = bevel();
- unsigned int w = area().width() - borderWidth() * 2 - sidemargin * 2;
- unsigned int h = area().height() - borderWidth() * 2 - bevel() * 2;
+ int w = area().width() - borderWidth() * 2 - sidemargin * 2;
+ int h = area().height() - borderWidth() * 2 - bevel() * 2;
switch (_justify_vert) {
case RenderStyle::RightBottomJustify:
@@ -128,12 +129,13 @@ void Label::renderForeground(Surface &surface)
// find a string that will fit inside the area for text
ustring::size_type text_len = t.size();
- unsigned int length;
+ int length;
do {
t.resize(text_len);
length = _font->measureString(t);
} while (length > w && text_len-- > 0);
+ if (length < 0) continue; // lines too long get skipped
if (text_len <= 0) continue; // won't fit anything
diff --git a/otk/rect.hh b/otk/rect.hh
index fe98dcb5..f5e755cc 100644
--- a/otk/rect.hh
+++ b/otk/rect.hh
@@ -14,13 +14,13 @@ public:
Rect() : _p(), _s() {}
Rect(const Point &p, const Size &s) : _p(p), _s(s) {}
Rect(const Rect &r) : _p(r._p), _s(r._s) {}
- Rect(int x, int y, unsigned int w, unsigned int h)
+ Rect(int x, int y, int w, int h)
: _p(x, y), _s(w, h) {}
inline int x() const { return _p.x(); }
inline int y() const { return _p.y(); }
- inline unsigned int width() const { return _s.width(); }
- inline unsigned int height() const { return _s.height(); }
+ inline int width() const { return _s.width(); }
+ inline int height() const { return _s.height(); }
inline int left() const { return _p.x(); }
inline int top() const { return _p.y(); }
diff --git a/otk/renderstyle.cc b/otk/renderstyle.cc
index 13d9e577..ae2a3a18 100644
--- a/otk/renderstyle.cc
+++ b/otk/renderstyle.cc
@@ -56,8 +56,8 @@ RenderStyle::RenderStyle(int screen, const std::string &stylefile)
_file(stylefile)
{
// pick one..
-#define FIERON
-//#define MERRY
+//#define FIERON
+#define MERRY
#ifdef FIERON
_root_color = new RenderColor(_screen, 0x272a2f);
diff --git a/otk/screeninfo.cc b/otk/screeninfo.cc
index 560a5636..535156e9 100644
--- a/otk/screeninfo.cc
+++ b/otk/screeninfo.cc
@@ -17,7 +17,9 @@ using std::string;
namespace otk {
-ScreenInfo::ScreenInfo(unsigned int num) {
+ScreenInfo::ScreenInfo(int num) {
+ assert(num >= 0 && num < ScreenCount(**display));
+
_screen = num;
_root_window = RootWindow(**display, _screen);
diff --git a/otk/screeninfo.hh b/otk/screeninfo.hh
index 440573aa..584d92ec 100644
--- a/otk/screeninfo.hh
+++ b/otk/screeninfo.hh
@@ -21,7 +21,7 @@ private:
Colormap _colormap;
int _depth;
- unsigned int _screen;
+ int _screen;
std::string _display_string;
Size _size;
#ifdef XINERAMA
@@ -30,13 +30,13 @@ private:
#endif
public:
- ScreenInfo(unsigned int num);
+ ScreenInfo(int num);
inline Visual *visual() const { return _visual; }
inline Window rootWindow() const { return _root_window; }
inline Colormap colormap() const { return _colormap; }
inline int depth() const { return _depth; }
- inline unsigned int screen() const { return _screen; }
+ inline int screen() const { return _screen; }
inline const Size& size() const { return _size; }
inline const std::string& displayString() const { return _display_string; }
#ifdef XINERAMA
diff --git a/otk/size.hh b/otk/size.hh
index 91539614..57447d5d 100644
--- a/otk/size.hh
+++ b/otk/size.hh
@@ -2,17 +2,19 @@
#ifndef __size_hh
#define __size_hh
+#include <cassert>
+
namespace otk {
class Size {
- unsigned int _w, _h;
+ int _w, _h;
public:
Size() : _w(1), _h(1) {}
- Size(unsigned int w, unsigned int h) : _w(w), _h(h) {}
- Size(const Size &s) : _w(s._w), _h(s._h) {}
+ Size(int w, int h) : _w(w), _h(h) { assert(_w >= 0 && _h >= 0); }
+ Size(const Size &s) : _w(s._w), _h(s._h) { assert(_w >= 0 && _h >= 0); }
- inline unsigned int width() const { return _w; }
- inline unsigned int height() const { return _h; }
+ inline int width() const { return _w; }
+ inline int height() const { return _h; }
bool operator==(const Size &o) const { return _w == o._w && _h == o._h; }
bool operator!=(const Size &o) const { return _w != o._w || _h != o._h; }
diff --git a/otk/surface.cc b/otk/surface.cc
index aabbf85a..60e6824c 100644
--- a/otk/surface.cc
+++ b/otk/surface.cc
@@ -39,8 +39,8 @@ void Surface::setPixmap(const RenderColor &color)
void Surface::setPixmap(XImage *image)
{
- assert((unsigned)image->width == _size.width());
- assert((unsigned)image->height == _size.height());
+ assert(image->width == _size.width());
+ assert(image->height == _size.height());
if (_pixmap == None)
createObjects();
diff --git a/otk/truerendercontrol.cc b/otk/truerendercontrol.cc
index 2c7c42a4..fffaa05a 100644
--- a/otk/truerendercontrol.cc
+++ b/otk/truerendercontrol.cc
@@ -59,8 +59,8 @@ void TrueRenderControl::drawGradientBackground(
Surface &sf, const RenderTexture &texture) const
{
unsigned int r,g,b;
- unsigned int w = sf.size().width(), h = sf.size().height();
- unsigned int off, x;
+ int w = sf.size().width(), h = sf.size().height();
+ int off, x;
const ScreenInfo *info = display->screenInfo(_screen);
XImage *im = XCreateImage(**display, info->visual(), info->depth(),
@@ -102,29 +102,25 @@ void TrueRenderControl::drawGradientBackground(
if (texture.relief() != RenderTexture::Flat) {
if (texture.bevel() == RenderTexture::Bevel1) {
- if (w >= 1 && h >= 1) {
- for (off = 1, x = 1; x < w - 1; ++x, off++)
- highlight(data + off,
- data + off + (h-1) * w,
- texture.relief()==RenderTexture::Raised);
- for (off = 0, x = 0; x < h; ++x, off++)
- highlight(data + off * w,
- data + off * w + w - 1,
- texture.relief()==RenderTexture::Raised);
- }
+ for (off = 1, x = 1; x < w - 1; ++x, off++)
+ highlight(data + off,
+ data + off + (h-1) * w,
+ texture.relief()==RenderTexture::Raised);
+ for (off = 0, x = 0; x < h; ++x, off++)
+ highlight(data + off * w,
+ data + off * w + w - 1,
+ texture.relief()==RenderTexture::Raised);
}
if (texture.bevel() == RenderTexture::Bevel2) {
- if (w >= 2 && h >= 2) {
- for (off = 2, x = 2; x < w - 2; ++x, off++)
- highlight(data + off + w,
- data + off + (h-2) * w,
- texture.relief()==RenderTexture::Raised);
- for (off = 1, x = 1; x < h-1; ++x, off++)
- highlight(data + off * w + 1,
- data + off * w + w - 2,
- texture.relief()==RenderTexture::Raised);
- }
+ for (off = 2, x = 2; x < w - 2; ++x, off++)
+ highlight(data + off + w,
+ data + off + (h-2) * w,
+ texture.relief()==RenderTexture::Raised);
+ for (off = 1, x = 1; x < h-1; ++x, off++)
+ highlight(data + off * w + 1,
+ data + off * w + w - 2,
+ texture.relief()==RenderTexture::Raised);
}
}
@@ -146,7 +142,7 @@ void TrueRenderControl::verticalGradient(Surface &sf,
pixel32 current;
float dr, dg, db;
unsigned int r,g,b;
- unsigned int w = sf.size().width(), h = sf.size().height();
+ int w = sf.size().width(), h = sf.size().height();
dr = (float)(texture.secondary_color().red() - texture.color().red());
dr/= (float)h;
@@ -157,14 +153,14 @@ void TrueRenderControl::verticalGradient(Surface &sf,
db = (float)(texture.secondary_color().blue() - texture.color().blue());
db/= (float)h;
- for (unsigned int y = 0; y < h; ++y) {
+ for (int y = 0; y < h; ++y) {
r = texture.color().red() + (int)(dr * y);
g = texture.color().green() + (int)(dg * y);
b = texture.color().blue() + (int)(db * y);
current = (r << default_red_shift)
+ (g << default_green_shift)
+ (b << default_blue_shift);
- for (unsigned int x = 0; x < w; ++x, ++data)
+ for (int x = 0; x < w; ++x, ++data)
*data = current;
}
}
@@ -176,9 +172,9 @@ void TrueRenderControl::diagonalGradient(Surface &sf,
pixel32 current;
float drx, dgx, dbx, dry, dgy, dby;
unsigned int r,g,b;
- unsigned int w = sf.size().width(), h = sf.size().height();
+ int w = sf.size().width(), h = sf.size().height();
- for (unsigned int y = 0; y < h; ++y) {
+ for (int y = 0; y < h; ++y) {
drx = (float)(texture.secondary_color().red() - texture.color().red());
dry = drx/(float)h;
drx/= (float)w;
@@ -190,7 +186,7 @@ void TrueRenderControl::diagonalGradient(Surface &sf,
dbx = (float)(texture.secondary_color().blue() - texture.color().blue());
dby = dbx/(float)h;
dbx/= (float)w;
- for (unsigned int x = 0; x < w; ++x, ++data) {
+ for (int x = 0; x < w; ++x, ++data) {
r = texture.color().red() + ((int)(drx * x) + (int)(dry * y))/2;
g = texture.color().green() + ((int)(dgx * x) + (int)(dgy * y))/2;
b = texture.color().blue() + ((int)(dbx * x) + (int)(dby * y))/2;
@@ -209,9 +205,9 @@ void TrueRenderControl::crossDiagonalGradient(Surface &sf,
pixel32 current;
float drx, dgx, dbx, dry, dgy, dby;
unsigned int r,g,b;
- unsigned int w = sf.size().width(), h = sf.size().height();
+ int w = sf.size().width(), h = sf.size().height();
- for (unsigned int y = 0; y < h; ++y) {
+ for (int y = 0; y < h; ++y) {
drx = (float)(texture.secondary_color().red() - texture.color().red());
dry = drx/(float)h;
drx/= (float)w;
diff --git a/otk/widget.cc b/otk/widget.cc
index 8ab57708..25d5043d 100644
--- a/otk/widget.cc
+++ b/otk/widget.cc
@@ -26,7 +26,7 @@ Widget::Widget(int screen, EventDispatcher *ed, Direction direction, int bevel,
ExposureMask | StructureNotifyMask),
_alignment(RenderStyle::CenterJustify),
_direction(direction),
- _max_size(UINT_MAX, UINT_MAX),
+ _max_size(INT_MAX, INT_MAX),
_visible(false),
_bordercolor(0),
_borderwidth(0),
@@ -49,7 +49,7 @@ Widget::Widget(Widget *parent, Direction direction, int bevel)
ExposureMask | StructureNotifyMask),
_alignment(RenderStyle::CenterJustify),
_direction(direction),
- _max_size(UINT_MAX, UINT_MAX),
+ _max_size(INT_MAX, INT_MAX),
_visible(false),
_bordercolor(0),
_borderwidth(0),
@@ -120,7 +120,7 @@ void Widget::update()
void Widget::moveresize(const Rect &r)
{
- unsigned int w, h;
+ int w, h;
w = std::min(std::max(r.width(), minSize().width()), maxSize().width());
h = std::min(std::max(r.height(), minSize().height()), maxSize().height());
@@ -134,7 +134,7 @@ void Widget::moveresize(const Rect &r)
update();
}
-void Widget::internal_moveresize(int x, int y, unsigned w, unsigned int h)
+void Widget::internal_moveresize(int x, int y, int w, int h)
{
assert(w > 0);
assert(h > 0);
@@ -248,18 +248,15 @@ void Widget::layoutHorz()
if (visible.empty()) return;
- if ((unsigned)(_borderwidth * 2 + _bevel * 2) > _area.width() ||
- (unsigned)(_borderwidth * 2 + _bevel * 2) > _area.height())
- return; // not worth laying anything out!
-
- int x, y; unsigned int w, h; // working area
+ int x, y, w, h; // working area
x = y = _bevel;
w = _area.width() - _borderwidth * 2 - _bevel * 2;
h = _area.height() - _borderwidth * 2 - _bevel * 2;
+ if (w < 0 || h < 0) return; // not worth laying anything out!
int free = w - (visible.size() - 1) * _bevel;
if (free < 0) free = 0;
- unsigned int each;
+ int each;
std::list<Widget*> adjustable = visible;
@@ -279,7 +276,7 @@ void Widget::layoutHorz()
each = free / adjustable.size();
for (it = adjustable.begin(), end = adjustable.end(); it != end;) {
std::list<Widget*>::iterator next = it; ++next;
- unsigned int m = (*it)->maxSize().width() - (*it)->minSize().width();
+ int m = (*it)->maxSize().width() - (*it)->minSize().width();
if (m > 0 && m < each) {
free -= m;
if (free < 0) free = 0;
@@ -298,7 +295,7 @@ void Widget::layoutHorz()
else
each = 0;
for (it = visible.begin(), end = visible.end(); it != end; ++it) {
- unsigned int w;
+ int w;
// is the widget adjustable?
std::list<Widget*>::const_iterator
found = std::find(adjustable.begin(), adjustable.end(), *it);
@@ -311,8 +308,8 @@ void Widget::layoutHorz()
}
// align it vertically
int yy = y;
- unsigned int hh = std::max(std::min(h, (*it)->_max_size.height()),
- (*it)->_min_size.height());
+ int hh = std::max(std::min(h, (*it)->_max_size.height()),
+ (*it)->_min_size.height());
if (hh < h) {
switch(_alignment) {
case RenderStyle::RightBottomJustify:
@@ -347,18 +344,15 @@ void Widget::layoutVert()
if (visible.empty()) return;
- if ((unsigned)(_borderwidth * 2 + _bevel * 2) > _area.width() ||
- (unsigned)(_borderwidth * 2 + _bevel * 2) > _area.height())
- return; // not worth laying anything out!
-
- int x, y; unsigned int w, h; // working area
+ int x, y, w, h; // working area
x = y = _bevel;
w = _area.width() - _borderwidth * 2 - _bevel * 2;
h = _area.height() - _borderwidth * 2 - _bevel * 2;
+ if (w < 0 || h < 0) return; // not worth laying anything out!
int free = h - (visible.size() - 1) * _bevel;
if (free < 0) free = 0;
- unsigned int each;
+ int each;
std::list<Widget*> adjustable = visible;
@@ -378,7 +372,7 @@ void Widget::layoutVert()
each = free / adjustable.size();
for (it = adjustable.begin(), end = adjustable.end(); it != end;) {
std::list<Widget*>::iterator next = it; ++next;
- unsigned int m = (*it)->maxSize().height() - (*it)->minSize().height();
+ int m = (*it)->maxSize().height() - (*it)->minSize().height();
if (m > 0 && m < each) {
free -= m;
if (free < 0) free = 0;
@@ -397,7 +391,7 @@ void Widget::layoutVert()
else
each = 0;
for (it = visible.begin(), end = visible.end(); it != end; ++it) {
- unsigned int h;
+ int h;
// is the widget adjustable?
std::list<Widget*>::const_iterator
found = std::find(adjustable.begin(), adjustable.end(), *it);
@@ -410,8 +404,8 @@ void Widget::layoutVert()
}
// align it horizontally
int xx = x;
- unsigned int ww = std::max(std::min(w, (*it)->_max_size.width()),
- (*it)->_min_size.width());
+ int ww = std::max(std::min(w, (*it)->_max_size.width()),
+ (*it)->_min_size.width());
if (ww < w) {
switch(_alignment) {
case RenderStyle::RightBottomJustify:
@@ -434,8 +428,8 @@ void Widget::layoutVert()
void Widget::render()
{
if (!_texture || !_dirty) return;
- if ((unsigned)_borderwidth * 2 > _area.width() ||
- (unsigned)_borderwidth * 2 > _area.height())
+ if (_borderwidth * 2 > _area.width() ||
+ _borderwidth * 2 > _area.height())
return; // no surface to draw on
Surface *s = new Surface(_screen, Size(_area.width() - _borderwidth * 2,
@@ -481,8 +475,8 @@ void Widget::configureHandler(const XConfigureEvent &e)
ev.xconfigure.height = e.height;
while (XCheckTypedWindowEvent(**display, window(), ConfigureNotify, &ev));
- if (!((unsigned)ev.xconfigure.width == area().width() &&
- (unsigned)ev.xconfigure.height == area().height())) {
+ if (!(ev.xconfigure.width == area().width() &&
+ ev.xconfigure.height == area().height())) {
_area = Rect(_area.position(), Size(e.width, e.height));
update();
}
diff --git a/otk/widget.hh b/otk/widget.hh
index 5c366503..31103deb 100644
--- a/otk/widget.hh
+++ b/otk/widget.hh
@@ -102,7 +102,7 @@ protected:
RenderTexture *_texture;
private:
- void internal_moveresize(int x, int y, unsigned w, unsigned int h);
+ void internal_moveresize(int x, int y, int w, int h);
int _screen;
Widget *_parent;