Page 1 of 2

Good PB templates for starters

Posted: Thu Aug 17, 2023 10:35 am
by Piero
Can someone suggest me a good basic multiOS example (2 menus and 2 windows)?

Better if i test it with (Mac) beta? (because of that SetWindowCallback thing, or something else)

Thanks

Re: Noob Question

Posted: Thu Aug 17, 2023 10:48 am
by NicTheQuick
You don't need any WindowCallback for that.

You can find good and small examples in the help and in the examples folder. They usually are OS-independent.

Also please change the title of this topic to something more meaningful.

title changed!

Posted: Thu Aug 17, 2023 12:41 pm
by Piero
NicTheQuick wrote: Thu Aug 17, 2023 10:48 am You can find good and small examples in the help
I am not very happy with help (I'm not saying it's all bad) because some of the things I needed most were difficult to find even on forum (to be extremely concise; because of "too many results"...)
Sounds and Runprogram..................................

I just wondered if some Guru could suggest me a very well made example (I saw a LOT of very helpful tips on forum, cannot say the same about PB examples/help... also "unfortunately" I mostly use a Mac...)

Anyway "thanks" :wink:

PS: SetWindowCallback was not easy to find on help.................... I generally just need to click the "function" and trigger a shortcut............ bah... poor Mac ppl...

Re: Good templates for starters and PB rollbacks

Posted: Thu Aug 17, 2023 1:28 pm
by Bitblazer
There are quite a lot examples for purebasic use on the net. Most are for windows though ;)

I still have a big collection of PureBasic Resources on my website.

Image

The Purearea.Net archive has a nicely sorted list of examples.

The discord link for on-demand purebasic help is in my signature.

Re: Good templates for starters and PB rollbacks

Posted: Thu Aug 17, 2023 1:33 pm
by Piero
Bitblazer wrote: Thu Aug 17, 2023 1:28 pm Most are for windows though ;)
Thank you! (in advance, I'm a bit busy now :x )

Re: Good templates for starters and PB rollbacks

Posted: Thu Aug 17, 2023 1:42 pm
by Bitblazer
An additional tip would be to use the google advanced search and limit it to the purebasic Mac forum section (site or domain = viewforum.php?f=19).

Re: Noob Question

Posted: Thu Aug 17, 2023 2:22 pm
by Piero
NicTheQuick wrote: Thu Aug 17, 2023 10:48 am The english grammar is freeware, you can use it freely - But it's not Open Source, i.e. you can not change it or publish it in altered way.
Is for starters formal or informal?

For starters (idiom)
As a beginning or first step
For starters, we need to gather all the necessary information.
Let's order some appetizers for starters.

Re: Good templates for starters and PB rollbacks

Posted: Thu Aug 17, 2023 2:33 pm
by Piero
Bitblazer wrote: Thu Aug 17, 2023 1:42 pmlimit it to the purebasic Mac forum section
I asked for "good beginner's templates" working with all OSs!!!!!!!! :x
PS: Thank you! ;)

Re: Good templates for starters and PB rollbacks

Posted: Thu Aug 17, 2023 3:02 pm
by Piero
If you win/linux users saw what I saw while using PB... (but it will be forgotten, like tears in the rain...)
...I have a PC.......... (and I still remember my dual-boot Mac-Linux, four thoundreds years ago...)
I am not criticizing in a bad way (I fear Fred!) anyway I'm waiting for multi-os great stuff...

PS: please forgive my english

Re: Good templates for starters and PB rollbacks

Posted: Thu Aug 17, 2023 4:39 pm
by Bitblazer
Piero wrote: Thu Aug 17, 2023 3:02 pm If you win/linux users saw what I saw while using PB...
upload it to a free image hosting service like imgur - so we could maybe point out what to do better / different

ps: you can run windows or linux on a mac in an emulator window too

Re: Good templates for starters and PB rollbacks

Posted: Thu Aug 17, 2023 6:14 pm
by Piero
Bitblazer wrote: Thu Aug 17, 2023 4:39 pmwindows or linux on a mac in an emulator window
I know...
...now you silly PC ppl made me remember when I programmed my C64 in assembly... LDA, STA, push and pull from the stack, stuff like that...

I'm old :cry:

:mrgreen:

Re: Good templates for starters and PB rollbacks

Posted: Thu Aug 17, 2023 6:51 pm
by Piero
Bitblazer wrote: Thu Aug 17, 2023 4:39 pmfree image hosting service
:mrgreen:

Image

Re: title changed!

Posted: Thu Aug 17, 2023 10:41 pm
by NicTheQuick
Piero wrote: Thu Aug 17, 2023 12:41 pm
NicTheQuick wrote: Thu Aug 17, 2023 10:48 am You can find good and small examples in the help
I am not very happy with help (I'm not saying it's all bad) because some of the things I needed most were difficult to find even on forum (to be extremely concise; because of "too many results"...)
Sounds and Runprogram..................................

I just wondered if some Guru could suggest me a very well made example (I saw a LOT of very helpful tips on forum, cannot say the same about PB examples/help... also "unfortunately" I mostly use a Mac...)

Anyway "thanks" :wink:

PS: SetWindowCallback was not easy to find on help.................... I generally just need to click the "function" and trigger a shortcut............ bah... poor Mac ppl...
This is the example to "CreateMenu()" from the help:

Code: Select all

UsePNGImageDecoder()

