Introduction !DrWimpC Features DrWimpC library Examples


!Slider


The !Slider Example Illustrates ... Source Files and Functions Used

Automatic creation of the bar window.

Multiple draggable sliders with value icons in a window, both vertical and horizontal.

Use of the library functions drw_wimp_getsliderpcent and drw_wimp_putsliderpcent for displaying and updating a slider.

Simple implementation of nudger up and down buttons.

Use of a pop up menu for a window.

!Slider Overview.

Wimp Lib Actions

  • Mouse Click
  • Menu Selection
  • Sliders

Standard User Files.


.

Overview



!Slider has a single window that is opened when SELECT is clicked with the mouse pointer over the !Slider icon on the icon bar. The window is called main and is defined in the Templates file. The main window, info box and a standard bar menu (consisting of the three standard items of Info, Help and Quit) are loaded and created automatically.

The application opens a window loaded from a template file in the centre of the screen. The window consists of four draggable sliders, three horizontal and one vertical, each with a numeric value display which is adjusted when the slider is dragged. In addition, the vertical slider has up and down nudger buttons which when clicked on with the mouse adjust the numeric value of the slider up or down. The slider bar is redrawn to reflect the change in value.

Note that Sliders are more than the simple bar illustrated in the !bar which just displays a value. For a slider, its value can be set by a user interaction of either dragging the slider bar, or using nudger buttons to incerment or decrement the value, or your program can set its length by specifying a percentage value of the slider's total length.

A slider is interpreted in DrWimp and DrWimpC as being a vertical slider if its height exceeds it width, otherwise as a horizontal slider.

Sliders are constructed in a particular way, consisting of three icons - A bottom tiled icon (validation string R2). A slider back icon of full length of the slider, and the slider icon as a draggable front icon. The icons can be of any thickness, length and colour. The tiled icon is for enhancing the look of the display and is not used in calculating the length of the slider. The slider icon and slider back icon should be positioned in the window so that the slider back icon fits entirely behind the slider bar icon, and have a buttontype of Click/Drag and have no borders. They should also be filled.

Sliders can be of any length. The length of a slider is independent of the number value range it represents. This is achieved by representing the length of the slider bar as a percentage value of the full length of the slider back icon. In !Slider two number ranges are used for the horizontal sliders (0 - 100 and 0 - 255) to illustrate these properties.

[Top]

Application Data




int HUND;

This integer is used to keep track of the value range being used for the horizontal sliders. The range can be either 0 - 100 or 0 - 255.

Note: The range or the vertical slider is always 0 - 100.

[Back to the Function List]
[Top]


void sld_discard_trailingch(char *from, int c)


This function removes any characters matching the value of c from the end of a string, stopping at the first non matching character.

[Back to the Function List]
[Top]


void drw_uw_init(drw_uw_data *uwd)


This function carries out initialisation actions. The initial value range is 0 - 100, so HUND is set to TRUE.

Next, the pop up menu is created using the standard function drw_wimp_createmenu() to create the menu from an input string which consists of menu item names separated by a forward slash character. The first item in the string is the menu title. The returned pointer to the menu structure is conveniently stored in the user wimp data's main menu field.

Then, drw_wimp_getsliderpcent() is called to obtain the initial percentage value of the ratio of the length of each front slider icon to the length of its corresponding back icon. Each value will depend on how each slider is defined in the main window definition in the templates file. To maintain a consistent display of each value any trailing spaces are removed before setting the icon's text.

[Back to the Function List]
[Top]


void drw_u_mouseclick(wimp_w window, wimp_i icon, wimp_mouse_state button, int workx, int worky)


This function is called by the DrWimpC C library when a mouse click event is received for a window (and icon) belonging to your application, or your application's icon bar icon.

In !Slider this deals with the nudger buttons for the vertical slider. All that is required to implement the incremental nudger buttons is to test for the icon number being one of the nudger icons when the window is the main window, then take appropriate action. In this case the current percentage value of the vertical slider's length is obtained and incremented or decremented depending on which nudger button has been clicked. The function drw_wimp_putsliderpcent() is called to resize the slider for the new percentage length value, and the numeric display value is set to the new calculated value for the currently selected number range by calling drw_wimp_puticontext() for the relevant icon.

[Back to the Function List]
[Top]


wimp_i drw_u_slider(wimp_w window, wimp_i icon)

wimp_i drw_u_sliderback(wimp_w window, wimp_i icon)


To act on clicks and drag events for a slider the library needs to know which icons form a slider and slider back icon pair. These two functions are used together to provide that information.

[Back to the Function List]
[Top]


void drw_u_slidervalue(wimp_w window, wimp_i icon, double pcent, int dir)


This function is called during and at the end of a slider drag. The dir parameter indicates if the slider is a vertical slider (dir=1) or a horizontal slider (dir=0). The pcent value is the length of theslider as a percentage of the full length of the slider back icon. This example uses the pcent value to update its numeric values in the display according to the value range selected, indicated by the HUND value.

One point of note is the call to drw_wimp_bar when the slider has zero length (pcent=0). The BASIC version of this example remarks that this call is made "To help overcome some low end visual problems."

[Back to the Function List]
[Top]


wimp_menu *drw_u_menu(wimp_w window, wimp_i icon)


When the middle mouse button is pressed with the pointer is over a window belonging to your application, or your application's icon bar icon then the DrWimpC library prepares to open a menu and calls this function to request the menu structure for the menu to be opened. The window parameter indicates which window where the click occurs (window=-2 for the icon bar), and the icon indicates which icon the mouse pointer is over at the time of the menu click (or -1 for no icon).

In !Slider, only has a bar menu (pointed to by pwd->uwd->barmenu), and the pop up menu (pointed to by pwd->uwd->mainmenu) which is opened for a menu click in the main window.

If there is no menu to be opened return NULL.

[Back to the Function List]
[Top]


void sld_hundon(void)


sld_hundon() is called when the value range 0 - 100 is selected from the pop up menu in order to redisplay the numeric values for the horizontal sliders with the value in this range corresponding to the slider length. If this range is already selected there is nothing to do. HUND is set to TRUE.

[Back to the Function List]
[Top]


void sld_hundoff(void)


sld_hundoff() is called when the value range 0 - 100 is deselected and the alternative range of 0 - 255 is selected from the pop up menu in order to redisplay the numeric values for the horizontal sliders with the value in this range corresponding to the slider length. If the 0 - 255 range is already selected there is nothing to do. HUND is set to FALSE.

[Back to the Function List]
[Top]


void drw_u_menuselection(wimp_menu *menu, wimp_i item, char *font)


This function gets called when the DrWimpC library receives a menu selection event for a menu belonging to your application. (i.e. the user has chosen a menu item form a menu or submenu). The menu pointer points to the menu structure to which the chosen item belongs. item is the itm's index into the array of menu entries in the menu structure. Note that menu item numbers from the wimp start at 1, and the array will be indexed from 0. If the menu is a font menu then item is 0. The font parameter applies only to font menus when it will have a non NULL value.

The code in this function will contain a list of tests on the menu pointer to identify to which menu in your application the menu selection applies. It should always contain the test for the menu being the bar menu and the item equalling the item size - i.e. the last item on the bar menu which should be the application Quit item. Also, now standard is item 2 on the bar menu as the Help menu option that runs the help file supplied with your application. The standard code is to run the !Help file in your main application directory.

For !Slider, the only other menu is the pop up menu which allows the number range to be selected - 0 - 100 for item 1, and 0 - 255 for item 2, when sld_hundon() or sld_hundoff() is called.

[Back to the Function List]
[Top]