Author Topic: ModernUI_Spinner Control  (Read 1737 times)

fearless

  • Member
  • ***
  • Posts: 469
    • LetTheLightIn
ModernUI_Spinner Control
« on: June 28, 2019, 09:38:27 AM »
I updated my spinner control (original version is here: http://masm32.com/board/index.php?topic=1179.0)

Download

The control can be downloaded via the ModernUI repository or downloaded directly from this link: https://github.com/mrfearless/ModernUI/blob/master/Release/ModernUI_Spinner.zip?raw=true


Example

I created an example project to demonstrate it.

The example (which includes a Radasm project) can be downloaded via the ModernUI repository or downloaded directly from this link: https://github.com/mrfearless/ModernUI/blob/master/Release/MUISpinner1.zip?raw=true



There are a number of ways of adding image frames to the ModernUI_Spinner control.
The most basic level is to add individual images to construct the spinner animation. This can be done with the MUISpinnerAddFrame or MUISpinnerLoadFrame - using an image handle that is already loaded or using a resource id of an image.

For example, the first spinner it is comprised of 8 separate bitmap images:


For images that are circular, it can be more convenient to use the MUISpinnerAddImage or MUISpinnerLoadImage functions, as these only require one image. The image is copied a number of times into frame images - as specified by the dwNoFramesToCreate parameter. Each new frame image is incrementally rotated - based on the angle calculated for each new frame image. The bReverse parameter if set to TRUE will set the spinner animation to counter-clockwise. Note: the MUISpinnerAddImage or MUISpinnerLoadImage functions only work with png images or png's stored as RCDATA resources.

The far right spinner on the top row is created via loading a single png image:

Once loaded it is rotated and new frames are created to enable it to look like this:


For more complicated spinners, or spinners that are not circular in nature, the MUISpinnerAddSpriteSheet and MUISpinnerLoadSpriteSheet functions are provided. These allow you to provide a long (wide) image (bitmap, icon or png) handle (or resource id) that contains all the spinner frames in the one image. The image frames are extracted out of this image. The amount of frame images in the spritesheet is passed via the dwSpriteCount parameter.

The clock spinner is a good example of this, as it can't be rotated due to the buttons around its edge:

So either it can be constructed by manually adding each frame or by using a spritesheet like so:

Which looks like this once all the individual frames are extracted:


I put some compile time conditions to allow for using of TimerQueue, Multimedia Timer or WM_TIMER for the animation of the spinner.

The Icons8 website is a good source for spinners, and they can be adjusted for size and color etc before downloading - including under the additional download options button as a spritesheet (using apng format). Take note of the frames value, as you will need to use this so that the spritesheet can be divided up into the correct individual frames.

https://icons8.com/preloaders/en/search/spinner
fearless

CM690II Case, HX1000 PSU, Asus Z97, Intel i7-4790K, Seidon 120v Cooler, 16GB DDR3, MSI GTX 980TI

My Github  Twitter

Biterider

  • Member
  • ***
  • Posts: 391
  • ObjAsm32 + ObjAsm64 = ObjAsm
    • ObjAsm
Re: ModernUI_Spinner Control
« Reply #1 on: June 28, 2019, 04:02:45 PM »
Hi fearless
This is a very good job  :thumbsup:
Recently I needed something similar, but due to time constraints I used a different solution. I will try your control.
There are two things that need improvement:
- Under Win10 64, your application triggers a virus warning (Trojan).
- On some spinners there is a graphics error (see picture).

Keep this cool work going! The complete MUI is a good stuff  :thumbsup:

Biterider

jj2007

  • Member
  • *****
  • Posts: 9782
  • Assembler is fun ;-)
    • MasmBasic
Re: ModernUI_Spinner Control
« Reply #2 on: June 28, 2019, 05:19:03 PM »
It's beautiful, my compliments :thumbsup:

fearless

  • Member
  • ***
  • Posts: 469
    • LetTheLightIn
Re: ModernUI_Spinner Control
« Reply #3 on: June 28, 2019, 07:51:36 PM »
Thanks JJ and Biterider.
Its always work in progress ;-) but hopefully I can add to it all over time and build up a collection of useful UI controls.
Thats odd about the win10 x64 graphics issues - makes me think its dpi scaling related perhaps, as only a quarter of the image is shown for the spinners that are handled with the single image that is rotated - the manually added frames and spritesheet ones appear to look ok. Maybe its in using the GdipDrawRect in those single rotated images vs GdipDrawRectRect in the spritesheet functions. Something to look into though.

Also still have to do the x64 version at some point. But generally I'm behind with syncing my x64 version of the ModernUI controls and library vs the x86 version.
Thought about doing a ModernUI_Animation control which would likely be similar code, with additional code etc to handle a frame speed for each frame.
fearless

CM690II Case, HX1000 PSU, Asus Z97, Intel i7-4790K, Seidon 120v Cooler, 16GB DDR3, MSI GTX 980TI

My Github  Twitter

fearless

  • Member
  • ***
  • Posts: 469
    • LetTheLightIn
Re: ModernUI_Spinner Control
« Reply #4 on: June 28, 2019, 09:35:11 PM »
I updated the ModernUI_Spinner control to use the GdipDrawRectRectI instead of GdipDrawRect, hoping that this overrides any possible scaling issue - if that was the issue in win10 x64.
I uploaded MUISpinner1.exe to virustotal: https://www.virustotal.com/gui/file/d8c76960a7653fb3d688047101d662d0aa5c82fd0dfe33062f9ec888d7b6a7ae/detection
Only 4 false positives - so unsure how to combat that issue.
Attached is MUISpinner1.zip with just the updated exe to hopefully see if its fixed the issue on win10 x64
fearless

CM690II Case, HX1000 PSU, Asus Z97, Intel i7-4790K, Seidon 120v Cooler, 16GB DDR3, MSI GTX 980TI

My Github  Twitter

Biterider

  • Member
  • ***
  • Posts: 391
  • ObjAsm32 + ObjAsm64 = ObjAsm
    • ObjAsm
Re: ModernUI_Spinner Control
« Reply #5 on: June 28, 2019, 09:38:38 PM »
Hi fearless
Unfortunately, it behaves like the first version  :undecided:


Biterider

fearless

  • Member
  • ***
  • Posts: 469
    • LetTheLightIn
Re: ModernUI_Spinner Control
« Reply #6 on: June 28, 2019, 10:20:09 PM »
Well thats a strange one for sure. :D have to think on that for a bit, maybe I can create a dc and bitmap, then handle the original image with that as the backing and get that graphics context, instead of getting the graphics context straight from the image.

Do you have a high dpi monitor? I think it's a scaling issue, but don't know for sure - maybe its an issue with the actual png image somehow?
fearless

CM690II Case, HX1000 PSU, Asus Z97, Intel i7-4790K, Seidon 120v Cooler, 16GB DDR3, MSI GTX 980TI

My Github  Twitter

LiaoMi

  • Member
  • ****
  • Posts: 593
Re: ModernUI_Spinner Control
« Reply #7 on: June 28, 2019, 10:46:54 PM »
Hi fearless,

try so ..
Code: [Select]
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<assembly xmlns="urn:schemas-microsoft-com:asm.v1" manifestVersion="1.0" xmlns:asmv3="urn:schemas-microsoft-com:asm.v3">
  <asmv3:application>
    <asmv3:windowsSettings xmlns="http://schemas.microsoft.com/SMI/2005/WindowsSettings">
      <dpiAware>True/PM</dpiAware>
    </asmv3:windowsSettings>
  </asmv3:application>
  <dependency>
    <dependentAssembly>
      <assemblyIdentity
        type="win32"
        name="Microsoft.Windows.Common-Controls"
        version="6.0.0.0"
        publicKeyToken="6595b64144ccf1df"
        language="*"
        processorArchitecture="*"/>
    </dependentAssembly>
  </dependency>
  <trustInfo xmlns="urn:schemas-microsoft-com:asm.v3">
    <security>
      <requestedPrivileges>
        <requestedExecutionLevel
          level="requireAdministrator"
          uiAccess="false"/>
        </requestedPrivileges>
    </security>
  </trustInfo>
