It is currently Mon Jun 17, 2019 1:48 am

All times are UTC + 1 hour




Post new topic Reply to topic  [ 14 posts ] 
Author Message
 Post subject: module_scroll
PostPosted: Fri Apr 27, 2018 4:32 pm 
Offline
Enthusiast
Enthusiast

Joined: Mon Nov 25, 2013 6:41 am
Posts: 763
Image

Code:
;
; Os              : All
; Version         : 1.4
; License         : Free
; Module name     : Scroll
; Author          : mestnyi
; PB version:     : 5.46 =< 5.62
; Last updated    : 22 Sep 2018
; Topic           : https://www.purebasic.fr/english/posting.php?mode=edit&f=12&p=521603
;

CompilerIf #PB_Compiler_IsMainFile
  DeclareModule Constant
    CompilerIf #PB_Compiler_Version =< 546
      Enumeration #PB_EventType_FirstCustomValue
        #PB_EventType_Resize
      EndEnumeration
    CompilerEndIf
  EndDeclareModule
  Module Constant : EndModule : UseModule Constant
CompilerEndIf

DeclareModule Scroll
  EnableExplicit
  #Vertical = #PB_ScrollBar_Vertical
 
  Structure PAGE
    Pos.l
    Length.l
    ScrollStep.l
  EndStructure
 
  Structure COLOR
    Front.l[4]
    Fore.l[4]
    Back.l[4]
    Line.l[4]
    Frame.l[4]
  EndStructure
 
  Structure COORDINATE
    y.l[4]
    x.l[4]
    height.l[4]
    width.l[4]
  EndStructure
 
  Structure STRUCT Extends COORDINATE
    Max.l
    Min.l
   
    Both.b ; we see both scrolbars
   
    Type.l
    Focus.l
    Buttons.l
    Button.Page
   
    Radius.l
   
    Hide.b[2]
    Alpha.a[2]
    Disable.b[2]
    Vertical.b
    DrawingMode.l
   
    Page.PAGE
    Area.PAGE
    Thumb.PAGE
    Color.Color[4]
  EndStructure
 
  Declare.b Draw(*Scroll.Struct)
  Declare.l Y(*Scroll.Struct)
  Declare.l X(*Scroll.Struct)
  Declare.l Width(*Scroll.Struct)
  Declare.l Height(*Scroll.Struct)
  Declare.b SetState(*Scroll.Struct, ScrollPos.l)
  Declare.l SetAttribute(*Scroll.Struct, Attribute.l, Value.l)
  Declare.b SetColor(*Scroll.Struct, ColorType.l, Color.l, Item.l=- 1, State.l=1)
  Declare.b Resize(*This.Struct, iX.l,iY.l,iWidth.l,iHeight.l, *Scroll.Struct=#Null)
  Declare.b Resizes(*v.Struct, *h.Struct, X.l,Y.l,Width.l,Height.l)
  Declare.b Updates(*v.Struct, *h.Struct, ScrollArea_X, ScrollArea_Y, ScrollArea_Width, ScrollArea_Height)
  Declare.b CallBack(*This.Struct, EventType.l, MouseX.l, MouseY.l, WheelDelta.l=0, AutoHide.b=0, *Scroll.Struct=#Null)
  Declare.b Gadget(*Scroll.Struct, X.l,Y.l,Width.l,Height.l, Min.l, Max.l, PageLength.l, Flag.l, Radius.l=0)
 
  Declare DrawArrow(X,Y, Size, Direction, Color, Thickness = 1)
EndDeclareModule

Module Scroll
  Macro Colors(_this_, _i_, _ii_, _iii_)
    If _this_\Color[_i_]\Line[_ii_]
      _this_\Color[_i_]\Line[_iii_] = _this_\Color[_i_]\Line[_ii_]
    Else
      _this_\Color[_i_]\Line[_iii_] = _this_\Color[0]\Line[_ii_]
    EndIf
   
    If _this_\Color[_i_]\Fore[_ii_]
      _this_\Color[_i_]\Fore[_iii_] = _this_\Color[_i_]\Fore[_ii_]
    Else
      _this_\Color[_i_]\Fore[_iii_] = _this_\Color[0]\Fore[_ii_]
    EndIf
   
    If _this_\Color[_i_]\Back[_ii_]
      _this_\Color[_i_]\Back[_iii_] = _this_\Color[_i_]\Back[_ii_]
    Else
      _this_\Color[_i_]\Back[_iii_] = _this_\Color[0]\Back[_ii_]
    EndIf
   
    If _this_\Color[_i_]\Frame[_ii_]
      _this_\Color[_i_]\Frame[_iii_] = _this_\Color[_i_]\Frame[_ii_]
    Else
      _this_\Color[_i_]\Frame[_iii_] = _this_\Color[0]\Frame[_ii_]
    EndIf
  EndMacro
 
  Macro BoxGradient(_type_, _x_,_y_,_width_,_height_,_color_1_,_color_2_, _radius_=0, _alpha_=255)
    BackColor(_color_1_&$FFFFFF|_alpha_<<24)
    FrontColor(_color_2_&$FFFFFF|_alpha_<<24)
    If _type_
      LinearGradient(_x_,_y_, (_x_+_width_), _y_)
    Else
      LinearGradient(_x_,_y_, _x_, (_y_+_height_))
    EndIf
    RoundBox(_x_,_y_,_width_,_height_, _radius_,_radius_)
    BackColor(#PB_Default) : FrontColor(#PB_Default) ; bug
  EndMacro
 
  Macro ResetColor(_this_)
    Colors(_this_, 0, 1, 0)
    Colors(_this_, 1, 1, 0)
    Colors(_this_, 2, 1, 0)
    Colors(_this_, 3, 1, 0)
   
   
    Colors(_this_, 1, 1, 1)
    Colors(_this_, 2, 1, 1)
    Colors(_this_, 3, 1, 1)
   
    Colors(_this_, 1, 2, 2)
    Colors(_this_, 2, 2, 2)
    Colors(_this_, 3, 2, 2)
   
    Colors(_this_, 1, 3, 3)
    Colors(_this_, 2, 3, 3)
    Colors(_this_, 3, 3, 3)
  EndMacro
 
  Macro ThumbPos(_this_, _scroll_pos_)
    (_this_\Area\Pos + Round((_scroll_pos_-_this_\Min) * (_this_\Area\Length / (_this_\Max-_this_\Min)), #PB_Round_Nearest))
  EndMacro
 
  Macro ThumbLength(_this_)
    Round(_this_\Area\Length - (_this_\Area\Length / (_this_\Max-_this_\Min))*((_this_\Max-_this_\Min) - _this_\Page\Length), #PB_Round_Nearest)
  EndMacro
 
  Procedure DrawArrow(X,Y, Size, Direction, Color, Thickness = 1)
    Protected I
   
   
    If Direction = 1
      For i = 0 To Size
        ; в верх
        LineXY((X+i)+Size,(Y+i-1)-(Thickness),(X+i)+Size,(Y+i-1)+(Thickness),Color) ; Левая линия
        LineXY(((X+(Size))-i),(Y+i-1)-(Thickness),((X+(Size))-i),(Y+i-1)+(Thickness),Color) ; правая линия
      Next
    ElseIf Direction = 3
      For i = 0 To Size
        ; в низ
        LineXY((X+i),(Y+i)-(Thickness),(X+i),(Y+i)+(Thickness),Color) ; Левая линия
        LineXY(((X+(Size*2))-i),(Y+i)-(Thickness),((X+(Size*2))-i),(Y+i)+(Thickness),Color) ; правая линия
      Next
    ElseIf Direction = 0 ; в лево
      For i = 0 To Size 
        ; в лево
        LineXY(((X+1)+i)-(Thickness),(((Y-2)+(Size))-i),((X+1)+i)+(Thickness),(((Y-2)+(Size))-i),Color) ; правая линия
        LineXY(((X+1)+i)-(Thickness),((Y-2)+i)+Size,((X+1)+i)+(Thickness),((Y-2)+i)+Size,Color)         ; Левая линия
      Next
    ElseIf Direction = 2 ; в право
      For i = 0 To Size
        ; в право
        LineXY(((X+2)+i)-(Thickness),((Y-2)+i),((X+2)+i)+(Thickness),((Y-2)+i),Color) ; Левая линия
        LineXY(((X+2)+i)-(Thickness),(((Y-2)+(Size*2))-i),((X+2)+i)+(Thickness),(((Y-2)+(Size*2))-i),Color) ; правая линия
      Next
    EndIf
   
  EndProcedure
 
  Procedure.i Match(Value.i, Grid.i, Max.i=$7FFFFFFF)
    If Grid
      Value = Round((Value/Grid), #PB_Round_Nearest) * Grid : If (Value>Max) : Value=Max : EndIf
    EndIf
   
    ProcedureReturn Value
  EndProcedure
 
  Procedure.l Pos(*This.Struct, ThumbPos.l)
    Protected ScrollPos.l
   
    With *This
      ScrollPos = Match(\Min + Round((ThumbPos - \Area\Pos) / (\Area\Length / (\Max-\Min)), #PB_Round_Nearest), \Page\ScrollStep)
      If (\Vertical And \Type = #PB_GadgetType_TrackBar) : ScrollPos = ((\Max-\Min)-ScrollPos) : EndIf
    EndWith
   
    ProcedureReturn ScrollPos
  EndProcedure
 
  ;-
  Procedure.b Draw(*Scroll.Struct)
    With *Scroll
      If Not \Hide And \Alpha
        ; Draw scroll bar background
        DrawingMode(#PB_2DDrawing_Default|#PB_2DDrawing_AlphaBlend)
        RoundBox(\X[0],\Y[0],\Width[0],\Height[0],\Radius,\Radius,\Color[0]\Back&$FFFFFF|\Alpha<<24)
       
        If \Vertical
          ; Draw left line
          If \Both
            ; "Это пустое пространство между двумя скроллами тоже закрашиваем если скролл бара кнопки не круглые"
            If Not \Radius : Box(\X[2],\Y[2]+\height[2]+1,\Width[2],\Height[2],\Color[0]\Back&$FFFFFF|\Alpha<<24) : EndIf
            Line(\X[0],\Y[0],1,\height[0]-\Radius/2,\Color[0]\Line&$FFFFFF|\Alpha<<24)
          Else
            Line(\X[0],\Y[0],1,\Height[0],\Color[0]\Line&$FFFFFF|\Alpha<<24)
          EndIf
        Else
          ; Draw top line
          If \Both
            Line(\X[0],\Y[0],\width[0]-\Radius/2,1,\Color[0]\Line&$FFFFFF|\Alpha<<24)
          Else
            Line(\X[0],\Y[0],\Width[0],1,\Color[0]\Line&$FFFFFF|\Alpha<<24)
          EndIf
        EndIf
       
        If \Thumb\Length
          ; Draw thumb
          DrawingMode(\DrawingMode|#PB_2DDrawing_AlphaBlend)
          BoxGradient(\Vertical,\X[3],\Y[3],\Width[3],\Height[3],\Color[3]\Fore,\Color[3]\Back, \Radius, \Alpha)
         
          ; Draw thumb frame
          If \DrawingMode = #PB_2DDrawing_Gradient
            DrawingMode(#PB_2DDrawing_Outlined|#PB_2DDrawing_AlphaBlend)
            RoundBox(\X[3],\Y[3],\Width[3],\Height[3],\Radius,\Radius,\Color[3]\Frame&$FFFFFF|\Alpha<<24)
          EndIf
        EndIf
       
        If \Button\Length
          ; Draw buttons
          DrawingMode(\DrawingMode|#PB_2DDrawing_AlphaBlend)
          BoxGradient(\Vertical,\X[1],\Y[1],\Width[1],\Height[1],\Color[1]\Fore,\Color[1]\Back, \Radius, \Alpha)
          BoxGradient(\Vertical,\X[2],\Y[2],\Width[2],\Height[2],\Color[2]\Fore,\Color[2]\Back, \Radius, \Alpha)
         
          ; Draw buttons frame
          If \DrawingMode = #PB_2DDrawing_Gradient
            DrawingMode(#PB_2DDrawing_Outlined|#PB_2DDrawing_AlphaBlend)
            RoundBox(\X[1],\Y[1],\Width[1],\Height[1],\Radius,\Radius,\Color[1]\Frame&$FFFFFF|\Alpha<<24)
            RoundBox(\X[2],\Y[2],\Width[2],\Height[2],\Radius,\Radius,\Color[2]\Frame&$FFFFFF|\Alpha<<24)
          EndIf
         
          ; Draw arrows
          DrawingMode(#PB_2DDrawing_Default|#PB_2DDrawing_AlphaBlend)
          DrawArrow(\X[1]+(\Width[1]-6)/2,\Y[1]+(\Height[1]-3)/2, 3, Bool(\Vertical), \Color[1]\Line&$FFFFFF|\Alpha<<24)
          DrawArrow(\X[2]+(\Width[2]-6)/2,\Y[2]+(\Height[2]-3)/2, 3, Bool(\Vertical)+2, \Color[2]\Line&$FFFFFF|\Alpha<<24)
        EndIf
       
        If \DrawingMode = #PB_2DDrawing_Gradient
          ; Draw thumb lines
          DrawingMode(#PB_2DDrawing_Default|#PB_2DDrawing_AlphaBlend)
          If \Vertical
            Line(\X[3]+(\Width[3]-8)/2,\Y[3]+\Height[3]/2-3,9,1,\Color[3]\Line&$FFFFFF|\Alpha<<24)
            Line(\X[3]+(\Width[3]-8)/2,\Y[3]+\Height[3]/2,9,1,\Color[3]\Line&$FFFFFF|\Alpha<<24)
            Line(\X[3]+(\Width[3]-8)/2,\Y[3]+\Height[3]/2+3,9,1,\Color[3]\Line&$FFFFFF|\Alpha<<24)
          Else
            Line(\X[3]+\Width[3]/2-3,\Y[3]+(\Height[3]-8)/2,1,9,\Color[3]\Line&$FFFFFF|\Alpha<<24)
            Line(\X[3]+\Width[3]/2,\Y[3]+(\Height[3]-8)/2,1,9,\Color[3]\Line&$FFFFFF|\Alpha<<24)
            Line(\X[3]+\Width[3]/2+3,\Y[3]+(\Height[3]-8)/2,1,9,\Color[3]\Line&$FFFFFF|\Alpha<<24)
          EndIf
        EndIf
      EndIf
    EndWith
  EndProcedure
 
  Procedure.l X(*Scroll.Struct)
    Protected Result.l
   
    If *Scroll
      With *Scroll
        If Not \Hide[1] And \Alpha
          Result = \X
        Else
          Result = \X+\Width
        EndIf
      EndWith
    EndIf
   
    ProcedureReturn Result
  EndProcedure
 
  Procedure.l Y(*Scroll.Struct)
    Protected Result.l
   
    If *Scroll
      With *Scroll
        If Not \Hide[1] And \Alpha
          Result = \Y
        Else
          Result = \Y+\Height
        EndIf
      EndWith
    EndIf
   
    ProcedureReturn Result
  EndProcedure
 
  Procedure.l Width(*Scroll.Struct)
    Protected Result.l
   
    If *Scroll
      With *Scroll
        If Not \Hide[1] And \Width And \Alpha
          Result = \Width
        EndIf
      EndWith
    EndIf
   
    ProcedureReturn Result
  EndProcedure
 
  Procedure.l Height(*Scroll.Struct)
    Protected Result.l
   
    If *Scroll
      With *Scroll
        If Not \Hide[1] And \Height And \Alpha
          Result = \Height
        EndIf
      EndWith
    EndIf
   
    ProcedureReturn Result
  EndProcedure
 
  Procedure.b SetState(*Scroll.Struct, ScrollPos.l)
    Protected Result.b
   
    With *Scroll
      If (\Vertical And \Type = #PB_GadgetType_TrackBar) : ScrollPos = ((\Max-\Min)-ScrollPos) : EndIf
     
      If ScrollPos < \Min : ScrollPos = \Min : EndIf
      If ScrollPos > (\Max-\Page\Length)
        ScrollPos = (\Max-\Page\Length)
      EndIf
     
      If \Page\Pos<>ScrollPos : \Page\Pos=ScrollPos
        \Thumb\Pos = ThumbPos(*Scroll, ScrollPos)
       
        If \Vertical
          \Y[3] = \Thumb\Pos
          \Height[3] = \Thumb\Length
        Else
          \X[3] = \Thumb\Pos
          \Width[3] = \Thumb\Length
        EndIf
       
        Result = #True
      EndIf
    EndWith
   
    ProcedureReturn Result
  EndProcedure
 
  Procedure.l SetAttribute(*Scroll.Struct, Attribute.l, Value.l)
    Protected Result.l
   
    With *Scroll
      Select Attribute
        Case #PB_ScrollBar_Minimum
          If \Min <> Value
            \Min = Value
            \Page\Pos = Value
            Result = #True
          EndIf
         
        Case #PB_ScrollBar_Maximum
          If \Max <> Value
            If \Min > Value
              \Max = \Min + 1
            Else
              \Max = Value
            EndIf
           
            \Page\ScrollStep = (\Max-\Min) / 100
           
            Result = #True
          EndIf
         
        Case #PB_ScrollBar_PageLength
          If \Page\Length <> Value
            If Value > (\Max-\Min) : \Max = Value ; Если этого page_length вызвать раньше maximum то не правильно работает
              \Page\Length = (\Max-\Min)
            Else
              \Page\Length = Value
            EndIf
           
            Result = #True
          EndIf
         
      EndSelect
    EndWith
   
    ProcedureReturn Result
  EndProcedure
 
  Procedure.b SetColor(*Scroll.Struct, ColorType.l, Color.l, Item.l=- 1, State.l=1)
    Protected Result
   
    With *Scroll
      Select ColorType
        Case #PB_Gadget_LineColor
          If Item=- 1
            \Color\Line[State] = Color
          Else
            \Color[Item]\Line[State] = Color
          EndIf
         
        Case #PB_Gadget_BackColor
          If Item=- 1
            \Color\Back[State] = Color
          Else
            \Color[Item]\Back[State] = Color
          EndIf
         
        Case #PB_Gadget_FrontColor
        Default ; Case #PB_Gadget_FrameColor
          If Item=- 1
            \Color\Frame[State] = Color
          Else
            \Color[Item]\Frame[State] = Color
          EndIf
         
      EndSelect
    EndWith
   
    ResetColor(*Scroll)
   
    ProcedureReturn Bool(Color)
  EndProcedure
 
  Procedure.b Resize(*This.Struct, X.l,Y.l,Width.l,Height.l, *Scroll.Struct=#Null)
    Protected Result, Lines, ScrollPage
   
    With *This
      ScrollPage = ((\Max-\Min) - \Page\Length)
      Lines = Bool(\Type=#PB_GadgetType_ScrollBar)
     
      If *Scroll
        If \Vertical
          If Height=#PB_Ignore : If *Scroll\Hide : Height=(*Scroll\Y+*Scroll\Height)-\Y : Else : Height = *Scroll\Y-\Y : EndIf : EndIf
        Else
          If Width=#PB_Ignore : If *Scroll\Hide : Width=(*Scroll\X+*Scroll\Width)-\X : Else : Width = *Scroll\X-\X : EndIf : EndIf
        EndIf
      EndIf
     
      ;
      If X=#PB_Ignore : X = \X[0] : EndIf : If Y=#PB_Ignore : Y = \Y[0] : EndIf
      If Width=#PB_Ignore : Width = \Width[0] : EndIf : If Height=#PB_Ignore : Height = \Height[0] : EndIf
     
      ;
      If ((\Max-\Min) >= \Page\Length)
        If \Vertical
          \Area\Pos = Y+\Button\Length
          \Area\Length = (Height-\Button\Length*2)
        Else
          \Area\Pos = X+\Button\Length
          \Area\Length = (Width-\Button\Length*2)
        EndIf
       
        If \Area\Length
          \Thumb\Length = ThumbLength(*This)
         
          If (\Area\Length > \Button\Length)
            If \Button\Length
              If (\Thumb\Length < \Button\Length)
                \Area\Length = Round(\Area\Length - (\Button\Length-\Thumb\Length), #PB_Round_Nearest)
                \Thumb\Length = \Button\Length
              EndIf
            Else
              If (\Thumb\Length < 7)
                \Area\Length = Round(\Area\Length - (7-\Thumb\Length), #PB_Round_Nearest)
                \Thumb\Length = 7
              EndIf
            EndIf
          Else
            \Thumb\Length = \Area\Length
          EndIf
         
          If \Area\Length > 0
            If (\Type <> #PB_GadgetType_TrackBar) And (\Thumb\Pos+\Thumb\Length) >= (\Area\Length+\Button\Length)
              SetState(*This, ScrollPage)
            EndIf
           
            \Thumb\Pos = ThumbPos(*This, \Page\Pos)
          EndIf
        EndIf
      EndIf
     
     
      \X[0] = X : \Y[0] = Y : \Width[0] = Width : \Height[0] = Height                                             ; Set scroll bar coordinate
     
      If \Vertical
        \X[1] = X + Lines : \Y[1] = Y : \Width[1] = Width - Lines : \Height[1] = \Button\Length                   ; Top button coordinate on scroll bar
        \X[2] = X + Lines : \Width[2] = Width - Lines : \Height[2] = \Button\Length : \Y[2] = Y+Height-\Height[2] ; Botom button coordinate on scroll bar
        \X[3] = X + Lines : \Width[3] = Width - Lines : \Y[3] = \Thumb\Pos : \Height[3] = \Thumb\Length           ; Thumb coordinate on scroll bar
      Else
        \X[1] = X : \Y[1] = Y + Lines : \Width[1] = \Button\Length : \Height[1] = Height - Lines                  ; Left button coordinate on scroll bar
        \Y[2] = Y + Lines : \Height[2] = Height - Lines : \Width[2] = \Button\Length : \X[2] = X+Width-\Width[2]  ; Right button coordinate on scroll bar
        \Y[3] = Y + Lines : \Height[3] = Height - Lines : \X[3] = \Thumb\Pos : \Width[3] = \Thumb\Length          ; Thumb coordinate on scroll bar
      EndIf
     
      \Hide[1] = Bool(Not ((\Max-\Min) > \Page\Length))
      ProcedureReturn \Hide[1]
    EndWith
  EndProcedure
 
  Procedure.b Updates(*v.Struct, *h.Struct, ScrollArea_X, ScrollArea_Y, ScrollArea_Width, ScrollArea_Height)
    Protected iWidth = X(*v), iHeight = Y(*h)
    Static hPos, vPos : vPos = *v\Page\Pos : hPos = *h\Page\Pos
   
    ; Вправо работает как надо
    If ScrollArea_Width<*h\Page\Pos+iWidth
      ScrollArea_Width=*h\Page\Pos+iWidth
      ; Влево работает как надо
    ElseIf ScrollArea_X>*h\Page\Pos And
           ScrollArea_Width=*h\Page\Pos+iWidth
      ScrollArea_Width = iWidth
    EndIf
   
    ; Вниз работает как надо
    If ScrollArea_Height<*v\Page\Pos+iHeight
      ScrollArea_Height=*v\Page\Pos+iHeight
      ; Верх работает как надо
    ElseIf ScrollArea_Y>*v\Page\Pos And
           ScrollArea_Height=*v\Page\Pos+iHeight
      ScrollArea_Height = iHeight
    EndIf
   
    If ScrollArea_X>0 : ScrollArea_X=0 : EndIf
    If ScrollArea_Y>0 : ScrollArea_Y=0 : EndIf
   
    If ScrollArea_X<*h\Page\Pos : ScrollArea_Width-ScrollArea_X : EndIf
    If ScrollArea_Y<*v\Page\Pos : ScrollArea_Height-ScrollArea_Y : EndIf
   
    If *v\Max<>ScrollArea_Height : SetAttribute(*v, #PB_ScrollBar_Maximum, ScrollArea_Height) : EndIf
    If *h\Max<>ScrollArea_Width : SetAttribute(*h, #PB_ScrollBar_Maximum, ScrollArea_Width) : EndIf
   
    If *v\Page\Length<>iHeight : SetAttribute(*v, #PB_ScrollBar_PageLength, iHeight) : EndIf
    If *h\Page\Length<>iWidth : SetAttribute(*h, #PB_ScrollBar_PageLength, iWidth) : EndIf
   
    If ScrollArea_Y<0 : SetState(*v, (ScrollArea_Height-ScrollArea_Y)-ScrollArea_Height) : EndIf
    If ScrollArea_X<0 : SetState(*h, (ScrollArea_Width-ScrollArea_X)-ScrollArea_Width) : EndIf
   
    *v\Hide = Resize(*v, #PB_Ignore, #PB_Ignore, #PB_Ignore, #PB_Ignore, *h)
    *h\Hide = Resize(*h, #PB_Ignore, #PB_Ignore, #PB_Ignore, #PB_Ignore, *v)
   
    If *v\Hide : *v\Page\Pos = 0 : If vPos : *v\Hide = vPos : EndIf : Else : *v\Page\Pos = vPos : *h\Width = iWidth+*v\Width : EndIf
    If *h\Hide : *h\Page\Pos = 0 : If hPos : *h\Hide = hPos : EndIf : Else : *h\Page\Pos = hPos : *v\Height = iHeight+*h\Height : EndIf
   
    ProcedureReturn Bool(ScrollArea_Height>=iHeight Or ScrollArea_Width>=iWidth)
  EndProcedure
 
  Procedure.b Resizes(*v.Struct, *h.Struct, X.l,Y.l,Width.l,Height.l )
    If Width=#PB_Ignore : Width = *v\X+*v\Width : Else : Width+x : EndIf
    If Height=#PB_Ignore : Height = *h\Y+*h\Height : Else : Height+y : EndIf
   
    Protected iWidth = Width-Width(*v), iHeight = Height-Height(*h)
   
    If *v\width And *v\Page\Length<>iHeight : SetAttribute(*v, #PB_ScrollBar_PageLength, iHeight) : EndIf
    If *h\height And *h\Page\Length<>iWidth : SetAttribute(*h, #PB_ScrollBar_PageLength, iWidth) : EndIf
   
    *v\Hide = Resize(*v, Width-*v\Width, Y, #PB_Ignore, #PB_Ignore, *h) : iWidth = Width-Width(*v)
    *h\Hide = Resize(*h, X, Height-*h\Height, #PB_Ignore, #PB_Ignore, *v) : iHeight = Height-Height(*h)
   
    If *v\width And *v\Page\Length<>iHeight : SetAttribute(*v, #PB_ScrollBar_PageLength, iHeight) : EndIf
    If *h\height And *h\Page\Length<>iWidth : SetAttribute(*h, #PB_ScrollBar_PageLength, iWidth) : EndIf
   
    If *v\width : *v\Hide = Resize(*v, #PB_Ignore, #PB_Ignore, #PB_Ignore, #PB_Ignore, *h) : EndIf
    If *h\height : *h\Hide = Resize(*h, #PB_Ignore, #PB_Ignore, #PB_Ignore, #PB_Ignore, *v) : EndIf
   
    ; Do we see both scrolbars?
    *v\Both = Bool(Not *h\Hide)
    *h\Both = Bool(Not *v\Hide)
   
    If *v\Hide : *v\Page\Pos = 0 : Else
      If *h\Radius : Resize(*h, #PB_Ignore, #PB_Ignore, *v\x+*v\Radius/2-1, #PB_Ignore) : EndIf
    EndIf
    If *h\Hide : *h\Page\Pos = 0 : Else
      If *v\Radius : Resize(*v, #PB_Ignore, #PB_Ignore, #PB_Ignore, *h\y+*v\Radius/2-1) : EndIf
    EndIf
   
    ProcedureReturn Bool(*v\Hide|*h\Hide)
  EndProcedure
 
  Procedure.b CallBack(*This.Struct, EventType.l, MouseX.l, MouseY.l, WheelDelta.l=0, AutoHide.b=0, *Scroll.Struct=#Null)
    Protected Result, Buttons
    Static LastX, LastY, Last, *Thisis.Struct, Cursor, Drag, Down
   
    With *This
      ;       If \Hide
      ;         If *This = *Thisis
      ;           \Buttons = 0
      ;           \Focus = 0
      ;         EndIf
      ;       EndIf
     
      ; get at point buttons
      If Down ; GetGadgetAttribute(EventGadget(), #PB_Canvas_Buttons)
        Buttons = \Buttons
      Else
        If (Mousex>=\x And Mousex<\x+\Width And Mousey>\y And Mousey=<\y+\Height)
          If (Mousex>\x[1] And Mousex=<\x[1]+\Width[1] And  Mousey>\y[1] And Mousey=<\y[1]+\Height[1])
            Buttons = 1
          ElseIf (Mousex>\x[3] And Mousex=<\x[3]+\Width[3] And Mousey>\y[3] And Mousey=<\y[3]+\Height[3])
            Buttons = 3
          ElseIf (Mousex>\x[2] And Mousex=<\x[2]+\Width[2] And Mousey>\y[2] And Mousey=<\y[2]+\Height[2])
            Buttons = 2
          Else
            Buttons =- 1
          EndIf
        EndIf
      EndIf
     
      ; get
      Select EventType
        Case #PB_EventType_MouseWheel 
          If *Thisis = *This
            Select WheelDelta
              Case-1 : Result = SetState(*This, \Page\Pos - (\Max-\Min)/30)
              Case 1 : Result = SetState(*This, \Page\Pos + (\Max-\Min)/30)
            EndSelect
          EndIf
         
        Case #PB_EventType_MouseLeave
          If Not Drag : \Buttons = 0 : Buttons = 0 : LastX = 0 : LastY = 0 : EndIf
        Case #PB_EventType_LeftButtonUp : Down = 0 :  Drag = 0 :  LastX = 0 : LastY = 0
        Case #PB_EventType_LeftButtonDown : Down = 1
          If Buttons : \Buttons = Buttons : Drag = 1 : *Thisis = *This : EndIf
         
          Select Buttons
            Case - 1
              If *Thisis = *This Or (\Height>(\Y[2]+\Height[2]) And \Buttons =- 1)
                If \Vertical
                  Result = SetState(*This, Pos(*This, (MouseY-\Thumb\Length/2)))
                Else
                  Result = SetState(*This, Pos(*This, (MouseX-\Thumb\Length/2)))
                EndIf
              EndIf
            Case 1 : Result = SetState(*This, (\Page\Pos - \Page\ScrollStep))
            Case 2 : Result = SetState(*This, (\Page\Pos + \Page\ScrollStep))
            Case 3 : LastX = MouseX - \Thumb\Pos : LastY = MouseY - \Thumb\Pos
          EndSelect
         
        Case #PB_EventType_MouseMove
          If Drag
            If Bool(LastX|LastY)
              If *Thisis = *This
                If \Vertical
                  Result = SetState(*This, Pos(*This, (MouseY-LastY)))
                Else
                  Result = SetState(*This, Pos(*This, (MouseX-LastX)))
                EndIf
              EndIf
            EndIf
          Else
            If Buttons
              If Last <> Buttons
                If *Thisis>0 : CallBack(*Thisis, #PB_EventType_MouseLeave, MouseX, MouseY, WheelDelta) : EndIf
                EventType = #PB_EventType_MouseEnter
                Last = Buttons
              EndIf
             
              If *Thisis <> *This
                ; Debug "Мышь находится внутри"
                Cursor = GetGadgetAttribute(EventGadget(), #PB_Canvas_Cursor)
                SetGadgetAttribute(EventGadget(), #PB_Canvas_Cursor, #PB_Cursor_Default)
                *Thisis = *This
              EndIf
             
              \Buttons = Buttons
            ElseIf *Thisis = *This
              If Cursor <> GetGadgetAttribute(EventGadget(), #PB_Canvas_Cursor)
                ; Debug "Мышь находится снаружи"
                SetGadgetAttribute(EventGadget(), #PB_Canvas_Cursor, Cursor)
              EndIf
              EventType = #PB_EventType_MouseLeave
              \Buttons = 0
              *Thisis = 0
              Last = 0
            EndIf
          EndIf
         
      EndSelect
     
      ; set colors
      Select EventType
        Case #PB_EventType_Focus : \Focus = #True : Result = #True
        Case #PB_EventType_LostFocus : \Focus = #False : Result = #True
        Case #PB_EventType_LeftButtonDown, #PB_EventType_LeftButtonUp, #PB_EventType_MouseEnter, #PB_EventType_MouseLeave
          If Buttons>0
            \Color[Buttons]\Fore = \Color[Buttons]\Fore[2+Bool(EventType=#PB_EventType_LeftButtonDown)]
            \Color[Buttons]\Back = \Color[Buttons]\Back[2+Bool(EventType=#PB_EventType_LeftButtonDown)]
            \Color[Buttons]\Frame = \Color[Buttons]\Frame[2+Bool(EventType=#PB_EventType_LeftButtonDown)]
            \Color[Buttons]\Line = \Color[Buttons]\Line[2+Bool(EventType=#PB_EventType_LeftButtonDown)]
          ElseIf Not Drag And Not Buttons
            ResetColor(*This)
          EndIf
         
          Result = #True
         
      EndSelect
     
      If AutoHide =- 1 : *Scroll = 0
        If Not *Thisis : *Thisis =- 1 : EndIf
        AutoHide = Bool(EventType() = #PB_EventType_MouseLeave)
      ElseIf AutoHide And *Thisis = *This
        *Thisis =- 1
      EndIf
     
      ; Auto hides
      If (AutoHide And Not Drag And Not Buttons)
        If \Alpha <> \Alpha[1] : \Alpha = \Alpha[1]
          Result =- 1
        EndIf
      EndIf
      If EventType = #PB_EventType_MouseEnter And *Thisis =- 1
        If \Alpha < 255 : \Alpha = 255
         
          If *Scroll
            If \Vertical
              Resize(*This, #PB_Ignore, #PB_Ignore, #PB_Ignore, (*Scroll\y+*Scroll\height)-\y)
            Else
              Resize(*This, #PB_Ignore, #PB_Ignore, (*Scroll\x+*Scroll\width)-\x, #PB_Ignore)
            EndIf
          EndIf
         
          Result =- 2
        EndIf
      EndIf
    EndWith
   
    ProcedureReturn Result
  EndProcedure
 
  Procedure.b Gadget(*Scroll.Struct, X.l,Y.l,Width.l,Height.l, Min.l, Max.l, PageLength.l, Flag.l, Radius.l=0)
   
    With *Scroll
      \Alpha = 255
      \Alpha[1] = 0
      \Radius = Radius
      \Color[0]\Fore[1] = $F6F6F6
      \Color[0]\Frame[1] = $BABABA
     
      \Color[0]\Back[1] = $F9F9F9 ; $F0F0F0
      \Color[1]\Back[1] = $E2E2E2 
      \Color[2]\Back[1] = $E2E2E2
      \Color[3]\Back[1] = $E2E2E2
     
      \Color[0]\Line[1] = $FFFFFF
      \Color[1]\Line[1] = $5B5B5B
      \Color[2]\Line[1] = $5B5B5B
      \Color[3]\Line[1] = $5B5B5B
     
      ;
      \Color[0]\Fore[2] = $EAEAEA
      \Color[0]\Back[2] = $CECECE
      \Color[0]\Line[2] = $5B5B5B
      \Color[0]\Frame[2] = $8F8F8F
     
      ;
      \Color[0]\Fore[3] = $E2E2E2
      \Color[0]\Back[3] = $B4B4B4
      \Color[0]\Line[3] = $FFFFFF
      \Color[0]\Frame[3] = $6F6F6F
     
      ResetColor(*Scroll)
     
      \Type = #PB_GadgetType_ScrollBar
      \DrawingMode = #PB_2DDrawing_Gradient
      \Vertical = Bool(Flag&#PB_ScrollBar_Vertical)
     
      If \Vertical
        If width < 21
          \Button\Length = width - 1
        Else
          \Button\Length = 17
        EndIf
      Else
        If height < 21
          \Button\Length = height - 1
        Else
          \Button\Length = 17
        EndIf
      EndIf
     
      If \Min <> Min : SetAttribute(*Scroll, #PB_ScrollBar_Minimum, Min) : EndIf
      If \Max <> Max : SetAttribute(*Scroll, #PB_ScrollBar_Maximum, Max) : EndIf
      If \Page\Length <> Pagelength : SetAttribute(*Scroll, #PB_ScrollBar_PageLength, Pagelength) : EndIf
    EndWith
   
    ProcedureReturn Resize(*Scroll, X,Y,Width,Height)
  EndProcedure
 
EndModule

;- EXAMPLE
CompilerIf #PB_Compiler_IsMainFile
  Global *Vertical.Scroll::Struct=AllocateStructure(Scroll::Struct)
  Global *Horisontal_0.Scroll::Struct=AllocateStructure(Scroll::Struct)
  Global *Horisontal_1.Scroll::Struct=AllocateStructure(Scroll::Struct)
  Global *Horisontal_2.Scroll::Struct=AllocateStructure(Scroll::Struct)
  Global *Horisontal_3.Scroll::Struct=AllocateStructure(Scroll::Struct)
  Global *Horisontal_4.Scroll::Struct=AllocateStructure(Scroll::Struct)
  Global *Horisontal_5.Scroll::Struct=AllocateStructure(Scroll::Struct)
 
  Procedure CallBack()
    Protected Repaint
    Protected Canvas = EventGadget()
    Protected MouseX = GetGadgetAttribute(Canvas, #PB_Canvas_MouseX)
    Protected MouseY = GetGadgetAttribute(Canvas, #PB_Canvas_MouseY)
    Protected WheelDelta = GetGadgetAttribute(EventGadget(), #PB_Canvas_WheelDelta)
    Protected Width = GadgetWidth(Canvas)
    Protected Height = GadgetHeight(Canvas)
   
    Select EventType()
      Case #PB_EventType_Resize : ResizeGadget(Canvas, #PB_Ignore, #PB_Ignore, #PB_Ignore, #PB_Ignore) ; Bug (562)
       
        Scroll::Resize(*Vertical, Width-35, #PB_Ignore, #PB_Ignore, #PB_Ignore)
        Scroll::Resize(*Horisontal_0, #PB_Ignore, #PB_Ignore, Width-55, #PB_Ignore)
        Scroll::Resize(*Horisontal_1, #PB_Ignore, #PB_Ignore, Width-55, #PB_Ignore)
        Scroll::Resize(*Horisontal_2, #PB_Ignore, #PB_Ignore, Width-55, #PB_Ignore)
        Scroll::Resize(*Horisontal_3, #PB_Ignore, #PB_Ignore, Width-55, #PB_Ignore)
        Scroll::Resize(*Horisontal_4, #PB_Ignore, #PB_Ignore, Width-55, #PB_Ignore)
        Scroll::Resize(*Horisontal_5, #PB_Ignore, #PB_Ignore, Width-55, #PB_Ignore)
       
        Repaint = #True
    EndSelect
   
    If Scroll::CallBack(*Vertical, EventType(), MouseX, MouseY, WheelDelta)
      Repaint = #True
    EndIf
   
    If Scroll::CallBack(*Horisontal_0, EventType(), MouseX, MouseY, WheelDelta)
      Repaint = #True
    EndIf
    If Scroll::CallBack(*Horisontal_1, EventType(), MouseX, MouseY, WheelDelta)
      Repaint = #True
    EndIf
    If Scroll::CallBack(*Horisontal_2, EventType(), MouseX, MouseY, WheelDelta)
      Repaint = #True
    EndIf
    If Scroll::CallBack(*Horisontal_3, EventType(), MouseX, MouseY, WheelDelta)
      Repaint = #True
    EndIf
    If Scroll::CallBack(*Horisontal_4, EventType(), MouseX, MouseY, WheelDelta)
      Repaint = #True
    EndIf
    If Scroll::CallBack(*Horisontal_5, EventType(), MouseX, MouseY, WheelDelta)
      Repaint = #True
    EndIf
   
    If Repaint And StartDrawing(CanvasOutput(Canvas))
      Box(0,0,Width,Height)
      Scroll::Draw(*Vertical)
      Scroll::Draw(*Horisontal_0)
      Scroll::Draw(*Horisontal_1)
      Scroll::Draw(*Horisontal_2)
      Scroll::Draw(*Horisontal_3)
      Scroll::Draw(*Horisontal_4)
      Scroll::Draw(*Horisontal_5)
      StopDrawing()
    EndIf
   
  EndProcedure
 
  Procedure ResizeCallBack()
    ResizeGadget(1, #PB_Ignore, #PB_Ignore, WindowWidth(EventWindow(), #PB_Window_InnerCoordinate)-20, WindowHeight(EventWindow(), #PB_Window_InnerCoordinate)-20)
    CompilerIf #PB_Compiler_Version =< 546
      PostEvent(#PB_Event_Gadget, EventWindow(), 1, #PB_EventType_Resize)
    CompilerEndIf
  EndProcedure
 
  If OpenWindow(0, 0, 0, 325, 223, "Scroll on the canvas", #PB_Window_SystemMenu | #PB_Window_SizeGadget | #PB_Window_ScreenCentered)
    CanvasGadget(1,  10,10,305,203, #PB_Canvas_Keyboard)
    SetGadgetAttribute(1, #PB_Canvas_Cursor, #PB_Cursor_Cross)
   
    With *Vertical
      Scroll::Gadget(*Vertical, 270, 10,  25, 183 ,0, 300, 50, #PB_ScrollBar_Vertical, 4)
      Scroll::SetState(*Vertical, 100)
    EndWith
   
    With *Horisontal_0
      \Hide = Scroll::Gadget(*Horisontal_0, 10, 10, 250,  18, 30, 100, 30, 0)
      Scroll::SetColor(*Horisontal_0, #PB_Gadget_BackColor, $5A98FF)
      Scroll::SetState(*Horisontal_0, 50)
      \Button\Length=0
    EndWith
    With *Horisontal_1
      \Hide = Scroll::Gadget(*Horisontal_1, 10, 43, 250,  18, 30, 300, 30, 0)
      Scroll::SetState(*Horisontal_1, 150)
    EndWith
    With *Horisontal_2
      \Hide = Scroll::Gadget(*Horisontal_2, 10, 76, 250,  18, 30, 100, 30, 0, 304)
      Scroll::SetColor(*Horisontal_2, #PB_Gadget_BackColor, $BF853F)
      Scroll::SetState(*Horisontal_2, 50)
      \Button\Length=0
    EndWith
    With *Horisontal_3
      \Hide = Scroll::Gadget(*Horisontal_3, 10, 109, 250,  14, 30, 300, 30, 0, 304)
      Scroll::SetState(*Horisontal_3, 150)
      \Button\Length=35
    EndWith
    With *Horisontal_4
      \Hide = Scroll::Gadget(*Horisontal_4, 10, 142, 250,  18, 30, 100, 30, 0, 10)
      Scroll::SetColor(*Horisontal_4, #PB_Gadget_BackColor, $2EC450)
      Scroll::SetState(*Horisontal_4, 50)
      \Button\Length=0
    EndWith
    With *Horisontal_5
      \Hide = Scroll::Gadget(*Horisontal_5, 10, 175, 250,  18, 30, 300, 30, 0, 10)
      Scroll::SetState(*Horisontal_5, 150)
    EndWith
   
    PostEvent(#PB_Event_Gadget, 0,1,#PB_EventType_Resize)
    BindEvent(#PB_Event_SizeWindow, @ResizeCallBack())
    BindGadgetEvent(1, @CallBack())
    WindowBounds(0, #PB_Default,223,#PB_Default,223)
    Repeat : Until WaitWindowEvent() = #PB_Event_CloseWindow
  EndIf
CompilerEndIf


Last edited by mestnyi on Sun Sep 30, 2018 7:40 pm, edited 26 times in total.

Top
 Profile  
Reply with quote  
 Post subject: Re: module_scroll
PostPosted: Fri Apr 27, 2018 4:34 pm 
Offline
Enthusiast
Enthusiast

Joined: Mon Nov 25, 2013 6:41 am
Posts: 763
This is a full-fledged scroll bar gadget based on a scroll module. :)
module_scrollbar.pbi http://www.purebasic.fr/english/posting.php?mode=post&f=12


Last edited by mestnyi on Sat Sep 22, 2018 4:13 pm, edited 3 times in total.

Top
 Profile  
Reply with quote  
 Post subject: Re: module_scroll and module_scrollbar
PostPosted: Fri Apr 27, 2018 4:40 pm 
Offline
Enthusiast
Enthusiast

Joined: Mon Nov 25, 2013 6:41 am
Posts: 763
Here is one example of how to use. :)
http://www.purebasic.fr/english/viewtopic.php?f=13&t=54098&p=522143#p522143


Last edited by mestnyi on Sat May 12, 2018 1:45 pm, edited 3 times in total.

Top
 Profile  
Reply with quote  
 Post subject: Re: module_scroll and module_scrollbar
PostPosted: Fri Apr 27, 2018 6:58 pm 
Offline
Addict
Addict

Joined: Fri Nov 09, 2012 11:04 pm
Posts: 1657
Location: Uttoxeter, UK
@mestnyi,

Nice example. Thank you for sharing. :D

Appears to work on my MacBook, too.

_________________
DE AA EB


Top
 Profile  
Reply with quote  
 Post subject: Re: module_scroll and module_scrollbar
PostPosted: Thu May 03, 2018 11:30 pm 
Offline
Addict
Addict
User avatar

Joined: Mon Jul 25, 2005 3:51 pm
Posts: 3548
Location: Utah, USA
Great example.

I did notice one or two strange effects when using the example. If a picture is drug so that it is off of the bottom right hand corner you can still see the corner of the canvas even when both scrollbars are present. The scrollbars also disappear when an object is selected that is completely visible even if there are others which are partially or completely offscreen to the right or bottom.

_________________
Image


Top
 Profile  
Reply with quote  
 Post subject: Re: module_scroll and module_scrollbar
PostPosted: Fri May 04, 2018 8:56 pm 
Offline
User
User

Joined: Fri Aug 16, 2013 2:52 pm
Posts: 65
davido wrote:
@mestnyi,

Nice example. Thank you for sharing. :D

Appears to work on my MacBook, too.


Indeed. Thanks!

_________________
This signature was removed by [removed] for your own safety.


Top
 Profile  
Reply with quote  
 Post subject: Re: module_scroll and module_scrollbar
PostPosted: Sat May 05, 2018 8:52 am 
Offline
Enthusiast
Enthusiast

Joined: Mon Nov 25, 2013 6:41 am
Posts: 763
Quote:
If a picture is drug so that it is off of the bottom right hand corner you can still see the corner of the canvas even when both scrollbars are present.

This is treated with a clip output.
If you want to show an example of how you use it, and I'll show you how to solve it :)
Quote:
The scrollbars also disappear when an object is selected that is completely visible even if there are others which are partially or completely offscreen to the right or bottom.

This is not very clear, so if you showed an example, it would be good


Top
 Profile  
Reply with quote  
 Post subject: Re: module_scroll and module_scrollbar
PostPosted: Sat May 05, 2018 9:35 am 
Offline
Enthusiast
Enthusiast

Joined: Mon Nov 25, 2013 6:41 am
Posts: 763
Demivec here is one example of how this can be used.
Update v0003
Code:
XIncludeFile "module_scroll.pbi"

CompilerIf #PB_Compiler_IsMainFile
  If LoadImage(0, #PB_Compiler_Home+"Examples\Sources\Data\Background.bmp")     ; Измените путь/имя файла на собственное изображение 32x32 пикселя
    ResizeImage(0,ImageWidth(0)*2,ImageHeight(0)*2)
  EndIf
  Define a,i
 
  Global *Vertical.Scroll::Struct=AllocateStructure(Scroll::Struct)
  Global *Horisontal.Scroll::Struct=AllocateStructure(Scroll::Struct)
 
  Procedure CallBack()
    Protected Repaint, iWidth, iHeight
    Protected Canvas = EventGadget()
    Protected MouseX = GetGadgetAttribute(Canvas, #PB_Canvas_MouseX)
    Protected MouseY = GetGadgetAttribute(Canvas, #PB_Canvas_MouseY)
    Protected WheelDelta = GetGadgetAttribute(EventGadget(), #PB_Canvas_WheelDelta)
    Protected Width = GadgetWidth(Canvas)
    Protected Height = GadgetHeight(Canvas)
   
   
    Select EventType()
      Case #PB_EventType_Resize : ResizeGadget(Canvas, #PB_Ignore, #PB_Ignore, #PB_Ignore, #PB_Ignore) ; Bug (562)
        Scroll::Resizes(*Vertical, *Horisontal, 0, 0, Width, Height)
        Repaint = #True
    EndSelect
   
    If Scroll::CallBack(*Vertical, EventType(), MouseX, MouseY, WheelDelta) : Repaint = #True : EndIf
    If Scroll::CallBack(*Horisontal, EventType(), MouseX, MouseY, WheelDelta) : Repaint = #True : EndIf
   
    iWidth = Scroll::X(*Vertical)
    iHeight = Scroll::Y(*Horisontal)
   
    If Repaint And StartDrawing(CanvasOutput(Canvas))
      Box(0,0,Width,Height, $FFFFFF)
      ClipOutput(0,0, iWidth, iHeight)
      DrawImage(ImageID(0), -*Horisontal\Page\Pos, -*Vertical\Page\Pos)
      UnclipOutput()
      Scroll::Draw(*Vertical)
      Scroll::Draw(*Horisontal)
      StopDrawing()
    EndIf
  EndProcedure
 
  Procedure ResizeCallBack()
    ResizeGadget(1, #PB_Ignore, #PB_Ignore, WindowWidth(EventWindow(), #PB_Window_InnerCoordinate)-20, WindowHeight(EventWindow(), #PB_Window_InnerCoordinate)-20)
  EndProcedure
 
  If OpenWindow(0, 0, 0, 325, 160, "Scroll on the canvas", #PB_Window_SystemMenu | #PB_Window_SizeGadget | #PB_Window_ScreenCentered)
    CanvasGadget(1,  10,10,305,140, #PB_Canvas_Keyboard)
    SetGadgetAttribute(1, #PB_Canvas_Cursor, #PB_Cursor_Hand)
   
    With *Vertical
      *Vertical\Hide = Scroll::Gadget(*Vertical, 0, 0,  20, 0 ,0, ImageHeight(0), 0, #PB_ScrollBar_Vertical)
    EndWith
    With *Horisontal
      *Horisontal\Hide = Scroll::Gadget(*Horisontal, 0, 0, 0,  20, 0, ImageWidth(0), 0, 0)
    EndWith
   
;     ; Set style windows 8
;     *Vertical\DrawingMode = #PB_2DDrawing_Default
;     Scroll::SetColor(*Vertical, #PB_Gadget_BackColor, *Vertical\Color\Back, 1)
;     Scroll::SetColor(*Vertical, #PB_Gadget_BackColor, *Vertical\Color\Back, 2)
;     
;     Scroll::SetColor(*Vertical, #PB_Gadget_BackColor, $7E7E7E, 1, 3)
;     Scroll::SetColor(*Vertical, #PB_Gadget_BackColor, $7E7E7E, 2, 3)
;     
;     Scroll::SetColor(*Vertical, #PB_Gadget_BackColor, *Vertical\Color\Back[2], 3)
;     Scroll::SetColor(*Vertical, #PB_Gadget_BackColor, *Vertical\Color\Back[3], 3, 2)
;     Scroll::SetColor(*Vertical, #PB_Gadget_BackColor, $7E7E7E, 3, 3)
;     
;     *Horisontal\DrawingMode = #PB_2DDrawing_Default
;     Scroll::SetColor(*Horisontal, #PB_Gadget_BackColor, *Horisontal\Color\Back, 1)
;     Scroll::SetColor(*Horisontal, #PB_Gadget_BackColor, *Horisontal\Color\Back, 2)
;     
;     Scroll::SetColor(*Horisontal, #PB_Gadget_BackColor, $7E7E7E, 1, 3)
;     Scroll::SetColor(*Horisontal, #PB_Gadget_BackColor, $7E7E7E, 2, 3)
;     
;     Scroll::SetColor(*Horisontal, #PB_Gadget_BackColor, *Horisontal\Color\Back[2], 3)
;     Scroll::SetColor(*Horisontal, #PB_Gadget_BackColor, *Horisontal\Color\Back[3], 3, 2)
;     Scroll::SetColor(*Horisontal, #PB_Gadget_BackColor, $7E7E7E, 3, 3)
   
    Scroll::SetState(*Vertical, 150)
    Scroll::SetState(*Horisontal, 100)
   
    PostEvent(#PB_Event_Gadget, 0,1,#PB_EventType_Resize)
    BindGadgetEvent(1, @CallBack())
   
    ;PostEvent(#PB_Event_SizeWindow) ; Bug
    BindEvent(#PB_Event_SizeWindow, @ResizeCallBack())
    Repeat : Until WaitWindowEvent() = #PB_Event_CloseWindow
  EndIf
CompilerEndIf


Last edited by mestnyi on Tue Aug 07, 2018 9:01 pm, edited 6 times in total.

Top
 Profile  
Reply with quote  
 Post subject: Re: module_scroll
PostPosted: Sun May 06, 2018 7:14 pm 
Offline
Addict
Addict
User avatar

Joined: Sun Nov 05, 2006 11:42 pm
Posts: 4453
Location: Lyon - France
Very nice.
Thanks for sharing 8)

_________________
ImageThe happiness is a road...
Not a destination


Top
 Profile  
Reply with quote  
 Post subject: Re: module_scroll and module_scrollbar
PostPosted: Mon May 07, 2018 12:23 am 
Offline
Addict
Addict
User avatar

Joined: Mon Jul 25, 2005 3:51 pm
Posts: 3548
Location: Utah, USA
mestnyi wrote:
Quote:
The scrollbars also disappear when an object is selected that is completely visible even if there are others which are partially or completely offscreen to the right or bottom.

This is not very clear, so if you showed an example, it would be good


I realize this is regarding only demo code I just wasn't sure if you were happy with the results being demonstrated.

Follow these steps to demonstrate some peculiar things with image dragging example:

    * Drag image of Doughnut off the right of canvas window and drop it.
    - Horizontal Scrollbar is present.
    * Click on any image visible on canvas (i.e. plane) and drag it a few pixels.
    - Horizontal Scrollbar disappears.
    * Click and drag image of Plane off right of canvas window and drop it further to the right of where Doughnut was dropped.
    - Same as above.
    * Click on Horizontal Scrollbar and drag it all the way to the right.
    - Image of Plane is completely visible.
    * If image of Doughnut is visible and to the left of the Plane, click and drag image of Doughnut to the left slowly.
    - Mouse Pointer will now not be align to image and be offset.
    * Also, any image that is drug completely off the left of the canvas cannot be accessed
    anymore because scrollbars will not appear to allow scrolling to it and nothing can cause them to appear.


Do you plan on adding any events and event handling for clicking the empty scrollbar area? Possibilities would include things such as scrolling the canvas by one full screen height or width for each click or alternatively just scrolling to the absolute position indicated by where the click occurred.

_________________
Image


Top
 Profile  
Reply with quote  
 Post subject: Re: module_scroll
PostPosted: Mon May 07, 2018 1:13 pm 
Offline
Enthusiast
Enthusiast

Joined: Mon Nov 25, 2013 6:41 am
Posts: 763
Quote:
Follow these steps to demonstrate some peculiar things with image dragging example:

Updated the codes now look. :)


Top
 Profile  
Reply with quote  
 Post subject: Re: module_scroll
PostPosted: Wed May 09, 2018 8:02 am 
Offline
Addict
Addict

Joined: Sat Mar 02, 2013 9:17 am
Posts: 931
Looks very nice
Many new interesting codes !

_________________
http://www.nachtoptik.de


Top
 Profile  
Reply with quote  
 Post subject: Re: module_scroll
PostPosted: Wed May 09, 2018 8:48 am 
Offline
Enthusiast
Enthusiast

Joined: Mon Nov 25, 2013 6:41 am
Posts: 763
walbus wrote:
Looks very nice
Many new interesting codes !

I'm glad if someone likes you. Any improvements are welcome. :)


Top
 Profile  
Reply with quote  
 Post subject: Re: module_scroll
PostPosted: Wed May 09, 2018 8:59 am 
Offline
Addict
Addict

Joined: Sat Mar 02, 2013 9:17 am
Posts: 931
I like the way you look at it.
A stable and cool basic´s engine is the key to a successful tool
Very good work !

_________________
http://www.nachtoptik.de


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

All times are UTC + 1 hour


Who is online

Users browsing this forum: No registered users and 6 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