provide RenderControls to all otk from the display class. initialize them all there. try use bitshifts instead of color tables in the TrueRenderControl class for finding correct rgbs. Move the image/pixmap/xftdraw into the surface class, and it maintains them, recreating them when it resizes.
This commit is contained in:
parent
a4dd208a79
commit
9b6e5f9cf4
16 changed files with 203 additions and 126 deletions
|
@ -7,6 +7,7 @@
|
||||||
#include "display.hh"
|
#include "display.hh"
|
||||||
#include "screeninfo.hh"
|
#include "screeninfo.hh"
|
||||||
#include "gccache.hh"
|
#include "gccache.hh"
|
||||||
|
#include "rendercontrol.hh"
|
||||||
#include "util.hh"
|
#include "util.hh"
|
||||||
|
|
||||||
extern "C" {
|
extern "C" {
|
||||||
|
@ -84,6 +85,7 @@ Display::Display()
|
||||||
_scroll_lock_mask(0),
|
_scroll_lock_mask(0),
|
||||||
_grab_count(0),
|
_grab_count(0),
|
||||||
_screenInfoList(),
|
_screenInfoList(),
|
||||||
|
_renderControlList(),
|
||||||
_gccache((GCCache*) 0)
|
_gccache((GCCache*) 0)
|
||||||
{
|
{
|
||||||
int junk;
|
int junk;
|
||||||
|
@ -168,7 +170,11 @@ DISPLAY environment variable approriately.\n\n"));
|
||||||
// Get information on all the screens which are available.
|
// Get information on all the screens which are available.
|
||||||
_screenInfoList.reserve(ScreenCount(_display));
|
_screenInfoList.reserve(ScreenCount(_display));
|
||||||
for (int i = 0; i < ScreenCount(_display); ++i)
|
for (int i = 0; i < ScreenCount(_display); ++i)
|
||||||
_screenInfoList.push_back(ScreenInfo(i));
|
_screenInfoList.push_back(i);
|
||||||
|
|
||||||
|
_renderControlList.reserve(ScreenCount(_display));
|
||||||
|
for (int i = 0; i < ScreenCount(_display); ++i)
|
||||||
|
_renderControlList.push_back(RenderControl::getRenderControl(i));
|
||||||
|
|
||||||
_gccache = new GCCache(_screenInfoList.size());
|
_gccache = new GCCache(_screenInfoList.size());
|
||||||
}
|
}
|
||||||
|
@ -193,7 +199,7 @@ const ScreenInfo* Display::screenInfo(int snum)
|
||||||
|
|
||||||
const ScreenInfo* Display::findScreen(Window root)
|
const ScreenInfo* Display::findScreen(Window root)
|
||||||
{
|
{
|
||||||
ScreenInfoList::iterator it, end = _screenInfoList.end();
|
std::vector<ScreenInfo>::iterator it, end = _screenInfoList.end();
|
||||||
for (it = _screenInfoList.begin(); it != end; ++it)
|
for (it = _screenInfoList.begin(); it != end; ++it)
|
||||||
if (it->rootWindow() == root)
|
if (it->rootWindow() == root)
|
||||||
return &(*it);
|
return &(*it);
|
||||||
|
@ -201,6 +207,14 @@ const ScreenInfo* Display::findScreen(Window root)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
const RenderControl *Display::renderControl(int snum)
|
||||||
|
{
|
||||||
|
assert(snum >= 0);
|
||||||
|
assert(snum < (signed) _renderControlList.size());
|
||||||
|
return _renderControlList[snum];
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
void Display::grab()
|
void Display::grab()
|
||||||
{
|
{
|
||||||
if (_grab_count == 0)
|
if (_grab_count == 0)
|
||||||
|
|
|
@ -12,6 +12,7 @@ namespace otk {
|
||||||
|
|
||||||
class ScreenInfo;
|
class ScreenInfo;
|
||||||
class GCCache;
|
class GCCache;
|
||||||
|
class RenderControl;
|
||||||
|
|
||||||
class Display;
|
class Display;
|
||||||
|
|
||||||
|
@ -21,10 +22,6 @@ extern Display *display;
|
||||||
//! Manages a single X11 display.
|
//! Manages a single X11 display.
|
||||||
class Display
|
class Display
|
||||||
{
|
{
|
||||||
public:
|
|
||||||
//! A List of ScreenInfo instances
|
|
||||||
typedef std::vector<ScreenInfo> ScreenInfoList;
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
//! The X display
|
//! The X display
|
||||||
::Display *_display;
|
::Display *_display;
|
||||||
|
@ -57,7 +54,11 @@ private:
|
||||||
int _grab_count;
|
int _grab_count;
|
||||||
|
|
||||||
//! A list of information for all screens on the display
|
//! A list of information for all screens on the display
|
||||||
ScreenInfoList _screenInfoList;
|
std::vector<ScreenInfo> _screenInfoList;
|
||||||
|
|
||||||
|
//! A list of RenderControl objects, which are used for all graphics on a
|
||||||
|
//! screen
|
||||||
|
std::vector<RenderControl*> _renderControlList;
|
||||||
|
|
||||||
//! A cache for re-using GCs, used by the drawing objects
|
//! A cache for re-using GCs, used by the drawing objects
|
||||||
/*!
|
/*!
|
||||||
|
@ -100,6 +101,9 @@ public:
|
||||||
//! Find a ScreenInfo based on a root window
|
//! Find a ScreenInfo based on a root window
|
||||||
const ScreenInfo* findScreen(Window root);
|
const ScreenInfo* findScreen(Window root);
|
||||||
|
|
||||||
|
//! Gets the RenderControl for a screen
|
||||||
|
const RenderControl *renderControl(int snum);
|
||||||
|
|
||||||
//! Returns if the display has the xkb extension available
|
//! Returns if the display has the xkb extension available
|
||||||
inline bool xkb() const { return _xkb; }
|
inline bool xkb() const { return _xkb; }
|
||||||
//! Returns the xkb extension's event base
|
//! Returns the xkb extension's event base
|
||||||
|
|
|
@ -13,14 +13,10 @@ namespace otk {
|
||||||
FocusLabel::FocusLabel(Widget *parent)
|
FocusLabel::FocusLabel(Widget *parent)
|
||||||
: FocusWidget(parent), _text("")
|
: FocusWidget(parent), _text("")
|
||||||
{
|
{
|
||||||
const ScreenInfo *info = display->screenInfo(screen());
|
|
||||||
_xftdraw = XftDrawCreate(**display, window(), info->visual(),
|
|
||||||
info->colormap());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
FocusLabel::~FocusLabel()
|
FocusLabel::~FocusLabel()
|
||||||
{
|
{
|
||||||
XftDrawDestroy(_xftdraw);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -72,7 +68,8 @@ void FocusLabel::update(void)
|
||||||
|
|
||||||
FocusWidget::update();
|
FocusWidget::update();
|
||||||
|
|
||||||
ft->drawString(_xftdraw, x, 0, *text_color, t);
|
display->renderControl(_screen)->
|
||||||
|
drawString(this, *ft, x, 0, *text_color, t);
|
||||||
} else
|
} else
|
||||||
FocusWidget::update();
|
FocusWidget::update();
|
||||||
}
|
}
|
||||||
|
|
|
@ -3,7 +3,6 @@
|
||||||
#define __label_hh
|
#define __label_hh
|
||||||
|
|
||||||
#include "focuswidget.hh"
|
#include "focuswidget.hh"
|
||||||
#include "font.hh"
|
|
||||||
|
|
||||||
namespace otk {
|
namespace otk {
|
||||||
|
|
||||||
|
@ -22,8 +21,6 @@ public:
|
||||||
virtual void setStyle(Style *style);
|
virtual void setStyle(Style *style);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
//! Object used by Xft to render to the drawable
|
|
||||||
XftDraw *_xftdraw;
|
|
||||||
//! Text displayed in the label
|
//! Text displayed in the label
|
||||||
ustring _text;
|
ustring _text;
|
||||||
};
|
};
|
||||||
|
|
43
otk/font.cc
43
otk/font.cc
|
@ -14,9 +14,9 @@ extern "C" {
|
||||||
#include <algorithm>
|
#include <algorithm>
|
||||||
|
|
||||||
#include "font.hh"
|
#include "font.hh"
|
||||||
|
#include "surface.hh"
|
||||||
#include "util.hh"
|
#include "util.hh"
|
||||||
#include "display.hh"
|
#include "display.hh"
|
||||||
#include "color.hh"
|
|
||||||
#include "screeninfo.hh"
|
#include "screeninfo.hh"
|
||||||
|
|
||||||
extern "C" {
|
extern "C" {
|
||||||
|
@ -82,47 +82,6 @@ Font::~Font(void)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void Font::drawString(XftDraw *d, int x, int y, const Color &color,
|
|
||||||
const ustring &string) const
|
|
||||||
{
|
|
||||||
assert(d);
|
|
||||||
|
|
||||||
if (_shadow) {
|
|
||||||
XftColor c;
|
|
||||||
c.color.red = 0;
|
|
||||||
c.color.green = 0;
|
|
||||||
c.color.blue = 0;
|
|
||||||
c.color.alpha = _tint | _tint << 8; // transparent shadow
|
|
||||||
c.pixel = BlackPixel(**display, _screen_num);
|
|
||||||
|
|
||||||
if (string.utf8())
|
|
||||||
XftDrawStringUtf8(d, &c, _xftfont, x + _offset,
|
|
||||||
_xftfont->ascent + y + _offset,
|
|
||||||
(FcChar8*)string.c_str(), string.bytes());
|
|
||||||
else
|
|
||||||
XftDrawString8(d, &c, _xftfont, x + _offset,
|
|
||||||
_xftfont->ascent + y + _offset,
|
|
||||||
(FcChar8*)string.c_str(), string.bytes());
|
|
||||||
}
|
|
||||||
|
|
||||||
XftColor c;
|
|
||||||
c.color.red = color.red() | color.red() << 8;
|
|
||||||
c.color.green = color.green() | color.green() << 8;
|
|
||||||
c.color.blue = color.blue() | color.blue() << 8;
|
|
||||||
c.pixel = color.pixel();
|
|
||||||
c.color.alpha = 0xff | 0xff << 8; // no transparency in Color yet
|
|
||||||
|
|
||||||
if (string.utf8())
|
|
||||||
XftDrawStringUtf8(d, &c, _xftfont, x, _xftfont->ascent + y,
|
|
||||||
(FcChar8*)string.c_str(), string.bytes());
|
|
||||||
else
|
|
||||||
XftDrawString8(d, &c, _xftfont, x, _xftfont->ascent + y,
|
|
||||||
(FcChar8*)string.c_str(), string.bytes());
|
|
||||||
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
unsigned int Font::measureString(const ustring &string) const
|
unsigned int Font::measureString(const ustring &string) const
|
||||||
{
|
{
|
||||||
XGlyphInfo info;
|
XGlyphInfo info;
|
||||||
|
|
12
otk/font.hh
12
otk/font.hh
|
@ -3,6 +3,7 @@
|
||||||
#define __font_hh
|
#define __font_hh
|
||||||
|
|
||||||
#include "ustring.hh"
|
#include "ustring.hh"
|
||||||
|
#include "truerendercontrol.hh"
|
||||||
|
|
||||||
extern "C" {
|
extern "C" {
|
||||||
#include <X11/Xlib.h>
|
#include <X11/Xlib.h>
|
||||||
|
@ -15,6 +16,7 @@ extern "C" {
|
||||||
namespace otk {
|
namespace otk {
|
||||||
|
|
||||||
class Color;
|
class Color;
|
||||||
|
class Surface;
|
||||||
|
|
||||||
class Font {
|
class Font {
|
||||||
/*
|
/*
|
||||||
|
@ -60,13 +62,9 @@ public:
|
||||||
|
|
||||||
unsigned int measureString(const ustring &string) const;
|
unsigned int measureString(const ustring &string) const;
|
||||||
|
|
||||||
//! Draws a string into an XftDraw object
|
// The RenderControl classes use the internal data to render the fonts, but
|
||||||
/*!
|
// noone else needs it, so its private.
|
||||||
Be Warned: If you use an XftDraw object and a color, or a font from
|
friend class RenderControl;
|
||||||
different screens, you WILL have unpredictable results! :)
|
|
||||||
*/
|
|
||||||
void drawString(XftDraw *d, int x, int y, const Color &color,
|
|
||||||
const ustring &string) const;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -11,14 +11,10 @@ namespace otk {
|
||||||
Label::Label(Widget *parent)
|
Label::Label(Widget *parent)
|
||||||
: Widget(parent), _text("")
|
: Widget(parent), _text("")
|
||||||
{
|
{
|
||||||
const ScreenInfo *info = display->screenInfo(screen());
|
|
||||||
_xftdraw = XftDrawCreate(**display, window(), info->visual(),
|
|
||||||
info->colormap());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Label::~Label()
|
Label::~Label()
|
||||||
{
|
{
|
||||||
XftDrawDestroy(_xftdraw);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void Label::setStyle(Style *style)
|
void Label::setStyle(Style *style)
|
||||||
|
@ -66,7 +62,8 @@ void Label::update(void)
|
||||||
|
|
||||||
Widget::update();
|
Widget::update();
|
||||||
|
|
||||||
ft->drawString(_xftdraw, x, 0, *style()->getTextUnfocus(), t);
|
display->renderControl(_screen)->
|
||||||
|
drawString(this, *ft, x, 0, *style()->getTextUnfocus(), t);
|
||||||
} else
|
} else
|
||||||
Widget::update();
|
Widget::update();
|
||||||
}
|
}
|
||||||
|
|
|
@ -3,7 +3,6 @@
|
||||||
#define __label_hh
|
#define __label_hh
|
||||||
|
|
||||||
#include "widget.hh"
|
#include "widget.hh"
|
||||||
#include "font.hh"
|
|
||||||
|
|
||||||
namespace otk {
|
namespace otk {
|
||||||
|
|
||||||
|
@ -22,8 +21,6 @@ public:
|
||||||
virtual void setStyle(Style *style);
|
virtual void setStyle(Style *style);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
//! Object used by Xft to render to the drawable
|
|
||||||
XftDraw *_xftdraw;
|
|
||||||
//! Text displayed in the label
|
//! Text displayed in the label
|
||||||
ustring _text;
|
ustring _text;
|
||||||
};
|
};
|
||||||
|
|
|
@ -9,6 +9,10 @@
|
||||||
#include "rendertexture.hh"
|
#include "rendertexture.hh"
|
||||||
#include "display.hh"
|
#include "display.hh"
|
||||||
#include "screeninfo.hh"
|
#include "screeninfo.hh"
|
||||||
|
#include "surface.hh"
|
||||||
|
#include "color.hh"
|
||||||
|
#include "font.hh"
|
||||||
|
#include "ustring.hh"
|
||||||
|
|
||||||
extern "C" {
|
extern "C" {
|
||||||
#ifdef HAVE_STDLIB_H
|
#ifdef HAVE_STDLIB_H
|
||||||
|
@ -23,19 +27,17 @@ namespace otk {
|
||||||
|
|
||||||
RenderControl *RenderControl::getRenderControl(int screen)
|
RenderControl *RenderControl::getRenderControl(int screen)
|
||||||
{
|
{
|
||||||
const ScreenInfo *info = display->screenInfo(screen);
|
|
||||||
|
|
||||||
// get the visual on the screen and return the correct type of RenderControl
|
// get the visual on the screen and return the correct type of RenderControl
|
||||||
int vclass = info->visual()->c_class;
|
int vclass = display->screenInfo(screen)->visual()->c_class;
|
||||||
switch (vclass) {
|
switch (vclass) {
|
||||||
case TrueColor:
|
case TrueColor:
|
||||||
return new TrueRenderControl(info);
|
return new TrueRenderControl(screen);
|
||||||
case PseudoColor:
|
case PseudoColor:
|
||||||
case StaticColor:
|
case StaticColor:
|
||||||
// return new PseudoRenderControl(info);
|
// return new PseudoRenderControl(screen);
|
||||||
case GrayScale:
|
case GrayScale:
|
||||||
case StaticGray:
|
case StaticGray:
|
||||||
// return new GrayRenderControl(info);
|
// return new GrayRenderControl(screen);
|
||||||
default:
|
default:
|
||||||
printf(_("RenderControl: Unsupported visual %d specified. Aborting.\n"),
|
printf(_("RenderControl: Unsupported visual %d specified. Aborting.\n"),
|
||||||
vclass);
|
vclass);
|
||||||
|
@ -43,7 +45,7 @@ RenderControl *RenderControl::getRenderControl(int screen)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
RenderControl::RenderControl(const ScreenInfo *screen)
|
RenderControl::RenderControl(int screen)
|
||||||
: _screen(screen)
|
: _screen(screen)
|
||||||
{
|
{
|
||||||
printf("Initializing RenderControl\n");
|
printf("Initializing RenderControl\n");
|
||||||
|
@ -58,4 +60,47 @@ RenderControl::~RenderControl()
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void RenderControl::drawString(Surface *sf, const Font &font, int x, int y,
|
||||||
|
const Color &color, const ustring &string) const
|
||||||
|
{
|
||||||
|
assert(sf);
|
||||||
|
assert(sf->_screen == _screen);
|
||||||
|
XftDraw *d = sf->_xftdraw;
|
||||||
|
assert(d);
|
||||||
|
|
||||||
|
if (font._shadow) {
|
||||||
|
XftColor c;
|
||||||
|
c.color.red = 0;
|
||||||
|
c.color.green = 0;
|
||||||
|
c.color.blue = 0;
|
||||||
|
c.color.alpha = font._tint | font._tint << 8; // transparent shadow
|
||||||
|
c.pixel = BlackPixel(**display, _screen);
|
||||||
|
|
||||||
|
if (string.utf8())
|
||||||
|
XftDrawStringUtf8(d, &c, font._xftfont, x + font._offset,
|
||||||
|
font._xftfont->ascent + y + font._offset,
|
||||||
|
(FcChar8*)string.c_str(), string.bytes());
|
||||||
|
else
|
||||||
|
XftDrawString8(d, &c, font._xftfont, x + font._offset,
|
||||||
|
font._xftfont->ascent + y + font._offset,
|
||||||
|
(FcChar8*)string.c_str(), string.bytes());
|
||||||
|
}
|
||||||
|
|
||||||
|
XftColor c;
|
||||||
|
c.color.red = color.red() | color.red() << 8;
|
||||||
|
c.color.green = color.green() | color.green() << 8;
|
||||||
|
c.color.blue = color.blue() | color.blue() << 8;
|
||||||
|
c.pixel = color.pixel();
|
||||||
|
c.color.alpha = 0xff | 0xff << 8; // no transparency in Color yet
|
||||||
|
|
||||||
|
if (string.utf8())
|
||||||
|
XftDrawStringUtf8(d, &c, font._xftfont, x, font._xftfont->ascent + y,
|
||||||
|
(FcChar8*)string.c_str(), string.bytes());
|
||||||
|
else
|
||||||
|
XftDrawString8(d, &c, font._xftfont, x, font._xftfont->ascent + y,
|
||||||
|
(FcChar8*)string.c_str(), string.bytes());
|
||||||
|
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -12,10 +12,13 @@ namespace otk {
|
||||||
class ScreenInfo;
|
class ScreenInfo;
|
||||||
class Surface;
|
class Surface;
|
||||||
class RenderTexture;
|
class RenderTexture;
|
||||||
|
class Font;
|
||||||
|
class Color;
|
||||||
|
class ustring;
|
||||||
|
|
||||||
class RenderControl {
|
class RenderControl {
|
||||||
protected:
|
protected:
|
||||||
const ScreenInfo *_screen;
|
int _screen;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
// color tables, meaning, 256 (possibly) different shades of each color,
|
// color tables, meaning, 256 (possibly) different shades of each color,
|
||||||
|
@ -58,13 +61,18 @@ protected:
|
||||||
int _ncolors;
|
int _ncolors;
|
||||||
*/
|
*/
|
||||||
|
|
||||||
RenderControl(const ScreenInfo *screen);
|
RenderControl(int screen);
|
||||||
|
|
||||||
public:
|
public:
|
||||||
virtual ~RenderControl();
|
virtual ~RenderControl();
|
||||||
|
|
||||||
static RenderControl *getRenderControl(int screen);
|
static RenderControl *getRenderControl(int screen);
|
||||||
|
|
||||||
|
//! Draws a string onto a Surface
|
||||||
|
virtual void drawString(Surface *sf, const Font &font, int x, int y,
|
||||||
|
const Color &color, const ustring &string) const;
|
||||||
|
|
||||||
|
//! Draws a background onto a Surface, as specified by a RenderTexture
|
||||||
virtual void drawBackground(Surface *sf,
|
virtual void drawBackground(Surface *sf,
|
||||||
const RenderTexture &texture) const = 0;
|
const RenderTexture &texture) const = 0;
|
||||||
};
|
};
|
||||||
|
|
|
@ -6,29 +6,78 @@
|
||||||
|
|
||||||
#include "surface.hh"
|
#include "surface.hh"
|
||||||
#include "display.hh"
|
#include "display.hh"
|
||||||
|
#include "screeninfo.hh"
|
||||||
|
|
||||||
|
extern "C" {
|
||||||
|
#include <X11/Xutil.h>
|
||||||
|
}
|
||||||
|
|
||||||
namespace otk {
|
namespace otk {
|
||||||
|
|
||||||
Surface::Surface()
|
Surface::Surface(int screen)
|
||||||
: _size(1, 1),
|
: _screen(screen),
|
||||||
_pm(None)
|
_size(1, 1),
|
||||||
|
_im(0),
|
||||||
|
_pm(None),
|
||||||
|
_xftdraw(0)
|
||||||
{
|
{
|
||||||
|
createObjects();
|
||||||
}
|
}
|
||||||
|
|
||||||
Surface::Surface(const Point &size)
|
Surface::Surface(int screen, const Point &size)
|
||||||
: _size(size),
|
: _screen(screen),
|
||||||
_pm(None)
|
_size(size),
|
||||||
|
_im(0),
|
||||||
|
_pm(None),
|
||||||
|
_xftdraw(0)
|
||||||
{
|
{
|
||||||
|
createObjects();
|
||||||
}
|
}
|
||||||
|
|
||||||
Surface::~Surface()
|
Surface::~Surface()
|
||||||
{
|
{
|
||||||
if (_pm != None) XFreePixmap(**display, _pm);
|
destroyObjects();
|
||||||
|
}
|
||||||
|
|
||||||
|
void Surface::createObjects()
|
||||||
|
{
|
||||||
|
assert(!_im); assert(_pm == None); assert(!_xftdraw);
|
||||||
|
|
||||||
|
const ScreenInfo *info = display->screenInfo(_screen);
|
||||||
|
|
||||||
|
_im = XCreateImage(**display, info->visual(), info->depth(),
|
||||||
|
ZPixmap, 0, NULL, _size.x(), _size.y(), 32, 0);
|
||||||
|
|
||||||
|
_pm = XCreatePixmap(**display, info->rootWindow(), _size.x(), _size.y(),
|
||||||
|
info->depth());
|
||||||
|
|
||||||
|
_xftdraw = XftDrawCreate(**display, _pm, info->visual(), info->colormap());
|
||||||
|
}
|
||||||
|
|
||||||
|
void Surface::destroyObjects()
|
||||||
|
{
|
||||||
|
assert(_im); assert(_pm != None); assert(_xftdraw);
|
||||||
|
|
||||||
|
// do the delete ourselves cuz we alloc it with new not malloc
|
||||||
|
delete [] _im->data;
|
||||||
|
_im->data = NULL;
|
||||||
|
XDestroyImage(_im);
|
||||||
|
_im = 0;
|
||||||
|
|
||||||
|
XFreePixmap(**display, _pm);
|
||||||
|
_pm = None;
|
||||||
|
|
||||||
|
XftDrawDestroy(_xftdraw);
|
||||||
|
_xftdraw = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Surface::setSize(int w, int h)
|
void Surface::setSize(int w, int h)
|
||||||
{
|
{
|
||||||
|
if (w == _size.x() && h == _size.y()) return; // no change
|
||||||
|
|
||||||
_size.setPoint(w, h);
|
_size.setPoint(w, h);
|
||||||
|
destroyObjects();
|
||||||
|
createObjects();
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -7,28 +7,42 @@
|
||||||
|
|
||||||
extern "C" {
|
extern "C" {
|
||||||
#include <X11/Xlib.h>
|
#include <X11/Xlib.h>
|
||||||
|
#define _XFT_NO_COMPAT_ // no Xft 1 API
|
||||||
|
#include <X11/Xft/Xft.h>
|
||||||
}
|
}
|
||||||
|
|
||||||
namespace otk {
|
namespace otk {
|
||||||
|
|
||||||
|
class ScreenInfo;
|
||||||
|
|
||||||
class Surface {
|
class Surface {
|
||||||
|
int _screen;
|
||||||
Point _size;
|
Point _size;
|
||||||
|
XImage *_im;
|
||||||
Pixmap _pm;
|
Pixmap _pm;
|
||||||
|
XftDraw *_xftdraw;
|
||||||
|
|
||||||
|
void createObjects();
|
||||||
|
void destroyObjects();
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
Surface();
|
Surface(int screen);
|
||||||
Surface(const Point &size);
|
Surface(int screen, const Point &size);
|
||||||
|
|
||||||
virtual void setSize(int w, int h);
|
virtual void setSize(int w, int h);
|
||||||
|
|
||||||
public:
|
public:
|
||||||
virtual ~Surface();
|
virtual ~Surface();
|
||||||
|
|
||||||
|
inline int screen(void) const { return _screen; }
|
||||||
virtual const Point& size() const { return _size; }
|
virtual const Point& size() const { return _size; }
|
||||||
virtual int width() const { return _size.x(); }
|
virtual int width() const { return _size.x(); }
|
||||||
virtual int height() const { return _size.y(); }
|
virtual int height() const { return _size.y(); }
|
||||||
virtual Pixmap pixmap() const { return _pm; } // TEMP
|
virtual Pixmap pixmap() const { return _pm; } // TEMP
|
||||||
|
|
||||||
|
// The RenderControl classes use the internal objects in this class to render
|
||||||
|
// to it. Noone else needs them tho, so they are private.
|
||||||
|
friend class RenderControl;
|
||||||
friend class TrueRenderControl;
|
friend class TrueRenderControl;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -20,7 +20,7 @@ extern "C" {
|
||||||
|
|
||||||
namespace otk {
|
namespace otk {
|
||||||
|
|
||||||
TrueRenderControl::TrueRenderControl(const ScreenInfo *screen)
|
TrueRenderControl::TrueRenderControl(int screen)
|
||||||
: RenderControl(screen),
|
: RenderControl(screen),
|
||||||
_red_offset(0),
|
_red_offset(0),
|
||||||
_green_offset(0),
|
_green_offset(0),
|
||||||
|
@ -28,12 +28,13 @@ TrueRenderControl::TrueRenderControl(const ScreenInfo *screen)
|
||||||
{
|
{
|
||||||
printf("Initializing TrueColor RenderControl\n");
|
printf("Initializing TrueColor RenderControl\n");
|
||||||
|
|
||||||
|
Visual *visual = display->screenInfo(_screen)->visual();
|
||||||
unsigned long red_mask, green_mask, blue_mask;
|
unsigned long red_mask, green_mask, blue_mask;
|
||||||
|
|
||||||
// find the offsets for each color in the visual's masks
|
// find the offsets for each color in the visual's masks
|
||||||
red_mask = screen->visual()->red_mask;
|
red_mask = visual->red_mask;
|
||||||
green_mask = screen->visual()->green_mask;
|
green_mask = visual->green_mask;
|
||||||
blue_mask = screen->visual()->blue_mask;
|
blue_mask = visual->blue_mask;
|
||||||
|
|
||||||
while (! (red_mask & 1)) { _red_offset++; red_mask >>= 1; }
|
while (! (red_mask & 1)) { _red_offset++; red_mask >>= 1; }
|
||||||
while (! (green_mask & 1)) { _green_offset++; green_mask >>= 1; }
|
while (! (green_mask & 1)) { _green_offset++; green_mask >>= 1; }
|
||||||
|
@ -52,6 +53,7 @@ TrueRenderControl::~TrueRenderControl()
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
static inline void renderPixel(XImage *im, unsigned char *dp,
|
static inline void renderPixel(XImage *im, unsigned char *dp,
|
||||||
unsigned long pixel)
|
unsigned long pixel)
|
||||||
{
|
{
|
||||||
|
@ -102,34 +104,28 @@ void TrueRenderControl::drawBackground(Surface *sf,
|
||||||
assert(sf);
|
assert(sf);
|
||||||
|
|
||||||
int w = sf->width(), h = sf->height();
|
int w = sf->width(), h = sf->height();
|
||||||
|
XImage *im = sf->_im;
|
||||||
XImage *im = XCreateImage(**display, _screen->visual(), _screen->depth(),
|
Pixmap pm = sf->_pm;
|
||||||
ZPixmap, 0, NULL, w, h, 32, 0);
|
assert(im); assert(pm != None);
|
||||||
|
|
||||||
unsigned char *data = new unsigned char[im->bytes_per_line * h];
|
unsigned char *data = new unsigned char[im->bytes_per_line * h];
|
||||||
unsigned char *dp = data;
|
unsigned char *dp = data;
|
||||||
|
unsigned int bytes_per_pixel = im->bits_per_pixel/8;
|
||||||
|
|
||||||
for (int y = 0; y < h/3; ++y)
|
for (int y = 0; y < h/3; ++y)
|
||||||
for (int x = 0; x < w; ++x, dp += im->bits_per_pixel/8)
|
for (int x = 0; x < w; ++x, dp += bytes_per_pixel)
|
||||||
renderPixel(im, dp, (255*x/w) << _red_offset << _red_shift);
|
renderPixel(im, dp, (255*x/w) >> _red_shift << _red_offset);
|
||||||
for (int y = 0; y < h/3; ++y)
|
for (int y = 0; y < h/3; ++y)
|
||||||
for (int x = 0; x < w; ++x, dp += im->bits_per_pixel/8)
|
for (int x = 0; x < w; ++x, dp += bytes_per_pixel)
|
||||||
renderPixel(im, dp, (255*x/w) << _green_offset << _green_shift);
|
renderPixel(im, dp, (255*x/w) >> _green_shift << _green_offset);
|
||||||
for (int y = 0; y < h/3; ++y)
|
for (int y = 0; y < h/3; ++y)
|
||||||
for (int x = 0; x < w; ++x, dp += im->bits_per_pixel/8)
|
for (int x = 0; x < w; ++x, dp += bytes_per_pixel)
|
||||||
renderPixel(im, dp, (255*x/w) << _blue_offset << _blue_shift);
|
renderPixel(im, dp, (255*x/w) >> _blue_shift << _blue_offset);
|
||||||
|
|
||||||
im->data = (char*) data;
|
im->data = (char*) data;
|
||||||
|
|
||||||
if (!sf->_pm)
|
XPutImage(**display, pm, DefaultGC(**display, _screen),
|
||||||
sf->_pm = XCreatePixmap(**display, _screen->rootWindow(), w, h,
|
sf->_im, 0, 0, 0, 0, w, h);
|
||||||
_screen->depth());
|
|
||||||
XPutImage(**display, sf->_pm, DefaultGC(**display, _screen->screen()),
|
|
||||||
im, 0, 0, 0, 0, w, h);
|
|
||||||
|
|
||||||
//delete [] image->data;
|
|
||||||
//image->data = NULL;
|
|
||||||
XDestroyImage(im);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -4,24 +4,25 @@
|
||||||
|
|
||||||
#include "rendercontrol.hh"
|
#include "rendercontrol.hh"
|
||||||
|
|
||||||
|
#include <vector>
|
||||||
|
|
||||||
namespace otk {
|
namespace otk {
|
||||||
|
|
||||||
class TrueRenderControl : public RenderControl {
|
class TrueRenderControl : public RenderControl {
|
||||||
private:
|
private:
|
||||||
|
// the number of bits to shift a color value (from 0-255) to the right, to
|
||||||
|
// fit it into the the color mask (do this before the offset)
|
||||||
|
int _red_shift;
|
||||||
|
int _green_shift;
|
||||||
|
int _blue_shift;
|
||||||
|
|
||||||
// the offset of each color in a color mask
|
// the offset of each color in a color mask
|
||||||
int _red_offset;
|
int _red_offset;
|
||||||
int _green_offset;
|
int _green_offset;
|
||||||
int _blue_offset;
|
int _blue_offset;
|
||||||
|
|
||||||
// the number of bits to shift a color value (from 0-255) to fit it into the
|
|
||||||
// the color mask
|
|
||||||
int _red_shift;
|
|
||||||
int _green_shift;
|
|
||||||
int _blue_shift;
|
|
||||||
|
|
||||||
|
|
||||||
public:
|
public:
|
||||||
TrueRenderControl(const ScreenInfo *screen);
|
TrueRenderControl(int screen);
|
||||||
virtual ~TrueRenderControl();
|
virtual ~TrueRenderControl();
|
||||||
|
|
||||||
virtual void drawBackground(Surface *sf, const RenderTexture &texture) const;
|
virtual void drawBackground(Surface *sf, const RenderTexture &texture) const;
|
||||||
|
|
|
@ -15,7 +15,8 @@
|
||||||
namespace otk {
|
namespace otk {
|
||||||
|
|
||||||
Widget::Widget(Widget *parent, Direction direction)
|
Widget::Widget(Widget *parent, Direction direction)
|
||||||
: EventHandler(),
|
: Surface(parent->screen()),
|
||||||
|
EventHandler(),
|
||||||
_dirty(false), _focused(false),
|
_dirty(false), _focused(false),
|
||||||
_parent(parent), _style(parent->style()), _direction(direction),
|
_parent(parent), _style(parent->style()), _direction(direction),
|
||||||
_cursor(parent->cursor()), _bevel_width(parent->bevelWidth()),
|
_cursor(parent->cursor()), _bevel_width(parent->bevelWidth()),
|
||||||
|
@ -37,7 +38,8 @@ Widget::Widget(Widget *parent, Direction direction)
|
||||||
Widget::Widget(EventDispatcher *event_dispatcher, Style *style,
|
Widget::Widget(EventDispatcher *event_dispatcher, Style *style,
|
||||||
Direction direction, Cursor cursor, int bevel_width,
|
Direction direction, Cursor cursor, int bevel_width,
|
||||||
bool override_redirect)
|
bool override_redirect)
|
||||||
: EventHandler(),
|
: Surface(style->getScreen()),
|
||||||
|
EventHandler(),
|
||||||
_dirty(false),_focused(false),
|
_dirty(false),_focused(false),
|
||||||
_parent(0), _style(style), _direction(direction), _cursor(cursor),
|
_parent(0), _style(style), _direction(direction), _cursor(cursor),
|
||||||
_bevel_width(bevel_width), _ignore_config(0), _visible(false),
|
_bevel_width(bevel_width), _ignore_config(0), _visible(false),
|
||||||
|
|
|
@ -42,7 +42,6 @@ public:
|
||||||
inline Window window(void) const { return _window; }
|
inline Window window(void) const { return _window; }
|
||||||
inline const Widget *parent(void) const { return _parent; }
|
inline const Widget *parent(void) const { return _parent; }
|
||||||
inline const WidgetList &children(void) const { return _children; }
|
inline const WidgetList &children(void) const { return _children; }
|
||||||
inline unsigned int screen(void) const { return _screen; }
|
|
||||||
inline Rect rect(void) const { return Rect(_pos, size()); }
|
inline Rect rect(void) const { return Rect(_pos, size()); }
|
||||||
|
|
||||||
void move(const Point &to);
|
void move(const Point &to);
|
||||||
|
|
Loading…
Reference in a new issue