Spawnova / ShinsOverlayClass

A direct2d overlay for AutoHotkey
MIT License
65 stars 12 forks source link

ReSizing the (client) region semi-manually #6

Closed KRN-8 closed 9 months ago

KRN-8 commented 1 year ago

Is there a way to do some more math on the overlay size after the Class is done but before it is used for creating the overlay ?

A lot of the time, the client window setting is not very usefull (damn those app devs not setting it properly) soo i would like to substract a few pixels from the top and maybe third of the window from left (there is an add which i COULD disable but i would prefer supporting the devs as much as possible :-) )

Best case scenarion i would use the initial window to scan for the actual client window and then use these size params for creating the actual client sizef Classes (i would LOVE this to be a thing for both of your AMAZING Classes (scan & overlay))

With this i would probably end up semi-manually finding the portion of the window i want to work with and use it for BOTH of the Classes. Sort of like a localized singular window overlay, where both work with same coords (ofc. would be RAD if you did that, but that might be asking for a bit too much, soo im ok with a workaround i could make with the exposed internals/split functions for now ;-) )

Spawnova commented 1 year ago

When creating the class the second parameter handles whether it should overlay the entire window (including invisible borders) or just the client region, are you saying with that set to 1 the overlay is not correctly set to the client rectangle?

I could potentially add an offset function that lets you define x,y,w,h offsets to alter the overlay dimensions

KRN-8 commented 1 year ago

behaves the same if i set it to 0 or 1 or dont set it at all (probably cause of the default 1) it is the thing u mentioned in some of the YT videos (not sure if it was uploaded by your channel or a collab one) but, some windows just dont set the client part fully and keep the top toolbar

additionally a lot of applications have other sub parts and sub windows (like a sidebar or advertisment side pannel and such) and you usually wanna just work with one portion of the application :-)

soo, YES pls add the offset stuffies THAT would help a TON ORr explain how to use the current x,y,w,h to make another overlay using the main one :-) cause then i could make secondary overlay using the parameters of the old one and some scans and math ! yay

WAaaIT, COULD i actually just not use the offsets at first and then resize the overlay 1 scan afterwards ? then only reset to original size when your resize/recalculateWindow function(s?) get called ? ... hmm

Spawnova commented 1 year ago

One issue is that if you are using both of my libraries and you change positions then they are no longer on the same page, so it's important that they both are set correctly I think honestly you don't really need to change the overlay dimensions, but rather just only draw to the areas you are interested in, and for scanning just use region scans here is an example

regions := []
regions.main := {x:200,y:200,w:200:h:200}

;...

Draw:
if (overlay.BeginDraw()) {

    r := regions.main
    if (!scan.ImageRegion("test.png",r.x,r.y,r.w,r.h,0,x,y)) { ;if not found draw a red outline around the region
        overlay.DrawRectangle(r.x,r.y,r.w,r.h,0xFFFF0000)
    } else {
        overlay.DrawRectangle(r.x,r.y,r.w,r.h,0xFF00FF00) ;if found draw a green rectangle and a line
        overlay.DrawLine(r.x,r.y,x,y,0xFF00FF00)
    }

    overlay.EndDraw()
}
return
KRN-8 commented 1 year ago

yee, they indeed would need to be both set to the same thing RN im not doing regions at all, and just not using a lot of the scanned screen the thing is, if i used regions then the coordinates math would be considerably more complicated thou ;-( at that point i would rather do it properly

as i mentioned before im making a tilemap of sorts soo would be nice if i didnt have to do extrenious checking for bounding boxes of the game's screen portion (if else blocks scarry XD)

i will try this (region method you mentioned) and a few other methods, but it would be nice if we could create both classes with custom rectangle x,y,w,h and be able to extract these parameters from atleast one of them ;-)

KRN-8 commented 1 year ago

just the client region, are you saying with that set to 1 the overlay is not correctly set to the client rectangle?

i think i am, cause it IS set to 1 but i still offset the game rectangle by 2 pixelf from left and 1 from bottom to ge the true inset Game rectangle :-)

Spawnova commented 1 year ago

Yes, some games do not use the default window style and create their own, so their borders and title bar are actually part of the client area

KRN-8 commented 1 year ago

ye, thats sth. like what i thought is happening from the start

btw. did u miss this one ? https://github.com/Spawnova/ShinsOverlayClass/issues/6#issuecomment-1575465969

Spawnova commented 1 year ago

No, I saw it, I think in your case just creating some custom region and possibly even some helper functions is the best approach with that in mind you can easily scan your tiles by passing in their x,y index


f1::
if (ScanTile(scan,0xFF0000,3,2,0,x,y)) {
   msgbox % "Tile at index 3,2 matched the color red, position in the tile: " x "," y
}
return

;helper function, assumes zero based tiles
ScanTile(scan,color,tileX,tileY,var:=0,byref x:=0,byref y:=0) {
   r := {x:200,y:200,tileSize:32} ;tiles start at 200,200 and they are 32x32 pixels
   tileX := r.x + (tileX*r.tileSize)
   tileY := r.y + (tileY*r.tileSize)

   return scan.pixelregion(color,tileX,tileY,r.tileSize,r.tileSize,var,x,y)
}
KRN-8 commented 1 year ago

ye i was thinking sth. like this too, but i will also have to check the sub bounding box and scan for tile size (which i would have to anyways without img scaling XD) cause around 1/3 of the right side was covered with ads ... RIP soo tile(1,2) would be touching the top bar or the ad side pannel XD (OHNO)