Page 1 of 1

Enumerate question ...

Posted: Mon Aug 26, 2024 6:46 pm
by marc_256
Hi,

I'm converting my PB SerialTerminal program to full ScreenMode ...

but I'm stuck with a Enumeration problem
as I undertands, Enum is a compiler part...

Code: Select all

Enumeration
  #MyWindow
  #MyScreen
  #MyFont
  #MyMPU_Sprite
  #MyConverterSW_Sprite
  #MyConverterHW_Sprite
  ...
EndEnumeration
Then I create my sprites, example ...

Code: Select all

	CreateSprite (#MyMPU_Sprite, 250, 300, #PB_Sprite_AlphaBlending)
	CreateSprite (#MyConverterSW_Sprite, 250, 125, #PB_Sprite_AlphaBlending)
	CreateSprite (#MyConverterHW_Sprite, 250, 125, #PB_Sprite_AlphaBlending)
Then I populate the sprites with the Frames/Lines/Circles/Text ...

Code: Select all

	StartDrawing (SpriteOutput ())
		...
		...
		...
		...
	StopDrawing ()
Once the program is compiled, it works very well,


But then if I want to add more SignalConverters on the screen, (see image arrow below)
- I hover with mouse on the RibbonBar
- I click inside the SignalConverter Button
- I drag to the position
- I drop by release the mouse button
Till here it works ok,

- I need to create a new Sprite and populate it ...

Q1)
Now I need to add/create a new Sprite Numeration,
What is the best way to add (Enumerate) a image or sprite number ?
Can I just do this inside a compiled PB .exe file:

Code: Select all

  MyNextSprite.i = CreateSprite (#PB_Compiler_EnumerationValue, 250, 125, #PB_Sprite_AlphaBlending)
Or is there a better way ?


- I use Win10Pro + PB 5.73x64


thanks,
marc,

Image

Re: Enumerate question ...

Posted: Mon Aug 26, 2024 7:01 pm
by spikey
This is what #PB_Any is for:

Code: Select all

MyNextSprite.i = CreateSprite (#PB_Any, 250, 125, #PB_Sprite_AlphaBlending)
The function will return the PB number of the new object in this case.

You don't have to use unitary variable names to store these results, they could go in an array or a list which can provide an open ended structure. I do something similar for windows in https://www.purebasic.com/documentation ... _any1.html and https://www.purebasic.com/documentation ... _any2.html but the same principle can be applied to other objects too.

Alternatively, if you don't want to use #PB_Any, you can use sequential values after your enumeration ends:

Code: Select all

Enumeration
  #MyWindow
  #MyScreen
  #MyFont
  #MyMPU_Sprite
  #MyConverterSW_Sprite
  #MyConverterHW_Sprite
  #MyFirstCustomItem
EndEnumeration

Define ObjectCounter.i = #MyFirstCustomItem
; ...
CreateSprite (ObjectCounter, 250, 125, #PB_Sprite_AlphaBlending)
ObjectCounter + 1
Providing you guard against overlaps you shouldn't have any problems.

Re: Enumerate question ...

Posted: Mon Aug 26, 2024 7:22 pm
by marc_256
Hi spikey,

I love and will use the second option... 8)

Thanks,
Marc