Viewmat for J 501 PocketPC.
Posted by Eric Iverson on J Forum general/2002-December/012182
Download viewmat_ppc501.ijs (rename to viewmat.ijs)
NB. built from project: source\classes\graphics\viewmat\viewmat
NB. viewmat init
script_z_ jsystempath 'system\main\gl2.ijs'
coclass 'jviewmat'
COCLASSPATH=: ;: 'jviewmat jgl2 z'
MINWH=: 200 200 NB. minimum initial child pixel size
NB. =========================================================
create=: vmrun
NB. =========================================================
destroy=: 3 : 0
wd 'pclose'
codestroy''
)
NB. ========================================================
NB.*viewmat v view matrix in isigraph control
NB.
NB. y. = [hue] mat [;title]] (as for viewbmp)
NB.
NB. mat may be one of:
NB. boolean (black/white)
NB. other numeric (color scale from 0 upwards)
NB. other (converted to numeric)
NB.
NB. hue is: 3 column table of R-G-B triples
NB. or: list of RGB values
NB.
NB. if mat is boolean, x. defaults to black/white
NB. otherwise hue defaults to red - purple spectrum
NB.
NB. e.g. viewmat (?50 50$2);'';'Random Boolean'
viewmat=: 3 : 0
'' viewmat y.
:
a=. conew 'jviewmat'
empty x. vmrun__a y.
)
NB. viewmat util
NB. y. = mat [;hue [;title]] (as for viewbmp)
NB.
NB. mat may be one of:
NB. boolean (black/white)
NB. other numeric (color scale from 0 upwards)
NB. other (converted to numeric)
NB.
NB. hue is: 3 column table of R-G-B triples
NB. or: list of RGB values
NB.
NB. if mat is boolean, hue defaults to black/white
NB. otherwise hue defaults to red - purple spectrum
NB.
NB. e.g. viewmat (?50 50$2);'';'Random Boolean'
finite=: x: ^: _1
NB. =========================================================
NB.*gethue v generate color from color set
NB. x. is color set
NB. y. is values from 0 to 1, selecting color
gethue=: 4 : 0
y=. y.*<:#x.
b=. x. {~ <.y
t=. x. {~ >.y
k=. y-<.y
(t*k)+b*-.k
)
NB. =========================================================
NB. getvm
getvm=: 4 : 0
hue=. x.
'mat tit'=. 2 {. boxopen y.
tit=. tit, (0=#tit) # 'viewmat'
if. 2 = #$hue do. hue=. 256#. hue end. NB. |."1 hue end.
if. (3!:0 mat) e. 2 32 do.
mat=. (, i. ]) mat
else.
mat=. x: inverse mat
end.
if. 2 > #$mat do. mat=. ,: , mat end.
if. */ (,mat) e. 0 1 do.
if. #hue do. h=. ({.,{:) hue
else. h=. 0, <: 256^3 end.
mat=. mat { <. h
else.
if. #hue do. h=. hue
else. h=. 256 #. 255 * #: 7|3^i.6 end.
mat=. <. h gethue mat % >./ , mat
end.
mat ; tit
)
NB. =========================================================
fitvm=: 4 : 0
'w h'=. x.
mat=. y.
'r c'=. $ mat
exp=. (- 0: , }:) <. 0.5 + +/\ r $ h % r
mat=. exp # mat
exp=. (- 0: , }:) <. 0.5 + +/\ c $ w % c
exp #"1 mat
)
NB. viewmat win
NB.! ebi 120 134 for pocketpc avoids a resize and repaint problem
NB. =========================================================
VM=: 0 : 0
pc vm;
xywh 0 0 120 134;cc g isigraph rightmove bottommove;
pas 0 0;pcenter;ptop;
rem form end;
)
NB. =========================================================
vmrun=: 4 : 0
'MAT TITLE'=: x. getvm y.
wd VM
wd 'pn *',TITLE
vm_show 0
wd 'pshow'
)
NB. =========================================================
NB. vm_show
NB. y. is 0 = initial setting
NB. 1 = resize
vm_show=: 3 : 0
NB. mat=. finite MAT
gwh=. _2 {. 0 ". wd 'qchildxywhx g'
NB. if. y.=0 do.
NB. mwh=. |.$mat
NB. mwh=. MINWH >. <. mwh * <./ gwh % |.$mat
NB. dif=. mwh - gwh
NB. wd 'setxywhx g 0 0 ',": mwh
NB. 'fx fy fw fh'=. 0 ". wd 'qformx'
NB. wd 'pmovex ',": 0 >. fx,fy,dif + fw,fh
NB. wdfit ''
NB. else.
NB. mwh=. gwh
NB. end.
glclear''
glwantresize''
glnoerasebkgnd 1
glmap MM_RAW
s=. $MAT
wh=. >.gwh%s
r=.wh,"1~ wh*"1 |."1 s#:i.*/s
t=. 5 2032,"1[ 256 256 256#:,MAT
t=. t,"1 [2 2004 4 2022 0 0 6 2031
11!:2999 [2 2036,~,t,.r
)
NB. =========================================================
vm_g_size=: vm_show bind 1
vm_cancel=: vm_close=: destroy
viewmat_z_=: viewmat_jviewmat_ 