home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Acorn User 10
/
AU_CD10.iso
/
Archived
/
Updates
/
Flash
/
writeflash
/
!MakeFlash
/
c
/
button
< prev
next >
Wrap
Text File
|
2000-04-23
|
3KB
|
100 lines
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
//
#include "proto.h"
#include "bucket.h"
#include "main.h"
#include "flash.h"
#include "matrix.h"
#include "action.h"
#include "button.h"
static int button_write_record(BUTTONSTATE *state, int type);
int button_read(BUTTON *button) {
return 1;
}
int button_write(BUTTON *button) {
unsigned int i;
U32 ptr;
if (button->upcount == 0) return 1;
if (flush_bucket()) return 1;
ptr = read_position(NULL);
if (write_ushort(0)) return 1;
if (write_ushort(button->id)) return 1;
for (i = 0; i < button->upcount; i++)
if (button_write_record(button->up+i, BUTTONSTATE_UP)) return 1;
if (button->overcount == 0) {
if (button_write_record(button->up, BUTTONSTATE_OVER)) return 1;
} else {
for (i = 0; i < button->overcount; i++)
if (button_write_record(button->over+i, BUTTONSTATE_OVER))
return 1;
}
if (button->downcount == 0) {
if (button_write_record(button->up, BUTTONSTATE_DOWN)) return 1;
} else {
for (i = 0; i < button->downcount; i++)
if (button_write_record(button->down+i, BUTTONSTATE_DOWN))
return 1;
}
if (button->shapecount == 0) {
if (button_write_record(button->up, BUTTONSTATE_SHAPE)) return 1;
} else {
for (i = 0; i < button->shapecount; i++)
if (button_write_record(button->shape+i, BUTTONSTATE_SHAPE))
return 1;
}
if (write_ubyte(0)) return 1;
if (button->actioncount)
if (action_write_list(button->actions, button->actioncount))
return 1;
return update_record_header(stagDefineButton, ptr);
}
int button_create(BUTTON **button) {
*button = malloc(sizeof(BUTTON));
if (!*button) return 1;
memset(button, 0, sizeof(BUTTON));
return 1;
}
// -----------------------------------------------------------------
int button_write_record(BUTTONSTATE *state, int type) {
U8 flags;
flags = 0;
if (type == BUTTONSTATE_UP) flags |= 1<<BUTTONSTATE_UP;
if (type == BUTTONSTATE_OVER) flags |= 1<<BUTTONSTATE_OVER;
if (type == BUTTONSTATE_DOWN) flags |= 1<<BUTTONSTATE_DOWN;
if (type == BUTTONSTATE_SHAPE) flags |= 1<<BUTTONSTATE_SHAPE;
if (write_ubyte(flags)) return 1;
if (write_ushort(state->id)) return 1;
if (write_ushort(state->depth)) return 1;
if (matrix_write(&state->matrix)) return 1;
return 0;
}