home *** CD-ROM | disk | FTP | other *** search
/ ARM Club 3 / TheARMClub_PDCD3.iso / hensa / programming / desklib / examples / DeskLib / Examples / !Slider / c / !RunImage next >
Encoding:
Text File  |  1995-05-14  |  4.3 KB  |  158 lines

  1. /*
  2.     ####             #    #     # #
  3.     #   #            #    #       #          The FreeWare C library for
  4.     #   #  ##   ###  #  # #     # ###             RISC OS machines
  5.     #   # #  # #     # #  #     # #  #   ___________________________________
  6.     #   # ####  ###  ##   #     # #  #
  7.     #   # #        # # #  #     # #  #    Please refer to the accompanying
  8.     ####   ### ####  #  # ##### # ###    documentation for conditions of use
  9.     ________________________________________________________________________
  10.  
  11.     File:    Slider !RunImage
  12.     Author:  Jason Williams (Hacked together from !IncDec)
  13.              Julian Smith - typedef-d slider_updateproc
  14.     Version: 1.01 (Apr 1995)
  15.     Purpose: Demonstrate Sliders
  16.  
  17. */
  18.  
  19. #include "DeskLib:Core.h"
  20. #include "DeskLib:Window.h"            /* Window handling automation      */
  21. #include "DeskLib:Error.h"             /* Error despatcher                */
  22. #include "DeskLib:Event.h"             /* Event despatcher                */
  23. #include "DeskLib:EventMsg.h"          /* Wimp Message event dispatcher   */
  24. #include "DeskLib:Handler.h"           /* Default/example event handlers  */
  25. #include "DeskLib:Icon.h"              /* Icon handling automation        */
  26. #include "DeskLib:Resource.h"          /* Handles finding resource files  */
  27. #include "DeskLib:Screen.h"            /* Getting screen size info, etc   */
  28. #include "DeskLib:Template.h"          /* Template loading and caching    */
  29.  
  30. #include "DeskLib:Slider.h"
  31.  
  32.  
  33.  
  34. static BOOL quit=       FALSE;
  35. static window_handle    window;
  36.  
  37. static slider_info MySliderInfo;
  38.  
  39. typedef int (*slider_updateproc)( void *, void *);
  40.  
  41. static BOOL ByeBye(event_pollblock *event,void *ref)
  42. {
  43.  Window_Delete(window);
  44.  quit=TRUE;
  45.  return TRUE;
  46. }
  47.  
  48.  
  49.  
  50. BOOL RedrawWindow(event_pollblock *event, void *reference)
  51. /*  Called to redraw our window. We don't have anything to draw
  52.  *  except the slider, which we do by calling Slider_Redraw
  53.  */
  54. {
  55.   window_redrawblock redraw;
  56.   BOOL more;
  57.  
  58.   redraw.window = event->data.openblock.window;
  59.   Wimp_RedrawWindow(&redraw, &more);
  60.  
  61.   while (more)
  62.   {
  63.     Slider_Redraw(&MySliderInfo, &redraw.cliprect);
  64.     Wimp_GetRectangle(&redraw, &more);
  65.   }
  66.  
  67.   return(TRUE);
  68. }
  69.  
  70.  
  71. int SliderHasBeenUpdated(slider_info *info, void *reference)
  72. /* Called whenever the slider is updated during a drag. This provides
  73.  * an active display as you drag.
  74.  */
  75. {
  76.   int currentval = Slider_ReadValue(info);
  77.  
  78.   Icon_SetInteger(window, 3, currentval);
  79.  
  80.   return(0);
  81. }
  82.  
  83.  
  84.  
  85. BOOL IconClicked(event_pollblock *event, void *reference)
  86. {
  87.   if (!event->data.mouse.button.data.menu)               /* Not a MENU click */
  88.   {
  89.     int newvalue, closed = FALSE;
  90.     if (Slider_Drag(&MySliderInfo, &closed, &newvalue, NULL) == NULL)
  91.     {
  92.       /*  If the drag was successful, and the window has not been closed
  93.        *  in the meantime, then show the end-of-drag value in the other
  94.        *  icon in the window.
  95.        */
  96.       if (!closed)
  97.         Icon_SetInteger(window, 4, newvalue);
  98.     }
  99.  
  100.     return(TRUE);
  101.   }
  102.  
  103.   return(FALSE);
  104. }
  105.  
  106.  
  107.  
  108.  
  109. int main(void)
  110. {
  111.  Resource_InitialisePath("Slider");
  112.  Event_Initialise("Slider Test");
  113.  EventMsg_Initialise();
  114.  
  115.  Screen_CacheModeInfo();
  116.  
  117.  EventMsg_Claim(message_MODECHANGE,event_ANY,Handler_ModeChange,NULL);
  118.  
  119.  Template_Initialise();
  120.  Template_LoadFile("Templates");
  121.  window=Window_Create("main",0);
  122.  
  123.  MySliderInfo.window = window;
  124.  MySliderInfo.icon   = 0;
  125.  MySliderInfo.value  = 300;
  126.  MySliderInfo.limits.min = 30;
  127.  MySliderInfo.limits.max = 976;
  128.  MySliderInfo.colour.foreground = 11;
  129.  MySliderInfo.colour.background = 0;
  130.  MySliderInfo.border.x = MySliderInfo.border.y = 12;
  131.  MySliderInfo.knob.spritearea = 0;
  132.  MySliderInfo.knob.sprite = 0;
  133.  MySliderInfo.flags.vertical = FALSE;
  134.  MySliderInfo.flags.rgb = FALSE;
  135.  MySliderInfo.flags.dragging = FALSE;
  136.  MySliderInfo.flags.clickstop = FALSE;
  137.  MySliderInfo.flags.reserved = 0;
  138.  MySliderInfo.update = (slider_updateproc) SliderHasBeenUpdated;
  139.  MySliderInfo.reference = NULL;
  140.  
  141.  Slider_SetValue(&MySliderInfo, 375, NULL, NULL);
  142.  
  143.  Icon_SetText(window, 3, "-");
  144.  Icon_SetText(window, 4, "-");
  145.  
  146.  Event_Claim(event_CLOSE,window,event_ANY,ByeBye,            NULL);
  147.  Event_Claim(event_OPEN, window,event_ANY,Handler_OpenWindow,NULL);
  148.  Event_Claim(event_REDRAW, window,event_ANY,RedrawWindow,NULL);
  149.  Event_Claim(event_CLICK, window,event_ANY,IconClicked,NULL);
  150.  
  151.  Window_Show(window,open_CENTERED);
  152.  
  153.  while (!quit)
  154.    Event_Poll();
  155.  
  156.  return FALSE;
  157. }
  158.