Page 1 of 2

I'm being thick today!

Posted: Tue May 02, 2006 1:47 pm
by srod
Nothing new there! :D

Should the following, being drawn in Xor mode, not return the portion of the window being drawn on to it's original state?

Code: Select all

OpenWindow(0,0,0,640,480,"",#PB_Window_SystemMenu|#PB_Window_ScreenCentered) 

CreateImage(0,80,20) 
StartDrawing(ImageOutput(0)) 
  Box(0,0,80,20,#Green) 
StopDrawing() 

StartDrawing(WindowOutput(0)) 
  DrawingMode(#PB_2DDrawing_XOr)
  DrawImage(ImageID(0),10,10)
Delay(2000)
  DrawImage(ImageID(0),10,10)
StopDrawing() 

Repeat:Until WaitWindowEvent()=#PB_Event_CloseWindow 
What the smeg is going on here?

Posted: Tue May 02, 2006 2:16 pm
by ebs
srod,

I don't know about DrawImage(), but drawing directly on the window works as expected:

Code: Select all

OpenWindow(0,0,0,640,480,"",#PB_Window_SystemMenu|#PB_Window_ScreenCentered)

StartDrawing(WindowOutput(0))
DrawingMode(#PB_2DDrawing_XOr)
Box(10,10,80,20,#Green)
Delay(2000)
Box(10,10,80,20,#Green)
StopDrawing()

Repeat:Until WaitWindowEvent()=#PB_Event_CloseWindow 
Regards,
Eric

Posted: Tue May 02, 2006 2:18 pm
by Dare2
Not so sure on that (but what do I know?) :) Anyhow check this out:

Code: Select all

OpenWindow(0,0,0,640,480,"",#PB_Window_SystemMenu|#PB_Window_ScreenCentered)

StartDrawing(WindowOutput(0))
  Debug Hex(Point(2,2))
  DrawingMode(#PB_2DDrawing_XOr|#PB_2DDrawing_Transparent)
  Box(0,0,80,20,#Green)
StopDrawing()

Delay(1000)


StartDrawing(WindowOutput(0))
  Debug Hex(Point(2,2))
  DrawingMode(#PB_2DDrawing_XOr|#PB_2DDrawing_Transparent)
  Box(0,0,80,20,#Green)
StopDrawing()

Delay(1000)

StartDrawing(WindowOutput(0))
  Debug Hex(Point(2,2))
  DrawingMode(#PB_2DDrawing_XOr|#PB_2DDrawing_Transparent)
  Box(0,0,80,20,#Red)
StopDrawing()

Delay(1000)

StartDrawing(WindowOutput(0))
  Debug Hex(Point(2,2))
  DrawingMode(#PB_2DDrawing_XOr|#PB_2DDrawing_Transparent)
  Box(0,0,80,20,#Red)
StopDrawing()

Delay(1000)

StartDrawing(WindowOutput(0))
  Debug Hex(Point(2,2))
  DrawingMode(#PB_2DDrawing_XOr)
  Box(0,0,80,20,#Blue)

Delay(1000)

  Debug Hex(Point(2,2))
  DrawingMode(#PB_2DDrawing_XOr)
  Box(0,0,80,20,#Blue)
StopDrawing()

Delay(1000)

StartDrawing(WindowOutput(0))
  Debug Hex(Point(2,2))
  DrawingMode(#PB_2DDrawing_XOr)
  Box(0,0,80,20,$FFFFFF)

Delay(1000)

  Debug Hex(Point(2,2))
  DrawingMode(#PB_2DDrawing_XOr)
  Box(0,0,80,20,$FFFFFF)
StopDrawing()

Delay(1000)

StartDrawing(WindowOutput(0))
  Debug Hex(Point(2,2))
  DrawingMode(#PB_2DDrawing_XOr)
  Box(0,0,40,20,$000000)
  Box(40,0,40,20,$00FFFF)

Delay(1000)

  Debug Hex(Point(2,2))
  DrawingMode(#PB_2DDrawing_XOr)
  Box(0,0,40,20,$000000)
  Box(40,0,40,20,$00FFFF)
StopDrawing()

Repeat:Until WaitWindowEvent()=#PB_Event_CloseWindow
I get the same two end-result colours toggled, regardless. I expected some variation.


Edit: Started or-ing flags, hence the "transparent" bit up there, but it made no difference.

Posted: Tue May 02, 2006 2:29 pm
by netmaestro
srod wrote:What the smeg is going on here?
You're Xoring green with gray and getting the blackish color, then xoring green with black and getting the pink. It seems the expected behavior to me.

Posted: Tue May 02, 2006 2:39 pm
by Dare2
I thought Xor toggled bits when same root was applied?

Code: Select all

result = $D8E9EC 
apply = $00FF00

result = (result ! apply) : Debug Hex(result)
result = (result ! apply) : Debug Hex(result)
result = (result ! apply) : Debug Hex(result)
result = (result ! apply) : Debug Hex(result)

result = $AAAAAA
apply = $555555

result = (result ! apply) : Debug Hex(result)
result = (result ! apply) : Debug Hex(result)
result = (result ! apply) : Debug Hex(result)
result = (result ! apply) : Debug Hex(result)

result = $FFFFFF
apply = $080808

result = (result ! apply) : Debug Hex(result)
result = (result ! apply) : Debug Hex(result)
result = (result ! apply) : Debug Hex(result)
result = (result ! apply) : Debug Hex(result)

Posted: Tue May 02, 2006 2:44 pm
by srod
Thanks guys.

Netmaestro: it's definitely not correct as ebs' code shows. XOr ing twice should return us to our starting position; you can see this with some basic truth tables.

Ebs, yea thanks thats the expected result; but why not when we draw an image directly onto the window? Also, look what happens when I swicth green for black!

Code: Select all

OpenWindow(0,0,0,640,480,"",#PB_Window_SystemMenu|#PB_Window_ScreenCentered) 

StartDrawing(WindowOutput(0)) 
DrawingMode(#PB_2DDrawing_XOr) 
Box(10,10,80,20,#Black) 
Delay(2000) 
Box(10,10,80,20,#Black) 
StopDrawing() 

Repeat:Until WaitWindowEvent()=#PB_Event_CloseWindow 
Surely XOring black (=000000000...) etc. should leave the window untouced!

There's something weird going on here!

Posted: Tue May 02, 2006 2:47 pm
by srod
Sorry, dare I missed your first post. That just adds to the damn 'weirdness'!

I repeat, 'what the smeg is going on'??? :shock:

Posted: Tue May 02, 2006 2:48 pm
by netmaestro
maybe make a bug report?

Posted: Tue May 02, 2006 2:49 pm
by Dare2
* gets out the insect killer .. Fred! *

Posted: Tue May 02, 2006 2:52 pm
by srod
Yea, maybe. The only thing is that if this is a bug, I'd have thought someone would have reported this ages ago. It's more likely that I'm doing something daft!

I'll try using the API. If that works then I'll file a bug report, unless someone finds what I'm doing wrong first.

That caped crusader Sparkie will know! :)

Posted: Tue May 02, 2006 2:56 pm
by netmaestro
I've never drawn anything xored. As long as we're still in the questions forum, what's it used for mainly? Obviously you wanted to do something with it srod, what?

Posted: Tue May 02, 2006 2:57 pm
by Fangbeast
srod wrote:I repeat, 'what the smeg is going on'??? :shock:
Smeg?? There was a good smegging involved and I wasn't told????? Damn the inhumanity of some people!

Posted: Tue May 02, 2006 3:01 pm
by Dare2
lol.

@Netmaestro: My understanding is that it restores on second application. So you Xor and get wierdness (or strangely coloured things :)) then Xor with same thing again and get what you had to start with. But this is just MO.

Posted: Tue May 02, 2006 3:05 pm
by srod
netmaestro wrote:I've never drawn anything xored. As long as we're still in the questions forum, what's it used for mainly? Obviously you wanted to do something with it srod, what?
You can use it to superimpose images. I'm playing around with various forms of drag and drop right now, and having discovered what looks to be a bug in the common controls dll responsible for performing drag/drop (this bug seems to be discussed all over the web) I've decided to custom write a routine.

My first approach (after moving away from ImageList_BeginDrag_() etc.) was to simply Xor images.

If you Xor an image onto a window, then providing the image is not too complex, you'll see a kind of superimposed effect. To remove the effect and return the canvas to it's original form, you simply Xor the image once more in exactly the same position. In this way, the background is automatically restored etc.
It saves messing around with restoring the background manually - although this is looking to be my best bet right now!

Posted: Tue May 02, 2006 3:21 pm
by srod
Works with the API, even when drawing images to the window:

Code: Select all

OpenWindow(0,0,0,640,480,"",#PB_Window_SystemMenu|#PB_Window_ScreenCentered) 

CreateImage(0,80,30) 
StartDrawing(ImageOutput(0)) 
DrawText(0,0,"Test!")
StopDrawing() 

wdc=GetDC_(WindowID(0))
hdc=StartDrawing(ImageOutput(0)) 
  BitBlt_(wdc,0,0,80,30,hdc,0,0,#SRCINVERT) 
Delay(1000)
  BitBlt_(wdc,0,0,80,30,hdc,0,0,#SRCINVERT) 
  
StopDrawing() 

Repeat:Until WaitWindowEvent()=#PB_Event_CloseWindow 
:?

Think I'll post this in the bug forum.