PDA

View Full Version : Movable Resizable and Flickering


MerlinEl
10-19-2009, 11:09 PM
so ... Im created one rectangle over the max interface which
can be moved (shift click and drag in top or left part)
can be resized (shift click and drag in bottom or right part)

this time is flickering..:hmm: which cause me to beg for help again :cry:


--Resizable Movable Capture Frame WIP
--To move frame press Shift + LMB click on Top or Left part interface, and drag mouse
--To exit frame press RMB click on interface
--To resize press Shift + LMB on Left or Right part interface, and drag mouse

Global mc2FrameTDialog
Global mc2FrameLDialog
Global mc2FrameRDialog
Global mc2FrameBDialog

fn createCaptureFrame frame_scale =
(
if mc2FrameTDialog != undefined do destroyDialog mc2FrameTDialog
if mc2FrameLDialog != undefined do destroyDialog mc2FrameLDialog
if mc2FrameRDialog != undefined do destroyDialog mc2FrameRDialog
if mc2FrameBDialog != undefined do destroyDialog mc2FrameBDialog


local t_size = [ frame_scale.x+8, 8 ]
local l_size = [ 8 , frame_scale.y+8 ]
local r_size = [ 8 , frame_scale.y+8 ]
local b_size = [ frame_scale.x+8, 8 ]

local vs = getViewSize()
local ms = getMAXWindowSize()
local mc = (ms - frame_scale)/2

local t_pos = mc
local l_pos = [0,8]+mc
local r_pos = [frame_scale.x+8,0]+mc
local b_pos = [8,frame_scale.y+8]+mc

rollout mc2FrameLDialog "Left"
(
local dMove = false, DmPos
bitmap bmp_01 "" pos:[0,0] width:8 height:100 bitmap:(BitMap 1 1 color:green)
on mc2FrameLDialog open do (bmp_01.height = mc2FrameLDialog.height)
on mc2FrameLDialog rbuttonup pos do destroyDialog mc2FrameTDialog
-->MoveMode
on mc2FrameLDialog lbuttondown pos do (dMove = true; DmPos = pos)
on mc2FrameLDialog lbuttonup pos do (dMove = false)
on mc2FrameLDialog mouseMove pos do
if dMove and keyboard.shiftPressed do
(
local move_horizontal = mouse.screenpos - DmPos
move_horizontal.y = (getDialogPos mc2FrameLDialog).y
setDialogPos mc2FrameLDialog move_horizontal
setDialogPos mc2FrameTDialog (mouse.screenpos - DmPos)
)
)


rollout mc2FrameRDialog "Right"
(
local dMove = false, DmPos
bitmap bmp_01 "" pos:[0,0] width:8 height:100 bitmap:(BitMap 1 1 color:green)
on mc2FrameRDialog open do (bmp_01.height = mc2FrameRDialog.height)
on mc2FrameRDialog rbuttonup pos do destroyDialog mc2FrameTDialog
-->MoveMode
on mc2FrameRDialog lbuttondown pos do (dMove = true; DmPos = pos)
on mc2FrameRDialog lbuttonup pos do (dMove = false)
on mc2FrameRDialog mouseMove pos do
if dMove and keyboard.shiftPressed do
(
local move_horizontal = mouse.screenpos - DmPos
move_horizontal.y = (getDialogPos mc2FrameRDialog).y
setDialogPos mc2FrameRDialog move_horizontal
mc2FrameTDialog.updateFramesSize (mouse.screenpos - DmPos) axis:#Right
)
)


rollout mc2FrameBDialog "Bottom"
(
local dMove = false, DmPos
bitmap bmp_01 "" pos:[0,0] width:100 height:8 bitmap:(BitMap 1 1 color:green)
on mc2FrameBDialog open do (bmp_01.width = mc2FrameBDialog.width)
on mc2FrameBDialog rbuttonup pos do destroyDialog mc2FrameTDialog
-->MoveMode
on mc2FrameBDialog lbuttondown pos do (dMove = true; DmPos = pos)
on mc2FrameBDialog lbuttonup pos do (dMove = false)
on mc2FrameBDialog mouseMove pos do
if dMove and keyboard.shiftPressed do
(
local move_vertical = mouse.screenpos - DmPos
move_vertical.x = (getDialogPos mc2FrameBDialog).x
setDialogPos mc2FrameBDialog move_vertical
mc2FrameTDialog.updateFramesSize (mouse.screenpos - DmPos) axis:#Bottom
)
)


rollout mc2FrameTDialog "Top"
(
local dMove = false, DmPos, ds = sysInfo.DesktopSize, fs
bitmap bmp_01 "" pos:[0,0] width:100 height:8 bitmap:(BitMap 1 1 color:green)
-->Funtions
fn moveFrameToMousePos =
(
local mp = mouse.screenpos
if mp.x + fs.x/2 < fs.x or mp.x + fs.x/2 > ds.x do return false
if mp.y + fs.y/2 < fs.y or mp.y + fs.y/2 > ds.y do return false
if keyboard.shiftPressed do return false
--format "mouse pos:%\trolout size:%\n" mp rs

setDialogPos mc2FrameTDialog (mp + -[fs.x,fs.y]/2)
setDialogPos mc2FrameLDialog (mp + -[fs.x,fs.y-16]/2)
setDialogPos mc2FrameRDialog (mp + [fs.x,-fs.y]/2)
setDialogPos mc2FrameBDialog (mp + [-fs.x+16,fs.y]/2)
)
fn updateFramesPos pos =
(
setDialogPos mc2FrameRDialog [pos.x+fs.x, pos.y]
setDialogPos mc2FrameLDialog [pos.x, pos.y+8]
setDialogPos mc2FrameBDialog [pos.x+8, pos.y+fs.y]
completeRedraw()
)
fn updateFramesSize pos axis: =
(
case axis of
(
#Bottom:
(
local rp = getDialogPos mc2FrameRDialog
local si = pos.y - rp.y
mc2FrameRDialog.height = si
mc2FrameRDialog.bmp_01.height = si
mc2FrameLDialog.height = si
mc2FrameLDialog.bmp_01.height = si
fs.y = si
)
#Right:
(
local rp = getDialogPos mc2FrameTDialog
local si = pos.x - rp.x
mc2FrameTDialog.width = si
mc2FrameTDialog.bmp_01.width = si
mc2FrameBDialog.width = si
mc2FrameBDialog.bmp_01.width = si
fs.x = si
)
)
completeRedraw()
)
fn closeFrame =
(
if mc2FrameLDialog != undefined do destroyDialog mc2FrameLDialog
if mc2FrameRDialog != undefined do destroyDialog mc2FrameRDialog
if mc2FrameBDialog != undefined do destroyDialog mc2FrameBDialog
if mc2FrameTDialog != undefined do destroyDialog mc2FrameTDialog
)
-->MoveMode
on mc2FrameTDialog lbuttondown pos do (dMove = true; DmPos = pos)
on mc2FrameTDialog lbuttonup pos do (dMove = false)
on mc2FrameTDialog mouseMove pos do (if dMove and keyboard.shiftPressed do setDialogPos mc2FrameTDialog (mouse.screenpos - DmPos))
-->Dialog
on mc2FrameTDialog rbuttonup pos do destroyDialog mc2FrameTDialog
on mc2FrameTDialog open do
(
bmp_01.width = mc2FrameTDialog.width
fs = [mc2FrameTDialog.width, (getDialogSize mc2FrameLDialog).y]
--updateFramesPos()
)
on mc2FrameTDialog close do closeFrame()
-->Actions
on mc2FrameTDialog moved pos do updateFramesPos pos
)
createDialog mc2FrameLDialog pos:[l_pos.x, l_pos.y] width:l_size.x height:l_size.y style:#(#style_sysMenu)
createDialog mc2FrameRDialog pos:[r_pos.x, r_pos.y] width:r_size.x height:r_size.y style:#(#style_sysMenu)
createDialog mc2FrameBDialog pos:[b_pos.x, b_pos.y] width:b_size.x height:b_size.y style:#(#style_sysMenu)
createDialog mc2FrameTDialog pos:[t_pos.x, t_pos.y] width:t_size.x height:t_size.y style:#(#style_sysMenu)
)

