It is currently Mon Oct 14, 2019 9:56 pm

All times are UTC + 1 hour




Post new topic Reply to topic  [ 8 posts ] 
Author Message
 Post subject: Windowed screen inside a ScrollArea Gadget?
PostPosted: Thu May 22, 2014 11:42 am 
Offline
Addict
Addict

Joined: Mon Apr 28, 2003 2:22 pm
Posts: 942
Location: Europe
Hello Forum.

I tried to place a WindowedScreen inside a ScrollArea-Gadget with larger dimensions as the visible part of the ScrollAreaGadget.
It seems that it is not possible to scroll the ScreenArea in this Gadget so, my question: Is it possible to change the offset on the ScrollAreaGadget ?

_________________
Tranquil


Top
 Profile  
Reply with quote  
 Post subject: Re: Windowed screen inside a ScrollArea Gadget?
PostPosted: Thu May 22, 2014 6:37 pm 
Offline
Addict
Addict
User avatar

Joined: Sat Apr 26, 2003 8:26 am
Posts: 2924
Location: Planet Earth
Code:
SetGadgetAttribute() with one of the following attribute:
  #PB_ScrollArea_X           : Changes the current horizontal scrolling position (in pixels).
  #PB_ScrollArea_Y           : Changes the current vertical scrolling position (in pixels).
:?:


Top
 Profile  
Reply with quote  
 Post subject: Re: Windowed screen inside a ScrollArea Gadget?
PostPosted: Thu May 22, 2014 9:01 pm 
Offline
Addict
Addict

Joined: Mon Apr 28, 2003 2:22 pm
Posts: 942
Location: Europe
Unfortunately, this does not change the offset of the windowed screen. Its offset is still at x:0 y:0.

_________________
Tranquil


Top
 Profile  
Reply with quote  
 Post subject: Re: Windowed screen inside a ScrollArea Gadget?
PostPosted: Thu May 22, 2014 10:25 pm 
Offline
PureBasic Expert
PureBasic Expert

Joined: Sun Apr 12, 2009 6:27 am
Posts: 3416
If you are a Windows user

Code:
InitSprite()

