Draw three or nine part image
Posted: Thu Oct 04, 2012 7:04 am
Maybe someone can use this code. I was just curious how to do the asm for the x64 calling convention.
It uses Cocoa to draw a three or nine part image.
Images that are not on the corners are tiled, not stretched, to fill the required space.
All image parts need to be passed as ImageID.
The procedures can be used between StartDrawing() and StopDrawing() .
It uses Cocoa to draw a three or nine part image.
Images that are not on the corners are tiled, not stretched, to fill the required space.
All image parts need to be passed as ImageID.
The procedures can be used between StartDrawing() and StopDrawing() .
Code: Select all
Procedure DrawThreePartImage_addr()
ProcedureReturn ?dtpi_start
dtpi_start:
!extern _NSDrawThreePartImage
CompilerIf #PB_Compiler_Processor = #PB_Processor_x64
!sub rsp, 40
!movq [rsp ], xmm0
!movq [rsp + 8], xmm1
!movq [rsp + 16], xmm2
!movq [rsp + 24], xmm3
!mov r8, 2
!mov eax, 1
!cvtsi2sd xmm0, eax
!xor r9, r9
!call _NSDrawThreePartImage
!add rsp, 40
CompilerElse
!lea edx, [esp + 4]
!sub esp, 44
!mov ecx, 28
!dtpi_loop_x32:
!mov eax, [edx + ecx]
!mov [esp + ecx], eax
!sub ecx, 4
!jnc dtpi_loop_x32
!mov dword [esp + 32], 2
!mov dword [esp + 36], 0x3f800000
!mov dword [esp + 40], 0
!call _NSDrawThreePartImage
!add esp, 44
CompilerEndIf
!ret
EndProcedure
Procedure DrawNinePartImage_addr()
ProcedureReturn ?dnpi_start
dnpi_start:
!extern _NSDrawNinePartImage
CompilerIf #PB_Compiler_Processor = #PB_Processor_x64
!sub rsp, 88
!movq [rsp ], xmm0
!movq [rsp + 8], xmm1
!movq [rsp + 16], xmm2
!movq [rsp + 24], xmm3
!mov rax, [rsp + 96]
!mov [rsp + 32], rax
!mov rax, [rsp + 96 + 8]
!mov [rsp + 40], rax
!mov rax, [rsp + 96 + 16]
!mov [rsp + 48], rax
!mov rax, [rsp + 96 + 24]
!mov [rsp + 56], rax
!mov rax, [rsp + 96 + 32]
!mov [rsp + 64], rax
!mov eax, 1
!cvtsi2sd xmm0, eax
!call _NSDrawNinePartImage
!add rsp, 88
CompilerElse
!lea edx, [esp + 4]
!sub esp, 76
!mov ecx, 48
!dnpi_loop_x32:
!mov eax, [edx + ecx]
!mov [esp + ecx], eax
!sub ecx, 4
!jnc dnpi_loop_x32
!mov dword [esp + 52], 2
!mov dword [esp + 56], 0x3f800000
!mov dword [esp + 60], 0
!call _NSDrawNinePartImage
!add esp, 76
CompilerEndIf
!ret
EndProcedure
CompilerIf #PB_Compiler_Processor = #PB_Processor_x64
Prototype DrawThreePartImage_proto(x.d, y.d, w.d, h.d, i1, i2, i3, vertical = #False)
Prototype DrawNinePartImage_proto(x.d, y.d, w.d, h.d, i1, i2, i3, i4, i5, i6, i7, i8, i9)
CompilerElse
PrototypeC DrawThreePartImage_proto(x.f, y.f, w.f, h.f, i1, i2, i3, vertical = #False)
PrototypeC DrawNinePartImage_proto(x.f, y.f, w.f, h.f, i1, i2, i3, i4, i5, i6, i7, i8, i9)
CompilerEndIf
Global DrawThreePartImage.DrawThreePartImage_proto = DrawThreePartImage_addr()
Global DrawNinePartImage.DrawNinePartImage_proto = DrawNinePartImage_addr()