Closed SamSandq closed 9 months ago
This commit https://github.com/frang75/nappgui_src/commit/ee5c8c8d76b3604151f5d4bbea2e2f405dbfc2ed (Overlay Windows) adds two functions that can be used for this task.
window_control_frame()
https://nappgui.com/en/gui/window.html#f26
window_client_to_screen()
https://nappgui.com/en/gui/window.html#f27
An example of use: https://nappgui.com/en/howto/guihello.html#h11
I checked out your example, and it seems to do the trick nicely. Thanks!
I close this issue, feel free to reopen if needed.
I tested it and it does not achieve want I want. Specifically, my code is...
if (dragEventType == ddPerform) {
//where?
V2Df vpos = mouse_position_in_view(view_native(app->view));
j_mouse_cell(app, vpos.x, vpos.y, 0);
//which photo thumbnail?
uint32_t nPhoto = (app->mouse_cell_y) * app->ncols + app->mouse_cell_x;
//past end?
if (app->numImg <= nPhoto) return;
In other words, I am dragging a tag to the view where my thumbnail photos are and want to know where it was dropped. It's not a control, a view, so the window_control_frame
cannot be used, and the window_control_frame
does not help. I use the same kind of code to find out all drop locations.
I need a mouse_position_in_view(...)
like I have, or a better gui_mouse(<view or control or NULL>)
.
To get the mouse position in view coordinates you have to ways:
In macOS part: Using [theEvent locationInWindow]
like NAppGUI does. Show oslistener.m::i_mouse_position_in_view_coordinates(view, [theEvent locationInWindow], ¶ms.lx, ¶ms.ly);
In NAppGUI part: Using the inverse coordinate transform:
V2Df spos = gui_mouse_pos();
GuiControl *view_control = guicontrol(view); // From your View object
V2Df wpos = window_get_origin(your_view_window);
R2Df frame = window_control_frame(your_view_window, view_control);
V2Df mpos;
mpos.x = spos.x - wpos.x - frame.x; mpos.y = ...
I actually code very close to your first option; my function mouse_position_in_view(view_native(....))
and it works just fine.
I tried code more or less the same as yours, and it failed --- as does yours:
So something is amiss, but what?
Without debugging the only thing occurs to me is a bug on window_control_frame
. Change the code by this. If issue continue, try the get into window_control_frame
for more info.
R2Df window_control_frame(const Window *window, const GuiControl *control)
{
R2Df r2d;
GuiComponent *component = (GuiComponent*)control;
Cell *cell = NULL;
cassert_no_null(window);
cassert_no_null(component);
cassert(_component_window(component) == window);
cassert(i_in_active_layout(window, component) == TRUE);
_component_get_origin(component, &r2d.pos);
_component_get_size(component, &r2d.size);
cell = component->parent;
for (; cell != NULL;)
{
V2Df panel_pos;
Layout *layout = _cell_parent(cell);
Panel *panel = _layout_panel(layout);
if (panel != NULL)
{
GuiComponent *panel_component = (GuiComponent *)panel;
_component_get_origin(panel_component, &panel_pos);
r2d.pos.x += panel_pos.x;
r2d.pos.y += panel_pos.y;
cell = panel_component->parent;
}
else
{
cell = NULL;
}
}
return r2d;
}
I will check that tomorrow… hope we can it resolved
Currently it is possible to obtain the global mouse position using
V2Df pos = gui_mouse();
This should be enhanced to accept an argument, a view, and would then return the mouse position inside that view. This is used for instance when one wants use the relative position inside a view for positioning something, where a
pos = gui_mouse(myView)
would suffice. On a NULL argument the current global position should be returned.