If OpenWindow(0, 200, 200, 200, 100, "Image menu Example")
	If CreateImageMenu(0, WindowID(0))    ; menu creation starts....
		MenuTitle("Project")
		MenuItem(1, "Open" + Chr(9) + "Ctrl+O", LoadImage(0, #PB_Compiler_Home + "examples/sources/Data/ToolBar/Open.png"))
		MenuItem(2, "Save" + Chr(9) + "Ctrl+S", LoadImage(1, #PB_Compiler_Home + "examples/sources/Data/ToolBar/Save.png"))
		MenuBar()
		MenuItem(3, "Quit" + Chr(9) + "Ctrl+Q")
	EndIf
	
	Repeat : Until WaitWindowEvent() = #PB_Event_CloseWindow
EndIf
It creates one window with one menu with one title and a few subentries.

Now let's add a second window and move the event loop accordingly:

Code: Select all

UsePNGImageDecoder()

If OpenWindow(0, 200, 200, 200, 100, "Image menu Example 1")
	If CreateImageMenu(0, WindowID(0))    ; menu creation starts....
		MenuTitle("Project")
		MenuItem(1, "Open" + Chr(9) + "Ctrl+O", LoadImage(0, #PB_Compiler_Home + "examples/sources/Data/ToolBar/Open.png"))
		MenuItem(2, "Save" + Chr(9) + "Ctrl+S", LoadImage(1, #PB_Compiler_Home + "examples/sources/Data/ToolBar/Save.png"))
		MenuBar()
		MenuItem(3, "Quit" + Chr(9) + "Ctrl+Q")
	EndIf
EndIf
If OpenWindow(1, 200, 200, 200, 100, "Image menu Example 2")
	If CreateImageMenu(1, WindowID(1))    ; menu creation starts....
		MenuTitle("Project")
		MenuItem(1, "Open" + Chr(9) + "Ctrl+O", LoadImage(0, #PB_Compiler_Home + "examples/sources/Data/ToolBar/Open.png"))
		MenuItem(2, "Save" + Chr(9) + "Ctrl+S", LoadImage(1, #PB_Compiler_Home + "examples/sources/Data/ToolBar/Save.png"))
		MenuBar()
		MenuItem(3, "Quit" + Chr(9) + "Ctrl+Q")
	EndIf
EndIf
Repeat : Until WaitWindowEvent() = #PB_Event_CloseWindow
You now have two windows. Now let's add a simple event loop.

Code: Select all

UsePNGImageDecoder()

If OpenWindow(0, 200, 200, 200, 100, "Image menu Example 1")
	If CreateImageMenu(0, WindowID(0))    ; menu creation starts....
		MenuTitle("Project")
		MenuItem(1, "Open" + Chr(9) + "Ctrl+O", LoadImage(0, #PB_Compiler_Home + "examples/sources/Data/ToolBar/Open.png"))
		MenuItem(2, "Save" + Chr(9) + "Ctrl+S", LoadImage(1, #PB_Compiler_Home + "examples/sources/Data/ToolBar/Save.png"))
		MenuBar()
		MenuItem(3, "Quit" + Chr(9) + "Ctrl+Q")
	EndIf
EndIf
If OpenWindow(1, 200, 200, 200, 100, "Image menu Example 2")
	If CreateImageMenu(1, WindowID(1))    ; menu creation starts....
		MenuTitle("Project")
		MenuItem(1, "Open" + Chr(9) + "Ctrl+O", LoadImage(0, #PB_Compiler_Home + "examples/sources/Data/ToolBar/Open.png"))
		MenuItem(2, "Save" + Chr(9) + "Ctrl+S", LoadImage(1, #PB_Compiler_Home + "examples/sources/Data/ToolBar/Save.png"))
		MenuBar()
		MenuItem(3, "Quit" + Chr(9) + "Ctrl+Q")
	EndIf
EndIf

While IsWindow(0) Or IsWindow(1)
	Select WaitWindowEvent()
		Case #PB_Event_CloseWindow
			CloseWindow(EventWindow())
			Debug "Window " + Str(EventWindow()) + " was closed."
		
		Case #PB_Event_Menu
			Debug "Menu item " + Str(EventMenu()) + " in window " + Str(EventWindow()) + " was clicked."
		
	EndSelect
Wend

Debug "Program quitted."
That should answer your question. And as you can see it is as easy as to look into the help.

Re: Good templates for starters and PB rollbacks

Posted: Fri Aug 18, 2023 7:05 am
by Bitblazer
Piero wrote: Thu Aug 17, 2023 6:14 pm
Bitblazer wrote: Thu Aug 17, 2023 4:39 pmwindows or linux on a mac in an emulator window
I know...
...now you silly PC ppl made me remember when I programmed my C64 in assembly... LDA, STA, push and pull from the stack, stuff like that...

I'm old :cry:
I started with the ZX81 -> ZX Spectrum (plus).

So back in the day, we were rivals ;)

Good old platform wars ;)

ps : CommanderX16 / ZX Spectrum Next - in 2023 we are just old and strange ;)

Re: Good PB templates for starters

Posted: Fri Aug 18, 2023 5:00 pm
by Tenaja
The Tips & Tricks forum as well as the Showcase will have loads of examples.

FYI, os-specific API calls will have an underscore after the name, i.e SetWindowSize_(...), So they are platform dependant. Avoid those to simplify cross platform. (Otherwise, you can use conditional Compiler command to have an option for each os.)

TBH, i chose PB for is cross platform capability, but it's so limited because it's lowest common denominator that it's frustrating. Many users have written our own controls to bridge the deficiencies (see Tips), but because they aren't official PB, they vary in implementation. My view is the best thing PB could do is collect those formally, standardize them, and make them part of the included libraries. It would make it a solid alternative to Lazarus or the C options. (Or at least add them to a GitHub...)

Have fun!