AutoHotkey Community

It is currently May 26th, 2012, 8:44 pm

All times are UTC [ DST ]




Post new topic Reply to topic  [ 7 posts ] 
Author Message
PostPosted: August 26th, 2009, 3:53 am 
Offline

Joined: June 9th, 2008, 2:32 am
Posts: 936
Location: Canada
DownLoad


This is designed to allow some one to draw on a desktop with the GDIP functions. Hope you enjoy it.

Any ideas, comments, concerns or Ect appreciated.

CODE: ("Included in Download")
Code:
#SingleInstance, Force   
#NoEnv                                   
#Include, Gdip.ahk
SetBatchLines, -1               
         
Smoother = 5  ; Set between 1-10 For smooth values
; Options
CoordMode, Mouse
CoordMode, Pixel
Pen_Colour = FFFFFF
MySlider = 20
; End of Options


SplashImage, pens\spidergames.bmp, y50, Now Loading (Not Realy I just want you to look at me),, GDIP Desktop Drawer
Loop, 100
{
    Progress, %a_index%
    Sleep, 50
    if a_index = 100
        break
}

SplashImage off
Progress, Off

Gui, Add, Picture, gPannelClick, ColourPannel.bmp
Gui, Add, Text, w100 vColour,
Gui, Add, ListView, BackGroundFFFFFF ReadOnly w30 h30 x50 y180 vMyListView,
Gui, Add , Picture, x10 y180 vState0 gSubRoutine1, pens\PenPressedMulti.Bmp
Gui, Add , Picture, x10 y180 vState1 gSubRoutine1, pens\PenunPressedMulti.Bmp
Gui, Add , Picture, x10 y235 w20 h20 vpic, pic.Bmp
Gui, Add, Slider,  x80 y200 vMySlider gSlider Range1-50 Left AltSubmit Vertical, 20
Gui, Add, Button, gGDELETE, Clear
Gui, Show,, Pallet
GoSub, Pen
Return,

Slider:
GuiControl,,pic, *w%mySlider% *h%mySlider% pic.Bmp
Return,

PannelClick:
while GetKeyState("LButton")
{

MouseGetPos, x, y
PixelGetColor, SelectedColour,%x%, %y%, RGB
GuiControl, +Background%SelectedColour%, MyListView
GuiControl,, Colour,%SelectedColour%
Pen_Colour := SubStr(SelectedColour, 3)

}
Return,

;///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
;///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////***PEN***/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
;///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
Pen:
; Start gdi+
If !pToken := Gdip_Startup()  ; If DLL Did not loaded properly
{
   MsgBox, 48, gdiplus error!, Gdiplus failed to start. Please ensure you have gdiplus on your system
   ExitApp
}
OnExit, Exit


CoordMode, Mouse


GADD:
Gui, 3: -Caption +E0x80000 +LastFound +AlwaysOnTop +ToolWindow +OwnDialogs
Gui, 3: Show, NA
hwnd1 := WinExist()
hbm := CreateDIBSection(A_ScreenWidth, A_ScreenHeight)
hdc := CreateCompatibleDC()
obm := SelectObject(hdc, hbm)
G := Gdip_GraphicsFromHDC(hdc)
Gdip_SetSmoothingMode(G, 4)
Return,

SubRoutine1:
Sleep,1000
GuiControl, Hide, State1
if drawing = 0
 GoSub, GAdd ;  Creates PEN as tool

