Advertisement
deseven

simpleCanvasIndicator

Apr 30th, 2015
637
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. Enumeration
  2.   #wnd
  3.   #canvas
  4.   #plus
  5.   #minus
  6.   #aNone
  7.   #aCorner
  8.   #aCenter
  9.   #aSlideHor
  10.   #aSlideVer
  11. EndEnumeration
  12.  
  13. pointImg = 0
  14. points.b = 5
  15. newPoints.b = 5
  16. isAnimating = #False
  17.  
  18. UseJPEGImageDecoder()
  19. UsePNGImageDecoder()
  20.  
  21. Procedure drawPoints(points.b,animate.b = #False,aPlus.b = #True,aStep.b = 0)
  22.   Shared pointImg
  23.   StartDrawing(CanvasOutput(#canvas))
  24.   Box(0,0,400,40,$ffffff)
  25.   For i = 0 To points-1
  26.     If i = points-1 And animate
  27.       If aPlus
  28.         If GetGadgetState(#aCorner)
  29.           If IsImage(pointImg)
  30.             DrawImage(ImageID(pointImg),i*40+5,5,3*aStep,3*aStep)
  31.           Else
  32.             Box(i*40+5,5,3*aStep,3*aStep,$ff0000)
  33.           EndIf
  34.         ElseIf GetGadgetState(#aCenter)
  35.           If IsImage(pointImg)
  36.             DrawImage(ImageID(pointImg),i*40+5+(30-3*aStep)/2,5+(30-3*aStep)/2,3*aStep,3*aStep)
  37.           Else
  38.             Box(i*40+5+(30-3*aStep)/2,5+(30-3*aStep)/2,3*aStep,3*aStep,RGB(255-aStep*25,255-aStep*25,255))
  39.           EndIf
  40.         ElseIf GetGadgetState(#aSlideHor)
  41.           If IsImage(pointImg)
  42.             DrawImage(ImageID(pointImg),i*40+5+(400-i*40+5)/aStep+1,5,30,30)
  43.           Else
  44.             Box(i*40+5+(400-i*40+5)/aStep+1,5,30,30,RGB(255-aStep*25,255-aStep*25,255))
  45.           EndIf
  46.         ElseIf GetGadgetState(#aSlideVer)
  47.           If IsImage(pointImg)
  48.             DrawImage(ImageID(pointImg),i*40+5,-25+aStep*3,30,30)
  49.           Else
  50.             Box(i*40+5,-25+aStep*3,30,30,RGB(255-aStep*25,255-aStep*25,255))
  51.           EndIf
  52.         EndIf
  53.       Else
  54.         If GetGadgetState(#aCorner)
  55.           If IsImage(pointImg)
  56.             DrawImage(ImageID(pointImg),i*40+5,5,30/aStep,30/aStep)
  57.           Else
  58.             Box(i*40+5,5,30/aStep,30/aStep,$ff0000)
  59.           EndIf
  60.         ElseIf GetGadgetState(#aCenter)
  61.           If IsImage(pointImg)
  62.             DrawImage(ImageID(pointImg),i*40+5+(30-30/aStep)/2,5+(30-30/aStep)/2,30/aStep,30/aStep)
  63.           Else
  64.             Box(i*40+5+(30-30/aStep)/2,5+(30-30/aStep)/2,30/aStep,30/aStep,RGB(aStep*25,aStep*25,255))
  65.           EndIf
  66.         ElseIf GetGadgetState(#aSlideHor)
  67.           If IsImage(pointImg)
  68.             DrawImage(ImageID(pointImg),400-(400-i*40+5)/aStep,5,30,30)
  69.           Else
  70.             Box(400-(400-i*40+5)/aStep,5,30,30,RGB(aStep*25,aStep*25,255))
  71.           EndIf
  72.         ElseIf GetGadgetState(#aSlideVer)
  73.           If IsImage(pointImg)
  74.             DrawImage(ImageID(pointImg),i*40+5,5+aStep*3,30,30)
  75.           Else
  76.             Box(i*40+5,5+aStep*3,30,30,RGB(aStep*25,aStep*25,255))
  77.           EndIf
  78.         EndIf
  79.       EndIf
  80.     ElseIf IsImage(pointImg)
  81.       DrawImage(ImageID(pointImg),i*40+5,5,30,30)
  82.     Else
  83.       Box(i*40+5,5,30,30,$ff0000)
  84.     EndIf
  85.   Next
  86.   StopDrawing()
  87. EndProcedure
  88.  
  89. OpenWindow(#wnd,#PB_Ignore,#PB_Ignore,400,100,"Simple canvas indicator",#PB_Window_ScreenCentered|#PB_Window_SystemMenu)
  90. CanvasGadget(#canvas,0,0,400,40)
  91. ButtonGadget(#plus,0,40,200,40,"+1")
  92. ButtonGadget(#minus,200,40,200,40,"-1")
  93. OptionGadget(#aNone,5,80,75,20,"none")
  94. OptionGadget(#aCorner,80,80,80,20,"corner")
  95. OptionGadget(#aCenter,160,80,80,20,"center")
  96. OptionGadget(#aSlideHor,240,80,80,20,"slide x")
  97. OptionGadget(#aSlideVer,320,80,80,20,"slide y")
  98. SetGadgetState(#aNone,#True)
  99.  
  100. drawPoints(points)
  101.  
  102. Repeat
  103.   ev = WindowEvent()
  104.   If ev
  105.     If EventGadget() = #plus And points+1 <= 10 And EventType() = #PB_EventType_LeftClick
  106.       newPoints = points + 1
  107.       isAnimating = #True
  108.     ElseIf EventGadget() = #minus And points-1 >= 0 And EventType() = #PB_EventType_LeftClick
  109.       newPoints = points - 1
  110.       isAnimating = #True
  111.     ElseIf EventGadget() = #canvas And EventType() = #PB_EventType_LeftClick
  112.       If IsImage(pointImg) : FreeImage(pointImg) : EndIf
  113.       If LoadImage(pointImg,OpenFileRequester("Choose point image","","Image | *.bmp;*.jpg;*.png",0))
  114.         If IsImage(pointImg) : ResizeImage(pointImg,30,30,#PB_Image_Smooth) : EndIf
  115.       EndIf
  116.       drawPoints(points)
  117.     EndIf
  118.   ElseIf isAnimating
  119.     If aStep = 10
  120.       isAnimating = #False
  121.       aStep = 0
  122.       points = newPoints
  123.       drawPoints(points)
  124.     Else
  125.       aStep + 1
  126.       If newPoints > points
  127.         drawPoints(newPoints,#True,#True,aStep)
  128.       Else
  129.         drawPoints(points,#True,#False,aStep)
  130.       EndIf
  131.     EndIf
  132.     Delay(15)
  133.   Else
  134.     Delay(10)
  135.   EndIf
  136. Until ev = #PB_Event_CloseWindow
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement