Shadow for custom mouse cursor - windows

On "newer" Windows systems there is an option to make the OS draw a shadow beneath the mouse cursor:
However the custom cursors in my Delphi app don't show a shadow even if this setting is enabled. Do you have any idea how to arrange it so that Windows adds the shadow automagically? Or do I really have to check the user's preferences and conditionally draw the shadow myself like Mike Lischke did?
(This is a question that has been bugging me and others for some time:
Custom mouse cursor shadow
Custom cursor shadow
Custom cursor with shadow)

No, you don't need to check the user's global setting and draw the cursor yourself. You just need to provide a cursor with the alpha channel. Windows will either use alpha blending to draw your cursor or not, depending on the user's setting. Your cursors probably don't include the alpha channel so the shadow is never shown.

Related

Center pointerlockcontrols on the mouse curosr

The problem
As the cursor locks, the cursor is set to the position of the screen where i clicked. But i would like to have my cursor centered to the screen. As that is not possible for security reasons, the only available option is to move the camera(maybe with lookAt) towards the cursor position.
In my example i would like that when the cursor is locked that the little gray square in the center of the screen provokes a hover. This meaning that the cursor is exactly in the center of my camera.
The reason i want to achieve this is because i would like my clicks to be performed from the center of the screen, if i for instance want to trigger the onclick of a 3D object in front of the camera.
I would like to know if it is possible to do so with the pointerlockcontrols and if yes, how could one proceed ?
What i have so far
At the time i've just tried the basic implementation of pointerlockcontrols but can't figure out the way to put the cursor in the desired position.
Unfortunately pointerlockcontrols does not work on my codesandbox example.
The code sandbox that unfortunately does not work
Thanks in advance for your help.
Found my answer here :
Screen centered pointer lock controls
the trick is just to move the raycast to the center of the screen.

Common Controls on a Transparent Window?

While there are lots of variations of the question, there doesn't seem to be a specific answer to a simple case of wanting to use built-in common controls on a transparent window using Win32. I don't want the controls to be transparent, I just want the border around it to be transparent. I can't believe MS didn't update the .dll's to handle transparency when they added it, but I guess they forgot? Is there a specific method that works. A button can get close with WS_EX_TRANSPARENT, but flaky where it works most of the time but at times part of the border shows up. Edit controls, change depending on when get focus or not.
So the question is simply:
Is there a way to make common controls on transparent window so there is no white border around them?
If not, is there a good replacement library that does it via owner draw?
If some, which ones and what is the method?
Seems silly to reinvent the wheel just because of the area around the control.
TIA!!
If I am not mistaken, you can take the following steps to achieve this effect.
1.Create a GDI+ Bitmap object with the PixelFormat32bppPARGB pixel format.
2.Create a Graphics object to draw in this Bitmap object.
3.Do all your drawing into this object using GDI+.
4.Destroy the Graphics object created in step 2.
5.Call the GetHBITMAP method on the Bitmap object to get a Windows HBITMAP.
6.Destroy the Bitmap object.
7.Create a memory DC using CreateCompatibleDC and select the HBITMAP from step 5 into it.
8.Call UpdateLayeredWindow using the memory DC as a source.
9.Select previous bitmap and delete the memory DC.
10.Destroy the HBITMAP created in step 5.
This method should allow you to control the alpha channel of everything that is drawn: transparent for the background, opaque for the button.
A similar discussion: Transparent window containing opaque text and buttons

Direct2D: leave a region of a window render target untouched

I am drawing to a regular HwndRengerTarget but other windows, which have nothing to do with Direct2D, overlap it.
The problem is that these windows get painted over when I draw to the HwndRengerTarget.
I would like to tell Direct2D not to touch a specific region of the HwndRengerTarget (i.e. don't touch the pixels that are already on the screen), so that these windows remain correctly visible.
Is that possible?
If I draw normally then call RedrawWindow on the windows, it flickers a lot.
Thanks.
If you want to manually restrict your rendering to a certain region you can use layers (ID2D1Layer objects).
More info here Layers Overview
If the visible region is rectangular it may be simpler to use axis aligned clips via methods PushAxisAlignedClip and PopAxisAlignedClip.
ID2D1RenderTarget::PushAxisAlignedClip
Another method of restricting drawing to a certain shape is to render it to a bitmap and then use this bitmap via a bitmap brush in the FillGeomtry method.
ID2D1RenderTarget::FillGeometry
Why not arrange the windows (HWNDs) so that the Direct2D one is at the bottom of the z-index? It should be the first child of its parent. Then clipping will be automatic. You may need the WS_CLIPSIBLINGS window style.
I had the same problem.
Fixed by calling CreateWindowEx LAST for the D2D child HWND.
So AFTER all the other child windows are created.

Fading the cursor

I have a Windows application for which I would like to indicate that the content is dead/frozen/not interactable by fading it to 50%.
Is there a way to take the standard Windows cursor and fade it?
I have never seen a case of the Windows cursor being anything but 100% opaque, and I heavily suspect that there's no option to make it transparent because the uses are limited and the abuses are many (i.e. make cursor invisible, would cause massive frustration).
I don't know of any way to do that, and it makes sense there's none - it is not a part of Window's look and feel. You'd usually fade the dead/frozen/not interactable control rather than the cursor, and/or change the cursor to a standard hourglass or so.
Having that say, if fading the cursor is definitively what you want, you can create a faded image of the standard cursor, and load it when needed.

Shadow for custom mouse cursor (2)

After reading the answer to the Shadow for custom mouse cursor question, I did some testing.
From my Delphi application I loaded both 32bit and 24bit versions of my cursor. Never a shadow. I did the same with the standard Windows arrow pointer. No shadow either.
Also I tried the opposite and assigned my custom cursors to the "Normal select" pointer in the Windows mouse settings. Both the 24bit and 32bit pointer were given a shadow.
So, it appears having an alpha channel in a cursor doesn't influence the shadow behaviour. But what am I doing wrong in my application?
First step is adding the cursor to the application's resources via an .rc file with
CUR_EDGE_R Cursor DISCARDABLE "edge_r.cur"
And in the application it is loaded with:
const
crEdgeR = TCursor(135);
.
.
Screen.Cursors[crEdgeR] := LoadCursor(HInstance, 'CUR_EDGE_R');
So, what is the way to have Windows add a shadow to a custom cursor?
Note: I have seen posts on the internet suggesting to create two version of the mouse cursor, one with and one without shadow, and load the appropriate cursor, depending on the user's settings. This is not the solution I'm looking for.
In order to place a shadow under your custom cursor, you simply design the cursor with an Alpha channel (which enables semi transparency) and draw your shadow in place. You can even use Photoshop/GIMP (or any other capable graphics editor) to produce your cursor with a "Drop Shadow" effect, save it as a PNG, then use an Icon Editor (such as Microangello) to convert the PNG to a cursor.
As I understand it, none of the cursors shipped with Windows Vista/7 are designed as "flat", using some system effect to generate their shadows.

Resources