<compatibility xmlns="urn:schemas-microsoft-com:compatibility.v1">
<application>
<!--The ID below indicates app support for Windows Vista -->
<supportedOS Id="{e2011457-1546-43c5-a5fe-008deee3d3f0}"/>
<!--The ID below indicates app support for Windows 7 -->
<supportedOS Id="{35138b9a-5d96-4fbd-8e2d-a2440225f93a}"/>
<!--The ID below indicates app support for Windows 8 -->
<supportedOS Id="{4a2f28e3-53b9-4441-ba9c-d69d4a4a6e38}"/>
<!--The ID below indicates app support for Windows 8.1 -->
<supportedOS Id="{1f676c76-80e1-4239-95bb-83d0f6d0da78}"/>
<!--The ID below indicates app support for Windows 10 -->
<supportedOS Id="{8e0f7a12-bfb3-4fe8-b9a5-48fd50a15a9a}"/>
</application>
</compatibility>
</assembly>

Biterider

  • Member
  • ***
  • Posts: 391
  • ObjAsm32 + ObjAsm64 = ObjAsm
    • ObjAsm
Re: ModernUI_Spinner Control
« Reply #8 on: June 28, 2019, 10:51:58 PM »
Hi fearless
Im using a ASUS MX299Q wide screen. The resolution is set at 2560x1080 pixel running at 60Hz.
I hope this helps  :biggrin:

Biterider

LiaoMi

  • Member
  • ****
  • Posts: 593
Re: ModernUI_Spinner Control
« Reply #9 on: June 28, 2019, 11:57:59 PM »
Hi fearless
Im using a ASUS MX299Q wide screen. The resolution is set at 2560x1080 pixel running at 60Hz.
I hope this helps  :biggrin:

Biterider

I have a similar monitor, and I have the same effect, there must be another reason, not the screen resolution ...

fearless

  • Member
  • ***
  • Posts: 469
    • LetTheLightIn
Re: ModernUI_Spinner Control
« Reply #10 on: June 29, 2019, 12:34:30 AM »
I noticed that the png's from Icons8 are apng - which it turns out is an animated png - only seen this when using XnView and seen that the png contained x frames.
I opened those png's in IcoFx and exported out the single image which resulted in smaller png file sizes.
I'm hoping that maybe it was due to this. So I recompiled the MUISpinner.exe in the attached zip, hoping it was this, before I go off looking for other possible solutions.
Fingers crossed.
fearless

CM690II Case, HX1000 PSU, Asus Z97, Intel i7-4790K, Seidon 120v Cooler, 16GB DDR3, MSI GTX 980TI

My Github  Twitter

Biterider

  • Member
  • ***
  • Posts: 391
  • ObjAsm32 + ObjAsm64 = ObjAsm
    • ObjAsm
Re: ModernUI_Spinner Control
« Reply #11 on: June 29, 2019, 12:49:45 AM »
Hi fearless
Sorry, still the same effect...


Biterider

fearless

  • Member
  • ***
  • Posts: 469
    • LetTheLightIn
Re: ModernUI_Spinner Control
« Reply #12 on: June 29, 2019, 01:08:25 AM »
Ok thanks for testing for me.
I updated the rotation function to use the dc of the control and then use that for the graphics context, similar to how the spritesheets are loaded and handled.
Updated the sample MUISpinner1.exe again. If its still the same, then I'm currently out of ideas.
Does it show the correct image size for any of those affected spinners - specifically the first image as its just cloned if angle is 0/360, and the 180deg of the image is flipped rather than rotated, so just wondering if any of those appear as quick flashes in those spinners?
fearless

CM690II Case, HX1000 PSU, Asus Z97, Intel i7-4790K, Seidon 120v Cooler, 16GB DDR3, MSI GTX 980TI

My Github  Twitter

Biterider

  • Member
  • ***
  • Posts: 391
  • ObjAsm32 + ObjAsm64 = ObjAsm
    • ObjAsm
Re: ModernUI_Spinner Control
« Reply #13 on: June 29, 2019, 01:31:19 AM »
Hi fearless
One thought: It seems that the spinner image has sometimes and sometimes not an offset, like the hotspot of a cursor.
Biterider

fearless

  • Member
  • ***
  • Posts: 469
    • LetTheLightIn
Re: ModernUI_Spinner Control
« Reply #14 on: June 29, 2019, 01:46:45 AM »
Are they still animating but only showing a quarter of the image?
fearless

CM690II Case, HX1000 PSU, Asus Z97, Intel i7-4790K, Seidon 120v Cooler, 16GB DDR3, MSI GTX 980TI

My Github  Twitter