Procedure WndProc(hwnd, uMsg, wParam, lParam)
 result = #PB_ProcessPureBasicEvents

  Select uMsg
         
    Case #WM_HSCROLL
        Select wParam & $FFFF
          Case #SB_LINELEFT
               Result = GetScrollPos_(hwnd, #SB_HORZ)
               If Result >= 1
                  SetScrollPos_(hwnd, #SB_HORZ,Result-1,1)
                  ScrollWindowEx_(hwnd,1,0,0,0,0,0,#SW_ERASE| #SW_INVALIDATE|#SW_SCROLLCHILDREN)
                EndIf
     
          Case #SB_LINERIGHT
               Result = GetScrollPos_(hwnd, #SB_HORZ)
               If Result <= 999
                  SetScrollPos_(hwnd, #SB_HORZ,Result+1,1)                       
                  ScrollWindowEx_(hwnd,-1,0,0,0,0,0,#SW_ERASE| #SW_INVALIDATE|#SW_SCROLLCHILDREN)
               EndIf
               
          Case #SB_THUMBTRACK
               Result2 =GetScrollPos_(hwnd, #SB_HORZ)
               Result = (wParam >> 16 & $FFFF)
               If Result >= 0
                  SetScrollPos_(hwnd, #SB_HORZ,Result,1)
                  ScrollWindowEx_(hwnd,Result2-Result,0,0,0,0,0,#SW_ERASE|#SW_INVALIDATE| #SW_SCROLLCHILDREN)
               ElseIf Result <= 1000
                  SetScrollPos_(hwnd, #SB_HORZ,Result,1)
                  ScrollWindowEx_(hwnd,Result-Result2,0,0,0,0,0,#SW_ERASE|#SW_INVALIDATE| #SW_SCROLLCHILDREN)
               EndIf
        EndSelect
         
 
    Case #WM_VSCROLL,#WM_MOUSEWHEEL
        Select wParam & $FFFF       
          Case #SB_LINEUP
               Result = GetScrollPos_(hwnd, #SB_VERT)
               If wParam >> 16 & $FFFF <= 120 And Result >= 1
                  SetScrollPos_(hwnd, #SB_VERT,Result-1,1)
                  ScrollWindowEx_(hwnd,0,1,0,0,0,0,#SW_ERASE| #SW_INVALIDATE|#SW_SCROLLCHILDREN)
               ElseIf wParam >> 16 & $FFFF > 120 And Result <= 999
                  SetScrollPos_(hwnd, #SB_VERT,Result+1,1)
                  ScrollWindowEx_(hwnd,0,-1,0,0,0,0,#SW_ERASE| #SW_INVALIDATE|#SW_SCROLLCHILDREN)
               EndIf
;       
           Case #SB_LINEDOWN
               Result = GetScrollPos_(hwnd, #SB_VERT)
               If Result <= 999
                  SetScrollPos_(hwnd, #SB_VERT,Result+1,1)
                  ScrollWindowEx_(hwnd,0,-1,0,0,0,0,#SW_ERASE| #SW_INVALIDATE|#SW_SCROLLCHILDREN)
               EndIf
         
           Case #SB_THUMBTRACK
               Result2 =GetScrollPos_(hwnd, #SB_VERT)
               Result = (wParam >> 16 & $FFFF)
               If Result >= 0
                  SetScrollPos_(hwnd, #SB_VERT,Result,1)
                  ScrollWindowEx_(hwnd,0,Result2-Result,0,0,0,0,#SW_ERASE|#SW_INVALIDATE| #SW_SCROLLCHILDREN)
               ElseIf Result <= 1000
                  SetScrollPos_(hwnd, #SB_VERT,Result,1)
                  ScrollWindowEx_(hwnd,0,Result-Result2,0,0,0,0,#SW_ERASE|#SW_INVALIDATE| #SW_SCROLLCHILDREN)
               EndIf

        EndSelect
         
    Case #WM_KEYDOWN ,#WM_MENUSELECT
        Select wParam     
          Case #VK_LEFT
                Result = GetScrollPos_(hwnd, #SB_HORZ)
                If Result >= 1
                  SetScrollPos_(hwnd, #SB_HORZ,Result-1,1)
                  ScrollWindowEx_(hwnd,1,0,0,0,0,0,#SW_ERASE| #SW_INVALIDATE|#SW_SCROLLCHILDREN)
                EndIf
           
          Case #VK_RIGHT
                Result = GetScrollPos_(hwnd, #SB_HORZ)
                If Result <= 999
                  SetScrollPos_(hwnd, #SB_HORZ,Result+1,1)                       
                  ScrollWindowEx_(hwnd,-1,0,0,0,0,0,#SW_ERASE| #SW_INVALIDATE|#SW_SCROLLCHILDREN)
                EndIf
                         
          Case #VK_UP
                Result = GetScrollPos_(hwnd, #SB_VERT)
                If Result >= 1
                  SetScrollPos_(hwnd, #SB_VERT,Result-1,1)
                  ScrollWindowEx_(hwnd,0,1,0,0,0,0,#SW_ERASE| #SW_INVALIDATE|#SW_SCROLLCHILDREN)
                EndIf
             
          Case #VK_DOWN
                Result = GetScrollPos_(hwnd, #SB_VERT)
                If Result <= 999
                  SetScrollPos_(hwnd, #SB_VERT,Result+1,1)
                  ScrollWindowEx_(hwnd,0,-1,0,0,0,0,#SW_ERASE| #SW_INVALIDATE|#SW_SCROLLCHILDREN)
                EndIf
             
          Case #VK_PRIOR
                Result = GetScrollPos_(hwnd, #SB_VERT)
                If Result >= 1
                  SetScrollPos_(hwnd, #SB_VERT,Result-50,1)
                  ScrollWindowEx_(hwnd,0,50,0,0,0,0,#SW_ERASE| #SW_INVALIDATE|#SW_SCROLLCHILDREN)
                EndIf
             
          Case #VK_NEXT
                Result = GetScrollPos_(hwnd, #SB_VERT)
                If Result <= 999
                  SetScrollPos_(hwnd, #SB_VERT,Result+50,1)
                  ScrollWindowEx_(hwnd,0,-50,0,0,0,0,#SW_ERASE| #SW_INVALIDATE|#SW_SCROLLCHILDREN)
                EndIf
                 
        EndSelect

  EndSelect   
  ProcedureReturn result
EndProcedure

Min = 0
Max = 2000

OpenWindow(0,0,0,800,600,"Scroll Window Client Area",#PB_Window_SystemMenu| #WS_HSCROLL| #WS_VSCROLL| #PB_Window_ScreenCentered| #PB_Window_MaximizeGadget| #PB_Window_SizeGadget)
SetWindowColor(0,$000000)
SetScrollRange_(WindowID(0),#SB_VERT,Min,Max,1)
SetScrollRange_(WindowID(0),#SB_HORZ,Min,Max,1)
OpenWindowedScreen(WindowID(0),0,0,2000,2000)
  CreateSprite(0, 20, 20)
  If StartDrawing(SpriteOutput(0))
    Box(0, 0, 20, 20, RGB(255, 0, 155))
    Box(5, 5, 10, 10, RGB(155, 0, 255))
    StopDrawing()
  EndIf


SetWindowCallback(@WndProc())

  direction = 2
  Repeat
    ; It's very important to process all the events remaining in the queue at each frame
    ;
    Repeat
      Event = WindowEvent()
     
      Select Event
        Case #PB_Event_Gadget
          If EventGadget() = 0
            End
          EndIf
       
        Case #PB_Event_CloseWindow
          End
      EndSelect
    Until Event = 0
 
    FlipBuffers()
    ClearScreen(RGB(0, 0, 0))
    DisplaySprite(0, x, x)
    x + direction
    If x > 140 : direction = -2 : EndIf
    If x < 0   : direction =  2 : EndIf
    Delay(1)
  ForEver


_________________
Egypt my love


Top
 Profile  
Reply with quote  
 Post subject: Re: Windowed screen inside a ScrollArea Gadget?
PostPosted: Fri May 23, 2014 8:14 am 
Offline
Addict
Addict

Joined: Mon Apr 28, 2003 2:22 pm
Posts: 942
Location: Europe
Hey RASHAD!

This is exactly what I'm was searching for! THANK YOU VERY MUCH MATE!!
Never thought that it is that complex to just scroll the WindowedScreen.

Shouldn't this be handled by PB by default?

_________________
Tranquil


Top
 Profile  
Reply with quote  
 Post subject: Re: Windowed screen inside a ScrollArea Gadget?
PostPosted: Fri May 23, 2014 12:01 pm 
Offline
PureBasic Expert
PureBasic Expert

Joined: Sun Apr 12, 2009 6:27 am
Posts: 3416
Hi Tranquil
I just got a thought ,tried it and it works
It maybe much simpler for you
PB 5.22 x86 - Win 8.1 x64
Have fun

Code:
InitSprite()

OpenWindow(0,0,0,800,600,"",#PB_Window_SystemMenu  | #PB_Window_ScreenCentered)
MDIGadget(0,-10,-40,810,640,0,0)

AddGadgetItem(0,1,"Test")
OpenWindowedScreen(WindowID(1),0,0,2000,2000)
  CreateSprite(0, 20, 20)
  If StartDrawing(SpriteOutput(0))
    Box(0, 0, 20, 20, RGB(255, 0, 155))
    Box(5, 5, 10, 10, RGB(155, 0, 255))
    StopDrawing()
  EndIf
 
 ResizeWindow(1,0,0,2000,2000)

direction = 2
  Repeat
    ; It's very important to process all the events remaining in the queue at each frame
    ;
    Repeat
      Event = WindowEvent()
     
      Select Event
        Case #PB_Event_Gadget
          If EventGadget() = 0
            End
          EndIf
       
        Case #PB_Event_CloseWindow
          End
      EndSelect
    Until Event = 0
 
    FlipBuffers()
    ClearScreen(RGB(0, 0, 0))
    DisplaySprite(0, x, x)
    x + direction
    If x > 140 : direction = -2 : EndIf
    If x < 0   : direction =  2 : EndIf
    Delay(1)
  ForEver


_________________
Egypt my love


Top
 Profile  
Reply with quote  
 Post subject: Re: Windowed screen inside a ScrollArea Gadget?
PostPosted: Fri May 23, 2014 1:04 pm 
Offline
Always Here
Always Here

Joined: Fri Oct 23, 2009 2:33 am
Posts: 5833
Location: Wales, UK
Very nicely done Rashad - I thought it probably couldn't be done 8)

_________________
IdeasVacuum
If it sounds simple, you have not grasped the complexity.


Top
 Profile  
Reply with quote  
 Post subject: Re: Windowed screen inside a ScrollArea Gadget?
PostPosted: Fri May 23, 2014 1:32 pm 
Offline
PureBasic Expert
PureBasic Expert

Joined: Sun Apr 12, 2009 6:27 am
Posts: 3416
Hi IdeasVacuum
Thanks
I still prefer method #1, It is so clean even it is complicated somehow

_________________
Egypt my love


Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 8 posts ] 

All times are UTC + 1 hour


Who is online

Users browsing this forum: hrcoder and 11 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
Jump to:  

 


Powered by phpBB © 2008 phpBB Group
subSilver+ theme by Canver Software, sponsor Sanal Modifiye