# HG changeset patch # User Michael Pavone # Date 1405999658 25200 # Node ID 0ec4f1b68a38f2c2a9d6545448a5751b52f173e7 # Parent 361a449a7235398962e3136ce511582322f70e2b Add copyTo method to texture that allows copying to a rectangular region on the renderer rather than stretching to fit the entire renderer diff -r 361a449a7235 -r 0ec4f1b68a38 modules/sdl.tp --- a/modules/sdl.tp Mon Jul 21 20:24:50 2014 -0700 +++ b/modules/sdl.tp Mon Jul 21 20:27:38 2014 -0700 @@ -142,6 +142,17 @@ intret } + llMessage: copyTo withVars: { + dst <- object ptr + dstOpaque <- cpointer ptr + intret <- obj_int32 ptr + } andCode: :dst { + dstOpaque <- (mcall: _rectPointer 1 dst) castTo: (cpointer ptr) + intret <- make_object: (addr_of: obj_int32_meta) NULL 0 + intret num!: (SDL_RenderCopy: renderer texture NULL (dstOpaque val)) + intret + } + llMessage: destroy withVars: {} andCode: { SDL_DestroyTexture: texture true @@ -328,6 +339,44 @@ true } + rect:size <- :x y :w h { + getter <- macro: :propName { + quote: (llMessage: propName withVars: { + intret <- obj_int32 ptr + } andCode: { + intret <- make_object: (addr_of: obj_int32_meta) NULL 0 + intret num!: ((addr_of: rect) propName) + intret + }) + } + setter <- macro: :propName { + quote: (llMessage: propName withVars: { + v <- obj_int32 ptr + } andCode: :v { + (addr_of: rect) propName: (v num) + self + }) + } + (((#{ + llProperty: rect withType: SDL_Rect + getter: x + setter: x! + getter: y + setter: y! + getter: w + setter: w! + getter: h + setter: h! + llMessage: _rectPointer withVars: { + retptr <- cpointer ptr + } andCode: { + retptr <- make_object: (addr_of: cpointer_meta) NULL 0 + retptr val!: (addr_of: (self rect)) + retptr + } + } x!: x) y!: y) w!: w) h!: h + } + llMessage: getError withVars: { str <- string ptr rawstr <- char ptr diff -r 361a449a7235 -r 0ec4f1b68a38 samples/sdl.tp --- a/samples/sdl.tp Mon Jul 21 20:24:50 2014 -0700 +++ b/samples/sdl.tp Mon Jul 21 20:27:38 2014 -0700 @@ -16,6 +16,7 @@ print: "Failed to copy texture to renderer: " . (sdl getError) . "\n" } surf free + tex copyTo: (sdl rect: 160 120 size: 320 224) render present sdl delay: 3000u32 tex destroy