English Amiga Board


Go Back   English Amiga Board > Coders > Coders. System

 
 
Thread Tools
Old 09 January 2022, 18:01   #1
Warty
Registered User
 
Join Date: Aug 2018
Location: Minneapolis, USA
Posts: 301
Finding out which window is in front of another?

Situation: I have 3 windows open, and am dragging an object from the front-most window, and want to drop it on one of the other 2 windows. I drag it to a place where windows 2 and 3 happen to overlap/exist. I want it to go to the window that is in front of the other.

(In screenshot, I'm trying to drop AMAX.readme onto the Emulators folder, but under the Emulators folder is a Games folder. I don't want it to go there.)

How do I know which window should get the drop? I can use MouseX/Y to check windows are at that point, but when there are 2+ windows...

I don't see any function that returns the depth of a window, and don't see anything in the window struct that is tracking depth, so I suppose the depth is a function of an exec list that tracks all the windows or something? I see functions for putting a window to the front, or putting it front of another window, but I don't see anything for comparing 2 windows and seeing which is in front. How have people solved this?
Attached Thumbnails
Click image for larger version

Name:	Screen Shot 2022-01-09 window depth q.png
Views:	71
Size:	72.3 KB
ID:	74346  
Warty is offline  
Old 09 January 2022, 18:53   #2
Thomas Richter
Registered User
 
Join Date: Jan 2019
Location: Germany
Posts: 3,233
The layers.library "WhichLayer()" tells you which layer a position on the bitmap is in, from which you can work your way back to the window the layer belongs to. Beware, however, that intuition may change this order any time as long as you don't lock the LayerInfo-structure, see again for the layers.library how to do that.

Window->NextWindow is a singly linked list of windows (not an exec style list), but it does not exactly state a "depth". In fact, there is no "Z coordinate" tracked anywhere.

The closest representative of what you are looking for is the Layer->Front and Layer->Back links, documented in graphics/clip.h. They keep a doubly-linked (though not exec-style) list of layers, ordering them from frontmost to backmost. Again, for these links to stay constant, lock the layerInfo of the screen.
Thomas Richter is offline  
Old 09 January 2022, 23:01   #3
Warty
Registered User
 
Join Date: Aug 2018
Location: Minneapolis, USA
Posts: 301
Thanks for the pointers, Thomas! That was exactly what I needed.

I haven't done much with Layers yet, but I'll have to dig into them more when I get around to needing to show the icons dragging from window to window. Right now, I'm still just rendering them within each window.

Some example code below in case anyone searches for this in future. one thing I did notice is that it will return a null window if the mouse is in the screen title bar area (and no window is on top of the title bar). Maybe it is always going to draw the menu bar over the backdrop window.

Code:
// Find the Surface under the mouse -- accounts for z depth (topmost window will be found)
WB2KWindow* App_FindSurfaceUnderMouse(WB2KApp* the_app)
{
	struct Layer_Info*	the_layer_info = &the_app->screen_->LayerInfo;
	struct Layer*		the_layer;
	struct Window*		the_window_under_mouse;
	WB2KWindow*			the_surface_under_mouse;
	
	// LOGIC:
	//   measuring just against window coords alone doesn't mean some other window wasn't in front
	//   the layer library has a function WhichLayer which will tell you which window is in front at the coords passed. 
	//   note from Thomas R on EAB: "intuition may change this order any time as long as you don't lock the LayerInfo-structure"
	
	LockLayerInfo(the_layer_info);
	
	the_layer = WhichLayer(the_layer_info, global_app->screen_->MouseX, global_app->screen_->MouseY);
	
	UnlockLayerInfo(the_layer_info);
	
	if (the_layer == NULL)
	{
		// don't know if this would ever return null, but...
		LOG_ERR(("App_FindSurfaceUnderMouse %d: Layer library returned a NULL for layer under mouse!!?", __LINE__));
		App_Destroy(); // crash early, crash often
	}
	
	the_window_under_mouse = the_layer->Window;	

	if (the_window_under_mouse == NULL)
	{
		// this DOES happen. Seems to occur only under the screen's title bar. The backdrop window starts at 0,0, but maybe title bar has special layer. 
		// for this app, this doesn't need to be fatal. 
		DEBUG_OUT(("App_FindSurfaceUnderMouse %d: Layer library thinks a layer not associated with a window was clicked.", __LINE__));
		return NULL;
	}
	
	the_surface_under_mouse = App_FindSurfaceByWindow(global_app, the_window_under_mouse);
	
	if (the_surface_under_mouse == NULL)
	{
		LOG_ERR(("App_FindSurfaceUnderMouse %d: the window Layer library says mouse was on a window, but that window doesn't appear to be a WB2K window", __LINE__, the_surface_under_mouse->title_));
		App_Destroy(); // crash early, crash often
	}

	return the_surface_under_mouse;
}
Warty is offline  
Old 09 January 2022, 23:51   #4
Thomas Richter
Registered User
 
Join Date: Jan 2019
Location: Germany
Posts: 3,233
Please keep the lock of the layer_info as long as you haven't verified the window pointer, namely to ensure that the pointer points to one of your windows. Note that the layer may get away as soon as you unlock the layer_info, i.e. you cannot safely evaluate layer->Window without the lock being held. As soon as you know that the window is your window, you can unlock because it is your program that controls the life time of this window.

That layer->Window is NULL may, indeed, happen because there are more layers than just those created by intuition for its windows.
Thomas Richter is offline  
Old 10 January 2022, 21:52   #5
Warty
Registered User
 
Join Date: Aug 2018
Location: Minneapolis, USA
Posts: 301
Ok, I modified to unlock only after I got what I needed out of that window object. Thanks again!
Warty is offline  
 


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools

Similar Threads
Thread Thread Starter Forum Replies Last Post
Focus active window to front when clicked with mouse Loki762 support.Other 11 21 March 2021 06:04
Front Lines Seiya Nostalgia & memories 0 31 July 2018 12:51
A4000 Front Thalion MarketPlace 2 11 July 2015 23:33
Bring window to front and focus when clicked rossb project.ClassicWB 7 21 April 2010 16:10

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +2. The time now is 19:00.

Top

Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2024, vBulletin Solutions Inc.
Page generated in 0.07920 seconds with 14 queries