hello i find a code from D. J. Peters and Kristopher Windsor and Counting_Pine then i modify it according to my need
Code: Select all
' Map Zooming Demo!
' By Kristopher Windsor
#include "fbgfx.bi"
using fb
Type coord
As Double x, y
End Type
Type coordi
As Integer x, y
End Type
Declare Sub _MultiPut(Byval lpTarget As Any Ptr = 0, _
Byval xMidPos As Integer, _
Byval yMidPos As Integer, _
Byval lpSource As Any Ptr, _
Byval xScale As Single = 1, _
Byval yScale As Single = 0, _ 'set to xScale value if not set
Byval Rotate As Single = 0, _
Byval alphavalue As Integer = 255)
Dim As Integer mouse_scroll, mouse_scroll_previous,sx,sy
Dim As Double scale
Dim As any Ptr map
Dim As coordi mouse
Dim As coord mapsize, mapposition, viewportsize, viewportposition 'all coords in pixels; position is topleft pos on screen
Dim As coord zoomtarget, newzoomtarget 'based on mouse coords; but in map coords
ScreenInfo sx,sy
screenres sx,0.995*sy,32,,GFX_SHAPED_WINDOW
Color RGBA(255,0,255,255),RGBA(255,0,255,255)
cls
mouse = Type(0, 0)
mapsize = Type(sx,sy)
mapposition = Type(0, 0)
viewportsize = Type(sx, sy)
viewportposition = Type(0, 0)
scale = viewportsize.x / mapsize.x
map = imagecreate(mapsize.x, mapsize.y)
Circle map, (640, 400),50,Rgb(199,1,2),,, 1, F
'or
'line map,(600,400)-(650,450),Rgb(199,1,2),bf
Do
mouse_scroll_previous = mouse_scroll
If Getmouse(mouse.x, mouse.y, mouse_scroll) Then mouse_scroll = mouse_scroll_previous
zoomtarget = Type((mouse.x - viewportposition.x - mapposition.x) / scale, _
(mouse.y - viewportposition.y - mapposition.y) / scale)
If mouse_scroll <> mouse_scroll_previous and point(mouse.x,mouse.y)=Rgb(199,1,2) Then
Select Case mouse_scroll - mouse_scroll_previous
Case Is < 0
scale /= 1.1
Case Is > 0
scale *= 1.1
End Select
If scale < .05 Then scale = .05
If scale > 5 Then scale = 5
newzoomtarget = Type((mouse.x - viewportposition.x - mapposition.x) / scale, _
(mouse.y - viewportposition.y - mapposition.y) / scale)
With mapposition
.x -= (zoomtarget.x - newzoomtarget.x) * scale
.y -= (zoomtarget.y - newzoomtarget.y) * scale
End With
End If
Screenlock
Cls
_multiput(, _
viewportposition.x + mapsize.x * scale / 2 + mapposition.x, _ ' +mapsize.x * scale / 2 because multiput wants to center coords
viewportposition.y + mapsize.y * scale / 2 + mapposition.y, _
map, scale, scale)
Screenunlock
Sleep(10, 1)
Loop
imagedestroy(map)
' Multiput by Joshy (D. J. Peters)
' Alpha Blending by Counting_Pine
' Above said functions combined by Kristopher Windsor
'multiput(target, x, y, source, scale,, rotate, alpha)
Sub _MultiPut(Byval lpTarget As Any Ptr = 0, _
Byval xMidPos As Integer, _
Byval yMidPos As Integer, _
Byval lpSource As Any Ptr, _
Byval xScale As Single = 1, _
Byval yScale As Single = 0, _ 'set to xScale value if not set
Byval Rotate As Single = 0, _
Byval alphavalue As Integer = 255)
If alphavalue < -1 Or alphavalue > 255 Then Exit Sub
If xScale < 0.001 Then xScale = 0.001
If yScale = 0 Then yScale = xScale
If yScale < 0.001 Then yScale = 0.001
Dim As Integer MustRotate, MustLock
'variables for the alpha blending
Dim As Uinteger srb = Any
Dim As Uinteger drb = Any
Dim As Uinteger rb = Any
Dim As Uinteger sr = Any, sg = Any, sb = Any, sa = Any, sa2 = Any
Dim As Uinteger dr = Any, dg = Any, db = Any, da = Any, da2 = Any
Dim As Uinteger r = Any, g = Any, b = Any, a = Any
If lpTarget= 0 Then MustLock = 1
If Rotate <> 0 Then MustRotate = 1
Dim As Integer TargetWidth,TargetHeight,TargetPitch
If MustLock Then
Screeninfo _
TargetWidth , _
TargetHeight,,, _
TargetPitch
lpTarget=Screenptr
Else
TargetWidth = Cptr(Uinteger Ptr,lpTarget)[2]
TargetHeight = Cptr(Uinteger Ptr,lpTarget)[3]
TargetPitch = Cptr(Uinteger Ptr,lpTarget)[4]
lpTarget += 32
End If
Dim As Integer SourceWidth,SourceHeight,SourcePitch
If Cptr(Integer Ptr,lpSource)[0] = 7 Then
SourceWidth = Cptr(Uinteger Ptr,lpSource)[2]
SourceHeight = Cptr(Uinteger Ptr,lpSource)[3]
SourcePitch = Cptr(Uinteger Ptr,lpSource)[4]
lpSource += 32
Else
SourceWidth = Cptr(Ushort Ptr,lpSource)[0] Shr 3
SourceHeight = Cptr(Ushort Ptr,lpSource)[1]
SourcePitch = SourceWidth
lpSource += 2
End If
#define xs 0 'screen
#define ys 1
#define xt 2 'texture
#define yt 3
Dim As Single Points(3,3)
points(0,xs)=-SourceWidth/2 * xScale
points(1,xs)= SourceWidth/2 * xScale
points(2,xs)= points(1,xs)
points(3,xs)= points(0,xs)
points(0,ys)=-SourceHeight/2 * yScale
points(1,ys)= points(0,ys)
points(2,ys)= SourceHeight/2 * yScale
points(3,ys)= points(2,ys)
points(1,xt)= SourceWidth-1
points(2,xt)= points(1,xt)
points(2,yt)= SourceHeight-1
points(3,yt)= points(2,yt)
Dim As Uinteger i
Dim As Single x,y
If MustRotate Then
For i=0 To 3
x=points(i,xs)*Cos(Rotate) - points(i,ys)*Sin(Rotate)
y=points(i,xs)*Sin(Rotate) + points(i,ys)*Cos(Rotate)
points(i,xs)=x:points(i,ys)=y
Next
End If
Dim As Integer yStart,yEnd,xStart,xEnd
yStart=100000:yEnd=-yStart:xStart=yStart:xEnd=yEnd
#define LI 0 'LeftIndex
#define RI 1 'RightIndex
#define IND 0 'Index
#define NIND 1 'NextIndex
Dim As Integer CNS(1,1) 'Counters
For i=0 To 3
points(i,xs)=Int(points(i,xs)+xMidPos)
points(i,ys)=Int(points(i,ys)+yMidPos)
If points(i,ys)<yStart Then yStart=points(i,ys):CNS(LI,IND)=i
If points(i,ys)>yEnd Then yEnd =points(i,ys)
If points(i,xs)<xStart Then xStart=points(i,xs)
If points(i,xs)>xEnd Then xEnd =points(i,xs)
Next
If yStart =yEnd Then Exit Sub
If yStart>=TargetHeight Then Exit Sub
If yEnd <0 Then Exit Sub
If xStart = xEnd Then Exit Sub
If xStart>=TargetWidth Then Exit Sub
If xEnd <0 Then Exit Sub
Dim As Ubyte Ptr t1,s1
Dim As Ushort Ptr t2,s2
Dim As Uinteger Ptr t4,s4
#define ADD 0
#define CMP 1
#define SET 2
Dim As Integer ACS(1,2) 'add compare and set
ACS(LI,ADD)=-1:ACS(LI,CMP)=-1:ACS(LI,SET)=3
ACS(RI,ADD)= 1:ACS(RI,CMP)= 4:ACS(RI,SET)=0
#define EX 0
#define EU 1
#define EV 2
#define EXS 3
#define EUS 4
#define EVS 5
Dim As Single E(2,6),S(6),Length,uSlope,vSlope
Dim As Integer U,UV,UA,UN,V,VV,VA,VN
' share the same highest point
CNS(RI,IND)=CNS(LI,IND)
' loop from Top to Bottom
While yStart<yEnd
'Scan Left and Right sides together
For i=LI To RI
' bad to read but fast and short ;-)
If yStart=points(CNS(i,IND),ys) Then
CNS(i,NIND)=CNS(i,IND)+ACS(i,Add)
If CNS(i,NIND)=ACS(i,CMP) Then CNS(i,NIND)=ACS(i,SET)
While points(CNS(i,IND),ys) = points(CNS(i,NIND),ys)
CNS(i, IND)=CNS(i,NIND)
CNS(i,NIND)=CNS(i, IND)+ACS(i,Add)
If CNS(i,NIND)=ACS(i,CMP) Then CNS(i,NIND)=ACS(i,SET)
Wend
E(i,EX) = points(CNS(i, IND),xs)
E(i,EU) = points(CNS(i, IND),xt)
E(i,EV) = points(CNS(i, IND),yt)
Length = points(CNS(i,NIND),ys)
Length -= points(CNS(i, IND),ys)
If Length <> 0.0 Then
E(i,EXS) = points(CNS(i, NIND),xs)-E(i,EX):E(i,EXS)/=Length
E(i,EUS) = points(CNS(i, NIND),xt)-E(i,EU):E(i,EUS)/=Length
E(i,EVS) = points(CNS(i, NIND),yt)-E(i,EV):E(i,EVS)/=Length
End If
CNS(i,IND)=CNS(i,NIND)
End If
Next
If (yStart<0) Then Goto SkipScanLine
xStart=E(LI,EX)+0.5:If xStart>=TargetWidth Then Goto SkipScanLine
xEnd =E(RI,EX)-0.5:If xEnd < 0 Then Goto SkipScanLine
If (xStart=xEnd) Then Goto SkipScanLine
Length=xEnd-xStart
uSlope=E(RI,EU)-E(LI,EU):uSlope/=Length
vSlope=E(RI,EV)-E(LI,EV):vSlope/=Length
If xstart<0 Then
Length=Abs(xStart)
U=Int(E(LI,EU)+uSlope*Length)
V=Int(E(LI,EV)+vSlope*Length)
xStart = 0
Else
U=Int(E(LI,EU)):V=Int(E(LI,EV))
End If
If xEnd>=TargetWidth Then xEnd=TargetWidth-1
UV=Int(uSlope):UA=(uSlope-UV)*10000:UN=0
VV=Int(vSlope):VA=(vSlope-VV)*10000:VN=0
xEnd-=xStart
t4=Cptr(Integer Ptr,lpTarget)+yStart*(TargetPitch Shr 2)+xStart:xStart=0
Select Case alphavalue
Case 255
While xStart<xEnd
s4=Cptr(Integer Ptr,lpSource)+V*(SourcePitch Shr 2)+U
If (*s4 And &HFFFFFF) <> &HFF00FF Then *t4 = *s4
U+=UV:UN+=UA:If UN>=10000 Then U+=1:UN-=10000
V+=VV:VN+=VA:If VN>=10000 Then V+=1:VN-=10000
If u<0 Then u=0
If v<0 Then v=0
xStart+=1:t4+=1
Wend
Case -1
While xStart<xEnd
s4=Cptr(Integer Ptr,lpSource)+V*(SourcePitch Shr 2)+U
If (*s4 And &HFFFFFF) <> &HFF00FF Then
'***** start alpha blending
sa = *s4 Shr 24
da = 256 - sa
srb = *s4 And &h00ff00ff
sg = *s4 Xor srb
drb = *t4 And &h00ff00ff
dg = *t4 Xor drb
rb = (drb * da + srb * sa) And &hff00ff00
g = (dg * da + sg * sa) And &h00ff0000
*t4 = (rb Or g) Shr 8 Or &hff000000
'***** end alpha blending
End If
U+=UV:UN+=UA:If UN>=10000 Then U+=1:UN-=10000
V+=VV:VN+=VA:If VN>=10000 Then V+=1:VN-=10000
If u<0 Then u=0
If v<0 Then v=0
xStart+=1:t4+=1
Wend
Case Else
sa = alphavalue
da = 256 - sa
While xStart<xEnd
s4=Cptr(Integer Ptr,lpSource)+V*(SourcePitch Shr 2)+U
If (*s4 And &HFFFFFF) <> &HFF00FF Then
'***** start alpha blending
srb = *s4 And &h00ff00ff
sg = *s4 Xor srb
drb = *t4 And &h00ff00ff
dg = *t4 Xor drb
rb = (drb * da + srb * sa) And &hff00ff00
g = (dg * da + sg * sa) And &h00ff0000
*t4 = (rb Or g) Shr 8 Or &hff000000
'***** end alpha blending
End If
U+=UV:UN+=UA:If UN>=10000 Then U+=1:UN-=10000
V+=VV:VN+=VA:If VN>=10000 Then V+=1:VN-=10000
If u<0 Then u=0
If v<0 Then v=0
xStart+=1:t4+=1
Wend
End Select
SkipScanLine:
E(LI,EX)+=E(LI,EXS):E(LI,EU)+=E(LI,EUS):E(LI,EV)+=E(LI,EVS)
E(RI,EX)+=E(RI,EXS):E(RI,EU)+=E(RI,EUS):E(RI,EV)+=E(RI,EVS)
yStart+=1:If yStart=TargetHeight Then yStart=yEnd 'exit loop
Wend
End Sub