drawing = 1       ;  tells computer we are now drawing
pPen := Gdip_CreatePen(0xc0(Pen_Colour), myslider)  ; Creates pen tool with the chosen colour and size;
Hotkey, $*LButton, LleftClick, On   
Hotkey, $*LButton Up, LleftClickup, On
Gui, 5:Add, Text,, Click Pen here to`n remove tool
 Gui, 5:Show, x0 y0 w100 h100, Winhold
Return,

ButtonClear:
GoSub, GDELETE
Return,

LleftClick:
Left_Click := True

while Left_Click =1
{
MouseGetpos, NewX, NewY
if lx !=
 Gdip_DrawLine(G, pPen, lx, ly, NewX, NewY)
UpdateLayeredWindow(hwnd1, hdc, 0, 0, A_ScreenWidth, A_ScreenHeight)  ; refresh screen to show drawings
sleep % Smoother
lx = %NewX%
ly = %NewY%
}
lx := ""
ly := ""

if NewX between 0 and 100   ; if mouse is in the selected box Destroy the drawing surface
{
if NewY between 0 and 100
{
Gui, 5:Destroy
Hotkey, $*LButton, LleftClick, off
Hotkey, $*LButton Up, LleftClickUp, off
GuiControl, Show, State1
Return,
}
}

LleftClickup:
Left_Click := False
Return,




GDelete:

; DELETE GRAHPICS SUB
Gui, Submit, NoHide
SelectObject(hdc, obm)

; Now the bitmap may be deleted
   DeleteObject(hbm)

; Also the device context related to the bitmap may be deleted
   DeleteDC(hdc)

; The graphics may now be deleted
   Gdip_DeleteGraphics(G)
Gui, 3:Destroy
UpdateLayeredWindow(hwnd1, hdc, 0, 0, A_ScreenWidth, A_ScreenHeight)
drawing = 0
Return,



;#######################################################################

Exit:
; gdi+ may now be shutdown on exiting the program
Gdip_Shutdown(pToken)
ExitApp
Return

_________________
Image
I know i have 6 legs. It's cuz I'm special.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: August 26th, 2009, 6:30 am 
Offline

Joined: August 8th, 2008, 7:26 pm
Posts: 117
Location: Raahe, Finland
Quote:
Now Loading (Not Realy I just want you to look at me!


Haha

Nice script anyway

Good for digital drawing boards. :lol:

_________________
Hezzu - excuse the english!


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: August 27th, 2009, 1:32 am 
Offline

Joined: June 9th, 2008, 2:32 am
Posts: 936
Location: Canada
lol.

Im still trying to figure out how to smooth the line better. I've tryed drawing with the eclipse but it just draw circles too far apart.

_________________
Image
I know i have 6 legs. It's cuz I'm special.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: August 27th, 2009, 12:48 pm 
a bad way,add pPen2, draw DrawEllipse every points.

Code:
pPen2 := Gdip_CreatePen(0xc0(Pen_Colour), myslider/2)
Gdip_DrawEllipse(G, pPen2, lx-myslider/4, ly-myslider/4, myslider/2, myslider/2)


Report this post
Top
  
Reply with quote  
 Post subject:
PostPosted: August 27th, 2009, 1:12 pm 
Offline

Joined: June 9th, 2008, 2:32 am
Posts: 936
Location: Canada
i just said i tryed that and it didn't work. The circles get spread out too far away.

_________________
Image
I know i have 6 legs. It's cuz I'm special.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: August 27th, 2009, 2:11 pm 
Code:
#SingleInstance, Force   
#NoEnv                                   
#Include, Gdip.ahk
SetBatchLines, -1               
         
Smoother = 5  ; Set between 1-10 For smooth values
; Options
CoordMode, Mouse
CoordMode, Pixel
Pen_Colour = FFFFFF
MySlider = 20
; End of Options


SplashImage, pens\spidergames.bmp, y50, Now Loading (Not Realy I just want you to look at me),, GDIP Desktop Drawer
Loop, 100
{
    Progress, %a_index%
    Sleep, 50
    if a_index = 100
        break
}

SplashImage off
Progress, Off

Gui, Add, Picture, gPannelClick, ColourPannel.bmp
Gui, Add, Text, w100 vColour,
Gui, Add, ListView, BackGroundFFFFFF ReadOnly w30 h30 x50 y180 vMyListView,
Gui, Add , Picture, x10 y180 vState0 gSubRoutine1, pens\PenPressedMulti.Bmp
Gui, Add , Picture, x10 y180 vState1 gSubRoutine1, pens\PenunPressedMulti.Bmp
Gui, Add , Picture, x10 y235 w20 h20 vpic, pic.Bmp
Gui, Add, Slider,  x80 y200 vMySlider gSlider Range1-50 Left AltSubmit Vertical, 20
Gui, Add, Button, gGDELETE, Clear
Gui, Show,, Pallet
GoSub, Pen
Return,

Slider:
GuiControl,,pic, *w%mySlider% *h%mySlider% pic.Bmp
Return,

PannelClick:
while GetKeyState("LButton")
{

MouseGetPos, x, y
PixelGetColor, SelectedColour,%x%, %y%, RGB
GuiControl, +Background%SelectedColour%, MyListView
GuiControl,, Colour,%SelectedColour%
Pen_Colour := SubStr(SelectedColour, 3)

}
Return,

;///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
;///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////***PEN***/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
;///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
Pen:
; Start gdi+
If !pToken := Gdip_Startup()  ; If DLL Did not loaded properly
{
   MsgBox, 48, gdiplus error!, Gdiplus failed to start. Please ensure you have gdiplus on your system
   ExitApp
}
OnExit, Exit


CoordMode, Mouse


GADD:
Gui, 3: -Caption +E0x80000 +LastFound +AlwaysOnTop +ToolWindow +OwnDialogs
Gui, 3: Show, NA
hwnd1 := WinExist()
hbm := CreateDIBSection(A_ScreenWidth, A_ScreenHeight)
hdc := CreateCompatibleDC()
obm := SelectObject(hdc, hbm)
G := Gdip_GraphicsFromHDC(hdc)
Gdip_SetSmoothingMode(G, 4)
Return,

SubRoutine1:
Sleep,1000
GuiControl, Hide, State1
if drawing = 0
 GoSub, GAdd ;  Creates PEN as tool

drawing = 1       ;  tells computer we are now drawing
;
pPen := Gdip_CreatePen(0xc0(Pen_Colour), myslider)  ; Creates pen tool with the chosen colour and size;
pPen2 := Gdip_CreatePen(0xc0(Pen_Colour), myslider/2)
;
Hotkey, $*LButton, LleftClick, On   
Hotkey, $*LButton Up, LleftClickup, On
Gui, 5:Add, Text,, Click Pen here to`n remove tool
 Gui, 5:Show, x0 y0 w100 h100, Winhold
