1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243
|
<title> Scrollbars </title>
<ul>
<li> <a href="#scroll"> Scrollbars </a>
<li> <a href="scrollbar.html#fMHS"> MakeHorizScrollbar </a>
<li> <a href="scrollbar.html#fMVS"> MakeVertScrollbar </a>
<li> <a href="scrollbar.html#fSS"> SetScrollbar </a>
<li> <a href="scrollbar.html#fSTB"> SetThumbBitmap </a>
</ul>
<hr>
<p>
<h2> <a name="scroll"> Scrollbars </a> </h2>
<p>
A scrollbar is a widget that allows a user to control some numeric
quantity interactively by using the mouse to scroll a slider, similar
to the volume slider on some radios. The slider is called the "thumb"
or "thumb area" in X terminology.
<hr>
<p>
<a name="fMHS"> <b>
Widget MakeHorizScrollbar(int length, ScrollCB scroll_func, void *data);
</b> </a>
<p>
<a name="fMVS"> <b>
Widget MakeVertScrollbar(int height, ScrollCB scroll_func, void *data);
</b> </a>
<p>
These two routines create scrollbars. Scrollbars allow the user to
interactively control some numeric quantity with the mouse.
<p>
When the user presses the left mouse button, the value represented by
the scrollbar increases. When the press the middle mouse button, they
can interactively adjust the value. Clicking the right mouse button
decreases the value represented by the scrollbar.
<p>
The arguments to create a scrollbar are its length or height in
pixels, a callback function to call when the scrollbar changes value
and an extra void pointer argument that is passed to the callback
function.
<p>
If these routines fail, they return NULL.
<p>
To set what values a scrollbar represents, you must use
<a href="scrollbar.html#fSS"> SetScrollbar() </a>.
These two routines only make a scrollbar and do not
set it to return useful values. You always have to call
<a href="scrollbar.html#fSS"> SetScrollbar() </a>
to set what a scrollbar represents (see the
documentation for
<a href="scrollbar.html#fSS"> SetScrollbar() </a>
for more information).
<p>
Your callback routine is called everytime the scrollbar changes.
Since the calculations are done in floating point, the value may not
have changed enough to be interesting, but your routine is still
called. You should take care to see that the value changed enough to
be interesting to your applications (i.e. it is wasteful for a text
editor to repaint the window when the new value is 0.003 different
than the old value).
<p>
A scrollbar callback routine should be declared as follows:
<p>
<pre>
void scroll_func(Widget w, float new_val, void *data)
{
}
</pre>
<p>
The first argument, w, is the scrollbar widget that the user is
manipulating. The second argument is a floating point value that
represents the new value of the scrollbar. The third argument is the
void pointer argument that was passed to Make{Horiz,Vert}Scrollbar().
<p>
SEE ALSO :
<a href="scrollbar.html#fSS"> SetScrollbar() </a>,
<a href="scrollbar.html#fSTB"> SetThumbBitmap() </a>,
<a href="misc.html#fSWP"> SetWidgetPos() </a>,
<a href="misc.html#fSFC"> SetFgColor() </a>,
<a href="misc.html#fSBC"> SetBgColor() </a>,
<a href="misc.html#fSBC2"> SetBorderColor() </a>
<hr>
<p>
<a name="fSS"> <b>
void SetScrollbar(Widget w, float where, float max, float size_shown);
</b> </a>
<p>
This function lets you set the values that a scrollbar represents.
The first argument is a scrollbar widget. The next three arguments
are floating point numbers that specify the parameters of the
scrollbar.
<p>
Before discussing the details of the three float arguments, let us get
some terms straight. When we refer to the `container' of a scrollbar,
we mean the entire box that makes up the scrollbar. The `thumb' of a
scrollbar is the gray area that the user can grab to manipulate. We
refer to the size or length of the thumb area (the amount of grey) as
the `size shown'. The total amount represented by the scrollbar is
called `max'.
<p>
The arguments mean the following:
<p>
<pre>
where -- this floating point number specifies where in the
container the top of the thumb area should start. If
you have a maximum value of 100 and where is 50, the
beginning of the thumb will be in the middle of the
container.
max -- The maximum value that the scroll bar can have. You
will receive numbers in the range 0 to max (inclusive).
Obviously max should be a positive, and is a float.
size_shown -- This float value controls how big the grey area that
the user can grab is. This represents how much of
whatever it is you are representing is visible. For
example, a text editor which shows 24 lines of text
would set size_shown to be 24 (out of whatever max
is). If you want the scrollbar to represent a
percentage of something, where when it is 100%, the
grey area is also 100% of the box, then you should
set the size_shown to be equal to max. If this is
confusing, there are examples below.
</pre>
<p>
Now, some examples to clarify things (in the following, assume that
the argument, w, represents a scrollbar widget created with the
<a href="scrollbar.html#fMHS"> MakeHorizScrollbar() </a>
or
<a href="scrollbar.html#fMVS"> MakeVertScrollbar() </a>
routines).
<p>
For the first example, let's assume you want a scrollbar to let you
set a color value which can range between 0 and 255 with the initial
value at 67. You sould set the scrollbar as follows:
<pre>
SetScrollbar(w, 67.0, 255.0, 1.0);
</pre>
<p>
The first value, 67.0, is where we would like the beginning of the
thumb area to appear. The next value, 255, is the maximum value the
scrollbar can attain. The third value, 1, is the size of the thumb
area (the amount represented by the thumb relative to the maximum
size). This scrollbar will now return values in the range of 0 to 255
(inclusive). The thumb area will be small, and represents one value
of the 255 possible divisions. The position of the thumb area in the
container represents its value.
<p>
For the next example, suppose we wish to make a scrollbar represent
some percentage of a value. That is, the size of the thumb area
should be proportional to the value of the scrollbar relative to its
maximum (so when the value is at it maximum, the thumb area is 100% of
the scrollbar).
<p>
In this case we would like the size of the thumb area to represent the
amount of the variable (note the difference from the above example).
Let us suppose we want a scrollbar which can represent a percentage 0
to 100, with the initial value being 50.
<pre>
SetScrollbar(w, 50.0, 100.0, 100.0);
</pre>
<p>
The first value, 50, is where the thumb area begins (in the middle of
the container). The next number is 100, and represents the maximum
value of the scrollbar. The next number, again 100, is the size
shown. Making this value the same as the max value (in this case
100) causes the thumb area to vary according to the value the
scrollbar represents.
<p>
As a final example, let us take a text editor which is displaying a
file. In this case, let us assume the text file is 259 lines long,
the window can display 47 lines, and the top line currently displayed
is 72. To create the correct scrollbar, we would do the following:
<pre>
SetScrollbar(w, 72.0, 259.0, 47.0);
</pre>
<p>
This creates a scrollbar which has a thumb area whose size is 47/259
of the entire container, and is positioned 72/259'ths of the way down
the container.
<p>
SEE ALSO:
<a href="scrollbar.html#fMHS"> MakeHorizScrollbar() </a>,
<a href="scrollbar.html#fMVS"> MakeVertScrollbar() </a>,
<a href="scrollbar.html#fSTB"> SetThumbBitmap() </a>,
<a href="misc.html#fSWP"> SetWidgetPos() </a>
<hr>
<p>
<a name="fSTB"> <b>
void SetThumbBitmap(Widget w, char *black_bits, int width, int height);
</b> </a>
<p>
Sets a bitmap for the thumb area in the scrollbar. This function is
similar to SetWidgetBitmap(), which one can refer to for details. The
default bitmap is a black & white combination of pixels. To get instead
an entirely black thumb area, one can use
<pre>
static unsigned char black_bits[] = { 0xff };
SetThumbBitmap(scroll_widget, black_bits, 8, 1);
</pre>
The default is equivalent to
<pre>
static unsigned char black_bits[] = { 0xaa, 0x55 };
SetThumbBitmap(scroll_widget, black_bits, 8, 2);
</pre>
SEE ALSO:
<a href="scrollbar.html#fMHS"> MakeHorizScrollbar() </a>,
<a href="scrollbar.html#fMVS"> MakeVertScrollbar() </a>,
<a href="misc.html#fSWP"> SetWidgetPos() </a>
<a href="misc.html#fSWB"> SetWidgetBitmap() </a>
<hr>
<p>
<a name="fSSS"> <b>
void SetScrollbarStep(Widget w, float fact)
</b> </a>
<p>
Sets the fraction of the scrollbar that gets increased or decreased
when the left or right mouse buttons is pressed. The scrollbar thus
moves faster as fact increases. The default value is fact = 0.1 .
See also the explanations concerning the scrollbar callback functions.
<p>
SEE ALSO:
<a href="scrollbar.html#fMHS"> MakeHorizScrollbar() </a>,
<a href="scrollbar.html#fMVS"> MakeVertScrollbar() </a>,
<hr>
<p>
<a name="fSSD"> <b>
void SetScrollbarDirection(float dir)
</b> </a>
<p>
The effect of this function is to possibly affect the scrollbar step
by a signed factor dir (normally equal to +1 or -1). If dir = -1, the
direction of the scrollbar moves are reversed with respect to mouse
clicks. This function is useful to deal with the tricky behaviour of the
standard libraries Xaw, Xaw3d, Xaw95 (Libsx can be linked with any of
these). Actually Xaw3d, Xaw95 behave differently of Xaw with respect to
the action of mouse clicks on scrollbars, and the SetScrollbarDirection()
function can then be used to adjust that behaviour according to the needs.
<p>
SEE ALSO:
<a href="scrollbar.html#fSSS"> SetScrollbarStep() </a>,
|