I'm being thick today!

Just starting out? Need help? Post your questions and find answers here.
srod
PureBasic Expert
PureBasic Expert
Posts: 10589
Joined: Wed Oct 29, 2003 4:35 pm
Location: Beyond the pale...

I'm being thick today!

Post 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?
I may look like a mule, but I'm not a complete ass.
ebs
Enthusiast
Enthusiast
Posts: 557
Joined: Fri Apr 25, 2003 11:08 pm

Post 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
Dare2
Moderator
Moderator
Posts: 3321
Joined: Sat Dec 27, 2003 3:55 am
Location: Great Southern Land

Post 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.
@}--`--,-- A rose by any other name ..
User avatar
netmaestro
PureBasic Bullfrog
PureBasic Bullfrog
Posts: 8451
Joined: Wed Jul 06, 2005 5:42 am
Location: Fort Nelson, BC, Canada

Post 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.
BERESHEIT
Dare2
Moderator
Moderator
Posts: 3321
Joined: Sat Dec 27, 2003 3:55 am
Location: Great Southern Land

Post 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)
@}--`--,-- A rose by any other name ..
srod
PureBasic Expert
PureBasic Expert
Posts: 10589
Joined: Wed Oct 29, 2003 4:35 pm
Location: Beyond the pale...

Post 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!
I may look like a mule, but I'm not a complete ass.
srod
PureBasic Expert
PureBasic Expert
Posts: 10589
Joined: Wed Oct 29, 2003 4:35 pm
Location: Beyond the pale...

Post 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:
I may look like a mule, but I'm not a complete ass.
User avatar
netmaestro
PureBasic Bullfrog
PureBasic Bullfrog
Posts: 8451
Joined: Wed Jul 06, 2005 5:42 am
Location: Fort Nelson, BC, Canada

Post by netmaestro »

maybe make a bug report?
BERESHEIT
Dare2
Moderator
Moderator
Posts: 3321
Joined: Sat Dec 27, 2003 3:55 am
Location: Great Southern Land

Post by Dare2 »

* gets out the insect killer .. Fred! *
@}--`--,-- A rose by any other name ..
srod
PureBasic Expert
PureBasic Expert
Posts: 10589
Joined: Wed Oct 29, 2003 4:35 pm
Location: Beyond the pale...

Post 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! :)
I may look like a mule, but I'm not a complete ass.
User avatar
netmaestro
PureBasic Bullfrog
PureBasic Bullfrog
Posts: 8451
Joined: Wed Jul 06, 2005 5:42 am
Location: Fort Nelson, BC, Canada

Post 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?
BERESHEIT
User avatar
Fangbeast
PureBasic Protozoa
PureBasic Protozoa
Posts: 4789
Joined: Fri Apr 25, 2003 3:08 pm
Location: Not Sydney!!! (Bad water, no goats)

Post 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!
Amateur Radio/VK3HAF, (D-STAR/DMR and more), Arduino, ESP32, Coding, Crochet
Dare2
Moderator
Moderator
Posts: 3321
Joined: Sat Dec 27, 2003 3:55 am
Location: Great Southern Land

Post 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.
@}--`--,-- A rose by any other name ..
srod
PureBasic Expert
PureBasic Expert
Posts: 10589
Joined: Wed Oct 29, 2003 4:35 pm
Location: Beyond the pale...

Post 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!
I may look like a mule, but I'm not a complete ass.
srod
PureBasic Expert
PureBasic Expert
Posts: 10589
Joined: Wed Oct 29, 2003 4:35 pm
Location: Beyond the pale...

Post 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.
I may look like a mule, but I'm not a complete ass.
Post Reply