Author |
Topic |
|
PeterPanino
933 Posts |
Posted - May 02 2023 : 14:49:25
|
I need to show the Layer Properties dialog for a selected Layer, either by:
1. Invoking the Layer's context menu by right-clicking the Layer and selecting the Layer Properties Dialog menu item, or: 2. Programmatically invoking the Layer's Property dialog, e.g., by double-clicking the Layer while holding the CTRL key.
Unfortunately, when I right-click a Layer, no Layer context menu is shown, but rather a context menu with items that refer to the whole image (not to the Layer) is shown:
I suppose it is a fundamental and obvious UI feature to show the context menu of the right-clicked object and not the context menu of a completely different object. So how can I show the context menu of the right-clicked Layer? |
|
xequte
38611 Posts |
Posted - May 02 2023 : 16:24:45
|
Hi Peter
What is the value for ImageEnView1.PopupMenus?
http://www.imageen.com/help/TImageEnView.PopupMenus.html
It should be:
// Display popup with buttons relevant to editing layers. If right-clicking a layer, it changes to methods for the current layer ImageEnView1.PopupMenus := [ ievLayerEditing, ievLayerSelection ];
Nigel Xequte Software www.imageen.com
|
|
|
PeterPanino
933 Posts |
Posted - May 02 2023 : 17:33:53
|
Hi Nigel,
I've tried that already. But this shows the Layer context menu even when I right-click a regular image without any Layer present:
|
|
|
xequte
38611 Posts |
|
PeterPanino
933 Posts |
Posted - May 03 2023 : 02:18:57
|
"If you need more configuration"
IMO, showing the correct context menu for the right-clicked object should be automatically controlled by ImageEn: Nobody would want to show the Layer context menu when right-clicking Layer 0 (the background image). |
|
|
PeterPanino
933 Posts |
Posted - May 03 2023 : 03:22:11
|
I have now found the most simple/best solution that works perfectly:
procedure TformMain.ImageEnView1MouseDown(Sender: TObject; Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
begin
var ThisLayer := ImageEnView1.FindLayerAt(X, Y);
if Button = mbLeft then
begin
// ...
end
else if Button = mbRight then
begin
if ThisLayer > 0 then
ImageEnView1.PopupMenus := [ievLayerEditing, ievLayerSelection]
else if ThisLayer = 0 then
ImageEnView1.PopupMenus := [ievViewing, ievEditing, ievSelection];
end;
end;
Now the correct context menu is shown in any case! |
|
|
PeterPanino
933 Posts |
Posted - May 03 2023 : 05:40:25
|
This adds more flexibility by showing the CONTEXT TOOLBAR instead of the context menu when holding down the CTRL key while right-clicking a Layer:
procedure TformMain.ImageEnView1MouseDown(Sender: TObject; Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
begin
var ThisLayer := ImageEnView1.FindLayerAt(X, Y);
if Button = mbLeft then
begin
ImageEnView1.AutoToolbars := [];
// ...
end
else if Button = mbRight then
begin
if ThisLayer > 0 then // right-clicked a floating Layer (not the Background)
begin
// only CTRL modifier key pressed:
if (GetKeyState(VK_CONTROL) < 0) and (GetKeyState(VK_SHIFT) >= 0) and (GetKeyState(VK_MENU) >= 0) then
begin
ImageEnView1.PopupMenus := [];
ImageEnView1.AutoToolbars := [ievLayerEditing, ievLayerSelection];
end
// NO modifier key pressed:
else if (GetKeyState(VK_CONTROL) >= 0) and (GetKeyState(VK_SHIFT) >= 0) and (GetKeyState(VK_MENU) >= 0) then
begin
ImageEnView1.PopupMenus := [ievLayerEditing, ievLayerSelection];
ImageEnView1.AutoToolbars := [];
end
end
else if ThisLayer = 0 then // right-clicked the Background Image
begin
ImageEnView1.PopupMenus := [ievViewing, ievEditing, ievSelection];
ImageEnView1.AutoToolbars := [];
end;
end;
end;
I love the flexibility in ImageEn.
Layer context menu with no modifier keys pressed:
Layer context toolbar with CTRL key pressed:
|
|
|
PeterPanino
933 Posts |
Posted - May 04 2023 : 13:43:31
|
Hi Nigel,
I want to add an item to the popup context menu when right-clicking a Layer: Merge to Background.
So I followed your link above and applied the example on the page "TIEGlobalSettings.OnAddPopupMenuItem":
procedure TformMain.IEGlobalSettings1AddPopupMenuItem(Sender: TObject; ToolbarID, ButtonID: Integer; var Include: Boolean);
begin
if ToolbarID = Layer_Selection_PopupMenu_ID then
begin
if ButtonID = IELayersMergeToBackground_Button_ID then
Include := True;
end;
end;
Unfortunately, it does not work. So how can I add the desired menu item?
In other words: What is the TIEGlobalSettings.OnAddPopupMenuItem event handler good for if it does not work? |
|
|
PeterPanino
933 Posts |
Posted - May 04 2023 : 17:00:41
|
Meanwhile, I use this code to configure the LayerSelection context menu:
procedure TformMain.FormCreate(Sender: TObject);
begin
// layer-Popupmenu:
IEGlobalSettings().LayerSelectionPopupMenu := [
ivbLayersPropsDlg, // TImageEnViewLayersShowPropertiesDialog
ivbLayersGroup, // TImageEnViewLayersGroup, TImageEnViewLayersUngroup
ivbLayersOther, // IELayerFlipHorz_Button_ID, IELayerFlipVert_Button_ID
ivbLayersStyle, // TIELayerFill, TIELayerBorder, TIELayerBorderWidth
ivbLayersSize, // TIELayerRestoreAspectRatio, TIELayerSizeToFit, TIEImageLayerRestoreSize
//ivbLayersProps,
//ivbLayersEdit,
ivbLayersEditCurrent // TImageEnViewLayersMergeToBackground, TImageEnViewLayersRemoveCurrent,
// TImageEnViewLayersCropBackground, TIELayerConvertToImageLayer
];
This results in the following Layer context menu:
However, to achieve better fine-tuning, it would be important that the "TIEGlobalSettings.OnAddPopupMenuItem" would work as intended. |
|
|
xequte
38611 Posts |
Posted - May 04 2023 : 22:06:53
|
Hi Peter
Please read the documentation:
http://www.imageen.com/help/TIEGlobalSettings.OnAddPopupMenuItem.html
The event occurs once for each item specified by the popup menu property, so you need to add it to the popup list to be offered.
However this is one of the things that is changed in the upcoming 12.0.5. From v12.0.5 all items are output to OnAddPopupMenuItem, OnAddToolbarButton, etc, and you can include/exclude more simply.
You can email me for a beta if you like.
Nigel Xequte Software www.imageen.com
|
|
|
PeterPanino
933 Posts |
|
xequte
38611 Posts |
Posted - May 05 2023 : 17:07:29
|
Hi Peter
We're hoping to get it out before the end of May, but you can email me for a beta.
Nigel Xequte Software www.imageen.com
|
|
|
|
Topic |
|
|
|