GDI+ standard library 1.45 by tic

Post your working scripts, libraries and tools
tic
Posts: 92
Joined: 03 Nov 2014, 03:10

Re: GDI+ standard library 1.45 by tic

23 Oct 2017, 23:45

tidbit wrote:
tic wrote:beep
no offense tic, but can we remove your download link and only keep _All ?
Yes, I shall do so until Gdip2 is done. I've been so busy that I haven't had a chance to look at it
dd900 wrote:Hey tic just got around to trying out Gdip2. I'm having a bit of trouble with example 3 (create-gui-from-image). If I try to set the x and y coords to anything but 0 the right and bottom sides of the image get cut off.
Currently it has no overloads, so you have to provide the x and y parameters in a single object (See example 8)

Code: Select all

win1.Update({ x: (A_ScreenWidth-size1.width)//2, y: (A_ScreenHeight-size1.height)//2 })
clow_yakayi
Posts: 39
Joined: 15 Oct 2017, 10:15

Re: GDI+ standard library 1.45 by tic

25 Oct 2017, 09:15

Hey guys,
I cant figure out how to make my cross hairs work after initial initiation of the application i am developing.
At start its loads fine, but when i click to pause the area of zoom and then start it again the cross hairs don't appear. Also the issue is flicker cross hairs, but i am not sure if that can be avoidable.

My script should operate like this:
When you launch it ask for source window, works on game windows best(calculator seams to not work with my app), then once you give the proper window name it opens 3 guis. One a copy of the whole window, 2nd is the panel for my app. Inside the panel there is a frame to hold the maximized refreshing image of where the mouse is/should be of the chosen window. It uses the same bitmap that's a copy of the real chosen window just used differently in a different gui. And is meant to have cross hairs while the frame is active. There is a button OK to initiate that frame if it is stopped. When you click left mouse button on the full window copy gui the zoom frame freezes till you click OK button.

How it actually works:
gets name of the window(no validation yet), when name is correct if fills the full copy gui and initiates the zoom frame with cross hair like it should. reacts to left click appropriately. But when its initiated again it fails to draw the cross hairs in the zoom frame.

Code: Select all

#SingleInstance, Force
#NoEnv
SetBatchLines, -1

#Include Gdip_All.ahk 
CoordMode Mouse, Screen
pToken := Gdip_Startup()

global magWinSide := 256, winName, winX, winY, winW, winH
global srcPrintFrame, destPrintFrame, destFullFrame

InputBox, winName,, Please Enter The Window Title
winSetup()
activate()

winSetup()
{	
	WinGet, prnSrcID, ID, % winName
	WinGetPos, winX, winY, winW, winH, % winName
	
	Gui, PnCfgMain: +AlwaysOnTop 
	
	Gui, PnCfgMain: Show, % "x" 0 " y" 0 " w" magWinSide " h" magWinSide + 400, PaneConfigMain
		
	Gui, PnCfgMain: Add, Button, % "y+" magWinSide " gactivate Default ", OK 

	WinGet, pnCfgMainID, ID, PaneConfigMain
	WinGet pnCfgMainID, ID, PaneConfigMain
	Gui, PnCfgSrc: -Border -Caption
	
	Gui, PnCfgSrc: Show , % "w" winW " h" winH " x" 0 " y" 0, PaneConfigSource
		
	WinGet pnCfgSrcID, ID, PaneConfigSource

	srcPrintFrame := GetDC(prnSrcID)
	destPrintFrame := GetDC(pnCfgMainID)
	destFullFrame := GetDC(pnCfgSrcID)
	
	StretchBlt(destFullFrame, 0, 0, winW, winH, srcPrintFrame, 0, 0, winW, winH, 0xCC0020)
	
}

activate()
{
	zoom := 16
	zSide := magWinSide / zoom
	
	Loop
	{
		MouseGetPos, x, y
		x -= zSide/2
		y -= zSide/2
		If (x=x_old) && (y=y_old)
			Continue
		x_old:=x, y_old:=y
		
		StretchBlt(destPrintFrame, 0, 0, magWinSide, magWinSide, srcPrintFrame, x, y, zSide, zSide, 0xCC0020)
			
		crshDIBS := CreateDIBSection(magWinSide, magWinSide)
		crshRegObj := SelectObject(destPrintFrame, crshDIBS)
		destGpxDCP := Gdip_GraphicsFromHDC(destPrintFrame)
		pen1 := Gdip_CreatePen(0x660000ff, 10)
				
		Gdip_DrawLine(destGpxDCP, pen1, 0, magWinSide/2, magWinSide, magWinSide/2)
		Gdip_DrawLine(destGpxDCP, pen1, magWinSide/2, 0, magWinSide/2, magWinSide)
		
		GetKeyState, state, LButton
		if state = D
		{
			;zoomAct--
			break
		}
	}
}

PnCfgMainGuiClose()
{
	ExitApp
}



Gdip_Shutdown(pToken)
clow_yakayi
Posts: 39
Joined: 15 Oct 2017, 10:15

Re: GDI+ standard library 1.45 by tic

25 Oct 2017, 09:17

Also please help me understand more about the mechanics behind building, Device Contexts, Bitmaps, Graphics, Pens and such. Because do to specific functions and refreshing loops that I have. I am not sure if I should create any object once or and delete them at the end, or should I create and delete those objects for every refresh.
clow_yakayi
Posts: 39
Joined: 15 Oct 2017, 10:15

Re: GDI+ standard library 1.45 by tic

25 Oct 2017, 21:08

I figured out my main issue, it was the Gdip_Shutdown placement, but i still not sure when i should delete objects used to draw shapes when in a loop.
dd900
Posts: 76
Joined: 27 Oct 2013, 16:03

Re: GDI+ standard library 1.45 by tic

29 Oct 2017, 11:53

Thanks for the help tic. I have another question. What would be the proper way to use BitBlt with Gdip2?

This works with the original library:

Code: Select all

Gui, New, +HwndhMain -Caption
Gui, %hMain%:Show, w1280 h720 x40 y40
dcMain := GetDC(hMain)
, hbm := CreateDIBSection(1280, 720)
, hdc := CreateCompatibleDC()
, obm := SelectObject(hdc, hbm)
, G := Gdip_GraphicsFromHDC(hdc)
, Gdip_SetInterpolationMode(G, 7)
, pBitmap := Gdip_CreateBitmapFromFile("layer1_.png")
, Gdip_DrawImage(G, pBitmap, 0,0, 1280, 720)
, BitBlt(dcMain, 0, 0, 1280, 720, hdc, 0, 0)
This doesn't work with Gdip2:

Code: Select all

x := new Gdip.Window(new Gdip.Point(40, 40), new Gdip.Size(1280, 720))
, xDC := Gdip.Object.GetDC(x.hwnd)
, gdipObj := new Gdip.Bitmap(new Gdip.Size(1280, 720))
, gdipObj.DrawImage(Gdip.BitmapFromFile("layer1_.png"), new Gdip.Point(0, 0), new Gdip.Size(1280, 720))
, Gdip.Object.BitBlt(xDC, 0, 0, x.width, x.height, gdipObj.obj.hdc, 0, 0)
I realize this isn't the best use of BitBlt, but I'm just trying to show code so I can get some help. I know the window is there because I can't click anything on screen.
tic
Posts: 92
Joined: 03 Nov 2014, 03:10

Re: GDI+ standard library 1.45 by tic

06 Nov 2017, 21:46

dd900 wrote:Thanks for the help tic. I have another question. What would be the proper way to use BitBlt with Gdip2?

Code: Select all

x := new Gdip.Window(new Gdip.Point(40, 40), new Gdip.Size(1280, 720))
, xDC := Gdip.Object.GetDC(x.hwnd)
, gdipObj := new Gdip.Bitmap(new Gdip.Size(1280, 720))
, gdipObj.DrawImage(Gdip.BitmapFromFile("layer1_.png"), new Gdip.Point(0, 0), new Gdip.Size(1280, 720))
, Gdip.Object.BitBlt(xDC, 0, 0, x.width, x.height, gdipObj.obj.hdc, 0, 0)
Hi dd900

Yes, using BitBlt with a layered window isn't intended. Just use win1.Update() for that. For an example of using Bitblt with a standard window here is an example.
Remember there could be breaking changes in future versions of Gdip2

https://github.com/tariqporter/Gdip2

Code: Select all

#Persistent
#SingleInstance Force

#Include Gdip2.ahk

gdip1 := new Gdip()
size1 := new Gdip.Size(200, 200)
options1 := {}
options1.brush := new gdip1.Brush(187, 255, 255, 255)
options1.style := ["underline", "italic"]
options1.horizontalAlign := "center"
options1.width := size1.width
options1.height := size1.height
options1.size := 40

Gui, 1: -DPIScale
Gui, 1: Add, Picture, % "x10 y10 w" size1.width " h" size1.height " 0xE hwndhwndImage"
brush1 := new Gdip.Brush(new Gdip.Color(85, 50, 35), new Gdip.Color(190, 160, 140), 31)
obj1 := new Gdip.Object(size1)
ddc := obj1.GetDC(hwndImage)
Gui, 1: Show, AutoSize, Gdip2 - Bitblt Example
d := true
i := 1
SetTimer, Update, 30
return

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

Update:
if (i = 0 || i = 99) {
	d := !d
}
i := d ? i + 1 : i - 1
obj1.FillRectangle(brush1, new Gdip.Point(0, 0), size1)
obj1.WriteText(i, options1)
obj1.BitBlt(ddc, 0, 0, obj1.width, obj1.height, obj1.hdc, 0, 0)
return

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

Esc::
ExitApp
return
guest3456
Posts: 2419
Joined: 09 Oct 2013, 10:31

Re: GDI+ standard library 1.45 by tic

07 Nov 2017, 09:21

tic, do you know that there is a unit testing framework already written in AHK, not requiring an external node dependency?

https://github.com/Uberi/Yunit

tic
Posts: 92
Joined: 03 Nov 2014, 03:10

Re: GDI+ standard library 1.45 by tic

07 Nov 2017, 11:35

guest3456 wrote:tic, do you know that there is a unit testing framework already written in AHK, not requiring an external node dependency?

https://github.com/Uberi/Yunit
That library is good, but as I am using ahk-loader

https://github.com/tariqporter/ahk-loader

Which will build my final Gdip2.ahk from all the separate files in my project, and watch for changes, then running unit tests in this way is no extra effort and also watches for changes and re-runs tests on change - Which I don't think Yunit does
User avatar
nnnik
Posts: 3340
Joined: 30 Sep 2013, 01:01
Location: Germany

Re: GDI+ standard library 1.45 by tic

14 Nov 2017, 16:23

https://github.com/mmikeww/AHKv2-Gdip/c ... af83a2db51
^This commit broke the library for AHK v1 users
Recommends AHK Studio
User avatar
jeeswg
Posts: 5143
Joined: 19 Dec 2016, 01:58
Location: UK

Re: GDI+ standard library 1.45 by tic

14 Nov 2017, 17:27

- @guest3456: In AHK v2, I recently discovered that the proper output value for SendMessage is now the output variable for the function and not ErrorLevel. (A separate issue, I also discovered that if you try to create a string key '123', obj["123"] := value, it is forced as an integer key.
- @nnnik and guest3456: Perhaps you could make it so that Gdip v2 could work in AHK v1.1, if you also include this library. This is why I wrote the library(/updated the work by Coco), I believe it's the only realistic way (without creating something horrendous,) to have scripts that are two-way compatible. Hmm, but loops are currently a problem, so maybe not.
commands as functions (AHK v2 functions for AHK v1) - AutoHotkey Community
https://autohotkey.com/boards/viewtopic ... 37&t=29689
guest3456
Posts: 2419
Joined: 09 Oct 2013, 10:31

Re: GDI+ standard library 1.45 by tic

14 Nov 2017, 18:23

nnnik wrote: https://github.com/mmikeww/AHKv2-Gdip/c ... af83a2db51
^This commit broke the library for AHK v1 users
yes, the readme was changed a few commits prior removing the mention of backwards compatibility. feel free to re-instate it if you can, and create a pull request. i thought it was no longer possible to be backwards compatible. in v2 "command" syntax now requires expressions as parameters, whereas in v1 its literal text. so how do you get around that?
jeeswg wrote:- @guest3456: In AHK v2, I recently discovered that the proper output value for SendMessage is now the output variable for the function and not ErrorLevel.
If SendMessage no longer uses ErrorLevel, then how could that be made backward compatible? v2 would require the function syntax to get the return value
jeeswg wrote: - @nnnik and guest3456: Perhaps you could make it so that Gdip v2 could work in AHK v1.1, if you also include this library. This is why I wrote the library(/updated the work by Coco), I believe it's the only realistic way (without creating something horrendous,) to have scripts that are two-way compatible.
commands as functions (AHK v2 functions for AHK v1) - AutoHotkey Community
https://autohotkey.com/boards/viewtopic ... 37&t=29689
i really don't want to include an external library. v2 was meant to break compatibility anyway, and lexikos doesn't seem to really care to try to compensate for it. so if its not easy, it might be a worthless cause



input requested. i've compiled a list of some of the required changes here:
https://github.com/mmikeww/AHKv2-Gdip/issues/11

User avatar
nnnik
Posts: 3340
Joined: 30 Sep 2013, 01:01
Location: Germany

Re: GDI+ standard library 1.45 by tic

15 Nov 2017, 02:12

Well this library was advised and people still tend to advise it as the standard for AHK v1.
However with backwards compatability removed this is no longer feasonable.
It might be better to break forwards compatability.
Recommends AHK Studio
User avatar
joedf
Posts: 6487
Joined: 29 Sep 2013, 17:08
Facebook: J0EDF
Google: +joedf
GitHub: joedf
Location: Canada, Quebec
Contact:

Re: GDI+ standard library 1.45 by tic

15 Nov 2017, 08:45

break the backwards and the forwards. ;)
guest3456
Posts: 2419
Joined: 09 Oct 2013, 10:31

Re: GDI+ standard library 1.45 by tic

15 Nov 2017, 09:30

nnnik wrote:Well this library was advised and people still tend to advise it as the standard for AHK v1.
However with backwards compatability removed this is no longer feasonable.
It might be better to break forwards compatability.
the repo name clearly states AHKv2-Gdip. the latest readme clearly says that this library is for AHK v2 and mentions NO support for AHK v1. whoever is advising this library as the 'standard' for v1 is obviously incorrect, and giving bad advice, and probably shouldn't be listened to, since RTFM is such a basic thing. if you are using v1 then just use the Gdip_All linked in the very first post in this thread. why would a v1 user ever use a version clearly labelled v2? yes there are some bugfixes but thats not the responsibility of this repo to work with unsupported versions

the original version DID have support for both AHK v1 and AHK v2, because at that time, the v2 changes were not so radical, and backwards compatible support was easily possible.

regardless, as said, it may still be possible to make it backwards compatible, as discussed in the Issue here. someone would just need to do it and test it with the Example files and submit a pull request. i dont know when ill have time.
https://github.com/mmikeww/AHKv2-Gdip/issues/11

User avatar
nnnik
Posts: 3340
Joined: 30 Sep 2013, 01:01
Location: Germany

Re: GDI+ standard library 1.45 by tic

15 Nov 2017, 11:13

Yes indeed this library can no longer be reccomended.
Recommends AHK Studio
User avatar
nnnik
Posts: 3340
Joined: 30 Sep 2013, 01:01
Location: Germany

Re: GDI+ standard library 1.45 by tic

15 Nov 2017, 11:25

I have removed the references towards Gdip_all.ahk from the beginning of this topic and only left references towards the old library.
If you wish to publish this library further please create a new topic. ( I will split all posts about this new library into that topic then )
Recommends AHK Studio
guest3456
Posts: 2419
Joined: 09 Oct 2013, 10:31

Re: GDI+ standard library 1.45 by tic

15 Nov 2017, 11:35

nnnik wrote:Yes indeed this library can no longer be reccomended.
the library can clearly be recommended for AHK v2, as was its sole initial intent.

nnnik wrote:I have removed the references towards Gdip_all.ahk from the beginning of this topic and only left references towards the old library.
what are you doing?

are you even thinking before acting? what kind of moderator are you?

the link in the first post of this thread was tic's link to a WORKING v1 VERSION Gdip_All. tic added the link per the request here. it was NOT a link to the v2 library. you've now made it impossible for anyone to get a v1 version of Gdip_All. good work.

i've reported your post. hopefully other moderators and fix your mistakes.

nnnik wrote:If you wish to publish this library further please create a new topic. ( I will split all posts about this new library into that topic then )
this thread is historically for all questions of Gdip. the v2 library doesn't need a separate thread, since the changes are minor, and many people will search this thread first.

User avatar
nnnik
Posts: 3340
Joined: 30 Sep 2013, 01:01
Location: Germany

Re: GDI+ standard library 1.45 by tic

15 Nov 2017, 11:40

guest3456 wrote:
nnnik wrote:Yes indeed this library can no longer be reccomended.
the library can clearly be recommended for AHK v2, as was its sole initial intent.
nnnik wrote:I have removed the references towards Gdip_all.ahk from the beginning of this topic and only left references towards the old library.
what are you doing?

are you even thinking before acting? what kind of moderator are you?

the link in the first post of this thread was tic's link to a WORKING v1 VERSION Gdip_All. tic added the link per the request here. it was NOT a link to the v2 library. you've now made it impossible for anyone to get a v1 version of Gdip_All. good work.

i've reported your post. hopefully other moderators and fix your mistakes.
Hmm yes indeed this was a mistake I apologize.
guest3456 wrote:
nnnik wrote:If you wish to publish this library further please create a new topic. ( I will split all posts about this new library into that topic then )
this thread is historically for all questions of Gdip. the v2 library doesn't need a separate thread, since many people will search this thread first.
Well if that Gdip_All link wasn't pointing to you library I guess this is not neccessary either.
If you could provide the link to the AHK v1 Gdip_All Version I would add it back again myself.
Recommends AHK Studio
guest3456
Posts: 2419
Joined: 09 Oct 2013, 10:31

Re: GDI+ standard library 1.45 by tic

15 Nov 2017, 11:52

nnnik wrote:
guest3456 wrote:
nnnik wrote:I have removed the references towards Gdip_all.ahk from the beginning of this topic and only left references towards the old library.
it was NOT a link to the v2 library. you've now made it impossible for anyone to get a v1 version of Gdip_All.
If you could provide the link to the AHK v1 Gdip_All Version I would add it back again myself.
i don't have it. maybe tidbit or tic does. these quotes should notify them:

tidbit wrote:no offense tic, but can we remove your download link and only keep _All ?
tic wrote:Yes, I shall do so until Gdip2 is done. I've been so busy that I haven't had a chance to look at it

User avatar
nnnik
Posts: 3340
Joined: 30 Sep 2013, 01:01
Location: Germany

Re: GDI+ standard library 1.45 by tic

15 Nov 2017, 12:06

It also seems that I have been under the impression that your repository on GitHub was also the main repository of the Gdip_All.ahk, due to the old ReadMe that kind of only states the goal of implementing AHK v2 compatability.
I think instead of waiting for them it would be faster to implement AHK v1.1 backwards compatability.
This is the last Version that worked properly on v1.1 https://github.com/mmikeww/AHKv2-Gdip/b ... ip_All.ahk
I still think that you should create your own topic though in order to more clearly show the differences between Gdip_All and your script.
Recommends AHK Studio

Return to “Scripts and Functions”

Who is online

Users browsing this forum: Google [Bot] and 16 guests