home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Archive Magazine 1996
/
ARCHIVE_96.iso
/
discs
/
shareware
/
share_40
/
read
/
!Read
/
c
/
Read
< prev
next >
Wrap
Text File
|
1990-09-06
|
11KB
|
400 lines
/* Read IconBar handler
Tue,28 Aug 1990
Copyright C.T.Stretch 1990
*/
#include "readhdr.h"
#include "wkey.h"
#define UD read_ud()
int sw,sh,scw=22*32,sch=3200,lineoff;
int gx0,gy0,gx1,gy1,gxn=40,gyn=98;
int ch,cw,pw,qw,dw;
int spacebar,pixfact,wtfact,refact,befact,queryat;
int weight[CHARS],redge[CHARS],bedge[CHARS];
int cweight[CHARS],credge[CHARS],cbedge[CHARS],counts[CHARS];
int box[XMAX+1];
int disp,top,base;
int row,col;
BOOL learning=FALSE,skip;
int state=NOFONT,sprmem=0;
char *textarea,*countarea;
unsigned int *store,*fontarea;
sprite_area *area;
sprite_id scanspr={{0},sprite_id_addr};
menu barmenu,immenu,smenu,pmenu;
wimp_w image;
wimp_icon scanicon;
wimp_caretstr nocaret={0,-1,0,0,1<<25,0};
dbox db;
char icbuf[12]="font";
int ino;
char sfname[FNLEN+1],tfname[FNLEN+1],cfname[FNLEN+1],pfname[FNLEN+1];
char sfact[6]="0";
int xef,yef;
int rdfnt=0x666;
int dpci=4;
static void barclick(wimp_i i)
{
i=i;
}
void read_fred()
{ wimp_redrawstr r;
r.w=image;
wimpt_noerr(wimp_get_wind_state(image,(wimp_wstate*)&r));
r.box.x1+=r.scx-r.box.x0;
r.box.y0+=r.scy-r.box.y1;
r.box.x0=r.scx;
r.box.y1=r.scy;
wimpt_noerr(wimp_force_redraw(&r));
}
static void openup(int x,int y)
{ wimp_wstate state;
wimpt_noerr(wimp_get_wind_state(image,&state));
state.o.y+=y<<yef;state.o.x+=x<<xef;
wimpt_noerr(wimp_open_wind(&state.o));
}
static void saveit(char c)
{ switch(c)
{ case 1:saveas(SPRITE,sfname,0,spr_save,0,0,0);break;
case 2:saveas(TEXT ,tfname,0,text_save,0,0,0);break;
case 3:saveas(rdfnt,pfname,0,fnt_save,0,0,0);break;
case 4:saveas(rdfnt,cfname,0,fnt_save,0,0,(void*)1);break;
}
}
void read_set(int s)
{ int n,moff=2;
static char *sn[]={"","font","box","halt"};
for(n=3;n<8;n++) menu_setflags(immenu,n,0,0);
if(s!=state)
{ if(s>state)
{ if(state==NOFONT&&s>NOFONT) fnt_new();
if(state==NOBOX&&s>NOBOX) text_new();
if(s==HALT) state=HALT;
if(state>NOBOX&&s>HALT) { event_setmask(MASK1);state=s;}
}
else
{ if(state>HALT&&s<LEARN) event_setmask(MASK0);
if(state>NOBOX&&s<=NOBOX) text_lose();
if(state>NOFONT&&s<=NOFONT) fnt_lose();
state=s;
}
read_fred();
}
if(state>HALT) moff=1;
if(state!=HALT) menu_setflags(immenu,state+moff,1,0);
if(state<=HALT)
{ strcpy(icbuf,sn[state]);
wimpt_noerr(wimp_set_icon_state((wimp_w)-1,ino,0,0));
}
}
static void immenuproc(void *wh,char *h)
{ wh=wh;
switch(h[0])
{ case 1:proc_size();break;
case 2:if(h[2]) saveit(h[1]);break;
case 3:read_set(NOFONT);break;
case 4:read_set(NOBOX);break;
case 5:read_set((state==LEARN)?HALT:LEARN);break;
case 6:read_set((state==READ)?HALT:READ);break;
case 7:read_set((state==NONSTOP)?HALT:NONSTOP);break;
case 8:proc_proc(h);read_fred();break;
case 9:proc_adjust();break;
}
}
static void barmenuproc(void *wh,char *h)
{ dbox d;
wh=wh;
switch (h[0])
{ case 1:d=dbox_new("Info");
if(d)
{ dbox_setfield(d,4,"0.0, "__DATE__);
dbox_show(d);dbox_fillin(d);
dbox_dispose(&d);
}
break;
case 2:spr_scan();
break;
case 3:scan_size();break;
case 4:exit(0);
}
}
static void resize(int x,int y)
{ int n,dx,dy;
wimp_setcolour(11+3*16);
dx=(gx1-gx0)<<xef;
dy=(gy1-gy0)<<yef;
for(n=0;n<=gyn;n++)
{ bbc_move(x,y+(n*dy)/gyn);
bbc_drawby(dx,0);
}
for(n=0;n<=gxn;n++)
{ bbc_move(x+(n*dx)/gxn,y);
bbc_drawby(0,dy);
}
}
static void rebox(int x,int y)
{ int n,dx,dy;
wimp_setcolour(10+3*16);
dx=box[gxn]<<xef;
dy=(ch*gyn)<<yef;
for(n=0;n<=gyn;n++)
{ bbc_move(x,y-(ch*n<<yef));
bbc_drawby(dx,0);
}
for(n=0;n<=gxn;n++)
{ bbc_move(x+(box[n]<<xef),y);
bbc_drawby(0,-dy);
}
}
static void rechar(int x,int y)
{ wimp_setcolour(15+3*16);
bbc_move(x,y+(base<<yef));bbc_drawby(sw<<xef,0);
bbc_move(x,y+(top<<yef));bbc_drawby(sw<<xef,0);
bbc_move(x+((disp+box[col])<<xef),y+(base<<yef));
bbc_drawby(0,(top-base)<<yef);
bbc_move(x+((disp+box[col+1])<<xef),y+(base<<yef));
bbc_drawby(0,(top-base)<<yef);
}
static void redraw(wimp_redrawstr *r)
{ BOOL more;
int cy,bx,by,x,y;
r->w=image;
wimpt_noerr(wimp_redraw_wind(r,&more));
bx=r->box.x0-r->scx;x=bx+(gx0<<xef);
by=r->box.y1-r->scy;y=by+(gy0<<yef);cy=by+(gy1<<yef);
while(more)
{ wimpt_complain(wimp_ploticon(&scanicon));
switch(state)
{ case NOFONT:resize(x,y);break;
case NOBOX :rebox(x,cy);break;
default :rechar(bx,by);
}
wimp_get_rectangle(r,&more);
}
}
void read_ud()
{ BOOL more;
int cy,bx,by,x,y;
wimp_redrawstr r[1];
r->box.x0=0;r->box.x1=sw<<xef;
r->box.y0=0;r->box.y1=sh<<yef;
r->w=image;
wimpt_noerr(wimp_update_wind(r,&more));
bx=r->box.x0-r->scx;x=bx+(gx0<<xef);
by=r->box.y1-r->scy;y=by+(gy0<<yef);cy=by+(gy1<<yef);
while(more)
{ switch(state)
{ case NOFONT:resize(x,y);break;
case NOBOX :rebox(x,cy);break;
default :rechar(bx,by);
}
wimp_get_rectangle(r,&more);
}
}
static void mouse(wimp_mousestr *m)
{ int mx,my;
wimp_wstate st;
wimpt_noerr(wimp_get_wind_state(image,&st));
wimpt_noerr(wimp_set_caret_pos(&nocaret));
if(state>NOBOX) return;
UD;
mx=(m->x-st.o.box.x0+st.o.x)>>xef;
my=(m->y-st.o.box.y1+st.o.y)>>yef;
switch(m->bbits)
{ case wimp_BLEFT:if((mx<gx1&&my>gy0)||state==NOBOX) { gx0=mx;gy1=my;}
break;
case wimp_BRIGHT:if(state==NOBOX)break;
if(mx>gx0&&my<gy1) { gx1=mx;gy0=my;}
break;
}
UD;
}
static void keysize(int c)
{ switch(c)
{ case wkey_LEFT:if(gx0>0){UD;gx0--;UD;}break;
case wkey_RIGHT:if(gx0<gx1+1){UD;gx0++;UD;}break;
case wkey_UP:if(gy1<sh-1){UD;gy1++;UD;}break;
case wkey_DOWN:if(gy1>gy0+1){UD;gy1--;UD;}break;
case wkey_SLEFT:if(gx1>gx0+1){UD;gx1--;UD;}break;
case wkey_SRIGHT:if(gx1<sw-1){UD;gx1++;UD;}break;
case wkey_SUP:if(gy0<gy1-1){UD;gy0++;UD;}break;
case wkey_SDOWN:if(gy0>0){UD;gy0--;UD;}break;
default:wimpt_noerr(wimp_processkey(c));return;
}
}
static void keybox(int c)
{ switch(c)
{ case wkey_LEFT:if(gx0>0){UD;gx0--;UD;}break;
case wkey_RIGHT:if(gx0<sw-1){UD;gx0++;UD;}break;
case wkey_UP:if(gy1<sh-1){UD;gy1++;UD;}break;
case wkey_DOWN:if(gy1>0){UD;gy1--;UD;}break;
default:wimpt_noerr(wimp_processkey(c));return;
}
}
static void key(int c)
{ switch(c)
{ case wkey_CLEFT:openup(-sw,0);break;
case wkey_CRIGHT:openup(sw,0);break;
case wkey_CUP:openup(0,sh);break;
case wkey_CDOWN:openup(0,-sh);break;
default:switch(state)
{ case NOFONT:keysize(c);break;
case NOBOX:keybox(c);break;
default:wimpt_noerr(wimp_processkey(c));return;
}
}
}
static menu makebarmenu(void *n)
{ n=n;
menu_setflags(barmenu,2,0,!scan_check());
return barmenu;
}
static BOOL barhand(wimp_eventstr *e,void *v)
{ char *fn;
int ftype;
v=v;
switch(e->e)
{ case wimp_ESEND:case wimp_ESENDWANTACK:
switch(e->data.msg.hdr.action)
{ case wimp_MDATALOAD:ftype=xferrecv_checkinsert(&fn);
switch(ftype)
{ case SPRITE:spr_load(fn);break;
case TEXT:if(sprmem) text_load(fn);break;
default:if(ftype==rdfnt) fnt_load(fn);break;
}
break;
case wimp_MMODECHANGE:spr_mode();break;
}
break;
}
return FALSE;
}
static void handler(wimp_eventstr *e,void *w)
{ w=w;
switch(e->e)
{ case wimp_ENULL:locate_read();break;
case wimp_EREDRAW:redraw((wimp_redrawstr*)&(e->data.o));break;
case wimp_EOPEN:wimpt_noerr(wimp_open_wind(&(e->data.o)));break;
case wimp_EKEY:key(e->data.key.chcode);break;
case wimp_EBUT:mouse(&(e->data.but.m));break;
case wimp_ECLOSE:spr_lose();break;
case wimp_ESEND:case wimp_ESENDWANTACK:barhand(e,w);break;
}
}
static void mybaricon(void)
{ int bno;
wimp_icreate cr[1];
bno=baricon("!Read",1,barclick);
wimpt_noerr(wimp_delete_icon((wimp_w)-1,bno));
cr->w=(wimp_w)-1;
cr->i.box.x0=0;cr->i.box.x1=68;
cr->i.box.y0=-16;cr->i.box.y1=84;
cr->i.flags=wimp_ISPRITE|wimp_INDIRECT|(wimp_IBTYPE*wimp_BCLICKDEBOUNCE);
cr->i.flags|=wimp_ITEXT|(wimp_IFORECOL*7)|wimp_IFILLED|wimp_IHCENTRE;
cr->i.flags|=wimp_IBACKCOL;
cr->i.data.indirecttext.buffer=icbuf;
cr->i.data.indirecttext.validstring="S!read";
cr->i.data.indirecttext.bufflen=12;
wimpt_noerr(wimp_create_icon(cr,&ino));
wimpt_noerr(wimp_set_icon_state((wimp_w)-1,ino,0,0));
if(bno!=ino) werr(0,"Icon shift! old %d new %d",bno,ino);
}
static char *init(void)
{ wimp_wind *b;
wimpt_init("Read");
res_init("Read");
template_init();
dbox_init();
flex_init();
flex_alloc((flex_ptr)&area,0);
flex_alloc((flex_ptr)&fontarea,0);
flex_alloc((flex_ptr)&countarea,0);
flex_alloc((flex_ptr)&textarea,0);
if(!textarea) return "No memory";
db=dbox_new("char");
if(!db) return "char box";
barmenu=menu_new("Read",">Info,Scan,>Size,Quit");
if(!barmenu) return "barmenu";
mybaricon();
if(!event_attachmenumaker(win_ICONBAR,makebarmenu,barmenuproc,0))
return "barmenu proc";
win_register_event_handler(win_ICONBARLOAD,(win_event_handler)barhand,0);
b=template_syshandle("image");
if(!b) return "templates";
b->title.indirecttext.buffer=sfname;
b->title.indirecttext.bufflen=FNLEN+1;
if(wimp_create_wind(b,&image)) return "window";
win_register_event_handler(image,handler,0);
win_add_unknown_event_processor(barhand,0);
wimp_corrupt_fp_state_on_poll();
spr_mode();
win_claim_idle_events(image);
immenu=menu_new(
"Read",">Grid,Save,!New Font,New Box,Learn,Read,NonStop,Process,>Adjust");
smenu=menu_new("Save","~>Sprite,~>Text,~>Pixels,~>Counts");
menu_submenu(immenu,2,smenu);
pmenu=menu_new("Process","Invert|Rotate|Shear,sf,!Whole,Part");
menu_make_writeable(pmenu,4,sfact,6,"a0-9\\-");
menu_submenu(immenu,8,pmenu);
if(!immenu) return "menu";
if(!event_attachmenu(image,immenu,immenuproc,0)) return "menu proc";
nocaret.w=image;
scanicon.box.x0=0;scanicon.box.y0=0;
scanicon.flags=wimp_ISPRITE|wimp_INDIRECT;
scanicon.data.indirectsprite.nameisname=FALSE;
return 0;
}
static BOOL param(char *p)
{ int *pad;
if(p[0]!='-') return FALSE;
switch(p[1])
{ case 'f':pad=&rdfnt;break;
case 'w':pad=&scw;break;
case 'h':pad=&sch;break;
case 'x':pad=&gxn;break;
case 'y':pad=&gyn;break;
case 'p':pad=&dpci;break;
default:return FALSE;
}
*pad=atoi(p+2);
return TRUE;
}
int main(int n,char **p)
{ char *s;
int i;
for(i=1;i<n;i++) if(!param(p[i])){ printf("Bad parameters");return 0;}
s=init();
if(s)
{ werr(0,"Failed to initialise %s",s);
return 0;
}
for(;;) event_process();
return 0;
}