Sign in to follow this  
Followers 0
picea892

Control Shadow

5 posts in this topic

#1 ·  Posted (edited)

A while ago I was experimenting with shadows for controls. This is as far as I took it. Never did use it for a project but thought I'd share the work, perhaps someone can use it one day.

#include <GUIConstantsEx.au3>
#include <GUIConstants.au3>
#include <Math.au3>
#include <GDIPlus.au3>
commonbck()

Func commonbck()
    $Gui = GUICreate("Control Shadow", 460,400,-1,-1)
    GUICtrlCreatePic(StringLeft(@AutoItExe,StringLen(@AutoItExe)-12)&"\Examples\GUI\msoobe.jpg",0,0,460,400)
    GUICtrlSetState(-1,$GUI_DISABLE)
$edit=GUICtrlCreateEdit("test",100,100,200,100)
   shadedline($Gui,$edit,20)
   $but=GUICtrlCreatecombo("test",20,100,60,50)
    GUICtrlSetData(-1, "item2|item3", "item3") 
   shadedline($Gui,$but,10)
EndFunc
GUISetState()

While 1
sleep(10)
    Switch GUIGetMsg()
        Case $GUI_EVENT_CLOSE
            Exit
    EndSwitch
WEnd

Func shadedline($window,$control,$len)
    _GDIPlus_Startup()
    $radius=$len
    $contpos=controlGetPos($window,"",$control)
    $right=$contpos[2]+$radius
    $bottom=$contpos[3]
    $conthwd = GUICtrlGetHandle($control)
    $trans = GUICtrlCreatePic("", $contpos[0], $contpos[1],$right,$bottom)
    $hwd = GUICtrlGetHandle($trans)
    $hGraphic = _GDIPlus_GraphicsCreateFromHWND($hwd)
    $hBitmap1 = _GDIPlus_BitmapCreateFromGraphics($right+$radius,$bottom+$radius, $hGraphic)
    $hImage1=_GDIPlus_ImageGetGraphicsContext($hBitmap1)
    _GDIPlus_GraphicsSetSmoothingMode($hGraphic, 4)
$count=3
$previous =0
$previous2 =0
$go=0
Local $f = StringSplit('0x05000000|0x08000000|0x11000000|0x14000000|0x18000000|0x21000000|0x24000000|0x28000000|0x32000000|0x36000000|0x40000000|0x45000000|0x50000000|0x55000000|0x60000000|0x65000000|0x70000000', '|')
for $p = $right to $right-$len step -1
ConsoleWrite($p&@crlf)
  if $go<UBound($f) then
    $hPen2=_GDIPlus_PenCreate(BitOR($f[$go],0x000000),1)
Else
    $hPen2=_GDIPlus_PenCreate(BitOR(0x80000000,0x000000),1)
EndIf
    _GDIPlus_GraphicsDrawLine($hImage1,$p,1,$p,$bottom-1,$hPen2)
    _GDIPlus_GraphicsDrawLine($hImage1,$right-$radius, $bottom+$radius-$go,$p,$bottom,$hPen2)
  
 _GDIPlus_PenDispose($hPen2)
 $go=$go+1
Next
$hPen2=_GDIPlus_PenCreate(BitOR(0x70000000,0x000000),1)
_GDIPlus_GraphicsDrawLine($hImage1,$right-$radius-1,$bottom-1,$right-$radius,$bottom,$hPen2)
 _GDIPlus_PenDispose($hPen2)
$count=3
$previous =0
$previous2 =0
$go=0
for $p = $bottom to $bottom-$len step -1
  if $go<UBound($f) then
    $hPen2=_GDIPlus_PenCreate(BitOR($f[$go],0x000000),1)
Else
    $hPen2=_GDIPlus_PenCreate(BitOR(0x80000000,0x000000),1)
EndIf

    _GDIPlus_GraphicsDrawLine($hImage1,0,$p+$radius,$right-$radius-1,$p+$radius,$hPen2)
 _GDIPlus_PenDispose($hPen2)
  $go=$go+1
Next
    _GDIPlus_GraphicsSetSmoothingMode($hImage1, 2)
    $hBMP1 = _GDIPlus_BitmapCreateHBITMAPFromBitmap($hBitmap1)
    _WinAPI_DeleteObject(GUICtrlSendMsg($trans, 0x0172, 0, $hBMP1))
    _GDIPlus_GraphicsDispose($hImage1)
    _WinAPI_DeleteObject($hBMP1)
    _GDIPlus_BitmapDispose($hBitmap1)
    _GDIPlus_GraphicsDispose($hGraphic)
    _GDIPlus_Shutdown()
EndFunc
Edited by picea892

Share this post


Link to post
Share on other sites



Thats pretty cool :).

Try making the shadow more realistic. ;)


Minesweeper

A minesweeper game created in autoit, source available.

_Mouse_UDF

An UDF for registering functions to mouse events, made in pure autoit.

2D Hitbox Editor

A 2D hitbox editor for quick creation of 2D sphere and rectangle hitboxes.

Share this post


Link to post
Share on other sites

Yes, that was why I stopped.

Not sure if it was my math skills, my coding technique or my artistic ability that was holding me back but I was having trouble making it look realistic.

Perhaps others can build on my effort but I'm at a loss at how to make it more realistic.

Share this post


Link to post
Share on other sites

Hey ! she's pretty your little shadow ! Posted Image


AutoIt 3.3.14.2 X86 - SciTE 3.6.0WIN 8.1 X64 - Other Example Scripts

Share this post


Link to post
Share on other sites

@picea892

Well... Cool, but it would be easier and faster in this way:?

#include <StaticConstants.au3>
#include <WindowsConstants.au3>
#include <GUIConstants.au3>


$hForm1 = GUICreate("Control Shadow", 460, 400, -1, -1)
$iEdit = GUICtrlCreateButton("test", 100, 100, 200, 30)
_GUICtrlShadow(-1)
$iComb = GUICtrlCreateCombo("test", 20, 100, 60, 50)
GUICtrlSetData(-1, "item2|item3", "item3")
_GUICtrlShadow(-1)
GUISetState()

While 1
    Sleep(10)
    Switch GUIGetMsg()
        Case $GUI_EVENT_CLOSE
            Exit
    EndSwitch
WEnd

Func _GUICtrlShadow($iCtrlID = -1)
    Local $aCtrlPos = ControlGetPos("", "", GUICtrlGetHandle($iCtrlID))
    If @error Then Return @error
    Local $iLeft = $aCtrlPos[0], $iTop = $aCtrlPos[1], $iWidth = $aCtrlPos[2], $iHeight = $aCtrlPos[3]

    GUICtrlSetStyle($iCtrlID, -1, $WS_EX_TOPMOST)
    GUICtrlCreateLabel("", $iLeft + 6, $iTop + $iHeight, $iWidth - 2, 4, $WS_DISABLED + $SS_GRAYRECT)
    GUICtrlCreateLabel("", $iLeft + $iWidth, $iTop + 6, 4, $iHeight - 6, $WS_DISABLED + $SS_GRAYRECT)
EndFunc   ;==>_GUICtrlShadow

http://forum.autoitbrasil.com/ (AutoIt v3 Brazil!!!)

Somewhere Out ThereJames Ingram

somewh10.png

dropbo10.pngDownload Dropbox - Simplify your life!
Your virtual HD wherever you go, anywhere!

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0