createCaptureFrame [280,180]



If is there other way to do it , Im will be pleased to hear it :-)

sory for my bad english..

denisT
10-19-2009, 11:34 PM
how do you want to use it? what is it for?

your solution looks very complicated...

MerlinEl
10-20-2009, 07:36 AM
It is a visual frame for grab Max screen area for making Tutorials.

here is dotnet recorder (almost done)


if printScreenTestDialog != undefined do destroyDialog printScreenTestDialog

rollout printScreenTestDialog "" width:256 height:88

(

local cnt = 0, root = GetDir #image + "\\", frame_array = #()

Timer tmr_print "Timer" pos:[220,56] width:24 height:24 enabled:true interval:1000 active:false

button btn_start "Start" pos:[8,32] width:56 height:20

spinner spn_fps "FPS:" pos:[96,60] width:64 height:16 range:[1,100,1] type:#integer scale:1

button btn_stop "Stop" pos:[192,32] width:56 height:20

button btn_dir "Dir" pos:[8,60] width:56 height:20

GroupBox grp1 "" pos:[4,0] width:248 height:84

label lbl_info "Captured Frames: 0" pos:[76,36] width:108 height:16

button btn_close "Close" pos:[192,60] width:56 height:20

spinner spn_w "w" pos:[96,12] width:64 height:16 range:[64,5000,256] type:#integer scale:1

spinner spn_h "h" pos:[184,12] width:64 height:16 range:[64,5000,256] type:#integer scale:1

checkbox chk_crop "Croping:" pos:[8,12] width:72 height:16

fn CropImage OriginalImage TopLeft BottomRight =

(

btmCropped = (dotNetObject "Drawing.Bitmap" (BottomRight.Y - TopLeft.Y) (BottomRight.X - TopLeft.X)) --Create new bitmap object

grpOriginal = (dotNetClass "Drawing.Graphics").fromImage btmCropped --Create new Graphics object



newRect = dotnetObject "Drawing.rectangle" 0 0 btmCropped.Width btmCropped.Height

graphicsUnit = dotNetClass "Drawing.GraphicsUnit"

grpOriginal.DrawImage OriginalImage newRect TopLeft.X TopLeft.Y btmCropped.Width btmCropped.Height graphicsUnit.Pixel



Return btmCropped

)

fn crop img Hq:false = -- Image HighQuality

(

local w=spn_w.value

local h=spn_h.value

--SD.Bitmap(Width, Height, OriginalImage.PixelFormat)

local new_img = (dotNetObject "Drawing.Bitmap" w h) --Create new bitmap object

new_img.SetResolution img.HorizontalResolution img.VerticalResolution --copy dpi from img

local graphics_obj = (dotNetClass "Drawing.Graphics").fromImage new_img --Create new Graphics object

if Hq do

(

graphics_obj.SmoothingMode = graphics_obj.SmoothingMode.AntiAlias

graphics_obj.InterpolationMode = graphics_obj.InterpolationMode.HighQualityBicubic

graphics_obj.PixelOffsetMode = graphics_obj.PixelOffsetMode.HighQuality

)



--Graphic.DrawImage(OriginalImage, new SD.Rectangle(0, 0, Width, Height), X, Y, Width, Height, SD.GraphicsUnit.Pixel)

local rect = (dotnetObject "Drawing.rectangle" 0 0 img.width img.height)

local x = 10

local y = 10

print rect

graphics_obj.drawImage img rect X Y w h --graphics_obj.GraphicsUnit.Pixel)



/*

MemoryStream ms = new MemoryStream();

bmp.Save(ms, OriginalImage.RawFormat);

return ms.GetBuffer()

*/



graphics_obj.dispose()

return new_img



)

