 |
AutoHotkey Community Let's help each other out
|
| View previous topic :: View next topic |
| Author |
Message |
derRaphael
Joined: 23 Nov 2007 Posts: 841 Location: ~/.
|
Posted: Mon Nov 17, 2008 6:12 pm Post subject: [examples+minituts] The GDI+ Examplecodes thread |
|
|
| tic wrote: | | Happy gdiplusing people.... |
This is the Table of content for this thread.
Preface
since the topic GDI/GDI+ is quite vast and Tic did a wonderfull job by porting the flat-api to ahk, i'd like to invite everybody who has good usage examples of GDI+ to post in here with a screenshot (if applicable) and a rough description. To get a better insight of which examples are already in here, there will be a Table of Contents to help orient readers.
| derRaphael wrote: | For contributors
Please use a headerline in size 16 to give this thread a consistent look. This helps people who just scroll thru this thread, to better/faster identify example posts and comments to. |
Examplecodes
Not in this thread, but still interesting
Thanks for all the submissions so far! Keep scripting!
Last edited by derRaphael on Mon Feb 22, 2010 7:42 am; edited 20 times in total |
|
| Back to top |
|
 |
derRaphael
Joined: 23 Nov 2007 Posts: 841 Location: ~/.
|
Posted: Mon Nov 17, 2008 6:15 pm Post subject: |
|
|
Analogue Clock with GDI+
This is the 1st example of how to use GDI+ with ahk. It shows an analogue clock which is purely done with ahk.
| Code: | ; gdi+ ahk analogue clock example written by derRaphael
; Parts based on examples from Tic's GDI+ Tutorials and of course on his GDIP.ahk
; This code has been licensed under the terms of EUPL 1.0
#SingleInstance, Force
#NoEnv
SetBatchLines, -1
; Uncomment if Gdip.ahk is not in your standard library
;#Include, Gdip.ahk
If !pToken := Gdip_Startup()
{
MsgBox, 48, gdiplus error!, Gdiplus failed to start. Please ensure you have gdiplus on your system
ExitApp
}
OnExit, Exit
SysGet, MonitorPrimary, MonitorPrimary
SysGet, WA, MonitorWorkArea, %MonitorPrimary%
WAWidth := WARight-WALeft
WAHeight := WABottom-WATop
Gui, 1: -Caption +E0x80000 +LastFound +AlwaysOnTop +ToolWindow +OwnDialogs
Gui, 1: Show, NA
hwnd1 := WinExist()
ClockDiameter := 180
Width := Height := ClockDiameter + 2 ; make width and height slightly bigger to avoid cut away edges
CenterX := CenterY := floor(ClockDiameter/2) ; Center x
; Prepare our pGraphic so we have a 'canvas' to work upon
hbm := CreateDIBSection(Width, Height), hdc := CreateCompatibleDC()
obm := SelectObject(hdc, hbm), G := Gdip_GraphicsFromHDC(hdc)
Gdip_SetSmoothingMode(G, 4)
; Draw outer circle
Diameter := ClockDiameter
pBrush := Gdip_BrushCreateSolid(0x66008000)
Gdip_FillEllipse(G, pBrush, CenterX-(Diameter//2), CenterY-(Diameter//2),Diameter, Diameter)
Gdip_DeleteBrush(pBrush)
; Draw inner circle
Diameter := ceil(ClockDiameter - ClockDiameter*0.08) ; inner circle is 8 % smaller than clock's diameter
pBrush := Gdip_BrushCreateSolid(0x80008000)
Gdip_FillEllipse(G, pBrush, CenterX-(Diameter//2), CenterY-(Diameter//2),Diameter, Diameter)
Gdip_DeleteBrush(pBrush)
; Draw Second Marks
R1 := Diameter//2-1 ; outer position
R2 := Diameter//2-1-ceil(Diameter//2*0.05) ; inner position
Items := 60 ; we have 60 seconds
pPen := Gdip_CreatePen(0xff00a000, floor((ClockDiameter/100)*1.2)) ; 1.2 % of total diameter is our pen width
GoSub, DrawClockMarks
Gdip_DeletePen(pPen)
; Draw Hour Marks
R1 := Diameter//2-1 ; outer position
R2 := Diameter//2-1-ceil(Diameter//2*0.1) ; inner position
Items := 12 ; we have 12 hours
pPen := Gdip_CreatePen(0xc0008000, ceil((ClockDiameter//100)*2.3)) ; 2.3 % of total diameter is our pen width
GoSub, DrawClockMarks
Gdip_DeletePen(pPen)
; The OnMessage will let us drag the clock
OnMessage(0x201, "WM_LBUTTONDOWN")
UpdateLayeredWindow(hwnd1, hdc, WALeft+((WAWidth-Width)//2), WATop+((WAHeight-Height)//2), Width, Height)
SetTimer, sec, 1000
sec:
; prepare to empty previously drawn stuff
Gdip_SetSmoothingMode(G, 1) ; turn off aliasing
Gdip_SetCompositingMode(G, 1) ; set to overdraw
; delete previous graphic and redraw background
Diameter := ceil(ClockDiameter - ClockDiameter*0.18) ; 18 % less than clock's outer diameter
; delete whatever has been drawn here
pBrush := Gdip_BrushCreateSolid(0x00000000) ; fully transparent brush 'eraser'
Gdip_FillEllipse(G, pBrush, CenterX-(Diameter//2), CenterY-(Diameter//2),Diameter, Diameter)
Gdip_DeleteBrush(pBrush)
Gdip_SetCompositingMode(G, 0) ; switch off overdraw
pBrush := Gdip_BrushCreateSolid(0x66008000)
Gdip_FillEllipse(G, pBrush, CenterX-(Diameter//2), CenterY-(Diameter//2),Diameter, Diameter)
Gdip_DeleteBrush(pBrush)
pBrush := Gdip_BrushCreateSolid(0x80008000)
Gdip_FillEllipse(G, pBrush, CenterX-(Diameter//2), CenterY-(Diameter//2),Diameter, Diameter)
Gdip_DeleteBrush(pBrush)
; Draw HoursPointer
Gdip_SetSmoothingMode(G, 4) ; turn on antialiasing
t := A_Hour*360//12 + (A_Min*360//60)//12 +90
R1 := ClockDiameter//2-ceil((ClockDiameter//2)*0.5) ; outer position
pPen := Gdip_CreatePen(0xa0008000, floor((ClockDiameter/100)*3.5))
Gdip_DrawLine(G, pPen, CenterX, CenterY
, ceil(CenterX - (R1 * Cos(t * Atan(1) * 4 / 180)))
, ceil(CenterY - (R1 * Sin(t * Atan(1) * 4 / 180))))
Gdip_DeletePen(pPen)
; Draw MinutesPointer
t := A_Min*360//60+90
R1 := ClockDiameter//2-ceil((ClockDiameter//2)*0.25) ; outer position
pPen := Gdip_CreatePen(0xa0008000, floor((ClockDiameter/100)*2.7))
Gdip_DrawLine(G, pPen, CenterX, CenterY
, ceil(CenterX - (R1 * Cos(t * Atan(1) * 4 / 180)))
, ceil(CenterY - (R1 * Sin(t * Atan(1) * 4 / 180))))
Gdip_DeletePen(pPen)
; Draw SecondsPointer
t := A_Sec*360//60+90
R1 := ClockDiameter//2-ceil((ClockDiameter//2)*0.2) ; outer position
pPen := Gdip_CreatePen(0xa000FF00, floor((ClockDiameter/100)*1.2))
Gdip_DrawLine(G, pPen, CenterX, CenterY
, ceil(CenterX - (R1 * Cos(t * Atan(1) * 4 / 180)))
, ceil(CenterY - (R1 * Sin(t * Atan(1) * 4 / 180))))
Gdip_DeletePen(pPen)
UpdateLayeredWindow(hwnd1, hdc) ;, xPos, yPos, ClockDiameter, ClockDiameter)
return
DrawClockMarks:
Loop, % Items
Gdip_DrawLine(G, pPen
, CenterX - ceil(R1 * Cos(((a_index-1)*360//Items) * Atan(1) * 4 / 180))
, CenterY - ceil(R1 * Sin(((a_index-1)*360//Items) * Atan(1) * 4 / 180))
, CenterX - ceil(R2 * Cos(((a_index-1)*360//Items) * Atan(1) * 4 / 180))
, CenterY - ceil(R2 * Sin(((a_index-1)*360//Items) * Atan(1) * 4 / 180)) )
return
WM_LBUTTONDOWN() {
PostMessage, 0xA1, 2
return
}
esc::
Exit:
SelectObject(hdc, obm)
DeleteObject(hbm)
DeleteDC(hdc)
Gdip_DeleteGraphics(G)
Gdip_Shutdown(pToken)
ExitApp
Return |
enjoy
dR _________________
All scripts, unless otherwise noted, are hereby released under CC-BY |
|
| Back to top |
|
 |
Chronos
Joined: 12 Sep 2008 Posts: 8
|
Posted: Mon Nov 17, 2008 8:06 pm Post subject: |
|
|
A little drawing example
This was my first GDI+ toy. It draws (literally) my signature's logo. Maybe you like it.
| Code: | ; base from gdi+ ahk tutorial 2 written by tic (Tariq Porter)
; Requires Gdip.ahk either in your Lib folder as standard library or using #Include
#SingleInstance, Force
#NoEnv
SetBatchLines, -1
Critical
; Start gdi+
If !pToken := Gdip_Startup()
{
MsgBox, 48, gdiplus error!, Gdiplus failed to start. Please ensure you have gdiplus on your system
ExitApp
}
OnExit, Exit
Width := A_ScreenWidth, Height := A_ScreenHeight
Gui, 1: -Caption +E0x80000 +LastFound +AlwaysOnTop +ToolWindow +OwnDialogs
Gui, 1: Show, NA
hwnd1 := WinExist()
bPen := Gdip_CreatePen(0xFF000080, 4)
wPen := Gdip_CreatePen(0x80ffffff, 8)
Canvas := 0
speed := 2 ; scale the drawing speed (eg update the screen after so many lines)
; the smaller the number (min 1) the more "drawing" alike effect achieved.
; when set to 7 a fast drawing effect is achieved.
pBitmapDraw_%Canvas% := Gdip_CreateBitmap(Width, Height)
GDrawplus_%Canvas% := Gdip_GraphicsFromImage(pBitmapDraw_%Canvas%)
Gdip_SetSmoothingMode(GDrawplus_%Canvas%, 4)
hbmDraw_%Canvas% := CreateDIBSection(Width, Height)
hdcDraw_%Canvas% := CreateCompatibleDC()
obmDraw_%Canvas% := SelectObject(hdcDraw_%Canvas%, hbmDraw_%Canvas%)
GDraw_%Canvas% := Gdip_GraphicsFromHDC(hdcDraw_%Canvas%)
GoSub, makeCoords
Gdip_SetCompositingMode(GDraw_0, 1)
Loop,Parse,Data,`n,`r
{
StringSplit,Pos,A_LoopField,|
Gdip_DrawLine(GDraw_0, wPen, Pos1, Pos2, Pos3, Pos4)
Gdip_DrawLine(GDraw_0, bPen, Pos1, Pos2, Pos3, Pos4)
if !(Mod(A_Index,speed))
UpdateLayeredWindow(hwnd1, hdcDraw_0, 0, 0, Width, Height)
}
UpdateLayeredWindow(hwnd1, hdcDraw_0, 0, 0, Width, Height)
Gdip_DeletePen(bPen)
Gdip_DeletePen(wPen)
Gdip_DeleteGraphics(GDraw_0), SelectObject(hdcDraw_0, obmDraw_0), DeleteObject(hbmDraw_0), DeleteDC(hdcDraw_0)
return
esc::
Exit:
; Select the object back into the hdc
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)
Gdip_Shutdown(pToken)
ExitApp
makeCoords:
data=
(Join
182|496|193|485`n193|485|206|477`n206|477|206|460`n206|460|204|431`n204|431|197|423`n197|423|197|414`n
197|414|189|401`n189|401|185|372`n185|372|188|365`n194|363|194|363`n183|357|195|365`n182|357|161|348`n
161|348|140|337`n140|337|121|324`n121|324|106|310`n106|310|95|294`n95|294|86|279`n86|279|80|251`n
80|251|78|213`n78|213|83|188`n83|188|88|175`n88|175|93|180`n93|180|98|200`n98|200|102|217`n102|217|116|246`n
116|246|133|271`n133|271|151|285`n151|285|175|298`n175|298|206|305`n206|305|226|301`n226|301|250|291`n
250|291|272|283`n272|283|300|277`n300|277|323|277`n323|277|357|285`n357|285|376|295`n376|295|385|299`n
385|299|436|298`n436|298|455|291`n455|291|468|275`n468|275|468|237`n468|237|463|210`n463|210|460|189`n
460|189|453|178`n453|178|447|170`n447|170|446|164`n446|164|448|159`n448|159|459|166`n459|166|477|180`n
477|180|493|198`n493|198|502|221`n502|221|512|247`n512|247|512|272`n512|274|504|304`n504|304|491|321`n
491|321|469|338`n511|238|545|240`n545|240|605|242`n605|242|610|246`n610|246|626|252`n626|252|655|262`n
655|262|678|272`n678|272|681|277`n681|277|695|280`n695|280|696|285`n696|285|703|285`n703|285|723|276`n
723|276|739|264`n739|264|764|253`n764|253|791|251`n791|251|822|252`n822|252|858|262`n858|262|878|271`n
878|271|895|282`n895|282|908|293`n908|293|925|316`n925|316|928|342`n928|342|926|350`n926|350|930|361`n
930|361|927|372`n920|386|929|377`n929|377|921|383`n921|383|926|397`n926|397|913|403`n913|403|919|417`n
919|417|902|419`n883|342|897|367`n897|367|898|390`n898|390|901|421`n901|421|909|451`n909|451|924|490`n
924|490|929|504`n929|504|927|509`n921|509|930|516`n930|516|935|533`n935|533|935|545`n931|544|937|551`n
937|551|938|568`n938|568|929|576`n929|576|916|558`n934|577|941|591`n941|591|927|600`n927|600|924|612`n
924|612|916|602`n919|609|910|622`n910|622|892|614`n892|614|892|608`n892|608|887|612`n887|612|867|607`n
867|607|853|593`n853|593|839|599`n839|599|839|607`n839|607|831|604`n831|604|823|609`n823|609|811|601`n
822|597|805|600`n805|600|795|593`n804|605|786|611`n786|611|785|601`n785|601|779|601`n779|601|779|595`n
779|595|761|587`n761|587|761|561`n757|571|753|571`n753|571|753|558`n753|558|741|548`n741|548|738|541`n
738|541|742|526`n736|536|736|536`n720|501|720|501`n736|537|716|484`n716|500|704|485`n706|499|698|450`n
698|450|714|463`n706|498|697|482`n697|482|688|500`n687|440|689|513`n683|507|683|546`n683|546|662|592`n
662|592|637|610`n637|610|621|614`n621|614|607|608`n607|608|607|597`n607|597|611|592`n620|615|618|624`n
618|624|608|620`n608|620|598|631`n598|631|587|621`n587|621|575|626`n575|626|559|613`n559|613|547|630`n
547|630|533|622`n533|622|527|628`n527|628|513|621`n513|621|487|617`n487|617|499|600`n490|609|483|611`n
483|611|473|605`n473|605|475|597`n490|588|482|599`n482|599|460|598`n460|598|438|576`n438|576|429|548`n
429|548|428|501`n428|501|424|461`n422|508|423|483`n420|508|412|479`n412|479|402|501`n402|501|411|451`n
411|451|397|468`n397|468|391|503`n391|503|403|484`n392|488|378|505`n379|506|379|506`n359|514|378|507`n
379|508|358|516`n358|516|340|511`n349|515|341|519`n341|519|309|547`n307|527|306|550`n306|550|298|564`n
298|564|284|574`n284|574|263|588`n263|588|242|591`n242|591|221|586`n221|586|209|578`n209|578|198|564`n
198|564|198|552`n280|551|299|533`n299|533|266|551`n266|551|240|557`n240|557|222|557`n222|557|224|541`n
224|541|224|556`n224|556|202|553`n202|553|186|546`n186|546|189|521`n189|521|202|522`n202|522|202|518`n
202|516|194|504`n194|504|187|496`n187|496|182|496`n182|496|189|517`n189|517|195|518`n193|411|179|413`n
179|413|158|411`n158|411|136|391`n136|391|125|374`n125|374|120|347`n120|347|125|345`n125|345|157|347`n
126|348|140|351`n140|351|152|358`n152|358|182|369`n176|376|164|376`n154|374|154|374`n142|366|137|365`n
164|375|144|369`n150|386|165|386`n165|399|170|390`n172|399|185|389`n432|410|421|383`n420|383|421|354`n
421|354|427|328`n427|328|448|372`n448|372|456|372`n456|372|460|361`n460|361|468|368`n468|368|461|349`n
461|349|483|354`n488|354|471|341`n471|341|455|334`n455|334|428|327`n413|297|409|282`n409|282|434|293`n
428|285|434|264`n434|264|454|281`n437|261|464|260`n464|260|467|257`n514|247|574|243`n595|250|675|273`n
618|270|678|277`n660|288|693|285`n622|317|679|298`n575|318|604|291`n579|301|595|261`n218|486|241|494`n
241|494|253|488`n249|526|254|510`n254|511|266|500`n266|500|278|500`n278|500|278|508`n278|508|274|521`n
265|535|285|524`n285|524|288|509`n288|509|286|499`n286|499|281|493`n281|493|266|491`n266|491|255|497`n
255|497|245|508`n289|512|292|522`n292|522|299|525`n420|357|400|360`n400|360|391|345`n391|345|383|322`n
383|322|424|323`n424|323|453|305`n388|319|425|317`n380|312|414|315`n414|315|447|301`n447|301|417|305`n
417|305|391|306`n443|329|462|311`n462|311|482|285`n502|275|502|248`n502|248|476|202`n476|202|458|173`n
471|205|484|251`n471|220|477|270`n466|290|462|298`n514|275|521|288`n219|333|208|351`n208|351|194|364`n
207|353|192|352`n192|352|144|334`n144|334|118|315`n118|315|091|281`n121|310|104|287`n104|287|090|259`n
090|259|088|189`n088|189|098|238`n098|238|114|273`n114|273|143|301`n143|301|118|259`n118|259|104|228`n
133|313|159|330`n160|332|196|342`n196|342|208|339`n160|324|159|314`n166|316|169|327`n170|322|172|327`n
172|327|182|332`n182|332|187|324`n187|324|195|333`n195|333|198|329`n205|322|179|315`n179|315|150|300`n
191|374|204|388`n208|388|221|373`n221|373|219|365`n187|380|199|390`n199|390|192|396`n322|392|364|367`n
334|403|340|385`n341|388|354|381`n354|381|367|377`n367|377|367|396`n363|381|363|396`n363|396|358|398`n
358|398|352|391`n346|395|350|401`n350|401|343|406`n351|404|360|403`n360|403|371|394`n476|412|499|411`n
499|411|511|415`n511|415|511|427`n511|427|496|428`n496|428|485|422`n485|422|481|415`n600|422|612|411`n
612|411|632|407`n632|407|634|411`n634|411|628|421`n628|421|618|424`n618|424|603|424`n547|490|528|473`n
528|473|521|466`n521|466|521|459`n521|459|523|454`n523|454|530|454`n530|454|537|460`n537|460|546|474`n
546|474|556|482`n556|482|563|482`n563|482|570|478`n570|478|575|467`n575|467|579|461`n579|461|586|457`n
586|457|594|455`n594|455|597|460`n597|460|597|468`n597|468|588|475`n588|475|580|477`n580|477|569|486`n
547|463|555|470`n555|461|560|475`n560|475|568|469`n568|458|558|461`n558|461|551|454`n623|460|626|470`n
626|470|626|496`n626|496|618|506`n618|506|610|519`n610|519|591|520`n591|520|576|520`n576|520|564|512`n
564|512|557|501`n557|501|544|512`n544|512|519|522`n519|522|511|524`n511|524|502|519`n502|519|491|511`n
491|511|491|503`n491|503|486|495`n486|495|486|479`n486|479|486|468`n486|468|505|445`n530|605|521|583`n
521|583|518|576`n518|576|509|550`n509|550|507|522`n518|522|526|533`n526|533|534|533`n534|533|540|522`n
581|522|591|531`n591|531|595|531`n595|531|595|531`n599|524|601|523`n597|527|608|525`n602|548|602|548`n
596|583|596|583`n591|599|591|599`n591|599|600|554`n600|554|605|525`n531|597|533|591`n543|604|544|593`n
544|593|554|602`n554|602|562|600`n562|600|565|593`n565|593|570|597`n570|597|578|591`n578|591|582|595`n
551|575|551|575`n566|592|550|578`n522|569|555|568`n555|568|572|569`n572|569|592|565`n585|564|581|550`n
581|550|572|560`n572|560|564|565`n546|566|539|562`n539|562|532|549`n532|549|526|561`n589|536|591|553`n
591|553|596|559`n630|358|652|352`n651|352|645|371`n645|371|655|365`n655|365|656|374`n656|374|668|377`n
668|377|673|389`n673|389|674|401`n674|401|657|407`n657|407|669|404`n669|404|672|416`n679|411|679|411`n
679|414|688|392`n688|392|692|369`n692|369|686|330`n686|330|667|373`n632|352|648|338`n648|338|665|331`n
665|331|684|330`n670|374|678|367`n670|373|682|373`n674|385|684|379`n677|386|684|386`n684|386|678|398`n
441|411|441|406`n441|406|455|406`n460|408|440|401`n440|401|440|390`n440|390|447|382`n447|382|447|376`n
433|354|444|369`n444|369|433|365`n430|370|443|376`n442|382|431|376`n438|386|431|386`n431|386|434|395`n
676|318|701|303`n696|303|702|290`n747|363|776|357`n776|357|811|355`n811|355|827|362`n770|373|791|362`n
777|371|790|364`n802|371|777|359`n777|359|796|366`n804|373|808|377`n808|377|815|377`n815|377|813|400`n
813|400|824|391`n811|385|789|393`n789|393|775|393`n775|393|759|383`n767|397|778|401`n778|401|798|400`n
798|400|809|393`n801|413|824|399`n862|446|869|429`n869|429|853|403`n853|403|845|361`n845|361|860|357`n
860|357|892|365`n897|379|885|369`n850|373|865|370`n865|370|851|378`n869|368|891|382`n891|391|874|368`n
887|389|875|399`n875|399|856|391`n856|391|856|380`n856|380|870|374`n864|406|879|406`n879|406|888|402`n
763|357|790|348`n790|348|816|347`n816|347|828|354`n828|354|837|405`n837|405|837|409`n837|409|826|417`n
826|417|813|425`n813|425|812|440`n812|440|822|430`n822|430|836|426`n836|426|847|421`n847|421|857|429`n
857|429|860|440`n840|356|860|352`n860|352|890|361`n814|415|810|420`n813|441|829|441`n829|441|834|445`n
815|478|863|478`n863|478|824|483`n824|483|862|480`n862|480|855|472`n855|472|842|472`n842|472|819|475`n
730|393|733|424`n733|424|743|438`n743|438|758|451`n758|451|789|456`n706|407|713|398`n708|395|716|395`n
716|395|716|388`n716|388|734|365`n734|365|739|341`n730|340|743|335`n753|335|769|319`n769|319|774|320`n
774|320|789|316`n789|316|805|320`n805|320|815|320`n825|316|830|311`n830|311|824|294`n824|294|831|279`n
835|283|849|291`n835|291|837|305`n
)
data=
(Join
%data%
837|305|852|310`n849|304|861|311`n861|311|858|319`n858|319|863|325`n863|325|868|325`n848|301|874|312`n
878|314|886|322`n891|323|894|330`n887|335|892|340`n868|441|875|452`n875|452|886|457`n886|457|896|446`n
896|443|882|446`n882|446|870|436`n858|460|875|473`n875|473|876|487`n876|487|883|500`n883|500|908|514`n
885|488|908|514`n902|515|908|524`n908|524|917|529`n800|464|811|487`n803|473|803|499`n800|512|810|499`n
818|496|812|507`n812|507|812|534`n812|539|814|562`n814|562|831|570`n818|492|826|501`n820|498|824|514`n
824|514|834|514`n834|514|851|518`n702|413|711|450`n709|415|711|447`n715|414|720|447`n720|447|714|456`n
719|411|728|451`n728|451|719|461`n454|444|456|463`n456|463|462|473`n467|481|475|510`n475|510|484|521`n
484|521|491|522`n489|526|502|539`n607|540|627|520`n620|518|632|519`n632|519|644|498`n644|498|646|477`n
646|477|654|458`n654|458|658|440`n552|375|545|400`n545|400|576|399`n580|399|573|382`n581|388|594|401`n
606|402|607|388`n607|387|604|377`n620|389|634|388`n634|388|640|390`n642|406|645|400`n645|400|637|402`n
637|402|616|402`n616|402|604|405`n604|405|594|417`n594|417|588|413`n588|413|576|410`n576|410|576|404`n
612|392|616|398`n616|398|622|398`n630|394|633|395`n603|433|622|430`n622|430|637|419`n637|412|651|421`n
651|421|656|432`n513|439|508|436`n508|436|490|436`n490|436|473|422`n473|422|470|417`n470|417|457|430`n
457|430|457|432`n515|420|520|426`n520|426|528|413`n528|413|539|406`n539|406|543|411`n543|411|551|416`n
551|416|548|406`n548|406|571|400`n522|448|522|437`n522|437|532|431`n580|428|595|441`n595|441|596|428`n
518|400|533|391`n496|403|504|403`n504|403|510|395`n492|397|488|390`n488|390|482|390`n482|390|472|394`n
476|401|480|399`n463|452|468|444`n468|444|474|440`n636|433|651|450`n453|425|443|433`n450|426|439|421`n
439|421|433|420`n433|420|426|429`n445|428|427|435`n427|435|422|448`n425|444|435|442`n435|442|426|450`n
424|450|420|492`n425|460|438|453`n438|453|430|471`n431|507|438|477`n442|469|450|459`n450|459|450|449`n
442|468|429|494`n444|543|435|491`n435|491|451|474`n445|509|451|486`n451|486|463|474`n463|474|456|508`n
456|508|457|532`n474|540|465|518`n465|518|466|487`n478|521|489|558`n489|558|510|590`n514|586|489|537`n
492|523|494|521`n599|580|623|532`n602|587|620|559`n620|559|628|538`n628|538|631|520`n640|538|647|516`n
647|516|648|490`n656|527|659|507`n659|507|654|475`n654|475|664|485`n664|485|668|507`n669|538|674|508`n
674|508|676|488`n676|488|659|465`n660|443|660|453`n660|453|670|463`n670|463|677|476`n677|476|684|506`n
684|498|685|471`n685|471|673|450`n673|450|681|450`n681|450|686|458`n686|448|682|445`n682|445|676|442`n
676|442|686|439`n687|439|687|439`n681|429|690|439`n655|423|661|425`n661|425|671|425`n671|425|680|427`n
680|427|683|423`n683|423|679|416`n679|416|661|424`n653|544|648|545`n648|545|648|552`n648|552|658|561`n
658|561|669|559`n669|559|680|541`n663|570|649|582`n649|582|641|574`n633|566|629|568`n626|574|626|574`n
626|566|626|566`n625|579|628|568`n626|581|646|591`n646|591|662|586`n624|595|627|605`n603|612|602|618`n
593|622|587|613`n568|613|571|608`n571|608|590|608`n584|608|594|599`n530|616|547|606`n547|606|553|614`n
520|600|520|618`n520|618|511|611`n511|611|499|614`n499|614|504|598`n504|598|504|610`n480|572|467|581`n
467|581|456|574`n458|549|462|549`n462|549|466|556`n466|556|454|566`n454|566|444|566`n444|566|429|543`n
504|526|505|545`n505|545|492|534`n507|446|508|467`n508|467|512|473`n512|473|523|479`n574|490|591|478`n
591|478|604|471`n604|471|607|457`n607|457|603|451`n608|476|612|468`n581|486|594|488`n594|488|609|484`n
609|484|618|477`n618|477|623|467`n581|496|597|496`n597|496|609|494`n609|494|617|485`n584|503|596|504`n
596|504|608|502`n608|502|619|490`n597|515|607|505`n607|505|616|497`n581|510|571|502`n525|487|514|485`n
514|485|509|478`n497|463|502|486`n502|486|511|494`n514|496|527|498`n490|469|493|489`n493|489|503|497`n
503|497|530|504`n530|504|521|506`n521|506|540|506`n202|401|218|398`n202|413|208|410`n235|381|223|388`n
221|395|222|410`n222|410|213|443`n213|443|213|473`n213|473|208|482`n208|482|193|491`n217|476|243|415`n
214|358|226|341`n272|371|282|362`n282|362|287|372`n287|372|287|378`n287|378|279|391`n295|371|288|361`n
288|361|320|353`n309|345|331|332`n313|364|342|340`n343|346|356|346`n356|346|367|353`n367|353|373|370`n
373|370|367|370`n367|370|364|360`n364|360|358|354`n358|354|344|354`n331|368|345|361`n345|361|358|356`n
343|369|361|364`n361|364|361|358`n335|410|359|412`n359|412|368|404`n368|404|369|409`n383|408|381|447`n
381|447|371|468`n338|473|366|444`n368|431|366|420`n366|420|348|442`n365|436|367|429`n368|456|341|487`n
341|487|312|500`n315|509|333|499`n311|471|339|444`n333|499|300|489`n298|490|322|435`n290|479|310|434`n
310|434|310|405`n321|411|304|392`n304|392|296|396`n293|388|273|406`n273|406|256|441`n289|407|285|420`n
285|420|258|459`n258|459|262|462`n262|462|258|478`n258|478|276|486`n266|330|258|343`n258|343|266|346`n
266|346|284|325`n245|330|263|313`n227|325|238|312`n218|309|214|316`n214|316|219|325`n219|325|214|327`n
214|327|208|327`n208|327|206|320`n230|566|252|567`n239|561|263|565`n295|546|274|562`n274|562|255|572`n
255|572|227|574`n227|574|222|570`n222|570|218|568`n218|568|208|558`n266|572|288|567`n288|567|293|555`n
688|331|720|295`n720|295|740|276`n740|276|789|258`n751|265|727|279`n720|284|697|312`n728|333|740|333`n
740|333|747|324`n742|323|755|322`n729|317|729|327`n725|301|733|304`n733|304|741|316`n736|303|733|289`n
733|289|742|296`n742|288|749|299`n749|299|749|313`n749|313|756|289`n756|289|744|285`n756|309|756|299`n
756|322|763|308`n763|308|756|282`n756|282|769|292`n769|292|771|307`n768|315|773|315`n760|277|771|288`n
771|288|774|306`n778|320|782|293`n782|287|788|295`n788|295|788|305`n788|305|795|316`n795|316|808|313`n
816|313|805|307`n805|307|802|298`n802|298|804|286`n804|286|814|275`n814|275|820|270`n820|270|820|261`n
815|257|824|260`n824|260|837|261`n837|261|845|264`n772|271|781|277`n775|283|781|283`n786|274|792|275`n
795|288|805|272`n804|268|799|264`n792|259|794|273`n794|304|813|262`n813|262|805|254`n821|308|816|302`n
816|302|815|295`n815|295|830|273`n835|262|853|289`n853|289|853|294`n853|294|853|299`n873|300|865|301`n
865|301|855|289`n843|271|869|297`n854|274|873|290`n851|262|867|283`n848|268|871|295`n869|282|890|309`n
890|309|890|296`n878|279|900|304`n890|284|905|299`n905|299|904|313`n904|313|899|318`n911|303|906|315`n
869|273|884|296`n878|300|880|306`n883|313|891|319`n891|319|897|308`n901|322|915|317`n915|317|918|327`n
897|321|905|334`n905|328|915|333`n914|347|922|332`n892|347|903|350`n911|354|920|349`n908|361|922|358`n
922|358|917|368`n925|373|909|360`n913|368|903|370`n903|388|909|378`n905|397|915|389`n915|389|919|398`n
301|494|317|474`n312|492|319|484`n330|499|344|499`n715|482|715|472`n715|472|692|446`n716|465|720|473`n
720|473|729|473`n729|473|743|491`n716|483|732|494`n732|494|738|494`n738|494|748|502`n748|502|756|548`n
743|510|739|519`n739|519|729|510`n724|400|729|435`n729|435|739|463`n729|459|739|472`n743|471|749|486`n
744|465|743|452`n750|449|755|474`n755|456|764|498`n764|498|781|511`n752|494|755|478`n762|489|765|452`n
763|488|773|472`n773|472|770|452`n770|452|778|477`n778|477|774|485`n777|501|776|493`n776|493|785|477`n
785|477|782|455`n792|470|795|473`n792|473|796|491`n796|492|796|474`n796|487|795|498`n795|498|790|513`n
781|524|784|509`n778|515|774|540`n768|553|760|508`n773|553|782|558`n778|560|790|575`n789|593|774|561`n
763|561|771|571`n774|575|783|580`n802|523|802|562`n788|525|799|540`n785|535|795|545`n795|545|799|561`n
804|565|816|576`n794|571|805|571`n803|579|812|588`n815|578|816|583`n827|592|828|580`n828|580|820|569`n
835|596|839|580`n839|572|822|556`n822|556|824|531`n824|531|820|520`n812|480|817|466`n817|466|823|464`n
823|464|832|459`n832|459|851|465`n851|465|857|465`n829|450|832|457`n827|457|821|447`n818|453|818|462`n
812|458|808|453`n808|453|809|446`n795|459|803|459`n803|459|812|468`n888|468|916|502`n909|479|920|510`n
923|514|924|511`n916|511|903|495`n921|539|921|544`n921|544|917|559`n932|565|932|547`n932|586|920|582`n
920|582|921|573`n915|581|924|588`n924|588|911|590`n911|590|917|568`n917|568|908|554`n908|568|900|560`n
900|560|900|548`n900|548|903|538`n903|538|897|525`n910|546|911|543`n911|543|910|534`n842|495|845|509`n
841|517|847|531`n847|531|845|561`n845|561|856|575`n859|584|838|564`n838|564|839|534`n839|534|834|518`n
837|511|835|494`n853|512|847|503`n854|505|847|498`n860|497|865|504`n875|507|881|513`n867|514|867|505`n
871|518|877|521`n877|521|888|518`n893|527|895|533`n886|523|893|535`n885|531|884|546`n884|546|882|552`n
882|552|898|581`n898|566|903|588`n916|604|910|613`n910|613|896|593`n900|602|881|600`n881|600|874|603`n
878|593|877|578`n890|584|885|573`n885|573|878|573`n878|573|865|560`n865|560|864|537`n864|537|857|522`n
858|517|860|516`n873|527|876|542`n873|548|873|559`n873|559|875|560`n869|600|873|596`n873|596|873|591`n
873|591|868|581`n870|578|852|558`n852|558|852|553`n852|553|852|540`n852|540|854|522
)
return |
edit i removed unneeded lines from code and added a new feature called speed so the drawing can be adjusted. 1 (smalles value) will give an almost ghost like effect. default was 7. _________________

Last edited by Chronos on Tue Nov 18, 2008 4:07 pm; edited 1 time in total |
|
| Back to top |
|
 |
derRaphael
Joined: 23 Nov 2007 Posts: 841 Location: ~/.
|
Posted: Mon Nov 17, 2008 8:14 pm Post subject: |
|
|
Thank you, Chronos - ur examplecode looks weird, but the result is really impressive! it's a pitty, that the effect cannot be screenshotted without taking its suprise effect. your post is been linked from 1st post' toc and is definatly worth a try.
thank you!
greets
dR _________________
All scripts, unless otherwise noted, are hereby released under CC-BY |
|
| Back to top |
|
 |
skwire
Joined: 18 Jan 2006 Posts: 273 Location: Conway, Arkansas
|
Posted: Tue Nov 18, 2008 8:35 am Post subject: |
|
|
| Chronos wrote: | A little drawing example
This was my first GDI+ toy. It draws (literally) my signature's logo. Maybe you like it. |
Wow...too cool. I think I reloaded this four or fives times just to watch it again. Very very slick demonstration of what is possible. |
|
| Back to top |
|
 |
IsNull
Joined: 10 May 2007 Posts: 593 Location: .switzerland
|
Posted: Tue Nov 18, 2008 9:05 am Post subject: |
|
|
Chronos, how do you do that? I think the numbers (coordinates) are automatic calculated and not by your self,right? ^^
Is that a thing like a vector graphic, for example a svg? _________________ http://securityvision.ch
AHK 2D GAME ENGINE |
|
| Back to top |
|
 |
derRaphael
Joined: 23 Nov 2007 Posts: 841 Location: ~/.
|
Posted: Tue Nov 18, 2008 9:14 am Post subject: |
|
|
IsNull, when u take a closer look at the script u see that all coordinates are in the script x1,y1,x2,y2 these are being looped from a large chunk of data and drawn as lines
but i am sure, Chronos knows better
dR _________________
All scripts, unless otherwise noted, are hereby released under CC-BY |
|
| Back to top |
|
 |
Krogdor
Joined: 18 Apr 2008 Posts: 1390 Location: The Interwebs
|
Posted: Tue Nov 18, 2008 9:38 am Post subject: |
|
|
| skwire wrote: | | Chronos wrote: | A little drawing example
This was my first GDI+ toy. It draws (literally) my signature's logo. Maybe you like it. |
Wow...too cool. I think I reloaded this four or fives times just to watch it again. Very very slick demonstration of what is possible. |
Freakin' awesome. |
|
| Back to top |
|
 |
tic
Joined: 22 Apr 2007 Posts: 1786
|
Posted: Tue Nov 18, 2008 2:25 pm Post subject: |
|
|
Wow, that is quite cool. I wonder how you went about getting all the coordinates??
This topic will give me a chance to post all the things I've written and never posted. I promise you wont be disappointed....  |
|
| Back to top |
|
 |
Chronos
Joined: 12 Sep 2008 Posts: 8
|
Posted: Tue Nov 18, 2008 4:09 pm Post subject: |
|
|
to tic and isnull:
the coordinates were handmade ... i created a simple script drawing lines where i clicked with my mouse. these were saved into a seperate file. the here presented script just includes the coordinates and replays my "drawing" action _________________
 |
|
| Back to top |
|
 |
tic
Joined: 22 Apr 2007 Posts: 1786
|
Posted: Wed Nov 19, 2008 7:16 pm Post subject: |
|
|
Kiosk - Incomplete example of a layered OnScreen Keyboard
Ok, try this...
kiosk-1.76
I had originally made a much more complete version of this, but it didn't use the Gdi+ lib as we know it. This was before its existence
A couple of the buttons at the top dont do anything. The top left one is for dragging. I have removed the resize keyboard part. There is much more stuff including a magnifier in the earlier version
Peace
Last edited by tic on Thu Nov 20, 2008 1:42 pm; edited 1 time in total |
|
| Back to top |
|
 |
IsNull
Joined: 10 May 2007 Posts: 593 Location: .switzerland
|
Posted: Thu Nov 20, 2008 7:42 am Post subject: |
|
|
| Quote: | | the coordinates were handmade ... i created a simple script drawing lines where i clicked with my mouse. these were saved into a seperate file. the here presented script just includes the coordinates and replays my "drawing" action | could you post that drawing skript? I'm shure it would be very funny
@tic:
As far as I can see, you redraw the whole keyboard - even if It's only one button who changes (the hover action). It's not possible, to delete a single button grafic and create it new, isn't it? That would be great. _________________ http://securityvision.ch
AHK 2D GAME ENGINE |
|
| Back to top |
|
 |
tic
Joined: 22 Apr 2007 Posts: 1786
|
Posted: Thu Nov 20, 2008 9:09 am Post subject: |
|
|
| IsNull wrote: | | Quote: | | the coordinates were handmade ... i created a simple script drawing lines where i clicked with my mouse. these were saved into a seperate file. the here presented script just includes the coordinates and replays my "drawing" action | could you post that drawing skript? I'm shure it would be very funny
@tic:
As far as I can see, you redraw the whole keyboard - even if It's only one button who changes (the hover action). It's not possible, to delete a single button grafic and create it new, isn't it? That would be great. |
Actually it does only redraw the button necessary and not the whole keyboard. Check out from line 250. It only loops twice. Once to redraw the last hovered key as normal and secondly to draw the currently hovered key
By the way DerRaphael your clock is very nice  |
|
| Back to top |
|
 |
derRaphael
Joined: 23 Nov 2007 Posts: 841 Location: ~/.
|
Posted: Thu Nov 20, 2008 9:59 am Post subject: |
|
|
| tic wrote: | By the way DerRaphael your clock is very nice  |
Thank you, tic. Can you please add a header with size 16 formatted bold into your Kiosk post? this will help others, who just read thru this, to identify examples from comments. a screenshot 'd be nice, too but this is up to u.
greets
dR
btw toc updated _________________
All scripts, unless otherwise noted, are hereby released under CC-BY |
|
| Back to top |
|
 |
Chronos
Joined: 12 Sep 2008 Posts: 8
|
Posted: Thu Nov 20, 2008 9:22 pm Post subject: |
|
|
Lines Coordinates Recordertool
| IsNull wrote: | could you post that drawing skript? I'm shure it would be very funny  |
Sure i will. Basically it goes like this (but keep in mind, this script is pretty much primitive, so there's a lot of space for improvement left):
ctrl+f1: Loads previously saved coords.txt and draws it on screen. Regardless of any already set content. any already recorded lines will be lost.
ctrl+s: saves the current buffer of recorded linecoordinates
(Attention! When the MsgBox appears, You'll have to dismiss it via keyboard, otherwise the script will draw at the button.)
ctrl+z: Undos last action up to 1st stored line (erased lines will be shown in yellow)
lbutton: 1st click starts, 2nd click ends recording and draws the line.
esc: Exits the app any unsaved data gets lost.
There are three lines commented out. Re-enabling these will show a tooltip (to left position) of the current status (step 0:started, 1:done / count of lines) and the coordinatebuffer below this was mainly for testing the undo functionality
| Code: | #SingleInstance, Force
#NoEnv
SetBatchLines, -1
CoordMode,Mouse,Screen
; CoordMode,ToolTip,Screen
a:=0
steps := 0
; Start gdi+
If !pToken := Gdip_Startup()
{
MsgBox, 48, gdiplus error!, Gdiplus failed to start. Please ensure you have gdiplus on your system
ExitApp
}
OnExit, Exit
Width := A_ScreenWidth, Height := A_ScreenHeight
Gui, 1: -Caption +E0x80000 +LastFound +AlwaysOnTop +ToolWindow +OwnDialogs
Gui, 1: Show, NA
hwnd1 := WinExist()
hbm := CreateDIBSection(Width, Height)
hdc := CreateCompatibleDC()
obm := SelectObject(hdc, hbm)
G := Gdip_GraphicsFromHDC(hdc)
Gdip_SetSmoothingMode(G, 4)
pPen := Gdip_CreatePen(0xc0000000, 4)
ePen := Gdip_CreatePen(0xffffff00, 5)
UpdateLayeredWindow(hwnd1, hdc, 0, 0, Width, Height)
Return
LButton::
MouseGetPos,mx,my
a++
if (a=1)
Pos1 := mx, Pos2 := my
else if (a=2) {
Pos3 := mx, Pos4 := my
Gdip_DrawLine(G, pPen, Pos1, Pos2, Pos3, Pos4)
UpdateLayeredWindow(hwnd1, hdc, 0, 0, Width, Height)
Loop,3
Coords .= pos%A_index% "|"
Coords .= pos4 "`n"
a := 0
steps++
}
; tooltip,% a "/" steps "`n" coords,10,10
Return
^z::
a:=0
Loop,Parse,Coords,`n
if (A_index = steps)
tmp := A_LoopField
else
tCoords := tCoords A_LoopField "`n"
steps--
Coords := tCoords
tCoords := ""
StringSplit,Pos,tmp,|
Gdip_DrawLine(G, ePen, Pos1, Pos2, Pos3, Pos4)
UpdateLayeredWindow(hwnd1, hdc, 0, 0, Width, Height)
StringReplace,coords,coords,`n`n,`n,All
; tooltip,% steps "`n" coords,10,10
return
^s::
if (FileExist("coords.txt"))
FileDelete,coords.txt
FileAppend,%coords%,coords.txt
MsgBox FileSaved
return
^f1::
fileRead,data,coords.txt
Loop,Parse,Data,`n,`r
{
StringSplit,Pos,A_LoopField,|
Gdip_DrawLine(G, wPen, Pos1, Pos2, Pos3, Pos4)
Gdip_DrawLine(G, bPen, Pos1, Pos2, Pos3, Pos4)
}
UpdateLayeredWindow(hwnd1, hdc, 0, 0, Width, Height)
return
;#######################################################################
esc::
Exit:
SelectObject(hdc, obm)
DeleteObject(hbm)
DeleteDC(hdc)
Gdip_DeleteGraphics(G)
; gdi+ may now be shutdown on exiting the program
Gdip_Shutdown(pToken)
ExitApp
Return |
enjoy! _________________
 |
|
| Back to top |
|
 |
|
|
You can post new topics in this forum You can reply to topics in this forum
|
Powered by phpBB © 2001, 2005 phpBB Group
|