r3wp [groups: 83 posts: 189283]
  • Home
  • Script library
  • AltME Archive
  • Mailing list
  • Articles Index
  • Site search
 

World: r3wp

[View] discuss view related issues

Brock
31-Oct-2006
[5938]
here's the program I am using this in...
Henrik
31-Oct-2006
[5939]
set color to none for the face
Brock
31-Oct-2006
[5940x2]
REBOL [
	Title: "REBOL Logo Maker"
	Purpose: "Generate a Hilight image"
	Author: ["Carl Sassenrath" "Gabriele Santilli"]
	Version: 1.0.0

 Rights: "REBOL logo is a registered trademark of REBOL Technologies, 
 USA."
]

debug?: false
hilight-colour: 255.0.0 ;0.112.99	;request-color
character: uppercase request-text
font-type: "font-sans-serif"
xthin-chars: charset "I!J"
thin-chars: charset "1234567890ABDEFPRSZ"
normal-chars: charset"CGHKLNOTUVXY"
wide-chars: charset "WMQ"
xwide-chars: charset ""
special-chars: charset "*"

if font-type = "font-serif"[
;get-char: func [character][

 if find character xthin-chars 	[if debug? [print "xthin"] char-offset: 
 8x2 char-size: 14]

 if find character thin-chars 	[if debug? [print "thin"] char-offset: 
 7x2 char-size: 14]

 if find character normal-chars	[if debug? [print "normal"] char-offset: 
 6x2 char-size: 14]

 if find character wide-chars	[if debug? [print "wide"] char-offset: 
 5x2 char-size: 14]

 if find character xwide-chars	[if debug? [print "xwide"] char-offset: 
 4x2 char-size: 14]

 if find character special-chars	[if debug? [print "special"] char-offset: 
 5x-2 char-size: 28]
;]
]
if font-type = "font-sans-serif"[
;get-char: func [character][

 if find character xthin-chars 	[if debug? [print "xthin"] char-offset: 
 9x2 char-size: 14]

 if find character thin-chars 	[if debug? [print "thin"] char-offset: 
 7x2 char-size: 14]

 if find character normal-chars	[if debug? [print "normal"] char-offset: 
 6x2 char-size: 14]

 if find character wide-chars	[if debug? [print "wide"] char-offset: 
 5x2 char-size: 14]

 if find character xwide-chars	[if debug? [print "xwide"] char-offset: 
 4x2 char-size: 14]

 if find character special-chars	[if debug? [print "special"] char-offset: 
 4x-2 char-size: 26]
;]
]



font-style: make face/font [style: 'bold  name: font-type  size: 
char-size]

hilights: [
	transform 0 1 1 0x0 0x0
	fill-pen snow pen snow
	circle 10x10 9
	fill-pen black pen black
	circle 13x13 9
	fill-pen hilight-colour	;0.112.99
	pen hilight-colour	;serve dark green - 0.112.99
	circle 11x11 9
	fill-pen white pen white
	font font-style
	text 1 char-offset character 
		;]
	;]
]



insert-event-func func [face evt][
	if evt/type = 'resize [
		bx/size: out/size: evt/offset
		bx/size/y: out/size/y: evt/offset/x / 23 * 23
		n: to-decimal bx/size/x / 23
		;t-x: to-decimal bx/size/x / 23 + 5
		;t-y: to-decimal bx/size/y / 23 - 2
;		probe highlights ;logo-shape
;		halt
		hilights/3: n
		hilights/4: n
		loc: to-pair :t-x :t-y
		show out
	]
	evt
]


view/options center-face out: layout [
	origin 0

 bx: box 23x23 green effect [draw hilights effect [key: green]][  
  ;logo-shape][	; 

  file: request-file/only/save/file join %hilight- [character ".png"]
		if not file [exit]
		if not find file ".png" [append file ".png"]
		save/png file to-image bx
	]
][resize]
this was Carl & Gabrielle's Rebol logo maker that I am repurposing.
Henrik
31-Oct-2006
[5942]
>> view layout [backdrop effect [gradient 0x1 black white] y: box 
"test"]
(escape)
>> y/color
== none
Brock
31-Oct-2006
[5943x2]
thanks Henrik, however, I still don't see any transparency saved.
view layout [
	bx: box "test" [
			file: request-file/only/save/file %sample.png
			if not file [exit]
			if not find file ".png" [append file ".png"]
			save/png file to-image bx
	]

]
Pekr
31-Oct-2006
[5945x3]
don't you need to use effect merge?
view layout [b1: box 100x100 red at b1/offset b2: box 50x50 green 
edge [size: 2x2 color: blue] effect [merge]]
uhm, sorry, that works too, while I thought it will not :-)

 view layout [b1: box 100x100 red at b1/offset b2: box 50x50  edge 
 [size: 2x2 color: blue] with [color: none]]
Henrik
31-Oct-2006
[5948]
effect merge is only used when merging DRAW results with the background, 
AFAIK
Pekr
31-Oct-2006
[5949x2]
not sure - there was some change between 2.1 and later View iirc, 
maybe merge was first needed, later it was not, or vice versa ...
ah, now I get it - if there is some effect involved, simply setting 
color to none would not work, it is needed to add merge to effect 
block ... it is well described in view-system doc
Brock
1-Nov-2006
[5951x8]
hmm, still unable to save out the transparent png file to maintain 
the transparent part in the png file.  I was able to produce an image 
with two coloured boxes and then one box was then made transparent, 
however when saving that image out, the background appears the default 
grey colour that is used when no colour is specified.
I'm missing something key here... can the background colour be made 
transparent?
view lay: layout[
	origin 0
	backdrop 255.0.0
	box green 30x30
	at 15x15 box blue 30x30 effect[merge]
]

