home *** CD-ROM | disk | FTP | other *** search
/ ST-Computer Leser 2002 January / STC_CD_01_2002.iso / GAMES / BOINKO21 / SRC / SRC / EXTRAS.C < prev    next >
C/C++ Source or Header  |  2000-11-27  |  8KB  |  326 lines

  1. /*********************************************************
  2.  *                    EXTRAS.C                             *
  3.  *                    version 1.0                             *
  4.  *                                                         *
  5.  *  Dan Ackerman January, 2000                             *
  6.  *                                                         *
  7.  * Routines that don't fit properly elsewhere in code     *
  8.  * for iconification, getting AES version, and object     *
  9.  * manipulation.                                         *
  10.  *********************************************************/
  11.  
  12. #include <stdio.h>
  13. #include <string.h>
  14.  
  15. #include "boink.h"
  16.  
  17. /*  This identifies what AES you are running under 
  18.  *  based almost entirely on code by Ulf Ronald Anderson
  19.  */
  20.  
  21. int
  22. identify_AES(void)
  23. {    
  24.     void    *old_SSP;
  25.     long    search_id;
  26.     long    *search_p;
  27.     int        MiNT_flag = 0;
  28.     int        retv = AES_single;
  29.  
  30. #if OS_TOS
  31. /* cookie search is made in Super mode to access any RAM */
  32.  
  33.     old_SSP = (void *) Super(0L);
  34.     if ((search_p = *_cookies) == NULL)    goto exit_super;
  35.  
  36. search_loop:
  37.     search_id = *search_p;
  38.     if( search_id == 0L )    goto exit_super; /* search completed */
  39.     if( search_id == 0x4D674D63L  ||  search_id == 0x4D616758L ) retv = AES_MagiC;
  40.     if( search_id == 0x6E414553L ) retv = AES_nAES;
  41.     if( search_id == 0x476E7661L ) retv = AES_Geneva;
  42.     if( search_id == 0x4D694E54L ) MiNT_flag = 1;
  43.     search_p += 2;
  44.     goto    search_loop
  45. ;
  46. exit_super:
  47.     Super(old_SSP);
  48.  
  49.     if
  50.     (    retv == AES_single  &&  MiNT_flag
  51. #ifdef __GNUC__
  52.          && ( _global[1] > 1  ||  _global[1] <0 )
  53. #else
  54.           && ( _GemParBlk.global[1] > 1  ||  _GemParBlk.global[1] <0 )
  55. #endif
  56.     )
  57.         retv = AES_MTOS;
  58.  
  59. #endif /* OS_TOS */
  60.  
  61.     return( retv );
  62. }    /* Ends:    int identify_AES(void) */
  63.  
  64.  
  65. /* 
  66.  * Handle modifications for iconifying a window
  67.  */
  68. void
  69. iconify(int window_info, GRECT *new_size)
  70. {
  71.     win[window_info].status = 3; /* Iconified */
  72.                 
  73. #if OS_TOS
  74.     wind_set( win[window_info].handle, WF_ICONIFY, PTRS(new_size));
  75.     wind_set( win[window_info].handle, WF_NAME, win[window_info].title);
  76.     wind_get( win[window_info].handle, WF_WORKXYWH, ELTR(win[window_info].icon));
  77.  
  78.     /* Set icon's location for later redraws */
  79.  
  80.     win[window_info].icon_obj[ROOT].ob_x = win[window_info].icon.g_x;
  81.     win[window_info].icon_obj[ROOT].ob_y = win[window_info].icon.g_y;
  82.     win[window_info].icon_obj[ROOT].ob_width = win[window_info].icon.g_w;
  83.     win[window_info].icon_obj[ROOT].ob_height = win[window_info].icon.g_h;
  84.     win[window_info].icon_obj[ICON1].ob_x = (win[window_info].icon.g_w - win[window_info].icon_obj[ICON1].ob_width)/2;
  85.     win[window_info].icon_obj[ICON1].ob_y = (win[window_info].icon.g_h - win[window_info].icon_obj[ICON1].ob_height)/2;
  86. #endif /* OS_TOS */
  87. }
  88.  
  89. /*
  90.  * Handle modifications for uniconifying a window
  91.  */
  92. void
  93. un_iconify(int window_info,GRECT *new_size)
  94. {
  95.     win[window_info].status = 1;
  96.             
  97. #if OS_TOS
  98.     wind_set( win[window_info].handle, WF_UNICONIFY, PTRS(new_size));
  99.  
  100. /*    wind_get( win[window_info].handle, WF_WORKXYWH, &win[window_info].icon.g_x,&win[window_info].icon.g_y,&win[window_info].icon.g_w,&win[window_info].icon.g_h);
  101. */
  102.  
  103.     wind_get(win[window_info].handle, WF_CURRXYWH, ELTR(win[window_info].curr));
  104.              
  105. /*    wind_set( win[window_info].handle, WF_NAME, &win[window_info].title);*/
  106. #endif /* OS_TOS */
  107. }
  108.  
  109.  
  110. /*
  111.  * copy a string into a TEDINFO structure.
  112.  */
  113. void set_tedinfo(OBJECT *tree,int obj,char *source)
  114. {
  115.     char *dest;
  116.  
  117. #if OS_TOS    
  118.     dest=tree[obj].ob_spec.tedinfo->te_ptext;
  119. #else
  120.     dest=((TEDINFO *)tree[obj].ob_spec)->te_ptext;
  121. #endif
  122.     strcpy(dest,source);
  123. }
  124.  
  125. /*
  126.  * Get a string from a TEDINFO structure.
  127.  */
  128. void get_tedinfo(OBJECT *tree,int obj,char *dest)
  129. {
  130.     char *source;
  131.  
  132. #if OS_TOS    
  133.     source=tree[obj].ob_spec.tedinfo->te_ptext;
  134. #else
  135.     source=((TEDINFO *)tree[obj].ob_spec)->te_ptext;
  136. #endif
  137.     strcpy(dest,source);
  138. }
  139.  
  140. /*
  141.  * construct_path - build a GEMDOS path name out of a stem, which
  142.  * optionally has junk on the end which we must delete, and a filename
  143.  * which we are interested in.
  144. */
  145.  
  146. void
  147. construct_path(char *dest,const char *path,const char *name)
  148. {
  149.     char *s=NULL;        /* used to track the position after final \ or :*/
  150.  
  151.     if (path[0] && path[1]==':')
  152.         s=&dest[2];
  153.     while (*dest++=*path)
  154.         if (*path++=='\\')
  155.             s=dest;
  156.     if (!s)
  157.         s=dest;
  158.     strcpy(s,name);
  159. }
  160.  
  161. /* Set the text in an edit field */
  162. void
  163. set_edits(OBJECT *tree, int object,char *source)
  164. {
  165.     char *dest;
  166.     
  167.     dest = tree[object].ob_spec.tedinfo->te_ptext;
  168.  
  169.     strncpy(dest,source,tree[object].ob_spec.tedinfo->te_txtlen);
  170. }
  171.  
  172.  
  173. /* The heart of the paste routine */
  174.  
  175. void
  176. paste_text(int w_info)
  177. {
  178.     GRECT temp;
  179.     char scrap[128];
  180.     char scrap_name[128];
  181.     FILE *fp;
  182.     char line[500];
  183.                     
  184.     if (win[w_info].edit == 1)
  185.     {
  186.         wind_get(win[w_info].handle,WF_WORKXYWH,ELTR(temp));
  187.  
  188.         if(scrp_read((char *)scrap) == 0)
  189.             return;
  190.  
  191.         if (win[w_info].cur_item != -1)
  192.         {
  193.             construct_path(scrap_name,scrap,"SCRAP.TXT");
  194.             
  195.             if ((fp = fopen(scrap_name, "r")) > 0)
  196.             {
  197.                 fgets(line,500,fp);
  198.                 fclose(fp);
  199.  
  200.                 strcat(line,"\0");
  201.                                         
  202.                 objc_edit(win[w_info].window_obj, win[w_info].cur_item, 0, win[w_info].edit_pos, ED_END, &win[w_info].edit_pos);
  203.     
  204.                 set_edits(win[w_info].window_obj,win[w_info].cur_item,line);
  205.     
  206.                 objc_draw(win[w_info].window_obj,win[w_info].cur_item,7,ELTS(temp));
  207.  
  208.                 objc_edit(win[w_info].window_obj, win[w_info].cur_item, 0, win[w_info].edit_pos, ED_INIT, &win[w_info].edit_pos);
  209.             }
  210.         }
  211.     }
  212. }
  213.  
  214. void
  215. copy_paste(int w_info)
  216. {
  217.     char scrap[128];
  218.     char scrap_name[128];
  219.     GRECT p;
  220.     FILE   *pastefp;                  
  221.     char line[500];
  222.  
  223.     wind_get(win[w_info].handle,WF_WORKXYWH,ELTR(p));
  224.  
  225.     if(scrp_read((char *)scrap) == 0)
  226.         return;
  227.  
  228.     construct_path(scrap_name,scrap,"SCRAP.TXT");
  229.                     
  230.     if ((pastefp = fopen(scrap_name, "r")) > 0)
  231.     {
  232.         fclose(pastefp);
  233.         Fdelete(scrap_name);
  234.     }
  235.  
  236.     pastefp = fopen(scrap_name,"w");
  237.  
  238.     if (pastefp != NULL)
  239.     {
  240.         get_tedinfo(win[w_info].window_obj, win[w_info].cur_item,line);
  241.         
  242.         fwrite(line, sizeof(char), strlen(line), pastefp);
  243.  
  244.         fclose(pastefp);
  245.     }
  246.  
  247. }
  248.  
  249.  
  250. /* This sends a message to the main loop 
  251.  * We are just making certain that the app_id is set properly
  252.  */
  253.     
  254. int
  255. send_message(int msg[8])
  256. {
  257.     int newmsg[8];
  258.  
  259.     newmsg[0] = msg[0];
  260.     newmsg[1] = aes_id;    /* my apps id */
  261.     newmsg[2] = msg[2];
  262.     newmsg[3] = msg[3];   
  263.     newmsg[4] = msg[4];
  264.     newmsg[5] = msg[5];
  265.     newmsg[6] = msg[6];
  266.     newmsg[7] = msg[7];
  267.  
  268.     appl_write(msg[1], (int)sizeof(newmsg), newmsg);
  269.  
  270.     return(1);
  271. }
  272.  
  273. /* This sends a message to the main loop */
  274. int
  275. send_extmessage(int extapp, int msg0, int msg2, int msg3, int msg4, int msg5, int msg6, int msg7)
  276. {
  277.     int msg[8];
  278.  
  279.     msg[0] = msg0;
  280. #ifdef __GNUC__
  281.      msg[1] = _global[2];  /* my apps id */
  282. #else
  283.       msg[1] = _GemParBlk.global[2];  /* my apps id */
  284. #endif
  285.     msg[2] = msg2;
  286.     msg[3] = msg3;   
  287.     msg[4] = msg4;
  288.     msg[5] = msg5;
  289.     msg[6] = msg6;
  290.     msg[7] = msg7;
  291.  
  292.     appl_write(extapp, (int)sizeof(msg), msg);
  293.  
  294.     return(1);
  295. }
  296.  
  297. /* -------------------------------------------------------------------- */
  298. /*       boolean rc_intersect( GRECT *r1, GRECT *r2 );                  */
  299. /*                                                                      */
  300. /*       Calculate the intersecten of two rectangles.                   */
  301. /*                                                                      */
  302. /*       -> r1, r2       Pointer to the two rectangles structs.         */
  303. /*                                                                      */
  304. /*       <-              == 0  if the rectangles do not intersect       */
  305. /*                                                                      */
  306. /*                       != 0  if they intersect.                       */
  307. /* -------------------------------------------------------------------- */
  308. #if !GL_RCINTER
  309. int rc_intersect( GRECT *r1, GRECT *r2 )
  310. {
  311.    int x, y, w, h;
  312.  
  313.    x = max( r2->g_x, r1->g_x );
  314.    y = max( r2->g_y, r1->g_y );
  315.    w = min( r2->g_x + r2->g_w, r1->g_x + r1->g_w );
  316.    h = min( r2->g_y + r2->g_h, r1->g_y + r1->g_h );
  317.  
  318.    r2->g_x = x;
  319.    r2->g_y = y;
  320.    r2->g_w = w - x;
  321.    r2->g_h = h - y;
  322.  
  323.    return ( ((w > x) && (h > y) ) );
  324. }
  325. #endif
  326.