Next: X11TextEntryPane, Previous: X11PopupMenu, Up: Classes [Index]
X11ScrollBarPane ClassA X11ScrollBarPane object draws a basic scroll bar and allows
the user to move the scroll thumb by clicking and dragging.
Applications can set and read the scroll thumb’s size and position via
the object’s instance variables. In particular, the
thumbHeight instance variable sets the vertical size of the
scroll thumb, and the thumbDimensions method sets the coordinates
and height of the thumb when sliding it to a new position.
The scroll bar’s frame and thumb instance variables are
both Rectangle objects. Applications can use the
Rectangle class’s methods, like dimension, to set the
scroll position, and can read the position using the Rectangle
object’s instance variables. See Rectangle.
Here is an example program that demonstrates the basic steps needed to draw a scroll bar.
int main (int argv, char **argc) {
Integer new xWindowSize;
Integer new yWindowSize;
X11Pane new xPane;
X11PaneDispatcher new xTopLevelPane;
X11ScrollBarPane new xScrollBarPane;
X11CanvasPane new xCanvasPane;
InputEvent new e;
Exception new ex;
Application new scrollDemo;
String new pctstr;
Integer new strWidth;
scrollDemo enableExceptionTrace;
scrollDemo installExitHandlerBasic;
scrollDemo installAbortHandlerBasic;
xWindowSize = 400;
yWindowSize = 400;
xPane ftFontVar initFontLib;
xPane ftFont "DejaVu Sans", 0, 0, 0, 48.0;
xPane initialize xWindowSize, yWindowSize;
xPane inputStream eventMask = WINDELETE|EXPOSE|BUTTONPRESS|BUTTONRELEASE|MOTIONNOTIFY;
xTopLevelPane attachTo xPane;
xScrollBarPane attachTo xTopLevelPane, "20x100%+0+0";
xCanvasPane attachTo xTopLevelPane, "380x100%+20+0";
xPane map;
xPane raiseWindow;
xPane openEventStream;
xScrollBarPane background "lightblue";
xScrollBarPane refresh;
xCanvasPane background "navy";
xCanvasPane foreground "navy";
xPane ftFontVar namedX11Color "white";
xCanvasPane clear;
pctstr printOn "%0.2f%%", xScrollBarPane percent * 100.0;
strWidth = xPane ftFontVar textWidth pctstr;
xCanvasPane putStrXY (380 / 2) - (strWidth / 2), (400 / 2), pctstr;
xCanvasPane refresh;
while (TRUE) {
xPane inputStream queueInput;
if (xPane inputStream eventPending) {
e become xPane inputStream inputQueue unshift;
if (ex pending)
ex handle;
xPane subPaneNotify e;
switch (e eventClass value)
{
case EXPOSE:
xCanvasPane paneBuffer clear;
pctstr printOn "%0.2f%%", xScrollBarPane percent * 100;
strWidth = xPane ftFontVar textWidth pctstr;
xCanvasPane putStrXY (380 / 2) - (strWidth / 2), (400 / 2), pctstr;
xCanvasPane refresh;
break;
case WINDELETE:
xPane deleteAndClose;
exit (0);
break;
default:
xCanvasPane paneBuffer clear;
pctstr printOn "%0.2f%%", xScrollBarPane percent * 100;
strWidth = xPane ftFontVar textWidth pctstr;
xCanvasPane putStrXY (380 / 2) - (strWidth / 2), (400 / 2), pctstr;
xCanvasPane refresh;
break;
}
}
}
}
arrowCursorA X11Cursor object that contains the resource ID of the widget’s
arrow cursor. See X11Cursor.
bevelA Boolean that determines whether the scroll thumb is drawn
as a beveled widget.
draggingA Boolean object that is True while the right mouse button is
clicked while over the scroll thumb. See Boolean.
frameA Rectangle object that contains coordinates of the scroll bar frame.
See Rectangle.
frameWidthVarAn Integer that contains the width of the scrollbar’s visible frame
in pixels.
framePenA Pen object that sets the line color and width of the scroll bar frame.
See Pen.
grabCursorA X11Cursor object that contains the resource ID of the widget’s
grab cursor. See X11Cursor.
lastYAn Integer object that contains the previous PointerMotion
event’s y coordinate while dragging. See Integer.
marginAn Integer that defines the distance in pixels between the
pane’s edge and the outer edge of the scrollbar frame.
mouseOverA Boolean that is true if the pointer is over the scrollbar frame,
false otherwise.
paddingAn Integer that defines the distance in pixels between the inner
edge of the scrollbar frame and the thumb.
thumbA Rectangle object that contains coordinates of the scroll thumb.
See Rectangle.
thumbBackgrondColorA String that contains the name of the X11 color used to draw
the thumb.
thumbErasePenA Pen object that sets the color and line width of the scroll thumb
background when animating the thumb.
See Pen.
thumbHeightAn Integer that sets the height of the scroll thumb.
See Integer.
thumbPenA Pen object that sets the color and line width of the scroll thumb.
See Pen.
thumbPixA X11Bitmap that contains the thumb’s beveled image, if the
pane is drawn with bevel set to ‘true’.
attachTo (Object parentPane)Attaches the X11ScrollBarPane object to its parent pane,
which is usually a X11PaneDispatcher object. Also sizes the
pane and its buffers to fit within the visible window, and sets the
dimensions of the scrollbar’s visible frame and thumb.
background (String colorName)Sets the pane’s background color to colorName, and also sets the color to use when performing scrollbar animations.
drawThumb (void)eraseThumb (void)These methods animate the thumb so that it tracks the pointer’s position within the scrollbar.
frameWidth (Integer lineWidth)Calculates the scrollbar frame’s dimensions within the pane’s margins for the line width in pixels given as the argument.
new (String paneName)Creates a new X11ScrollBarPane object, initializes the pane’s
event handlers, and sets the default colors of the pane’s elements.
percent (void)Returns a Float with the position of the thumb’s top edge
in the usable trough of the scrollbar, as a percentage between 0.0
and 1.0.
The usable area of the trough is defined as the distance that the top edge of the scrollbar thumb can travel within the scrollbar’s margins; i.e,
usableTrough = aScrollBar size y -
((aScrollBar margin * 2) +
(aScrollBar frameWidthVar * 2) +
(aScrollBar padding * 2) +
(aScrollBar thumbHeight));
pointIsInThumb (Integer x, Integer, y)This method returns a Boolean value of true if the point
x,y is within the scroll bar thumb.
subPaneDestroy (Object subPane, InputEvent eventsubPaneExpose (Object subPane, InputEvent eventsubPanePointerInput (Object subPane, InputEvent eventsubPanePointerMotion (Object subPane, InputEvent eventsubPaneEnterNotify (Object subPane, InputEvent eventsubPaneLeaveNotify (Object subPane, InputEvent eventThe X11ScrollBarPane object’s event handlers for DESTROY,
EXPOSE, BUTTONPRESS/BUTTONRELEASE, MOTIONNOTIFY, ENTERWINDOWNOTIFY,
and LEAVEWINDOWNOTIFY X Window System events.
thumbDimensions (Integer y, Integer height)Calculates the position and size thumb’s rectangle within the pane using the vertical y position and the thumb’s height.
thumbPercent (Float pct)Calculates the thumb’s height as a percent of the trough’s vertical distance.
The argument, pct, is a Float between 0.0 and 1.0.
Note that, in order to make these calculations and update the thumb height in the pane’s viewing area, the scrollbar must already be attached to its parent pane, and the program needs to be receiving X events. So this method should only be used after a call to, for example, X11Pane : openEventStream.
Next: X11TextEntryPane, Previous: X11PopupMenu, Up: Classes [Index]