home *** CD-ROM | disk | FTP | other *** search
/ GEMini Atari / GEMini_Atari_CD-ROM_Walnut_Creek_December_1993.iso / files / gnu / gmlibs23 / rcsfix_c < prev    next >
Encoding:
Text File  |  1993-07-30  |  7.5 KB  |  297 lines

  1. /*    RSCFIX.C    09/16/86        Ric Clayton    */
  2. /*    STCREATE.c    04/20/85        ATARI        */
  3. /*    RSCREATE.C    05/18/84 - 11/01/84    LKW        */
  4. /*    Fix something    12/10/84 - 12/10/84    Derek Mui    */
  5. /*    Fix the  size    12/17/84                */
  6. /*    For ST        04/20/85        Derek Mui    */
  7. /*    For code resident rsc 09/16/86        Ric Clayton    */
  8.  
  9. /*****************************************************************************\
  10. *    rcsfix.doc 
  11. *
  12. *  RSCFIX.C -- A resource fixer for code-resident resources.
  13. *  
  14. *  RSCFIX.C  contains  a set of routines to prepare  a  code-resident 
  15. *  resource  for use.   It was derived from STCREATE.C,  found in the 
  16. *  RSCREATE  folder  on  the Resource Disk supplied  with  the  Atari 
  17. *  Developer's Kit.
  18. *  
  19. *  The  routines are driven by a main routine,  rsc_fix(),  which you 
  20. *  call  during your program initialization to prepare the  resource.  
  21. *  The  routines perform 2 distinct functions on the  resource.   The 
  22. *  first is to change all the offsets,  generated by RSC,  to address 
  23. *  pointers.   The  second  function  is  to change  all  the  object 
  24. *  rectangle  coordinates  and  sizes  from  characters  to   pixels, 
  25. *  according to the current screen resolution.
  26. *  
  27. *  First  get  the download the file RSCFIX.C and put  it  with  your 
  28. *  header  files. (e.g.  on  the compiler disk with  ALCYON,  in  the 
  29. *  HEADERS  folder with Megamax,  in the INCLUDE folder with  Micro-C 
  30. *  Shell and Mark Williams C, etc.)
  31. *  
  32. *  Next,  create  the  C source file using RCS or RCS2.   To do this, 
  33. *  run  the RCS program,  Open your resource file,  select the Output 
  34. *  option  from the Global menu,  select '.H' and '.C' ('.C' & '.RSH' 
  35. *  for RCS2),  click on OK,  and Close your resource.   Put the these 
  36. *  files with your source file(s).
  37. *  
  38. *  Then,  modify  your source file to include the resource's C source 
  39. *  and header files and 'RSCFIX.C'.   Change your call to rsrc_load() 
  40. *  to  rsc_fix().   Change  your call to rsrc_gaddr to load the  tree 
  41. *  pointer from the rs_trindex[] array.
  42. *  
  43. *  Limitations:   The  'adj' macro takes care of objects that are not 
  44. *  character  aligned but seems to have trouble when the root  object 
  45. *  of a tree is NOT character aligned.   Just make sure all your root 
  46. *  objects  are  character  aligned  and  you  should  not  have  any 
  47. *  problems.
  48. *  
  49. *  The following code fragment illustrates the use of rsc_fix().
  50. *  
  51. *  #include <obdefs.h>
  52. *  #include <gemdefs.h>
  53. *  .
  54. *  .
  55. *  .
  56. *  #ifndef BYTE                  / Take care of 'portability' / 
  57. *  #define BYTE char             / macros in the '.RSH' file. /
  58. *  #define WORD int
  59. *  #define LONG long
  60. *  #endif
  61. *  
  62. *  #include "resource.h"         / The header file from RSC   /
  63. *  #include "resource.rsh"       / The C source file from RSC /
  64. *  
  65. *  OBJECT *tree;                 / Pointer to an object tree  /
  66. *  .
  67. *  .
  68. *  / global declarations /
  69. *  .
  70. *  .
  71. *  #include <rscfix.c>           / Code to fixup resource     /
  72. *  
  73. *  void    sort(v,n)
  74. *  char    *v[];
  75. *  int     n;
  76. *          {
  77. *          .
  78. *          .
  79. *          }
  80. *  .
  81. *  .
  82. *  .
  83. *  void    do_form( rsc_tree, exit_obj )
  84. *  int     rsc_tree;
  85. *  int     exit_obj;
  86. *          {
  87. *          int     xdial, ydial, wdial, hdial;
  88. *          int     x, y, w, h;
  89. *          int     object;
  90. *  
  91. *          tree = (OBJECT *) rs_trindex[ rsc_tree ];
  92. *  
  93. *          form_center( tree, &xdial, &ydial, &wdial, &hdial );
  94. *          x = xdial + wdial/2;
  95. *          y = ydial + hdial/2;
  96. *          w = gl_wbox;
  97. *          h = gl_hbox;
  98. *          form_dial( 0, x, y, w, h, xdial, ydial, wdial, hdial );
  99. *          form_dial( 1, x, y, w, h, xdial, ydial, wdial, hdial );
  100. *  
  101. *          objc_draw( tree, ROOT, MAX_DEPTH, xdial, ydial, wdial, hdial );
  102. *  
  103. *          object = 0;
  104. *  
  105. *          while( object != exit_obj )
  106. *                  {
  107. *                  object = form_do( tree, 0 ) & 0x7FFF;
  108. *                  handle_object( tree, object );
  109. *                  .
  110. *                  .
  111. *                  .
  112. *                  }
  113. *  
  114. *          form_dial( 2, x, y, w, h, xdial, ydial, wdial, hdial );
  115. *          form_dial( 3, x, y, w, h, xdial, ydial, wdial, hdial );
  116. *          }
  117. *  
  118. *  main()
  119. *          {
  120. *          if ( appl_init() >= 0 )
  121. *                  {
  122. *                  rsc_fix();
  123. *                  .
  124. *                  .
  125. *                  graf_mouse( M_ON, 0x0L );
  126. *                  graf_mouse( ARROW, 0x0L );
  127. *                  do_form( TREE0, OKBUTTON );
  128. *                  .
  129. *                  .
  130. *                  appl_exit();
  131. *                  }
  132. *          }
  133. *  
  134. \*****************************************************************************/
  135.  
  136. /* rcsfix.c */
  137. #include <aesbind.h>
  138. #include <gemfast.h>
  139.  
  140. #ifndef BYTE                    /* Take care of 'portability' */ 
  141. typedef char           BYTE;     /* macros in the '.RSH' file. */
  142. typedef short         WORD;    /* i absolutely refuse to use */
  143. typedef unsigned long LONG;       /* silly includes like portab.h */
  144. #define NIL            (-1L)
  145. #endif
  146.  
  147. #include "fastbenh.h"         /* The header file from RSC   */
  148. #include "fastbenh.rsh"       /* The C source file from RSC */
  149.  
  150. #define adj(xywh, siz) \
  151.     (siz * ((xywh) & 0x00FF) + (((unsigned short)(xywh)) >> 8))
  152.  
  153. static void fix_trindex()
  154. {
  155.     int    test, ii;
  156.     
  157.     for (ii = 0; ii < NUM_TREE; ii++)
  158.     {
  159.     test = (int) rs_trindex[ii];
  160.     rs_trindex[ii] = (LONG) &rs_object[test];
  161.     }
  162. }
  163.  
  164. static void fix_str(where)
  165. long    *where;
  166. {
  167.     if (*where != NIL)
  168.     *where = (long) rs_strings[*where];
  169. }
  170.  
  171. static void fix_objects()
  172. {
  173.     int     ii;
  174.     long test;
  175.     int    wchar, hchar;
  176.     
  177.     graf_handle( &wchar, &hchar, &ii, &ii );
  178.     
  179.     for (ii = 0; ii < NUM_OBS; ii++)
  180.     {
  181.     rs_object[ii].ob_x = adj(rs_object[ii].ob_x, wchar);
  182.     rs_object[ii].ob_y = adj(rs_object[ii].ob_y, hchar);
  183.     rs_object[ii].ob_width = adj(rs_object[ii].ob_width, wchar);
  184.     rs_object[ii].ob_height = adj(rs_object[ii].ob_height, hchar);
  185.     test = (long) rs_object[ii].ob_spec;
  186.     
  187.     switch (rs_object[ii].ob_type)
  188.     {
  189.       case G_TITLE:
  190.       case G_STRING:
  191.       case G_BUTTON:
  192.         fix_str(&rs_object[ii].ob_spec);
  193.         break;
  194.       case G_TEXT:
  195.       case G_BOXTEXT:
  196.       case G_FTEXT:
  197.       case G_FBOXTEXT:
  198.         if (test != NIL)
  199.         rs_object[ii].ob_spec =
  200.             (LONG) &rs_tedinfo[test];
  201.         break;
  202.       case G_ICON:
  203.         if (test != NIL)
  204.         rs_object[ii].ob_spec =
  205.             (LONG) &rs_iconblk[test];
  206.         break;
  207.       case G_IMAGE:
  208.         if (test != NIL)
  209.         rs_object[ii].ob_spec =
  210.             (LONG) &rs_bitblk[test];
  211.         break;
  212.         
  213.         default:
  214.         break;
  215.     } /* switch */
  216.     } /* for */
  217. }
  218.  
  219. static void fix_tedinfo()
  220. {
  221.     int    ii;
  222.     
  223.     for (ii = 0; ii < NUM_TI; ii++)
  224.     {
  225.     fix_str(&rs_tedinfo[ii].te_ptext);
  226.     fix_str(&rs_tedinfo[ii].te_ptmplt);
  227.     fix_str(&rs_tedinfo[ii].te_pvalid);
  228.     }
  229. }
  230.  
  231. static void fix_frstr()
  232. {
  233.     int    ii;
  234.     
  235.     for (ii = 0; ii < NUM_FRSTR; ii++)
  236.     fix_str(&rs_frstr[ii]);
  237. }
  238.  
  239. static void fix_img(where)
  240. long    *where;
  241. {
  242.     if (*where != NIL)
  243.     *where = (long) (char *) rs_imdope[(int) *where].image;
  244. }
  245.  
  246. static void fix_iconblk()
  247. {
  248.     int    ii;
  249.     
  250.     for (ii = 0; ii < NUM_IB; ii++)
  251.     {
  252.     fix_img(&rs_iconblk[ii].ib_pmask);
  253.     fix_img(&rs_iconblk[ii].ib_pdata);
  254.     fix_str(&rs_iconblk[ii].ib_ptext);
  255.     }
  256. }
  257.  
  258. static void fix_bitblk()
  259. {
  260.     int    ii;
  261.     
  262.     for (ii = 0; ii < NUM_BB; ii++)
  263.     fix_img(&rs_bitblk[ii].bi_pdata);
  264. }
  265.  
  266. static void fix_bb(where)
  267. long    *where;
  268. {
  269.     if (*where != NIL)
  270.     *where = (long) (char *) &rs_bitblk[(char) *where];
  271. }
  272.  
  273. static void fix_frimg()
  274. {
  275.     int    ii;
  276.     
  277.     for (ii = 0; ii < NUM_FRIMG; ii++)
  278.     fix_bb(&rs_frimg[ii]);
  279. }
  280.  
  281.  
  282. /* this is the only 'exported' function in
  283.  * this module.
  284.  */
  285. void rsc_fix()
  286. {
  287.     fix_trindex();
  288.     fix_objects();
  289.     fix_tedinfo();
  290.     fix_iconblk();
  291.     fix_bitblk();
  292.     fix_frstr();
  293.     fix_frimg();
  294. }
  295.  
  296. #undef adj
  297.