PB_2DDrawing_XOr

Windows specific forum
mestnyi
Addict
Addict
Posts: 1105
Joined: Mon Nov 25, 2013 6:41 am

PB_2DDrawing_XOr

Post 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
User avatar
netmaestro
PureBasic Bullfrog
PureBasic Bullfrog
Posts: 8452
Joined: Wed Jul 06, 2005 5:42 am
Location: Fort Nelson, BC, Canada

Re: PB_2DDrawing_XOr

Post 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)
BERESHEIT
mestnyi
Addict
Addict
Posts: 1105
Joined: Mon Nov 25, 2013 6:41 am

Re: PB_2DDrawing_XOr

Post by mestnyi »

May I ask why you're drawing directly to the window?
Write designer for purebasik like sharpdevelop
built very very not easy
User avatar
netmaestro
PureBasic Bullfrog
PureBasic Bullfrog
Posts: 8452
Joined: Wed Jul 06, 2005 5:42 am
Location: Fort Nelson, BC, Canada

Re: PB_2DDrawing_XOr

Post by netmaestro »

I thought as much. Switch to a canvas for a designer, it's the best tool for the job.
BERESHEIT
mestnyi
Addict
Addict
Posts: 1105
Joined: Mon Nov 25, 2013 6:41 am

Re: PB_2DDrawing_XOr

Post 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 :)
Fred
Administrator
Administrator
Posts: 18361
Joined: Fri May 17, 2002 4:39 pm
Location: France
Contact:

Re: PB_2DDrawing_XOr

Post by Fred »

CanvasGadget() is the way to go, it's what we use in the built-in PureBasic form designer
mestnyi
Addict
Addict
Posts: 1105
Joined: Mon Nov 25, 2013 6:41 am

Re: PB_2DDrawing_XOr

Post by mestnyi »

User avatar
Olliv
Enthusiast
Enthusiast
Posts: 542
Joined: Tue Sep 22, 2009 10:41 pm

Re: PB_2DDrawing_XOr

Post 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.
User avatar
BasicallyPure
Enthusiast
Enthusiast
Posts: 539
Joined: Thu Mar 24, 2011 12:40 am
Location: Iowa, USA

Re: PB_2DDrawing_XOr

Post 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.
BasicallyPure
Until you know everything you know nothing, all you have is what you believe.
mestnyi
Addict
Addict
Posts: 1105
Joined: Mon Nov 25, 2013 6:41 am

Re: PB_2DDrawing_XOr

Post 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:
mestnyi
Addict
Addict
Posts: 1105
Joined: Mon Nov 25, 2013 6:41 am

Re: PB_2DDrawing_XOr

Post 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
Post Reply