AutoHotkey Homepage AutoHotkey Community
Let's help each other out
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

GDIP Pen Desktop Drawing Tool

 
Reply to topic    AutoHotkey Community Forum Index -> Scripts & Functions
View previous topic :: View next topic  
Author Message
SpiderGames



Joined: 09 Jun 2008
Posts: 936
Location: Canada

PostPosted: Wed Aug 26, 2009 2:53 am    Post subject: GDIP Pen Desktop Drawing Tool Reply with quote

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

_________________

I know i have 6 legs. It's cuz I'm special.
Back to top
View user's profile Send private message Send e-mail Visit poster's website AIM Address Yahoo Messenger MSN Messenger
Hezzu



Joined: 08 Aug 2008
Posts: 117
Location: Raahe, Finland

PostPosted: Wed Aug 26, 2009 5:30 am    Post subject: Reply with quote

Quote:
Now Loading (Not Realy I just want you to look at me!


Haha

Nice script anyway

Good for digital drawing boards. Laughing
_________________
Hezzu - excuse the english!
Back to top
View user's profile Send private message Send e-mail Visit poster's website
SpiderGames



Joined: 09 Jun 2008
Posts: 936
Location: Canada

PostPosted: Thu Aug 27, 2009 12:32 am    Post subject: Reply with quote

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.
_________________

I know i have 6 legs. It's cuz I'm special.
Back to top
View user's profile Send private message Send e-mail Visit poster's website AIM Address Yahoo Messenger MSN Messenger
ashimoi
Guest





PostPosted: Thu Aug 27, 2009 11:48 am    Post subject: Reply with quote

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)
Back to top
SpiderGames



Joined: 09 Jun 2008
Posts: 936
Location: Canada

PostPosted: Thu Aug 27, 2009 12:12 pm    Post subject: Reply with quote

i just said i tryed that and it didn't work. The circles get spread out too far away.
_________________

I know i have 6 legs. It's cuz I'm special.
Back to top
View user's profile Send private message Send e-mail Visit poster's website AIM Address Yahoo Messenger MSN Messenger
ashimoi
Guest





PostPosted: Thu Aug 27, 2009 1:11 pm    Post subject: Reply with quote

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
Back to top
SpiderGames



Joined: 09 Jun 2008
Posts: 936
Location: Canada

PostPosted: Thu Aug 27, 2009 7:27 pm    Post subject: Reply with quote

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)
_________________

I know i have 6 legs. It's cuz I'm special.
Back to top
View user's profile Send private message Send e-mail Visit poster's website AIM Address Yahoo Messenger MSN Messenger
Display posts from previous:   
Reply to topic    AutoHotkey Community Forum Index -> Scripts & Functions All times are GMT
Page 1 of 1

 
Jump to:  
You can post new topics in this forum
You can reply to topics in this forum


Powered by phpBB © 2001, 2005 phpBB Group