Hi all,
I'm getting mixed results with the below (rather messy) code.Errors cropping up on older systems.
Could you all give this code a try, let me know any findings? :) it works fine on my machine and I can't track the problem. I'm thinking its the clipboard code- (To the person who sent me this code: I lost your email, thanks for the code!)
I'm getting mixed results with the below (rather messy) code.Errors cropping up on older systems.
Could you all give this code a try, let me know any findings? :) it works fine on my machine and I can't track the problem. I'm thinking its the clipboard code- (To the person who sent me this code: I lost your email, thanks for the code!)
SuperStrict Framework brl.D3D7Max2D Import brl.Random Import brl.Win32MaxGUI SetGraphicsDriver GLMax2DDriver() Global width:Int=Desktop().width Global height:Int=Desktop().height Global hwnd:Int=QueryGadget(Desktop(),QUERY_HWND) Global window:TGadget=CreateWindow("Test",000,000,width,height,Null,WINDOW_hidden)',Null,15) Global canvas:tgadget=CreateCanvas(0,0,width,height,window,0) SetGraphics CanvasGraphics(canvas) Global pixmap:TPixmap=getpixmapfromwindow() If pixmap=Null Then RuntimeError "Grab Desktop Failed. I fart in your general direction. :P." 'Draw pixmap twice - seems to minimise bugs. DrawPixmap pixmap,0,0 Flip DrawPixmap pixmap,0,0 pixmap=GrabPixmap(0,0,width,height) 'grab again to clear alpha issues. Global topixmap:TPixmap=GrabPixmap(0,0,width-1,height-1);ClearPixels(topixmap,$000000) Global image:Timage=LoadImage(pixmap) 'Draw pixmap twice - seems to minimise bugs. DrawPixmap pixmap,0,0 Flip DrawPixmap pixmap,0,0 'Show window. This will be seamless with the desktop! ShowGadget window ActivateWindow(window) 'For swipe=0 To 0 Local swipe:Float=Rand(0,16) While PollEvent() Select EventID() Case EVENT_GADGETPAINT Case EVENT_WINDOWCLOSE End Case EVENT_APPTERMINATE End Case EVENT_GADGETACTION End Select Wend '------------------------------------------------- 'Execute screen transition! Swapscreens(pixmap,topixmap,40,40,swipe,10) '------------------------------------------------- 'OK, fade in the desktop again SetBlend ALPHABLEND For Local alpha#=0 To 1 Step 0.025 SetRotation 0 SetAlpha alpha DrawImage image,0,0 Flip Delay 30 Next SetBlend 0 'Next 'Hide window. Seamless! HideGadget window End Function Swapscreens(Fromimage:TPixmap,toimage:TPixmap,Xcount:Int,Ycount:Int,style:Int=0,lifemult#=1) GCSuspend() 'disable GC whilst fading. Seems to bring up the speed a little. Local chunk:tchunk Local oldrot#=GetRotation() Type tchunk Field image:TImage Field pixmap:TPixmap Field life# Field rot:Float Field x#,y# Field movex#,movey#=-1 Field xrotspeed#=Rnd(0,10),yrotspeed#=Rnd(0,10) Field xrot#,yrot# Field rotspeed#=Rnd(-12,12) Method Delete() Self.pixmap=Null Self.image=Null End Method End Type Local width:Int=fromimage.width Local height:Int=fromimage.height Local chunklist:TList=New TList Local chunksx:Float=Xcount Local chunksy:Float=Ycount Local chunksizex:Int=Float(width/(chunksx-1)) Local chunksizey:Int=Float(height/(chunksy-1)) Local toimage2:timage=LoadImage(toimage) Local fromimage2:timage=LoadImage(fromimage) DrawImage fromimage2,0,0 Flip For Local x1#=0 To chunksx For Local y1#=0 To chunksy Local startx:Int=(x1*chunksizex) Local starty:Int=(y1*chunksizey) chunk:tchunk=New tchunk chunk.x=startx+(chunksizex/2) chunk.y=starty+(chunksizey/2) If startx+chunksizex<=width And starty+chunksizey<=height Then 'Create image for this chunk! chunk.image=CreateImage(chunksizex,chunksizey) 'Grab from backbuffer into created image. GrabImage(chunk.image,startx,starty) SetImageHandle(chunk.image,chunksizex/2,chunksizey/2) ListAddLast chunklist,chunk chunk.life=1 Local x#=Float(x1/chunksx)*20 Local y#=Float(y1/chunksy)*20 If style=0 Then chunk.life=Abs(x-(chunksx/2.0))+Abs(y-(chunksy/2.0)) If style=1 Then chunk.life=(Abs((chunksx/2.0))+Abs((chunksy/2.0)))-(Abs(x-(chunksx/2.0))+Abs(y-(chunksy/2.0))) If style=2 Then chunk.life=(x+y) If style=3 Then chunk.life=(chunksx-x)+(chunksy-y) If style=4 Then chunk.life=y If style=5 Then chunk.life=(chunksy-y) If style=6 Then chunk.life=Abs(x-(chunksx/2.0)) If style=7 Then chunk.life=Abs(y-(chunksy/2.0)) If style=8 Then chunk.life=chunksx-Abs(x-(chunksx/2.0)) If style=9 Then chunk.life=chunksy-Abs(y-(chunksy/2.0)) If style=10 Then chunk.life=(chunksx+chunksy)-Abs((y+x)-(chunksy+chunksx)/2.0) If style=11 Then chunk.life=Abs((y+x)-(chunksy+chunksx)/2.0) If style=12 Then chunk.life=Abs((Sin(x*10)+Cos(y*20)))*10 If style=13 Then chunk.life=Abs(((1-Sin(x*10))+(1-Cos(y*20))))*10 If style=14 Then chunk.life=Abs((Sin(x*10)-Cos(y*20)))*10 If style=15 Then chunk.life=Abs((-Sin(x*40)+Cos((y*40)+180)))*10 If style=16 Then chunk.life=20-Abs((Sin(x*40)+Cos((y*40))))*10 'chunk.life=(chunk.life/Float((chunksX+chunksY)/2.0))*10.0 chunk.life=Int(chunk.life*5)+1'Int((chunk.life*lifemult)+1) EndIf Next Next Local count:Int Repeat count=0 Cls SetRotation 0 DrawImage toimage2,0,0 Delay 1 For chunk:tchunk=EachIn chunklist SetRotation chunk.rot If chunk.life<0 Then chunk.rot=chunk.rot+chunk.rotspeed EndIf DrawImage chunk.image,chunk.x,chunk.y chunk.life=chunk.life-1;If chunk.life=0 Then chunk.movey=Rnd(-3,-5);chunk.movex=Rnd(-5,5) If chunk.life<0 Then chunk.x=chunk.x+chunk.movex chunk.y=chunk.y+chunk.movey chunk.movey=chunk.movey+.3 EndIf If chunk.x>GraphicsWidth()+chunksizex Or chunk.x<-chunksizex Or chunk.y>GraphicsHeight()+chunksizey Then ListRemove chunklist,chunk;chunk.image=Null; count=count+1 Next Flip True If KeyHit(key_escape) Then End Until count=0 SetRotation oldrot DebugLog chunklist.count() GCResume() End Function Function GetScreenCaptureWidth:Int() Return Width End Function Function GetScreenCaptureHeight:Int() Return Height End Function Function getpixmapfromwindow:TPixmap(hwnd:Int=-1) Extern "Win32" Function GetDIBits(hdc:Int, bitmap:Int, Start:Int, Num:Int, bits:Byte Ptr, lpbi:Byte Ptr, usage:Int) Function CreateCompatibleBitmap(hdc:Int, Width:Int, Height:Int) Function CreateDIBSection(hdc:Int, pbmi:Byte Ptr, usage:Int, Bits:Byte Ptr, hSection:Int, Offset:Int) Function SelectObject(hdc:Int, obj:Int) Function CreateCompatibleDC(hdc:Int) Function GetDesktopWindow() Function GetWindowDC(hwnd:Int) Function GetDeviceCaps(hdc:Int, index:Int) Function DeleteDC(hdc:Int) Function DeleteObject(obj:Int) Function ReleaseDC(hwdn:Int, hdc:Int) Function BitBlt(hdc:Int,x:Int,y:Int,w:Int,h:Int,src_dc:Int,src_x:Int,src_y:Int,dwrop:Int) End Extern ?Win32 Type BITMAPINFO Field biSize:Int Field biWidth:Int Field biHeight:Int Field biPlanes:Short Field biBitCount:Short Field biCompression:Int Field biSizeImage:Int Field biXPelsPerMeter:Int Field biYPelsPerMeter:Int Field biClrUsed:Int Field biClrImportant:Int Field R:Byte Field G:Byte Field B:Byte Field Res:Byte End Type Const HORZRES:Int = 8 Const VERTRES:Int = 10 Local HwndDesktop:Int Local hdcDesktop:Int Local hdcMem:Int Local DesktopWidth:Int Local DesktopHeight:Int Local bmpMem:Int Local info:BITMAPINFO Local FinalPixmap:TPixmap If hwnd=-1 Then HwndDesktop = GetDesktopWindow() Else hwnddesktop=hwnd If Not HwndDesktop Return Null EndIf hdcDesktop = GetWindowDC(HwndDesktop) If Not HdcDesktop Return Null EndIf hdcMem = CreateCompatibleDC(hdcDesktop) If Not HdcMem Return Null EndIf DesktopWidth = GetDeviceCaps(hdcDesktop, HORZRES) DesktopHeight = GetDeviceCaps(hdcDesktop, VERTRES) If DesktopWidth = 0 Or DesktopHeight = 0 Return Null EndIf bmpMem = CreateCompatibleBitmap(hdcDesktop, DesktopWidth, DesktopHeight) If Not BmpMem Return Null EndIf If Not SelectObject(HdcMem, bmpMem) Return Null EndIf info = New BITMAPINFO info.biSize = SizeOf(info) info.biWidth = DesktopWidth info.biHeight = DesktopHeight info.biPlanes = 1 info.biBitCount = 32 info.biCompression = 0 If Not BitBlt(hdcMem,0,0,info.biWidth,info.biHeight, hdcDesktop,0,0,ROP_SRCCOPY) Return Null EndIf FinalPixmap = CreatePixmap(info.biWidth, info.biHeight, PF_BGRA8888) If Not GetDIBits(hdcMem, bmpMem, 0, info.biHeight, FinalPixmap.PixelPtr(0,0), info, 0) Return Null EndIf FinalPixmap = YFlipPixmap(FinalPixmap) DeleteDC(HdcMem) DeleteObject(bmpMem) ReleaseDC(hwndDesktop, hdcDesktop) Return FinalPixmap ? ?Linux Return Null ? ?MacOs Return Null ? End Function