save/png %sample.png to-image lay
presents an image with a red background, green box in upper left 
corner and the blue box is transparent in the lower right corner. 
 Save result shows red background image with green box.
adding effect [merge] to the backdrop now makes the backdrop transparent, 
however the save result shows the background in the default grey 
now instead of red.
removing the backdrop line altogether doesn't change the saved result 
from the step above.
adding   lay/color: none  after the definition of the layout block 
changes the saved result to now have a black background with the 
green box appearing inside in the top left corner.
changing the backdrop line to be   backdrop with [color: none]   
again saves out with the default grey background.
Rebolek
1-Nov-2006
[5959x2]
I;m not sure if PNG saver supports transparent color
Hm, seems I had different oppinion two years ago :) http://www.rebol.org/cgi-bin/cgiwrap/rebol/ml-display-thread.r?m=rmlHSHC
Cyphre
1-Nov-2006
[5961]
>> i: logo.gif
== make image! [100x24 #{
252525141414141414141414141414141414141414141414141414141414
14141414141414141414141414141414141414141414...
>> i/alpha: 128
== 128
>> save/png %test.png i
>>
Rebolek
1-Nov-2006
[5962]
Cyphre: This is is alpha channel, I think transparency means key 
color
Cyphre
1-Nov-2006
[5963x4]
IMO 'key color' is only alpha = 255 isn't it?
Maybe I don't know what exactly need?
what you exactly need
Ah, you mean the 'key color' in PNG format spec...then I think this 
cannot be controlled using the SAVE function IMO.
Henrik
1-Nov-2006
[5967]
rambo it?
Rebolek
1-Nov-2006
[5968]
it's not a bug, you can say 'missing feature' :)
Henrik
1-Nov-2006
[5969]
well, IMHO those also belong in RAMBO..
Rebolek
1-Nov-2006
[5970]
You need to manipulate tRNS chunk in PNG file. REBOL saves PNG files 
in color type 2 (true color) I think, so you must set tRNS chunk 
to RGB (2 bytes per color) value of color you want transparent. See 
http://www.faqs.org/rfcs/rfc2083.html
Cyphre
1-Nov-2006
[5971]
yes, you would need the tRNS chunk for that feature.
Brock
1-Nov-2006
[5972]
Out of my league, thanks for the responses.
Rebolek
1-Nov-2006
[5973]
Brock: or you can make mask image and set the areas you want transparent 
to alpha 255 and REBOL saves aplpha chanel
Brock
1-Nov-2006
[5974x2]
Rebolek, okay thanks, in theory I understand what needs to occure, 
but have no idea what this would look like in code.
If you are interested in possibly creating a sample, I'd love to 
see it.
Anton
1-Nov-2006
[5976]
Check out help.gif, it has an alpha channel, which survives after 
saving and loading.
	print mold help.gif/alpha
	save/png %image.png help.gif
	view layout [image (load %image.png)]

Now process the image, replacing a particular colour with transparent:
	img: copy help.gif
	colour: pick img 12x12

 repeat i length? img [if colour = pick img i [poke img i 0.0.0.255]]
	view layout [box red at 10x10 image (img)]
Maxim
1-Nov-2006
[5977]
but that alpha is only a one bit plane no?
Anton
1-Nov-2006
[5978]
No, 8-bit alpha. Observe:
	img: copy help.gif
	colour: pick img 12x12

 repeat i length? img [if colour = val: pick img i [val/4: mod i 256 
 poke img i val]]
	save/png %image.png img

 view layout [box 300x300 red at 20x20 image (load %image.png) (img/size 
 * 8)]
Maxim
1-Nov-2006
[5979x2]
that's really strange.   its possible that converting from bmp to 
png, RT realised the need to save the potential green mask.  so they 
probably store the image properly inside, but when creating one from 
scratch.. the channel is not.
and this leads me to... how in hell this you stumble accross this? 
 :-)
Anton
1-Nov-2006
[5981]
The image! datatype has an optional alpha channel. If it does not 
exist, it will be created when you set a pixel with alpha.
Maxim
1-Nov-2006
[5982]
ok, I read back a bit and I understand more the origin of the discussion. 
 I had assumed brock had an image with an alpha and was not able 
to save it out.  his real question basically... how do I CREATE the 
alpha channel from View gfx.

and you have answered that.

sorry for stickin my head in my ass, I should have read above.
Louis
1-Nov-2006
[5983]
Is there any way to disable the exit button in the upper right corner 
of a window (the button with the X in it) or else reprogram it to 
exit according to my own rebol code?
Maxim
1-Nov-2006
[5984]
the window's feel is different and accepts 'close events (in feel/detect).

it not very easy to deal with this because when you call 'view on 
a window, its feel is replaced automatically by view.  so you must 
explicitely replace the feel AFTER calling view on a layout or a 
face.


alternatively, you can also use an input even handler, which is probably 
a better solution:

this is one way to handle the close for all windows: 
   http://www.rebol.com/docs/view-system.html#section-5.13
Brock
2-Nov-2006
[5985x3]
Anton, great example... I was able to get this to work with a sample 
image that I created.  Thanks so much.
damn anti-aliasing!!  now I have fringing or a halo effect around 
my image due to anti-aliasing.  I'll see what I can do about this. 
 Thanks again.
(I'm trying to create custom rounded bullets)