fn printScreen file_name =

(

(dotnetClass "SendKeys").SendWait "{%} {PRTSC}"-- ("{PRTSC}")

(dotnetClass "Clipboard").ContainsImage()

local img = (dotnetClass "Clipboard").getImage() --dotNetObject:System.Drawing.Bitmap



if chk_crop.checked do

(

local s1 = [img.width, img.height] --image size

local s2 = [spn_w.value, spn_h.value] --new image size



if s1.x < s2.x or s1.y < s2.y do

(

--img.dispose()

print "Cant crop more! Image A is smaler than Image B"

return false

)

--define new image rect in pos [0, 0]

local s2_min = [0, 0] --min TL

local s2_max = [s2.x, s2.y] --max BR



--move rect center in to pos [0, 0]

s2_min = -[s2.x, s2.y]/2

s2_max = [s2.x, s2.y]/2

--move rect center in to mouse.screenpos

local mp = mouse.screenpos

local TopLeft = (mp + s2_min)

local BottomRight= (mp + s2_max)



--format "min:%\tmax:%\tnew min:%\tnew max:%\n" s2_min s2_max (mp + (s2_min/2)) (mp + (s2_max/2))

--or define new image rect from original image center



img = CropImage img TopLeft BottomRight

)



if img != undefined

then

(

img.tag = file_name

frame_array += #(img)

)

else (print "Error: Cant Grab Screen")

)

fn saveCapturedFrames =

(

local file_format = (dotNetClass "Drawing.Imaging.ImageFormat").jpeg

for i in frame_array do

(

i.Save i.tag file_format

i.dispose()

)

)

on printScreenTestDialog open do

(

theFileName = GetDir #image + "\\ImageClipboard.jpg"

)

on tmr_print tick do

(

cnt +=1

tmr_print.interval = 1000 / spn_fps.value

file_name = root + cnt as string + "printScreen.jpg"

printScreen file_name

lbl_info.text = "Captured Frames: "+ cnt as string

)

on btn_start pressed do

(

cnt = 0

frame_array = #()

tmr_print.active = true

)

on btn_stop pressed do

(

tmr_print.active = false

if frame_array.count != 0 and (querybox "Do you wish to save Captured Frames?" title:" Viewport Recorder:") do saveCapturedFrames()

)

on btn_dir pressed do

(

ShellLaunch root ""

)

on btn_close pressed do

(

destroyDialog printScreenTestDialog

)

)

createDialog printScreenTestDialog pos:[200,200] style:#(#style_border)

CGTalk Moderation
10-20-2009, 07:36 AM
This thread has been automatically closed as it remained inactive for 12 months. If you wish to continue the discussion, please create a new thread in the appropriate forum.