Return,

ButtonClear:
GoSub, GDELETE
Return,

LleftClick:
Left_Click := True

while Left_Click =1
{
MouseGetpos, NewX, NewY
if lx !=
;
{
 Gdip_DrawLine(G, pPen, lx, ly, NewX, NewY)
 Gdip_DrawEllipse(G, pPen2, lx-myslider/4, ly-myslider/4, myslider/2, myslider/2)
 }
 ;
UpdateLayeredWindow(hwnd1, hdc, 0, 0, A_ScreenWidth, A_ScreenHeight)  ; refresh screen to show drawings
sleep % Smoother
lx = %NewX%
ly = %NewY%
}
lx := ""
ly := ""

if NewX between 0 and 100   ; if mouse is in the selected box Destroy the drawing surface
{
if NewY between 0 and 100
{
Gui, 5:Destroy
Hotkey, $*LButton, LleftClick, off
Hotkey, $*LButton Up, LleftClickUp, off
GuiControl, Show, State1
Return,
}
}

LleftClickup:
Left_Click := False
Return,




GDelete:

; DELETE GRAHPICS SUB
Gui, Submit, NoHide
SelectObject(hdc, obm)

; Now the bitmap may be deleted
   DeleteObject(hbm)

; Also the device context related to the bitmap may be deleted
   DeleteDC(hdc)

; The graphics may now be deleted
   Gdip_DeleteGraphics(G)
Gui, 3:Destroy
UpdateLayeredWindow(hwnd1, hdc, 0, 0, A_ScreenWidth, A_ScreenHeight)
drawing = 0
Return,



;#######################################################################

Exit:
; gdi+ may now be shutdown on exiting the program
Gdip_Shutdown(pToken)
ExitApp
Return


Report this post
Top
  
Reply with quote  
 Post subject:
PostPosted: August 27th, 2009, 8:27 pm 
Offline

Joined: June 9th, 2008, 2:32 am
Posts: 936
Location: Canada
I tryed somethign similar to that a recieved the same results. The darker circles inside the line at "pauses" Is strange looking. Is there a way to set opasity to 100%? (Make it non- see through)

_________________
Image
I know i have 6 legs. It's cuz I'm special.


Report this post
Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 7 posts ] 

All times are UTC [ DST ]


Who is online

Users browsing this forum: Blackholyman, RoAltmann, Yahoo [Bot] and 10 guests


You can post new topics in this forum
You can reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Powered by phpBB® Forum Software © phpBB Group