To create a X11PixelCanvas, you need a parent Widget and an X11PixelCanvasColorTable pointer.
Once constructed, drawing functions can be used to draw on the canvas and carry out other miscellaneous functions.
Positions are defined ultimately in signed integer pixel values, with
<0,0> representing the lower left corner pixel of the window. So for
a canvas size of 320x240, the upper rightmost pixel is <319,239>.
Integers are used because it is possible to perform drag operations
outside the window using the mouse, so negative pixel values have
meaning. The X11PixelCanvas operates in three different color modes: Index,
RGB, and HSV. Presently RGB and HSV modes has not been completed.
For details on how to use this class, please see the
PixelCanvas instead for a detailed
description of how to build applications with the PixelCanvas.
Now several examples follow on how to construct one or more X11PixelCanvases,
with an explanation of the strategy involved
and their implications.
Graphics are drawn onto an off-screen pixmap after which the pixmap is painted
onto the screen. The refresh call will always update the pixmap.
enable/disable motion/position events
Does this canvas support cached display lists? The user of the
canvas should always check this, because undefined behaviour can
result when an attempt is made to use a list on a PixelCanvas
which does not support lists.
begin caching display commands - return list ID
trigger refresh callbacks with the specified reason.
Fonts and text
Set font via a DLFont object
Draw an array of 2D color data as a raster image for zoom = <1,1>
(Cacheable) Draw an array of 2D color data as a raster image,
taking note of the Bool mask.
Draw an array of 2D color data as a raster image for any positive integer zoom
(Cacheable) Draw a component of a multi-channel image, storing it
in buffers until flushComponentImages() is called.
Initialise the channel buffers.
Are the channel buffers initialised?
Fill one of the channel buffers.
(NOT CACHEABLE!) Flush the component buffers.
Draw a single point using current color
Draw a bunch of points using current color
Draw a bunch of unrelated points using current color
Draw a single line using current color
Draw a bunch of unrelated lines using current color
Draw a bunch of unrelated lines using current color
Draw a N-1 connected lines from Nx2 matrix of vertices
Draw a single polyline or connected line between the points given
Draw an N-sided polygon from Nx2 matrix of vertices
Draw a closed polygon
Draw and fill a closed polygon
Draw a rectangle
Draw a filled rectangle
Draw a set of points, specifying a color per point to be drawn.
Most efficient when points with same color are grouped into sequences.
Draw a set of lines, specifying a color per line to be drawn.
Most efficient when lines with same color are grouped into sequences
Graphics Attributes
void setLineWidth(uInt width);
Graphics Attributes
Get Graphics Attributes
uInt getLineWidth() const;
Get Graphics Attributes
Option control
Control the image-caching strategy
ClipWindow control
save/restore the current translation.
translation functions
set the draw buffer
whole buffer memory exchanges
partial buffer memory exchanges. (x1,y1 are blc, x2,y2 are trc)
return True if refresh is allowed, default impl is True always
Clear the window using the current clear color (default black)
Cause graphics commands to be flushed to the display
Set the color to use for clearing the display
Get/set the current foreground/background colors. These colors
are used when the special Strings "foreground" and "background"
are given for a color.
return the color used for clearing the display
Set the current color to a string recognized by XParseColor
Get color components in range 0 to 1 without actually
allocating the color. This is needed to set up other
devices, for example PgPlot.
Return the current color.
Return the color at some position
Return the RGB values of the color at some position
Event Handling
number returned depends on mode.
virtual Bool getPixelValue(uInt xpos, uInt ypos, Vector
ILColormap * makeColormap(
handle exposure callback
handle position callback
handle colorTable resize
resize the colortable by requesting a new number of cells
resize the colortable by requesting a new color cube
return the pixel canvas color table
set the pixel canvas color table
Return the width, height, depth of the display
Get the pixel density (in dots per inch [dpi]) of the PixelCanvas
resize the PixelCanvas to a new size
Return some things peculiar to the X11 pixel canvas
draw mode - Display::Compile (build display list) or Display::Draw (immediate mode)
Request buffer is used to batch requests to the X server
Return True if drawing commands should be sent to the pixmap
Return True if drawing commands should be sent to the window
Display list caching
Write an X Pixmap (xpm) file of the current pixmap
Handle the X expose event. This is caught by the pixel canvas
and forwarded as a refresh event only if the pixel canvas changed
dimensions. If there was no size change, the pixel canvas simply
copies its pixmap to the display without generating a refresh.
Display list optimization
Strip empty dl entries and make a new list
Display list optimization
replace sequences of line/lines with a single lines call
Display list optimization
replace sequences of point/points with a single point call
Display list optimization
Entry point
Select a list id for a new display list
resize the pixmap to match the window size
X11PixelCanvasColorTable pcct(xscreen, Display::Index, Display::Best, Display::System);
PixelCanvas * canvas1 = new X11PixelCanvas(myParent, &pcct, 320u, 240u);
PixelCanvas * canvas2 = new X11PixelCanvas(myParent, &pcct, 320u, 240u);
...
This application has requested the best index map available on the system
colormap.
X11PixelCanvasColorTable pcct1(xscreen, Display::Index, Display::Percent, Display::System, 50);
X11PixelCanvasColorTable pcct2(xscreen, Display::Index, Display::Best, Display::System);
PixelCanvas * canvas1 = new X11PixelCanvas(myParent, &pcct1, 320u, 240u);
PixelCanvas * canvas2 = new X11PixelCanvas(myParent, &pcct2, 320u, 240u);
This application creates two colortables. The first allocates half of whatever
colors are available in the System map, the second allocates the remaining
half.
X11PixelCanvasColorTable pcct1(xscreen, Display::Index, Display::Percent, Display::New, 50);
X11PixelCanvasColorTable pcct2(xscreen, Display::Index, Display::Best, &pcct1);
PixelCanvas * canvas1 = new X11PixelCanvas(myParent, &pcct1, 320u, 240u);
PixelCanvas * canvas2 = new X11PixelCanvas(myParent, &pcct2, 320u, 240u);
This application creates two colortables. The first allocates half of the
new X colormap, and the second one allocates the remaining half.
X11PixelCanvasColorTable pcct(xscreen, Display::Index, Display::Custom, Display::New, 128);
PixelCanvas * canvas1 = new X11PixelCanvas(myParent, &pcct, 320u, 240u);
PixelCanvas * canvas2 = new X11PixelCanvas(myParent, &pcct, 320u, 240u);
This application creates a fixed-size private colormap for its windows.
Motivation
Needed solid foundation for a PixelCanvas
Example
see the examples in the Display/test directory
Member Description
X11PixelCanvas()
Default ctor needed for derivation of Tk canvases
X11PixelCanvas(Widget parent, X11PixelCanvasColorTable * xpcctbl, uInt width, uInt height)
virtual void enableMotionEvents()
virtual void disableMotionEvents()
virtual void enablePositionEvents()
virtual void disablePositionEvents()
virtual Bool supportsLists()
virtual uInt newList()
virtual void endList()
end caching display commands
virtual void drawList(uInt list)
recall cached display commands
virtual void translateAllLists(Int xt, Int yt)
translate all lists
virtual void translateList(uInt list, Int xt, Int yt)
translate the list
virtual void deleteList(uInt list)
remove list from cache
virtual void deleteLists()
flush all lists from the cache
virtual Bool validList(uInt list)
return True if the list exists
virtual void refresh(const Display::RefreshReason &reason = Display::UserCommand, const Bool &explicitrequest = True)
Int textHeight(const String& text)
Int textWidth(const String& text)
Bool setFont(const String & font)
Bool setFont(DLFont* font)
Bool setFont(const String& font, const Int size)
void drawText(Int xoffset, Int yoffset, const String & text, Display::TextAlign alignment = Display::AlignCenter)
void drawText(Int xoffset, Int yoffset, const String & text, const Float& angle, Display::TextAlign alignment = Display::AlignCenter)
void drawImage(const Matrix<uInt> & data, Int xoffset, Int yoffset)
void drawImage(const Matrix<Int> & data, Int xoffset, Int yoffset)
void drawImage(const Matrix<uLong> & data, Int xoffset, Int yoffset)
void drawImage(const Matrix<Float> & data, Int xoffset, Int yoffset)
void drawImage(const Matrix<Double> & data, Int xoffset, Int yoffset)
virtual void drawImage(const Int &x, const Int &y, const Matrix<uInt> &data, const Matrix<Bool> &mask)
void drawImage(const Matrix<uInt> & data, Int xoffset, Int yoffset, uInt xzoom, uInt yzoom)
void drawImage(const Matrix<Int> & data, Int xoffset, Int yoffset, uInt xzoom, uInt yzoom)
void drawImage(const Matrix<uLong> & data, Int xoffset, Int yoffset, uInt xzoom, uInt yzoom)
void drawImage(const Matrix<Float> & data, Int xoffset, Int yoffset, uInt xzoom, uInt yzoom)
void drawImage(const Matrix<Double> & data, Int xoffset, Int yoffset, uInt xzoom, uInt yzoom)
void drawImage(const Matrix<uInt> &data, const Int &x, const Int &y, const Display::ColorComponent &colorcomponent)
void initialiseComponents(const Int &x, const Int &y, const IPosition &shape)
Bool componentsInitialised()
void bufferComponent(const Matrix<uInt> &data, const Int &x, const Int &y, const Display::ColorComponent &colorcomponent)
void flushComponentBuffers()
void drawPoint(Int x1, Int y1)
void drawPoint(Float x1, Float y1)
void drawPoint(Double x1, Double y1)
void drawPoints(const Vector<Int> & x1, const Vector<Int> & y1)
void drawPoints(const Vector<Float> & x1, const Vector<Float> & y1)
void drawPoints(const Vector<Double> & x1, const Vector<Double> & y1)
void drawPoints(const Matrix<Int> & verts)
void drawPoints(const Matrix<Float> & verts)
void drawPoints(const Matrix<Double> & verts)
void drawLine(Int x1, Int y1, Int x2, Int y2)
void drawLine(Float x1, Float y1, Float x2, Float y2)
void drawLine(Double x1, Double y1, Double x2, Double y2)
void drawLines(const Matrix<Int> & verts)
void drawLines(const Matrix<Float> & verts)
void drawLines(const Matrix<Double> & verts)
void drawLines(const Vector<Int> & x1, const Vector<Int> & y1, const Vector<Int> & x2, const Vector<Int> & y2)
void drawLines(const Vector<Float> & x1, const Vector<Float> & y1, const Vector<Float> & x2, const Vector<Float> & y2)
void drawLines(const Vector<Double> & x1, const Vector<Double> & y1, const Vector<Double> & x2, const Vector<Double> & y2)
void drawPolyline(const Matrix<Int> & verts)
void drawPolyline(const Matrix<Float> & verts)
void drawPolyline(const Matrix<Double> & verts)
void drawPolyline(const Matrix<Complex> & verts)
void drawPolyline(const Matrix<DComplex> & verts)
void drawPolyline(const Vector<Int> & x1, const Vector<Int> & y1)
void drawPolyline(const Vector<Float> & x1, const Vector<Float> & y1)
void drawPolyline(const Vector<Double> & x1, const Vector<Double> & y1)
void drawPolygon(const Matrix<Int> & verts)
void drawPolygon(const Matrix<Float> & verts)
void drawPolygon(const Matrix<Double> & verts)
void drawPolygon(const Vector<Int> & x1, const Vector<Int> & y1)
void drawPolygon(const Vector<Float> & x1, const Vector<Float> & y1)
void drawPolygon(const Vector<Double> & x1, const Vector<Double> & y1)
void drawFilledPolygon(const Vector<Int> & x1, const Vector<Int> & y1)
void drawFilledPolygon(const Vector<Float> & x1, const Vector<Float> & y1)
void drawFilledPolygon(const Vector<Double> & x1, const Vector<Double> & y1)
void drawRectangle(Int x1, Int y1, Int x2, Int y2)
void drawRectangle(Float x1, Float y1, Float x2, Float y2)
void drawRectangle(Double x1, Double y1, Double x2, Double y2)
void drawFilledRectangle(Int x1, Int y1, Int x2, Int y2)
void drawFilledRectangle(Float x1, Float y1, Float x2, Float y2)
void drawFilledRectangle(Double x1, Double y1, Double x2, Double y2)
void drawColoredPoints(const Vector<Int> & x1, const Vector<Int> & y1, const Vector<uInt> & colors)
void drawColoredPoints(const Vector<Float> & x1, const Vector<Float> & y1, const Vector<uInt> & colors)
void drawColoredPoints(const Vector<Double> & x1, const Vector<Double> & y1, const Vector<uInt> & colors)
virtual void drawColoredPoints(const Matrix<Int> &xy, const Vector<uInt> &colors)
virtual void drawColoredPoints(const Matrix<Float> &xy, const Vector<uInt> &colors)
virtual void drawColoredPoints(const Matrix<Double> &xy, const Vector<uInt> &colors)
void drawColoredLines(const Vector<Int> & x1, const Vector<Int> & y1, const Vector<Int> & x2, const Vector<Int> & y2, const Vector<uInt> & colors)
void drawColoredLines(const Vector<Float> & x1, const Vector<Float> & y1, const Vector<Float> & x2, const Vector<Float> & y2, const Vector<uInt> & colors)
void drawColoredLines(const Vector<Double> & x1, const Vector<Double> & y1, const Vector<Double> & x2, const Vector<Double> & y2, const Vector<uInt> & colors)
void setLineWidth(Float width)
void setDrawFunction(Display::DrawFunction function)
void setForeground(uLong color)
void setBackground(uLong color)
void setLineStyle(Display::LineStyle style)
void setCapStyle(Display::CapStyle style)
void setJoinStyle(Display::JoinStyle style)
void setFillStyle(Display::FillStyle style)
void setFillRule(Display::FillRule rule)
void setArcMode(Display::ArcMode mode)
Float getLineWidth() const
Display::DrawFunction getDrawFunction() const
uLong getForeground() const
uLong getBackground() const
Display::LineStyle getLineStyle() const
Display::CapStyle getCapStyle() const
Display::JoinStyle getJoinStyle() const
Display::FillStyle getFillStyle() const
Display::FillRule getFillRule() const
Display::ArcMode getArcMode() const
Bool enable(Display::Option option)
Bool disable(Display::Option option)
void setImageCacheStrategy(Display::ImageCacheStrategy strategy)
Display::ImageCacheStrategy imageCacheStrategy() const
Bool usePixmapImages() const
void setClipWindow(Int x1, Int y1, Int x2, Int y2)
void getClipWindow(Int & x1, Int & y1, Int & x2, Int & y2)
virtual void pushMatrix()
virtual void popMatrix()
virtual void loadIdentity()
zero the current translation
virtual void translate(Int xt, Int yt)
virtual void getTranslation(Int & xt, Int & yt) const
virtual Int xTranslation() const
virtual Int yTranslation() const
void setDrawBuffer(Display::DrawBuffer buf)
void copyBackBufferToFrontBuffer()
void copyFrontBufferToBackBuffer()
void swapBuffers()
void copyBackBufferToFrontBuffer(Int x1, Int y1, Int x2, Int y2)
void copyFrontBufferToBackBuffer(Int x1, Int y1, Int x2, Int y2)
void swapBuffers(Int x1, Int y1, Int x2, Int y2)
virtual Bool refreshAllowed() const
virtual void clear()
virtual void clear(Int x1, Int y1, Int x2, Int y2)
virtual void flush()
virtual void setClearColor(uInt color)
virtual void setClearColor(const String & color)
virtual void setClearColor(float r, float g, float b)
virtual void setDeviceForegroundColor(const String colorname)
virtual String deviceForegroundColor() const
virtual void setDeviceBackgroundColor(const String colorname)
virtual String deviceBackgroundColor() const
virtual uInt clearColor() const
virtual void getClearColor(float & r, float & g, float & b) const
void setColor(const String& colorName)
void setColor(uInt ColorIndex)
Set the current color to a specified index
void setColor(float c1, float c2, float c3)
Set the current color using current colorspace
All values must lie in the range of [0-1]
void setRGBColor(float r, float g, float b)
Set the current color using rgb colorspace
All values must lie in the range of [0-1]
void setHSVColor(float h, float s, float v)
Set the current color to an hsv colorspace
All values must lie in the range of [0-1]
Bool getColorComponents(const String &colorname, Float &r, Float &g, Float &b)
uInt color() const
void getColor(float & r, float & g, float & b) const
Return the current color as an RGB triple;
Bool getColor(int, int, uInt &)
Bool getRGBColor(int, int, float &, float &, float &)
static void handleEventsEH(Widget w, X11PixelCanvas * xpc, XEvent * ev, Boolean *)
void handleEvents(Widget w, XEvent * ev)
static void exposeCB(Widget , X11PixelCanvas * xpc, XtPointer callData)
static void positionEventCB(Widget, X11PixelCanvas * xpc, XtPointer callData)
static void colorTableResizeCB(PixelCanvasColorTable * pcctbl, uInt, X11PixelCanvas * xpc, Display::RefreshReason reason)
Bool resizeColorTable(uInt newSize)
Bool resizeColorTable(uInt nReds, uInt nGreens, uInt nBlues)
PixelCanvasColorTable * pcctbl() const
void setPcctbl(PixelCanvasColorTable * pcctbl)
virtual uInt width() const
virtual uInt height() const
virtual uInt depth() const
virtual void pixelDensity(Float &xdpi, Float &ydpi) const
Bool resize(uInt reqXSize, uInt reqYSize, Bool doCallbacks = True)
::XDisplay * display() const
Screen * screen() const
Visual * visual() const
Pixmap pixmap() const
Window drawWindow() const
GC gc() const
XColormap xcmap() const
X11PixelCanvasColorTable * xpcctbl() const
Display::DrawMode drawMode()
void * requestBuffer() const
Bool drawToPixmap() const
virtual Bool drawToWindow() const
void appendToDisplayList(X11PCDisplayListObject * obj)
virtual Bool writeXPixmap(const String &filename)
Bool resize_()
test for resize of the pixel canvas dimensions, returning
true if the size was changed.
void exposeHandler_()
Bool packDisplayList(String & str, PtrBlock<X11PCDisplayListObject *> * l, uInt count)
Bool applyConsecutiveLineOpt(String & s, PtrBlock<X11PCDisplayListObject *> * l)
Bool applyConsecutivePointOpt(String & s, PtrBlock<X11PCDisplayListObject *> * l)
Bool compactDisplayList(PtrBlock<X11PCDisplayListObject *> * l, uInt & count)
uInt pickListID()
void resizePixmap()