home *** CD-ROM | disk | FTP | other *** search
-
- #include <stdlib.h>
- #include <stdio.h>
- #include <string.h>
- #include <stdarg.h>
- #include "pca.h"
- #include "toolbox.h"
- #include "event.h"
- #include "wimplib.h"
- #include "gadgets.h"
- #include "window.h"
- #include "sprite.h"
- #include "ProgInfo.h"
- #include "wimp.h"
- #include "wimplib.h"
-
- #define WimpVersion 310
-
- static WimpPollBlock poll_block;
- static MessagesFD messages;
- static IdBlock id_block;
-
- int OtherTask=0,ThisTask;
-
- int handlers_attached=0;
-
- sprite_area * spblock;
-
- BOOL VALID=FALSE;
- char Display[255];
- char obname[100];
- tag * anch;
-
- typedef enum
- {
- red,
- green
- }operation;
-
-
- int change(int event_code, ToolboxEvent *event, IdBlock *id_block,void *handle);
- int quit_event(int event_code, ToolboxEvent *event, IdBlock *id_block,void *handle);
- int quit_message(WimpMessage *message,void *handle);
- int attach_handlers(int event_code,ToolboxEvent *event,IdBlock *id_block, void *handle);
- void werr(int fatal, char* format, ...);
- BOOL process(sprite_area *sp,sprite_ptr i,operation o,int value);
- void send_unhook(void);
- int close(int event_code, WimpPollBlock *event,IdBlock *id_block,void *v);
-
-
- /*
- * Event handler to be called when toolbox event 1
- * is generated (by click on the 'Quit' entry of
- * the iconbar menu.
- */
-
- int quit_event(int event_code, ToolboxEvent *event, IdBlock *id_block,void *handle)
- {
- event_code = event_code;
- event = event;
- id_block = id_block;
- handle = handle;
- send_unhook();
- exit(0);
- return(1);
- }
-
- int close(int event_code, WimpPollBlock *event,IdBlock *id_block,void *v)
- {
- static char * fred="No Picture";
- ObjectId Oid;
-
- Oid=(ObjectId)v;
-
- displayfield_set_value (0,Oid,1,fred);
- send_unhook();
- anch=NULL;
- VALID=FALSE;
- wimp_close_window((int*)event);
- return FALSE;
- }
-
-
-
-
- int change(int event_code, ToolboxEvent *event, IdBlock *id_block,void *handle)
- {
-
- char temp[8];
- int t;
- event = event;
- id_block = id_block;
- handle = handle;
-
-
- switch (event_code)
-
- {
- case Slider_ValueChanged:
- switch(id_block->self_component)
- {
-
-
- case 2:
-
- slider_get_value (0,id_block->self_id,id_block->self_component,&t);
- sprintf(temp,"%d",t );
- displayfield_set_value (0,id_block->self_id,6,temp);
- process((sprite_area *)(anch->base),(sprite_ptr)((int)anch->address+(int)anch->base) ,red,t);
-
-
- break;
-
- case 3:
- slider_get_value (0,id_block->self_id,id_block->self_component,&t);
- sprintf(temp,"%d",t );
- displayfield_set_value (0,id_block->self_id,7,temp);
- process((sprite_area *)(anch->base),(sprite_ptr)((int)anch->address+(int)anch->base) ,green,t);
-
- break;
-
- }
-
-
- break;
-
- }
-
-
-
- return(1);
- }
-
-
-
- /*
- * Message handler to be called on receipt of a
- * Quit or PreQuit message from the Wimp.
- */
-
-
- int quit_message(WimpMessage *message,void *handle)
- {
- message = message;
- handle = handle;
- send_unhook();
- exit(0);
- return(1);
- }
-
- int Info(WimpMessage *message,void *handle)
- {
- message->hdr.your_ref=message->hdr.my_ref;
- sprintf(message->data.bytes,"Alter red/green levels. editing '%s'",obname);
- message->hdr.size=64;
- wimp_send_message(17,message,message->hdr.sender,0,NULL);
-
- return(FALSE);
-
- }
-
- int WhosAbout_message(WimpMessage *message,void *handle)
-
- {
- imhere_block *e;
- handle=handle;
-
- e=(imhere_block *)message->data.words;
-
- if(e->flags!=0xff9 /* Actually a filetype*/) return(0);
- e->flags=(Flag_spritename | Flag_info);
- e->id=1;
- strcpy(e->menu,"Tool");
- strcpy(e->sprite,"!processor"); /* add sprite name */
- message->hdr.action_code=Message_ImHere;
- message->hdr.size=84;
- wimp_send_message(17,message,message->hdr.sender,0,NULL);
- return(FALSE);
- }
-
-
- void send_changed()
- {
- donemystuff_block *e;
- WimpMessage w;
-
- e=(donemystuff_block *)&w.data;
-
- w.hdr.size=64;
- w.hdr.action_code=Message_DoneMyStuff;
- w.hdr.sender=ThisTask;
- e->tagptr=anch;
-
- wimp_send_message (17,&w,0,0,NULL);
- }
-
- void send_unhook()
- {
- unhookme_block *e;
- WimpMessage w;
- if (OtherTask==0) return;
- e=(unhookme_block *)&w.data;
- w.hdr.size=64;
- w.hdr.action_code=Message_UnhookMe;
- w.hdr.sender=ThisTask;
- e->zero=0;
- e->reserved=0;
- e->handle=0;
- e->type=1;
- e->tagptr=anch;
- VALID=FALSE;
- wimp_send_message (17,&w, OtherTask,0,NULL);
- OtherTask=0;
- }
-
-
-
- int DoIt_message(WimpMessage *message,void *handle)
-
- {
- char *p;
- message_editblk *e;
-
- ObjectId Oid;
- Oid=(ObjectId)handle;
- e=(message_editblk *)message->data.words;
- anch=e->doyourstuff.tagptr;
-
-
- if (message->hdr.action_code==Message_DoYourStuff)
- {
- if (OtherTask!=message->hdr.sender)
- {
- send_unhook();
- OtherTask=message->hdr.sender;
- }
- p=e->doyourstuff.name;
- strcpy(obname,p);
- sprintf(Display,"Editing picture %s",obname);
- VALID=TRUE;
- }
- else
- {
-
- p=e->changed.newname;
- if (*p!=NULL)
- {
- strcpy(obname,p);
- sprintf(Display,"Editing picture %s",obname);
- }
- }
-
- if (VALID)
- {
- toolbox_show_object(0,Oid,0,NULL,NULL,NULL);
-
- if (p!=NULL) displayfield_set_value (0,Oid,1,Display);
-
- }
- return(FALSE);
-
- }
-
-
- int Invalid_message(WimpMessage *message,void *handle)
-
- {
- ObjectId Oid;
-
- message_editblk *e;
- _kernel_oserror * fault;
- static char * fred="No Picture";
-
-
- e=(message_editblk *)message->data.words;
-
- Oid=(ObjectId)handle;
-
-
- handle=handle;
-
- if(e->deselect.filetype!=0xff9) return(0);
-
- anch=NULL;
- VALID=FALSE;
- OtherTask=0;
- fault=displayfield_set_value (0,Oid,1,fred);
- if (fault!=NULL) werr(FALSE,fault->errmess);
- return(TRUE);
-
- }
-
-
-
-
- int main()
- {
- int toolbox_events = 0,
- wimp_messages = 0,
- event_code;
-
-
-
- /*
- * register ourselves with the Toolbox.
- */
-
- toolbox_initialise (0, WimpVersion, &wimp_messages, &toolbox_events, "<processor$Dir>",
- &messages, &id_block, 0, &ThisTask, 0);
-
-
- /*
- * initialise the event library.
- */
-
- event_initialise (&id_block);
-
- event_set_mask (1+256);
-
-
- /*
- * register handler for toolbox event 1,
- * which is generated by the 'Quit' option on the
- * iconbar menu. Also register message handlers
- * to quit properly when quit messages are
- * received from the wimp.
- */
-
- event_register_toolbox_handler(-1,1,quit_event,0);
- event_register_message_handler(Wimp_MQuit,quit_message,0);
- event_register_message_handler(Wimp_MPreQuit,quit_message,0);
-
-
- event_register_toolbox_handler(-1,Toolbox_ObjectAutoCreated,attach_handlers,NULL);
-
-
-
-
-
- spblock=NULL;
-
-
- /*
- * poll loop
- */
-
- while (TRUE)
- {
- event_poll (&event_code, &poll_block, 0);
- }
- }
-
-
-
- int attach_handlers(int event_code,ToolboxEvent *event,IdBlock *id_block, void *handle)
- {
- /* This function has been called as a result of an object being
- * auto-created. For this example that means our iconbar object
- * so we can now register all our other handlers for the rest
- * of our objects
- */
-
-
- ObjectClass obj_class;
-
-
- toolbox_get_object_class(0,id_block->self_id,&obj_class);
-
-
- switch(obj_class)
- {
- case Window_ObjectClass:
-
- if( handlers_attached==0)
- {
- event_register_toolbox_handler(id_block->self_id,Slider_ValueChanged,change,NULL);
- event_register_wimp_handler(-1,Wimp_ECloseWindow,close,(void*)id_block->self_id );
- event_register_message_handler(Message_WhosAbout,WhosAbout_message,(void*)id_block->self_id );
- event_register_message_handler(Message_DoYourStuff,DoIt_message,(void*)id_block->self_id );
- event_register_message_handler(Message_Changed,DoIt_message,(void*)id_block->self_id);
- event_register_message_handler(Message_Deselect,Invalid_message,(void*)id_block->self_id );
- event_register_message_handler(Message_Info,Info,(void*)id_block->self_id);
-
- }
- handlers_attached=1;
-
-
- break;
-
- case ProgInfo_ObjectClass:
-
- proginfo_set_version (0,id_block->self_id, "0.02 " __DATE__);
- break;
-
- }
-
-
- return 1;
- }
-
-
-
-
-
- void werr(int fatal, char* format, ...)
- {
- va_list va;
- _kernel_oserror e;
-
- e.errnum = 0;
- va_start(va, format);
- vsprintf(&e.errmess[0], format, va);
- va_end(va);
- wimp_report_error(&e, 0, "ReadMe",0,0,0);
- if (fatal) exit(1);
- }
-
-
- BOOL process(sprite_area *sp,sprite_ptr i,operation o,int value)
- {
- static int current[2]={0,0};
-
-
- int *image;
- int width,height,v_dpi,h_dpi,type;
- sprite_header* s_h;
-
- if (!VALID) return FALSE;
-
- s_h=(sprite_header*)i;
-
- s_h=(sprite_header*)i;
- width=s_h->width+1;
- height=s_h->height+1;
- type=(s_h->mode >> 27) & 0x1f;
- v_dpi=(s_h->mode >>14) & 0x1fff;
- h_dpi=(s_h->mode >>1) & 0x1fff;
- image=(int*) ((int)s_h+(int)s_h->image);
- switch (type)
- {
-
- case 6: break;
-
- default:
- werr(FALSE,"Unable to process sprites of type %d",type);
- return(FALSE);
- break;
- }
-
-
-
- switch(o)
- {
- int x,y,t;
- sprite_colour col;
- int r,g,b;
-
- case red:
-
- t=value-current[0];
- if(t==0) return(FALSE);
- for (x=0;x<width;x++)
- {
- for(y=0;y<height;y++)
- {
- col.colour=*image;
- r=col.colour & 0xff;
- g=(col.colour & 0xff00)>>8;
- b=(col.colour & 0xff0000)>>16;
-
- r+=t/4;
-
- r=(r & 255);
- g=(g % 256)<<8;
- b=(b % 256)<<16;
- col.colour=b | g | r;
-
-
- *image++=col.colour;
- }
- }
- current[0]=value;
- break;
- case green:
- t=value-current[1];
- if(t==0) return(FALSE);
-
- for (x=0;x<width;x++)
- {
- for(y=0;y<height;y++)
- {
-
- col.colour=*image;
- r=col.colour & 0xff;
- g=(col.colour & 0xff00)>>8;
- b=(col.colour & 0xff0000)>>16;
-
-
- g+=t/4;
-
- r=(r & 255);
- g=(g & 255)<<8;
- b=(b & 255)<<16;
- col.colour=b | g | r;
-
- *image++=col.colour;
-
-
- }
- }
-
- current[1]=value;
- break;
-
- }
-
- send_changed();
-
-
- return(TRUE);
- }
-
-
-
-