home *** CD-ROM | disk | FTP | other *** search
/ ARM Club 1 / ARM_CLUB_CD.iso / contents / apps / program / a / appmaker / !AppMaker / C_Source < prev    next >
Encoding:
Text File  |  1990-10-09  |  7.1 KB  |  322 lines

  1. #include "wimp.h"
  2. #include "wimpt.h"
  3. #include "win.h"
  4. #include "event.h"
  5. #include "baricon.h"
  6. #include "res.h"
  7. #include "resspr.h"
  8. #include "menu.h"
  9. #include "template.h"
  10. #include "dbox.h"
  11. #include "werr.h"
  12. #include "bbc.h"
  13. #include "os.h"
  14. #include "xfersend.h"
  15. #include "saveas.h"
  16. #include "colourmenu.h"
  17. #include "sprite.h"
  18.  
  19. #include <stdlib.h>
  20. #include <stdio.h>
  21. #include <string.h>
  22. #include <math.h>
  23.  
  24. #define icon_menu_INFO        1
  25. #define icon_menu_APPSIZE     2
  26. #define icon_menu_SPRITETEXT  3
  27. #define icon_menu_BORDERCOL   4
  28. #define icon_menu_BGNDCOL     5
  29. #define icon_menu_TEXTCOL     6
  30. #define icon_menu_CREATE      7
  31. #define icon_menu_QUIT        8
  32.  
  33. #define appsize_length 5
  34. #define spritetext_length 9
  35.  
  36. /******************************* GLOBAL DATA *******************************/
  37.  
  38. char appsize_buff[appsize_length];
  39. char spritetext_buff[spritetext_length];
  40.  
  41. char current_pathname[256] = "!App";
  42.  
  43. int appsize;
  44.  
  45. int bordercol = 11;
  46. int bgndcol = 8;
  47. int textcol = 9;
  48.  
  49. wimp_i baricon_handle;
  50.  
  51. menu icon_menu, appsize_menu, spritetext_menu, bordercol_menu, bgndcol_menu, textcol_menu;
  52.  
  53. /******************************** FUNCTIONS ********************************/
  54.  
  55. void null_proc(wimp_i icon)
  56. {
  57.   icon = icon;
  58. }
  59.  
  60. BOOL create_app(char *pathname, void *handle)
  61. {
  62. char buff[256], leafname[12];
  63. sprite_id sp;
  64. FILE *fp;
  65.  
  66.   handle = handle;                      /* dummy */
  67.  
  68.     /* find leafname, add ! if necessary */
  69.  
  70.   saveas_read_leafname_during_send(leafname, 12);
  71.   if (leafname[0] != '!')
  72.   {
  73.     int index = strlen(pathname)-strlen(leafname);
  74.  
  75.     pathname[index] = '!';
  76.     pathname[index+1] = '\0';
  77.     strcat(pathname, leafname);
  78.  
  79.     sprintf(buff, "!%s", leafname);
  80.     strcpy(leafname, buff);
  81.   }
  82.  
  83.     /* create application directory */
  84.  
  85.   sprintf(buff, "CDir %s", pathname);
  86.   if (wimpt_complain(os_cli(buff)) != 0)
  87.     return FALSE;
  88.  
  89.     /* generate !Sprites file */
  90.  
  91.   sp.tag = sprite_id_name;
  92.   sp.s.name = "file_000";
  93.  
  94.   if (wimpt_complain(sprite_rename(resspr_area(), &sp, leafname)) != 0)
  95.     return FALSE;
  96.   sp.s.name = leafname;
  97.  
  98.   sprintf(buff, "%s.!Sprites", pathname);
  99.   if (wimpt_complain(sprite_area_save(resspr_area(), buff)) != 0)
  100.     return FALSE;
  101.  
  102.   wimpt_noerr(sprite_rename(resspr_area(), &sp, "file_000"));
  103.  
  104.     /* generate !Run file */
  105.  
  106.   sprintf(buff, "%s.!Run", pathname);
  107.   fp = fopen(buff, "w");
  108.  
  109.   fprintf(fp, "Set %s$Dir <Obey$Dir>\012", leafname+1);
  110.   fprintf(fp, "IconSprites <Obey$Dir>.!Sprites\012");
  111.   fprintf(fp, "WimpSlot -min %dK -max %dK\012", appsize, appsize);
  112.   fprintf(fp, "Run <Obey$Dir>.!RunImage\012");
  113.  
  114.   if (fclose(fp) != 0)
  115.     return(FALSE);
  116.  
  117.   sprintf(buff, "SetType %s.!Run Obey", pathname);
  118.   if (wimpt_complain(os_cli(buff)) != 0)
  119.     return FALSE;
  120.  
  121.     /* update screen display */
  122.  
  123.   sprintf(buff, "IconSprites %s.!Sprites", pathname);
  124.   (void) os_cli(buff);
  125.   wimpt_forceredraw();
  126.  
  127.   strcpy(current_pathname, pathname);
  128.  
  129.   return TRUE;
  130. }
  131.  
  132. int text_val(char *p)
  133. {
  134. int val = 0;
  135.  
  136.   while((*p >= '0') && (*p <= '9'))
  137.   {
  138.     val = val * 10 + (*p - '0');
  139.     p++;
  140.   }
  141.  
  142.   return(val);
  143. }
  144.  
  145. void icon_draw(void)
  146. {
  147. int i;
  148.  
  149.     /* draw border */
  150.   bbc_gcol(0, bordercol);
  151.   bbc_rectanglefill(0, 0, 68, 68);
  152.  
  153.     /* draw background */
  154.   bbc_gcol(0, bgndcol);
  155.   bbc_rectanglefill(2, 4, 60, 56);
  156.  
  157.     /* add text */
  158.   bbc_gcol(0, textcol);
  159.   bbc_vdu(5);
  160.   bbc_move(2,60);
  161.   for (i = 0; i < 8; i++)
  162.   {
  163.     if (i == 4)
  164.       bbc_move(2,28);
  165.     bbc_vdu(spritetext_buff[i]);
  166.   }
  167. }
  168.  
  169. void icon_redraw(void)
  170. {
  171. sprite_id sp;
  172. sprite_state state;
  173.  
  174.   sp.tag = sprite_id_name;
  175.   sp.s.name = "file_000";
  176.  
  177.     /* update icon bar sprite */
  178.   wimpt_noerr(sprite_outputtosprite(resspr_area(), &sp, NULL, &state));
  179.   icon_draw();
  180.   wimpt_noerr(sprite_restorestate(state));
  181.   wimp_set_icon_state(win_ICONBAR, baricon_handle, 0, 0);
  182.  
  183.     /* update Wimp sprite (for 'saveas' dialogue box) */
  184.   wimpt_noerr(sprite_outputtosprite((sprite_area *) wimp_baseofsprites(), &sp, NULL, &state));
  185.   icon_draw();
  186.   wimpt_noerr(sprite_restorestate(state));
  187. }
  188.  
  189. void infobox(void)
  190. {
  191. dbox  d;
  192.  
  193.   if ((d = dbox_new("ProgInfo")) != NULL)
  194.   {
  195.     dbox_show(d);
  196.     dbox_fillin(d);
  197.     dbox_dispose(&d);
  198.   }
  199. }
  200.  
  201. void icon_menuproc(void *handle, char *hit)
  202. {
  203. wimp_mousestr m;
  204.  
  205.   handle = handle;
  206.  
  207.   switch (hit[0])
  208.   {
  209.   case icon_menu_INFO:
  210.     infobox();
  211.     break;
  212.  
  213.   case icon_menu_APPSIZE:
  214.     appsize = text_val(appsize_buff);
  215.     break;
  216.  
  217.   case icon_menu_SPRITETEXT:
  218.     icon_redraw();
  219.     break;
  220.  
  221.   case icon_menu_BORDERCOL:
  222.     menu_setflags(bordercol_menu, bordercol+1, 0, 0);
  223.     bordercol = hit[1] - 1;
  224.     menu_setflags(bordercol_menu, bordercol+1, 1, 0);
  225.     icon_redraw();
  226.     break;
  227.  
  228.   case icon_menu_BGNDCOL:
  229.     menu_setflags(bgndcol_menu, bgndcol+1, 0, 0);
  230.     bgndcol = hit[1] - 1;
  231.     menu_setflags(bgndcol_menu, bgndcol+1, 1, 0);
  232.     icon_redraw();
  233.     break;
  234.  
  235.   case icon_menu_TEXTCOL:
  236.     menu_setflags(textcol_menu, textcol+1, 0, 0);
  237.     textcol = hit[1] - 1;
  238.     menu_setflags(textcol_menu, textcol+1, 1, 0);
  239.     icon_redraw();
  240.     break;
  241.  
  242.   case icon_menu_CREATE:
  243.     wimpt_noerr(wimp_get_point_info(&m));
  244.     if (m.bbits && (wimp_BRIGHT + wimp_BLEFT) != 0)
  245.       create_app(current_pathname, (void *) 0);
  246.     else
  247.       saveas(0x000, current_pathname, 0, create_app, 0, 0, 0);
  248.     break;
  249.  
  250.   case icon_menu_QUIT:
  251.     exit(0);
  252.   }
  253. }
  254.  
  255. BOOL initialise(void)
  256. {
  257.   wimpt_init("AppMaker");
  258.   res_init("AppMaker");
  259.   resspr_init();
  260.   template_init();
  261.   dbox_init();
  262.  
  263.     /* top level menu */ 
  264.   if ((icon_menu = menu_new("AppMaker", ">Info, Program size| Sprite text, Border colour, Background colour, Text colour| >Create, Quit")) == NULL)
  265.     return FALSE;
  266.  
  267.    /* application size submenu */
  268.   if ((appsize_menu = menu_new("Size (K)", "A")) == NULL)
  269.     return FALSE;
  270.   menu_make_writeable(appsize_menu, 1, appsize_buff, appsize_length, "a0-9");
  271.   menu_submenu(icon_menu, icon_menu_APPSIZE, appsize_menu);
  272.   strcpy(appsize_buff, "32");
  273.   appsize_buff[2] = 13;
  274.   appsize = 32;
  275.  
  276.     /* sprite text submenu */
  277.   if ((spritetext_menu = menu_new("Sprite text", "A")) == NULL)
  278.     return FALSE;
  279.   menu_make_writeable(spritetext_menu, 1, spritetext_buff, spritetext_length, NULL);
  280.   menu_submenu(icon_menu, icon_menu_SPRITETEXT, spritetext_menu);
  281.   strcpy(spritetext_buff, "App Make");
  282.   spritetext_buff[8] = 13;
  283.  
  284.     /* border colour menu */
  285.   if ((bordercol_menu = colourmenu_make("Colour", FALSE)) == NULL)
  286.     return FALSE;
  287.   menu_setflags(bordercol_menu, bordercol+1, 1, 0);
  288.   menu_submenu(icon_menu, icon_menu_BORDERCOL, bordercol_menu);
  289.  
  290.     /* background colour menu */
  291.   if ((bgndcol_menu = colourmenu_make("Colour", FALSE)) == NULL)
  292.     return FALSE;
  293.   menu_setflags(bgndcol_menu, bgndcol+1, 1, 0);
  294.   menu_submenu(icon_menu, icon_menu_BGNDCOL, bgndcol_menu);
  295.  
  296.     /* text colour menu */
  297.   if ((textcol_menu = colourmenu_make("Colour", FALSE)) == NULL)
  298.     return FALSE;
  299.   menu_setflags(textcol_menu, textcol+1, 1, 0);
  300.   menu_submenu(icon_menu, icon_menu_TEXTCOL, textcol_menu);
  301.  
  302.   baricon_handle = baricon("file_000", (int) resspr_area(), null_proc);
  303.   if (!event_attachmenu(win_ICONBAR, icon_menu, icon_menuproc, 0))
  304.     return FALSE;
  305.   icon_redraw();
  306.  
  307.   return TRUE;
  308. }
  309.  
  310. /****************************** MAIN PROGRAM *******************************/
  311.  
  312. int main()
  313. {
  314.   if (!initialise())
  315.     return 1;
  316.  
  317.   while (TRUE)
  318.     event_process();
  319.  
  320.   return 0;
  321. }
  322.