Page 1 of 1

Adjustable Hole.......

Posted: Thu Feb 23, 2012 5:26 am
by IdeasVacuum
I have slapped together a simple Window that contains a transparent region. The region size is adjustable. The code works as required, the width of the transparent region is adjusted by dragging the Window width and the height of the region is adjusted via two splitter gadgets. However, it would be nice to be able to move the transparent region within the Window, and to have the currently opaque border semi-transparent. That I think would require a completely different approach (= better!) to what I have now:

Code: Select all

ExamineDesktops()

Enumeration
#WIN
#Image1
#Image2
#BorderTop
#TranspCv1
#TranspCv2
#BorderBtm
#BorderLh
#BorderRh
#SplitterTop
#SplitterBtm
EndEnumeration

Procedure ShowWin()
;-------------------

If OpenWindow(#WIN, 0, 0, 400, 200, "Adjustable Hole",#PB_Window_SystemMenu | #PB_Window_TitleBar | #PB_Window_MinimizeGadget | #PB_Window_SizeGadget | #PB_Window_Invisible | #PB_Window_ScreenCentered)

              SetWindowColor(#WIN,RGB(0,0,255))
              SetWindowLongPtr_(WindowID(#WIN),#GWL_EXSTYLE,#WS_EX_LAYERED | #WS_EX_TOPMOST)
                  SetWindowPos_(WindowID(#WIN),#HWND_TOPMOST,0, 0, 0, 0, #SWP_NOMOVE | #SWP_NOSIZE)

              SetLayeredWindowAttributes_(WindowID(#WIN),RGB(0,0,255),0,#LWA_COLORKEY)

                CanvasGadget(#BorderTop,    0,   0,   0, 0)
                CanvasGadget(#TranspCv1,    0,   0,   0, 0)
                CanvasGadget(#TranspCv2,    0,   0,   0, 0)
                CanvasGadget(#BorderBtm,    0,   0,   0, 0)
                CanvasGadget(#BorderLh,     0,   0,  10, 200)
                CanvasGadget(#BorderRh,   390,   0,  10, 200)
              SplitterGadget(#SplitterTop, 10,   0, 380,  98, #BorderTop,#TranspCv1)
              SplitterGadget(#SplitterBtm, 10, 104, 380,  98, #TranspCv2,#BorderBtm)

              PureRESIZE_SetGadgetResize(#BorderLh, 1, 1, 0, 1)
              PureRESIZE_SetGadgetResize(#BorderRh, 0, 1, 1, 1)
              PureRESIZE_SetGadgetResize(#SplitterTop, 1, 1, 1, 1)
              PureRESIZE_SetGadgetResize(#SplitterBtm, 1, 1, 1, 1)

              WindowBounds(#WIN, 30, 200, #PB_Ignore, 200) 

                HideWindow(#WIN,#False)
EndIf

EndProcedure


Procedure WaitForUser()
;----------------------

Repeat

    iEvent = WaitWindowEvent(1)

        StartDrawing(CanvasOutput(#TranspCv1))
           DrawingMode(#PB_2DDrawing_Default)
              FillArea(10,10,1,RGB(0,0,255))
           StopDrawing()

         StartDrawing(CanvasOutput(#TranspCv2))
             FillArea(10,10,1,RGB(0,0,255))
          StopDrawing()

        StartDrawing(CanvasOutput(#BorderTop))
             FillArea(10,10,1,RGB(185,185,185))
         StopDrawing()

        StartDrawing(CanvasOutput(#BorderBtm))
             FillArea(10,10,1,RGB(185,185,185))
         StopDrawing()

        StartDrawing(CanvasOutput(#BorderLh))
             FillArea(1,1,1,RGB(185,185,185))
         StopDrawing()

        StartDrawing(CanvasOutput(#BorderRh))
             FillArea(1,1,1,RGB(185,185,185))
         StopDrawing()

Until iEvent = #PB_Event_CloseWindow

EndProcedure

ShowWin()
WaitForUser()

End
Anyone have the know-how?

Note, the above code requires Gnozal's PureRESIZE lib. http://gnozal.ucoz.com/

Re: Adjustable Hole.......

Posted: Thu Feb 23, 2012 6:20 am
by c4s
Sorry I didn't fully understand what you mean but maybe this one helps: http://www.purebasic.fr/english/viewtop ... 12&t=45811

Re: Adjustable Hole.......

Posted: Thu Feb 23, 2012 11:35 am
by RASHAD
Hi IdeasVacuum
Quick and Dirty it needs some more work
But it is quit simple

Code: Select all

cur = LoadCursor_(0, #IDC_SIZEALL)

If OpenWindow(0, 0, 0, 700, 500, "Test", #PB_Window_SystemMenu|#PB_Window_ScreenCentered|#PB_Window_SizeGadget)
  SetWindowColor(0,$BDBDBF)
  SetWindowLongPtr_(WindowID(0),#GWL_EXSTYLE,#WS_EX_LAYERED)
  SetLayeredWindowAttributes_(WindowID(0),#Blue,0,#LWA_COLORKEY)
  StringGadget(1, 10, 10, 100, 100,"",#WS_SIZEBOX)
  StringGadget(2, -10, -10, 0, 0,"")
  SetGadgetColor(1,#PB_Gadget_BackColor,#Blue)
  SetClassLong_(GadgetID(1), #GCL_HCURSOR, cur)
  Repeat
    Select  WaitWindowEvent()
    
      Case #WM_CLOSE
        Quit = 1
        
      Case #WM_MOUSEMOVE      
        If GetActiveGadget() = 1
            ReleaseCapture_()
            SendMessage_(GadgetID(1), #WM_NCLBUTTONDOWN, #HTCAPTION, 0)
            MoveWindow_(GadgetID(1), GadgetX(1), GadgetY(1), GadgetWidth(1), GadgetHeight(1), 1)
            SetActiveGadget(2)
        EndIf
        
    EndSelect
  Until Quit = 1
EndIf
End
Edit : Window can be resized too

Re: Adjustable Hole.......

Posted: Thu Feb 23, 2012 1:42 pm
by IdeasVacuum
Hi Rashad

Thanks for that code, I can definitely work with it - cunning use of the second string gadget!

Re: Adjustable Hole.......

Posted: Thu Feb 23, 2012 1:51 pm
by IdeasVacuum
Hi c4s, not really what I was looking for yet a very interesting piece of code nonetheless and I can make use of border method I think.

Re: Adjustable Hole.......

Posted: Thu Feb 23, 2012 2:04 pm
by RASHAD
You are welcome
Another variation maybe it can be useful

Code: Select all

cur = LoadCursor_(0, #IDC_SIZEALL)

If OpenWindow(0, 0, 0, 700, 500, "Test", #PB_Window_SystemMenu|#PB_Window_ScreenCentered|#PB_Window_SizeGadget)
  SetWindowColor(0,$BDBDBF)
  SetWindowLongPtr_(WindowID(0),#GWL_EXSTYLE,#WS_EX_LAYERED)
  SetLayeredWindowAttributes_(WindowID(0),#Blue,0,#LWA_COLORKEY)  
  StringGadget(1, 10, 10, 100, 100,"")
  StringGadget(2, -10, -10, 0, 0,"")
  SetGadgetColor(1,#PB_Gadget_BackColor,#Blue)
  SetClassLong_(GadgetID(1), #GCL_HCURSOR, cur)
  ButtonGadget(3,16,16,40,25,"TEST")  
  SetWindowLongPtr_(GadgetID(1), #GWL_STYLE, GetWindowLongPtr_(GadgetID(1), #GWL_STYLE) | #WS_CLIPSIBLINGS)
  SetWindowPos_(GadgetID(1), #HWND_BOTTOM, -1, -1, -1, -1, #SWP_NOSIZE | #SWP_NOMOVE)

  Repeat
    Select  WaitWindowEvent()
    
      Case #PB_Event_Gadget
          Select EventGadget()
           Case 3 
              If GetWindowLongPtr_(GadgetID(1), #GWL_STYLE) & #WS_THICKFRAME
                  SetWindowLongPtr_(GadgetID(1), #GWL_STYLE, GetWindowLongPtr_(GadgetID(1), #GWL_STYLE)&~ #WS_THICKFRAME)
                  ResizeGadget(1,GadgetX(1), GadgetY(1),GadgetWidth(1)-2, GadgetHeight(1)-2)
              Else
                  SetWindowLongPtr_(GadgetID(1), #GWL_STYLE, GetWindowLongPtr_(GadgetID(1), #GWL_STYLE)|#WS_THICKFRAME)
                  ResizeGadget(1,GadgetX(1), GadgetY(1),GadgetWidth(1)-2, GadgetHeight(1)-2)
              EndIf 
          EndSelect
    
      Case #WM_CLOSE
        Quit = 1
        
       
      Case #WM_MOUSEMOVE      
        If GetActiveGadget() = 1
            ReleaseCapture_()
            SendMessage_(GadgetID(1), #WM_NCLBUTTONDOWN, #HTCAPTION, 0)
            MoveWindow_(GadgetID(1), GadgetX(1), GadgetY(1), GadgetWidth(1), GadgetHeight(1), 1)
            SetActiveGadget(2)
        EndIf
        
    EndSelect
  Until Quit = 1
EndIf
End

Re: Adjustable Hole.......

Posted: Thu Feb 23, 2012 5:22 pm
by IdeasVacuum
Hi Rashad, in the end, I have condensed your original code down to this:

Code: Select all

cur = LoadCursor_(0, #IDC_SIZEALL)

Enumeration
#Win
#Trans
EndEnumeration

If OpenWindow(#Win, 0, 0, 400, 200, "Hole",#PB_Window_SystemMenu | #PB_Window_TitleBar | #PB_Window_SizeGadget | #PB_Window_ScreenCentered)
 
                       SetWindowColor(#Win, RGB(185,185,185))
                    SetWindowLongPtr_(WindowID(#Win),#GWL_EXSTYLE,#WS_EX_LAYERED)
          SetLayeredWindowAttributes_(WindowID(#Win),RGB(0,0,255),0,#LWA_COLORKEY)
         
                         StringGadget(#Trans, 10, 50, 380, 50,"",#WS_THICKFRAME)
                       SetGadgetColor(#Trans,#PB_Gadget_BackColor,RGB(0,0,255))
                        SetClassLong_(GadgetID(#Trans), #GCL_HCURSOR, cur)

         Repeat
         
                StartDrawing(WindowOutput(#Win))
         
                              DrawingMode(#PB_2DDrawing_Outlined)
                                      Box(GadgetX(#Trans), GadgetY(#Trans), GadgetWidth(#Trans), GadgetHeight(#Trans),RGB(148,148,148))
                                         iX = GadgetX(#Trans)
                                         iY = GadgetY(#Trans)
                                         iW = GadgetWidth(#Trans)
                                         iH = GadgetHeight(#Trans)
                             
                                      For i = 1 To 6
                             
                                                  iX = iX + 1 : iY = iY + 1 : iW = iW - 2 : iH = iH - 2
                                              Box(iX, iY, iW, iH,RGB(148,148,148))
                                      Next i
                                 
                StopDrawing()
         
                Select WaitWindowEvent()
                
                       Case #WM_CLOSE : Quit = 1
                        
                       Case #WM_MOUSEMOVE
                       
                            If GetActiveGadget() = #Trans
                                      ;User dragged #Trans
                                      ReleaseCapture_()
                                         SendMessage_(GadgetID(#Trans), #WM_NCLBUTTONDOWN, #HTCAPTION, 0)
                
                            Else
                                      StickyWindow(#Win,#True)
                            EndIf
                   
                EndSelect
         
         Until Quit = 1

EndIf

End
I draw the rectangle because the gadget borders become easier to pick, especially if the gadget is to be dragged to a new position, and it looks better (in my view). I have also eliminated the 'dummy' string gadget :)

Re: Adjustable Hole.......

Posted: Thu Feb 23, 2012 5:30 pm
by RASHAD
Hi mate :D
You have a little problem
When you move the transparent area outside the window then back again
A redraw issue
Try to prevent that area from moving outside


EDIT: You deleted the dummy StringGadget but you did not solve it's action
Resize the Transparent area then try to resize the window

Re: Adjustable Hole.......

Posted: Thu Feb 23, 2012 6:49 pm
by IdeasVacuum
Hi Rashad

Now that's strange, I can't reproduce either of those issues :? I'm running on WinXP 32bit, have not tested Win7.

Re: Adjustable Hole.......

Posted: Thu Feb 23, 2012 7:12 pm
by RASHAD
I am on win 7
Did not test it with XP