home *** CD-ROM | disk | FTP | other *** search
/ Acorn User 10 / AU_CD10.iso / Archived / Updates / Flash / writeflash / !MakeFlash / c / button < prev    next >
Text File  |  2000-04-23  |  3KB  |  100 lines

  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <string.h>
  4. //
  5. #include "proto.h"
  6. #include "bucket.h"
  7. #include "main.h"
  8. #include "flash.h"
  9. #include "matrix.h"
  10. #include "action.h"
  11. #include "button.h"
  12.  
  13.  
  14. static int button_write_record(BUTTONSTATE *state, int type);
  15.  
  16.  
  17.  
  18. int button_read(BUTTON *button) {
  19.  
  20.   return 1;
  21. }
  22.  
  23.  
  24. int button_write(BUTTON *button) {
  25.  
  26.   unsigned int i;
  27.   U32 ptr;
  28.  
  29.   if (button->upcount == 0)                                 return 1;
  30.  
  31.   if (flush_bucket())                                       return 1;
  32.   ptr = read_position(NULL);
  33.   if (write_ushort(0))                                      return 1;
  34.   if (write_ushort(button->id))                             return 1;
  35.  
  36.   for (i = 0; i < button->upcount; i++)
  37.     if (button_write_record(button->up+i, BUTTONSTATE_UP))  return 1;
  38.  
  39.   if (button->overcount == 0) {
  40.     if (button_write_record(button->up, BUTTONSTATE_OVER))  return 1;
  41.   } else {
  42.     for (i = 0; i < button->overcount; i++)
  43.       if (button_write_record(button->over+i, BUTTONSTATE_OVER))
  44.                                                             return 1;
  45.   }
  46.  
  47.   if (button->downcount == 0) {
  48.     if (button_write_record(button->up, BUTTONSTATE_DOWN))  return 1;
  49.   } else {
  50.     for (i = 0; i < button->downcount; i++)
  51.       if (button_write_record(button->down+i, BUTTONSTATE_DOWN))
  52.                                                             return 1;
  53.   }
  54.  
  55.   if (button->shapecount == 0) {
  56.     if (button_write_record(button->up, BUTTONSTATE_SHAPE))  return 1;
  57.   } else {
  58.     for (i = 0; i < button->shapecount; i++)
  59.       if (button_write_record(button->shape+i, BUTTONSTATE_SHAPE))
  60.                                                             return 1;
  61.   }
  62.  
  63.   if (write_ubyte(0))                                       return 1;
  64.  
  65.   if (button->actioncount)
  66.     if (action_write_list(button->actions, button->actioncount))
  67.                                                             return 1;
  68.   return update_record_header(stagDefineButton, ptr);
  69. }
  70.  
  71.  
  72. int button_create(BUTTON **button) {
  73.  
  74.   *button = malloc(sizeof(BUTTON));
  75.   if (!*button)                         return 1;
  76.   memset(button, 0, sizeof(BUTTON));
  77.  
  78.   return 1;
  79. }
  80.  
  81.  
  82. // -----------------------------------------------------------------
  83.  
  84. int button_write_record(BUTTONSTATE *state, int type) {
  85.  
  86.   U8 flags;
  87.  
  88.   flags = 0;
  89.   if (type == BUTTONSTATE_UP)           flags |= 1<<BUTTONSTATE_UP;
  90.   if (type == BUTTONSTATE_OVER)         flags |= 1<<BUTTONSTATE_OVER;
  91.   if (type == BUTTONSTATE_DOWN)         flags |= 1<<BUTTONSTATE_DOWN;
  92.   if (type == BUTTONSTATE_SHAPE)        flags |= 1<<BUTTONSTATE_SHAPE;
  93.   if (write_ubyte(flags))               return 1;
  94.   if (write_ushort(state->id))          return 1;
  95.   if (write_ushort(state->depth))       return 1;
  96.   if (matrix_write(&state->matrix))     return 1;
  97.  
  98.   return 0;
  99. }
  100.