;################################################################; ;# #; ;# Rotina para realizar seleção em uma imagem. #; ;# /openimg - Para escolher uma nova imagem #; ;# Use o mouse para criar nova seleção, mover e redimensionar. #; ;# Autor: Fábio Cerqueira (SteelDay) #; ;# #; ;################################################################; ; Eventos da janela principal menu @rec { sclick: { tokenize 32 %img.Sel if ($chkCenter($mouse.x,$mouse.y,$1,$2,$3,$4)) { set %img.ModSel Move } elseif ($chkRedim($mouse.x,$mouse.y,$1,$2,$3,$4)) { set %img.ModSel Redim $v1 } else { set %img.ModSel New } set %img.X $mouse.x set %img.Y $mouse.y } mouse: { if (!$window(@recB)) || (!$window(@recT)) { window -phB +t @recB 0 0 $window(@rec).w $window(@rec).h window -hpB +t @recT 0 0 $window(@rec).w $window(@rec).h } if (%img.X != $null) && (%img.X != $null) { if (%img.ModSel == New) { set %img.Sel $newSelect(%img.X,%img.Y,$mouse.x,$mouse.y) } elseif (%img.ModSel == Move) { tokenize 32 %img.Sel set %img.Sel $moveSelect($1,$2,$3,$4) } elseif ($gettok(%img.ModSel,1,32) == Redim) { var %ponto = $gettok(%img.ModSel,2,32) tokenize 32 %img.Sel set %img.Sel $redimSelect(%ponto,$mouse.x,$mouse.y,$1,$2,$3,$4) } } } uclick: { if (%img.X != $null) && (%img.X != $null) { tokenize 32 %img.Sel if ($3) && ($4) { window -c @recC window -doCpB +b @recC 0 0 $round($3,0) $round($4,0) drawcopy @recT %img.Sel @recC 0 0 } unset %img.X unset %img.Y } } leave: { if (%img.X != $null) && (%img.X != $null) { unset %img.X unset %img.Y } } Abrir:openimg } ; Evento para janela de seleção menu @recC { sclick: { window -c @recC } Salvar:saveSelect } ;#######################################################; ;# Funções básicas #; ;#######################################################; ; Função de inicio para escolha de nova imagem. alias openImg { if ($shortfn($sfile(C:\*.jpg,Escolha a imagem))) { unset %img.* window -c @rec | window -c @recB | window -c @recT window -CpBdo +t @rec 0 0 $pic($v1).width $pic($v1).height drawpic @rec 0 0 $v1 window -phB +t @recT 0 0 $window(@rec).w $window(@rec).h drawcopy @rec 0 0 $window(@rec).w $window(@rec).h @recT 0 0 } } ; Função para salvar seleção alias saveSelect { mkdir imgCortes if ($$?"Digite um nome para sua imagem:") { drawsave @recC $+(imgCortes\,$v1,.bmp) window -c @recC } } ; Função usada para desenhar a seleção ; Sintaxe: /drawrectp @janela x y w h alias drawrectp { var %j = $1 tokenize 32 $2- drawrect -nrc %j 255 2 $1- drawrect -nfr %j 255 1 $calc($1 - 1) $calc($2 - 1) 5 5 drawrect -nfr %j 255 1 $calc(($1 + $3) - 4) $calc($2 - 1) 5 5 drawrect -nfr %j 255 1 $calc(($1 + $3) - 4) $calc(($2 + $4) - 4) 5 5 drawrect -nfr %j 255 1 $calc($1 - 1) $calc(($2 + $4) - 4) 5 5 drawrect -nfr %j 255 1 $calc(($1 + ($3 / 2)) - 1) $calc($2 - 1) 5 5 drawrect -nfr %j 255 1 $calc(($1 + ($3 / 2)) - 1) $calc(($2 + $4) - 4) 5 5 drawrect -nfr %j 255 1 $calc(($1 + $3) - 4) $calc(($2 + ($4 / 2)) - 4) 5 5 drawrect -nfr %j 255 1 $calc($1 - 1) $calc(($2 + ($4 / 2)) - 4) 5 5 drawrect -nre %j 255 1 $calc(($1 + ($3 / 2)) - 2) $calc(($2 + ($4 / 2)) - 2) 6 6 } ;#######################################################; ;# Funções para o controle da seleção #; ;#######################################################; ; Função para criar nova seleção. (Marca e retorna o valor(Coordenadas e W H) desta seleção) ; Sintaxe: $newSelect(x.sclick,y.sclick,x.mouse,y.mouse) ; /newSelect x.sclick y.sclick x.mouse y.mouse alias newSelect { var %img.TSel = $iif($3 > $1,$1,$3) $iif($4 > $2,$2,$4) $iif($calc($3 - $1) > 0,$v1,$calc($1 - $3)) $iif($calc($4 - $2) > 0,$v1,$calc($2 - $4)) drawcopy @recT 0 0 $window(@rec).w $window(@rec).h @recB 0 0 drawrectp @recB %img.TSel drawcopy -n @recB 0 0 $window(@rec).w $window(@rec).h @rec 0 0 drawdot @rec if ($isid) { return %img.TSel } } ; Função para mover seleção por completo. (Marca e retorna o valor(Coordenadas e W H) desta seleção) ; Sintaxe: $moveSelect(x,y,w,h) ; /moveSelect x y w h ; x y w h, da seleção atual. alias moveSelect { var %img.TSel = $calc($1 + ($mouse.x - (($1 + ($3 / 2)) - 2))) $calc($2 + ($mouse.y - (($2 + ($4 / 2)) - 2))) $3 $4 drawcopy @recT 0 0 $window(@rec).w $window(@rec).h @recB 0 0 drawrectp @recB %img.TSel drawcopy -n @recB 0 0 $window(@rec).w $window(@rec).h @rec 0 0 drawdot @rec if ($isid) { return %img.TSel } } ; Função para redimensionar a seleção (Marca e retorna o valor(Coordenadas e W H) desta seleção) ; Sintaxe: $redimSelect(ponto,x.mouse,y.mouse,x,y,w,h) ; /redimSelect ponto x.mouse y.mouse x y w h ; x y w h, da seleção atual. alias redimSelect { var %p = $1,%mouse.x = $2,%mouse.y = $3,%img.TSel = $4 $5 $6 $7 drawcopy @recT 0 0 $window(@rec).w $window(@rec).h @recB 0 0 ; Movimento para baixo tokenize 32 %img.TSel if ($calc($4 - (%mouse.y - $2)) > 0) && ($istok(1 2 3,%p,32)) { var %img.TSel = $1 %mouse.y $3 $calc($4 - (%mouse.y - $2)) } ; Movimento para direita tokenize 32 %img.TSel if ($calc($3 - (%mouse.x - $1)) > 0) && (($istok(1 7 8,%p,32))) { var %img.TSel = %mouse.x $2 $calc($3 - (%mouse.x - $1)) $4 } ; Movimento para cima tokenize 32 %img.TSel if ($calc($4 - (($2 + $4) - %mouse.y)) > 0) && ($istok(5 6 7,%p,32)) { var %img.TSel = $1 $2 $3 $calc($4 - (($2 + $4) - %mouse.y)) } ; Movimento para esquerda tokenize 32 %img.TSel if ($calc($3 - (($1 + $3) - %mouse.x)) > 0) && (($istok(3 4 5,%p,32))) { var %img.TSel = $1 $2 $calc($3 - (($1 + $3) - %mouse.x)) $4 } drawrectp @recB %img.TSel drawcopy -n @recB 0 0 $window(@rec).w $window(@rec).h @rec 0 0 drawdot @rec if ($isid) { return %img.TSel } } ;#######################################################; ;# Funções para verificações #; ;#######################################################; ; Função para verificar se o clique foi feito no centro da seleção. $true caso verdade. $falso caso falso ; Sintaxe: $chkCenter(x.mouse,y.mouse,x,y,w,h) ; x y w h, da seleção atual. alias chkCenter { return $inrect($1,$2,$calc(($3 + ($5 / 2)) - 2),$calc(($4 + ($6 / 2)) - 2),6,6) } ; Função para verificar que redimensionador foi selecionado ; Conta do canto superior esquerdo 1 (Canto superior esquerdo), 2 (Para Meio Superior) >> e vai sentido horário. Retorna 0 caso n seja selecionado nenhum ; Sintaxe: $chkRedim(x.mouse,y.mouse.,x,y,w,h) ; x y w h, da seleção atual. alias chkRedim { if ($inrect($1,$2,$calc($3 - 1),$calc($4 - 1),5,5)) { return 1 } elseif ($inrect($1,$2,$calc(($3 + ($5 / 2)) - 1),$calc($4 - 1),5,5)) { return 2 } elseif ($inrect($1,$2,$calc(($3 + $5) - 4),$calc($4 - 1),5,5)) { return 3 } elseif ($inrect($1,$2,$calc(($3 + $5) - 4),$calc(($4 + ($6 / 2)) - 4),5,5)) { return 4 } elseif ($inrect($1,$2,$calc(($3 + $5) - 4),$calc(($4 + $6) - 4),5,5)) { return 5 } elseif ($inrect($1,$2,$calc(($3 + ($5 / 2)) - 1),$calc(($4 + $6) - 4),5,5)) { return 6 } elseif ($inrect($1,$2,$calc($3 - 1),$calc(($4 + $6) - 4),5,5)) { return 7 } elseif ($inrect($1,$2,$calc($3 - 1),$calc(($4 + ($6 / 2)) - 4),5,5)) { return 8 } else { return 0 } } ;#######################################################; ;# Eventos #; ;#######################################################; ; Eventos para evitar erro por falta de buffer on *:close:@rec: { window -c @recB | window -c @recT | window -c @recC | unset %img.* } on *:close:@recB: { window -c @rec | window -c @recT | window -c @recC | unset %img.* | var %x = $input(Alguma janela foi fecha de forma inesperada.,oh,Erro!) } on *:close:@recT: { window -c @recB | window -c @rec | window -c @recC | unset %img.* | var %x = $input(Alguma janela foi fecha de forma inesperada.,oh,Erro!) }