Page 1 of 1

PB_2DDrawing_XOr

Posted: Wed Dec 10, 2014 12:27 am
by mestnyi
it is bug? with PB_2DDrawing_XOr not changes
does not change the color of the pen

Code: Select all

Procedure DrawSelector( Window,MouseX,MouseY,State,Pen =3,PenColor =$E2B256 ) 
  Static .i lastX, lastY, MoveMouseX, MoveMouseY
  Protected hDC
  If State 
    hDC = StartDrawing(WindowOutput(Window))
    If hDC
     DrawingMode(#PB_2DDrawing_Outlined|#PB_2DDrawing_XOr)
     
      Box(lastX, lastY, MoveMouseX-lastX, MoveMouseY-lastY,PenColor)
      lastX = MouseX :MoveMouseX = WindowMouseX(Window)
      lastY = MouseY :MoveMouseY = WindowMouseY(Window) 
      Box( lastX, lastY, MoveMouseX-lastX, MoveMouseY-lastY,PenColor)
      
      StopDrawing()
      Delay(50)
      ProcedureReturn State
    EndIf
  EndIf
EndProcedure

CompilerIf #PB_Compiler_IsMainFile
 If OpenWindow(1,0,0,750,500,"Rectangle Selection Demo",#PB_Window_ScreenCentered | #PB_Window_SystemMenu)
   Repeat 
      Select WaitWindowEvent()
        Case #PB_Event_CloseWindow
          Break
        Case #WM_LBUTTONDOWN :active=1
          Define  mx = WindowMouseX(1)
          Define  my = WindowMouseY(1)
        Case #WM_MOUSEMOVE :DrawSelector(1,mx,my,active)
        Case #WM_LBUTTONUP :active =0
      EndSelect
    ForEver
  EndIf
CompilerEndIf
And with SetROP2_(hdc, #R2_NOTXORPEN) changes

Code: Select all

Procedure DrawSelector( Window,MouseX,MouseY,State,Pen =3,PenColor =$E2B256 ) 
  Static .i lastX, lastY, MoveMouseX, MoveMouseY
  Protected hDC
  If State 
    hDC = StartDrawing(WindowOutput(Window))
    If hDC
     DrawingMode(#PB_2DDrawing_Outlined) :SetROP2_(hdc, #R2_NOTXORPEN)
      
      Box(lastX, lastY, MoveMouseX-lastX, MoveMouseY-lastY,PenColor)
      lastX = MouseX :MoveMouseX = WindowMouseX(Window)
      lastY = MouseY :MoveMouseY = WindowMouseY(Window) 
      Box( lastX, lastY, MoveMouseX-lastX, MoveMouseY-lastY,PenColor)
      
      StopDrawing()
      Delay(50)
      ProcedureReturn State
    EndIf
  EndIf
EndProcedure

CompilerIf #PB_Compiler_IsMainFile
 If OpenWindow(1,0,0,750,500,"Rectangle Selection Demo",#PB_Window_ScreenCentered | #PB_Window_SystemMenu)
   Repeat 
      Select WaitWindowEvent()
        Case #PB_Event_CloseWindow
          Break
        Case #WM_LBUTTONDOWN :active=1
          Define  mx = WindowMouseX(1)
          Define  my = WindowMouseY(1)
        Case #WM_MOUSEMOVE :DrawSelector(1,mx,my,active)
        Case #WM_LBUTTONUP :active =0
      EndSelect
    ForEver
  EndIf
CompilerEndIf

Re: PB_2DDrawing_XOr

Posted: Wed Dec 10, 2014 8:38 am
by netmaestro
I don't think there's good news to be had here with WindowOutput(). If you use a canvas or image as output you'll have the full power of the 2d drawing library available. Afaik #PB_2DDrawing_Xor has always given black output on the Windows OS. May I ask why you're drawing directly to the window? (it's relatively unusual for most types of project)

Re: PB_2DDrawing_XOr

Posted: Wed Dec 10, 2014 9:41 am
by mestnyi
May I ask why you're drawing directly to the window?
Write designer for purebasik like sharpdevelop
built very very not easy

Re: PB_2DDrawing_XOr

Posted: Wed Dec 10, 2014 9:46 am
by netmaestro
I thought as much. Switch to a canvas for a designer, it's the best tool for the job.

Re: PB_2DDrawing_XOr

Posted: Wed Dec 10, 2014 10:03 am
by mestnyi
Switch to a canvas for a designer, it's the best tool for the job.
This is a very bad look :)
I say looking at the built-purebasik
in my project much has been implemented :)

Re: PB_2DDrawing_XOr

Posted: Wed Dec 10, 2014 10:42 am
by Fred
CanvasGadget() is the way to go, it's what we use in the built-in PureBasic form designer

Re: PB_2DDrawing_XOr

Posted: Thu Dec 11, 2014 6:59 am
by mestnyi

Re: PB_2DDrawing_XOr

Posted: Thu Dec 11, 2014 10:09 am
by Olliv
mh?

you have exactly the same picture on the screen on canvasoutput than on naked windowoutput.

draw is automatically retraced on canvas. not on window...

keyboard and mouse events control are native and crossplatform on canvas.

on this detail canvasgadget and openglgadget are compatible, what it allows you to migrate your events work from canvas to opengl view, and add accelerated components.

Re: PB_2DDrawing_XOr

Posted: Thu Dec 11, 2014 5:42 pm
by BasicallyPure
mestnyi wrote:And what about my question?
It does seem a bit peculiar.

The value of PenColor has no effect on the rectangle color.
A little experimentation makes it more obvious what is going on.

Changing the window color seems to be the only thing that changes
the rectangle color. The color always seems to be the complementary
color of the window color, as if it was always XORed with $FFFFFF and
not the PenColor. Removing the #PB_2DDrawing_Outlined from the
drawing mode makes this easier to see.

Re: PB_2DDrawing_XOr

Posted: Thu Dec 11, 2014 8:35 pm
by mestnyi
In Linux, my first example works fine, :)
turns out this is a bug in Windows :|
Correct please!!! the more so using winapi it works :wink:

Re: PB_2DDrawing_XOr

Posted: Sat Dec 13, 2014 11:47 am
by mestnyi
Here fixed a :D

Code: Select all

Procedure __DrawingMode(Mode)
  Protected hDC
  If Mode & #PB_2DDrawing_XOr
    StopDrawing()
    hDC = StartDrawing(WindowOutput(GetActiveWindow()))
    DrawingMode(#PB_2DDrawing_XOr!Mode)
    SetROP2_(hDC, #R2_NOTXORPEN)
  Else
    DrawingMode(Mode)
  EndIf  
EndProcedure

Macro DrawingMode(Mode)
  __DrawingMode(Mode)
EndMacro

Procedure DrawSelector( Window,MouseX,MouseY,State,Pen =3,PenColor =$0F5FF3 ) 
  Static .i lastX, lastY, MoveMouseX, MoveMouseY
  Protected hDC
  If State 
    CompilerIf #PB_Compiler_OS = #PB_OS_Windows :Delay(50) 
    CompilerElseIf #PB_Compiler_OS = #PB_OS_Linux :PenColor = ( ~PenColor ) & $FFFFFF 
    CompilerEndIf
    
    hDC = StartDrawing(WindowOutput(Window))
    If hDC
      DrawingMode(#PB_2DDrawing_Outlined|#PB_2DDrawing_XOr)
      
      Box(lastX, lastY, MoveMouseX-lastX, MoveMouseY-lastY,PenColor)
      lastX = MouseX :MoveMouseX = WindowMouseX(Window)
      lastY = MouseY :MoveMouseY = WindowMouseY(Window) 
      Box( lastX, lastY, MoveMouseX-lastX, MoveMouseY-lastY,PenColor)
      
      StopDrawing()
      ProcedureReturn State
    EndIf
  EndIf
EndProcedure

CompilerIf #PB_Compiler_IsMainFile
  If OpenWindow(1,0,0,750,500,"Rectangle Selection Demo",#PB_Window_ScreenCentered | #PB_Window_SystemMenu)
    Repeat 
      Select WaitWindowEvent()
        Case #PB_Event_CloseWindow
          Break
        Case #WM_LBUTTONDOWN :active=1
          Define  mx = WindowMouseX(1)
          Define  my = WindowMouseY(1)
        Case #WM_MOUSEMOVE :DrawSelector(1,mx,my,active)
        Case #WM_LBUTTONUP :active =0
      EndSelect
    ForEver
  EndIf
CompilerEndIf