Project "Give a Pure Example"

Everything else that doesn't fall into one of the other PB categories.
User avatar
PedroMartins
User
User
Posts: 47
Joined: Sat Sep 02, 2017 7:30 pm

Project "Give a Pure Example"

Post by PedroMartins »

Hi, my name is Pedro Martins, and today 05-04-2018,
i've started this project to help every purebasic fan out there.

TOPIC RULES:
1º This topic is for posting working examples ONLY.
2º Yes i know that i can get examples in the rest of the forum. So go and get them.
3º This is just a topic for examples not a proposal to change actual documentation
4º Actual documentation is one thing this topic is another thing.
Don't use this topic for small talk.
6º If you find a "bug" or "typo" in examples just make a new one post reply with corrections and using proper layout. Give credit to author. :)
7º If an example of an instruction/procedure of a section already exists you can make a DIFFERENT one.
8º No example is better than the other.
9º Please put the name of your variables/procedures in english.
10º Please comment your examples in english.
11º Please try to make simple examples. Ok if you want you can make complex examples. :)
12º Follow topic layout
13º This project is open to all friends, foes, friends of friends and friends of foes LOL :mrgreen:
14º This topic is not for using in your private wars. This will be not transformed into a circus. Be warned.
15º Respect the rules of this topic or ...
16º Post Replies not in Layout Format will enter into ignore mode directly till they make a proper layout format on their their post replies.This is valid for all people.
17º Post Replies with improper messages will enter into ignore mode directly.This is valid for all people.
18º Cheers for this project are always welcome :)

******************************************************************
TOPIC LAYOUT - BEGIN
******************************************************************

----------------------------------------------------------------- copy to a new topic and then add code tags to put your code
Section name color = #0000FF
Instruction/Procedure name color = color=#8000FF
"Based on program from user" color: = color=#FFBF00

put your example code between code tags

Section: <name>

Instruction/Procedure: <name>

Based on program from user: <username> ; use this one if you want to give credits to someone

Example:
----------------------------------------------------------------- copy to a new topic

Code: Select all

; put in here your own code
; put in here code from others and with your enhancements. Give credits to original authors.
; add all the comments, suggestions you want in english only
; put in here bugs or typos that you may find for users can correct then
; example must work
*******************************************************************
TOPIC LAYOUT - END
*******************************************************************
Last edited by PedroMartins on Fri Apr 06, 2018 3:26 pm, edited 28 times in total.
highend
Enthusiast
Enthusiast
Posts: 123
Joined: Tue Jun 17, 2014 4:49 pm

Re: Project "Give a Pure Example"

Post by highend »

No, this will end fast
User avatar
PedroMartins
User
User
Posts: 47
Joined: Sat Sep 02, 2017 7:30 pm

Re: Project "Give a Pure Example"

Post by PedroMartins »

Section: Window

Instruction/Procedure: CloseWindow()

Example:

Code: Select all



Define quit=0

If OpenWindow(0, 0, 0, 300, 150, "my window", #PB_Window_SystemMenu+#PB_Window_ScreenCentered)
  Repeat
    Select WaitWindowEvent()
      Case #PB_Event_CloseWindow ;press the red button in window
        quit=1
    EndSelect   
  Until quit=1 
  CloseWindow(0)
EndIf


User avatar
PedroMartins
User
User
Posts: 47
Joined: Sat Sep 02, 2017 7:30 pm

Re: Project "Give a Pure Example"

Post by PedroMartins »

Section: Basic Keywords

Instruction/Procedure: For

Example:

Code: Select all

Define i

For i = 0 To 10
  Debug(i)
Next i
User avatar
PedroMartins
User
User
Posts: 47
Joined: Sat Sep 02, 2017 7:30 pm

Re: Project "Give a Pure Example"

Post by PedroMartins »

Section: Camera

Instruction/Procedure: CreateCamera()

Example:

Code: Select all

InitEngine3D()
InitSprite()
 
OpenWindow(0, 0, 0, 800, 600, "Player 1 versus Player 2", #PB_Window_SystemMenu | #PB_Window_ScreenCentered)
OpenWindowedScreen(WindowID(0), 0, 0, 800, 600, 0, 0, 0)
 
; Light
CreateLight(#PB_Any, RGB(25, 25, 180), -5, 10, 5, #PB_Light_Directional)
 
; Camera for player 1
CreateCamera(1, 0, 0, 100, 50)
CameraBackColor(1, RGB(0, 255, 0))
MoveCamera(1, 2, 1, 3, #PB_Absolute | #PB_Local)
CameraLookAt(1, 0, 0, 0)
 
; Camera for player 2
CreateCamera(2, 0, 50, 100, 50)
CameraBackColor(2, RGB(0, 0, 255))
MoveCamera(2, 2, 1, 3, #PB_Absolute | #PB_Local)
CameraLookAt(2, 0, 0, 0)
 
CreatePlane(0, 3, 3, 3, 3, 3, 3)
CreateEntity(0, MeshID(0), #PB_Material_None)
 
Repeat
  RenderWorld()
  FlipBuffers()
Until WaitWindowEvent(1) = #PB_Event_CloseWindow

User avatar
PedroMartins
User
User
Posts: 47
Joined: Sat Sep 02, 2017 7:30 pm

Re: Project "Give a Pure Example"

Post by PedroMartins »

Section: String

Instruction/Procedure: ValD()

Example:

Code: Select all


Define a.d
Define b.d = 0.0

a = ValD(StrD(1.0)) / b

Debug("a: "+a)

User avatar
PedroMartins
User
User
Posts: 47
Joined: Sat Sep 02, 2017 7:30 pm

Re: Project "Give a Pure Example"

Post by PedroMartins »

Section: Module

Instruction/Procedure: DeclareModule

Example:

Code: Select all

;*************************************************
; PROJECT DATA
;*************************************************
; Project name: Module mbox
; Project works on: Windows 7
;*************************************************
; Features
; - You can write text in the buttons
; - Don't need to define a result variable in main program
; - Project code and comments are all written in english
;*************************************************

DeclareModule mbox
 
  ; creating independent OS text for buttons
  Global mbox_button_ok_text$="OK"
  Global mbox_button_yes_text$="Yes"
  Global mbox_button_no_text$="No"
  Global mbox_button_cancel_text$="Cancel"
 
  Global mbox_result ; stores return value
   
  ; contants to represent flags (must be declared here for you to use it outside module)
  #mbox_noflags=0
  #mbox_ok=1
  #mbox_yesno=2
  #mbox_yesnocancel=3
  #mbox_info=11
  #mbox_warning=22
  #mbox_error=33
 
  ; constants for result of buttons press (must be declared here for you to use it outside module)
  #mbox_ok=1
  #mbox_yes=2
  #mbox_no=3
  #mbox_cancel=4
   
  Declare mbox_messagebox(boxtitle$,boxtext$,flags)

EndDeclareModule

Module mbox
  ; so what do we need ... hum ... a window, a text message, an image and some buttons ... let's enumerate this idea
  Enumeration mbox #PB_Compiler_EnumerationValue
    #mbox_window
    #mbox_textgadget_message
    #mbox_imagegadget
    #mbox_button_ok
    #mbox_button_cancel
    #mbox_button_yes
    #mbox_button_no
   
    #mbox_image_info
    #mbox_image_warning
    #mbox_image_error
   
    #mbox_font
   
  EndEnumeration
 
  ; $boxtitle - put the box title
  ; $boxtitle - put the box text
  ; flags - put the flags
  ; procedure will return something to variable mbox_result when you press buttons
 
  Procedure mbox_messagebox(boxtitle$,boxtext$,flags)
    Protected quit
    Protected backcolor=RGB(64,62,73)
    Protected forecolor=RGB(255,255,255)
    Protected fieldforecolor=RGB(0,0,0)
    Protected fieldbackcolor=RGB(181,230,29)
       
    ;need to create a dir called images
    Protected pathmoduleimages.s="images/"
    ;Protected pathmoduleimages.s=GetPathPart(ProgramFilename())+"modules/mbox/images/"
   
    UsePNGImageDecoder()
   
    ;get the 32x32 pixels images down there and give them this names
    LoadImage(#mbox_image_info,pathmoduleimages+"messagebox_info.png")
    LoadImage(#mbox_image_warning,pathmoduleimages+"messagebox_warning.png")
    LoadImage(#mbox_image_error,pathmoduleimages+"messagebox_error.png")
   
    ; let's make a window
    ;
    If OpenWindow(#mbox_window, 0, 0, 300, 150, boxtitle$, #PB_Window_ScreenCentered)
     
      SetWindowColor(#mbox_window, BackColor)
     
      StickyWindow(#mbox_window, #True) ; stay on top

      If LoadFont(#mbox_font, "Consolas", 10)
        SetGadgetFont(#PB_Default, FontID(#mbox_font))
      EndIf
     
      TextGadget(#mbox_textgadget_message,10,50,280,40,boxtext$)
      SetGadgetColor(#mbox_textgadget_message, #PB_Gadget_FrontColor, fieldforecolor)
      SetGadgetColor(#mbox_textgadget_message, #PB_Gadget_BackColor, fieldbackcolor)
           
      Select flags
        Case #mbox_ok
          ButtonGadget(#mbox_button_ok, 10, 110, 70, 30, "OK")
         
        Case #mbox_ok+#mbox_info
          ButtonGadget(#mbox_button_ok, 10, 110, 70, 30, mbox_button_ok_text$)
          ImageGadget(#mbox_imagegadget, 10, 10, 32, 32, ImageID(#mbox_image_info))
 
        Case #mbox_ok+#mbox_warning
          ButtonGadget(#mbox_button_ok, 10, 110, 70, 30, mbox_button_ok_text$)
          ImageGadget(#mbox_imagegadget, 10, 10, 32, 32, ImageID(#mbox_image_warning))
           
        Case #mbox_ok+#mbox_error
          ButtonGadget(#mbox_button_ok, 10, 110, 70, 30, mbox_button_ok_text$)
          ImageGadget(#mbox_imagegadget, 10, 10, 32, 32, ImageID(#mbox_image_error))
         
        Case #mbox_yesno
          ButtonGadget(#mbox_button_yes, 10, 110, 70, 30, mbox_button_yes_text$)
          ButtonGadget(#mbox_button_no, 85, 110, 70, 30, mbox_button_no_text$)
          ImageGadget(#mbox_imagegadget, 10, 10, 32, 32, ImageID(#mbox_image_info))
           
        Case #mbox_yesno+#mbox_info
          ButtonGadget(#mbox_button_yes, 10, 110, 70, 30, mbox_button_yes_text$)
          ButtonGadget(#mbox_button_no, 85, 110, 70, 30, mbox_button_no_text$)
          ImageGadget(#mbox_imagegadget, 10, 10, 32, 32, ImageID(#mbox_image_info))
           
        Case #mbox_yesno+#mbox_warning
          ButtonGadget(#mbox_button_yes, 10, 110, 70, 30, mbox_button_yes_text$)
          ButtonGadget(#mbox_button_no, 85, 110, 70, 30, mbox_button_no_text$)
          ImageGadget(#mbox_imagegadget, 10, 10, 32, 32, ImageID(#mbox_image_warning))
           
        Case #mbox_yesno+#mbox_error
          ButtonGadget(#mbox_button_yes, 10, 110, 70, 30, mbox_button_yes_text$)
          ButtonGadget(#mbox_button_no, 85, 110, 70, 30, mbox_button_no_text$)
          ImageGadget(#mbox_imagegadget, 10, 10, 32, 32, ImageID(#mbox_image_error)) 
         
        Case #mbox_yesnocancel
          ButtonGadget(#mbox_button_yes, 10, 110, 70, 30, mbox_button_yes_text$)
          ButtonGadget(#mbox_button_no, 85, 110, 70, 30, mbox_button_no_text$)
          ButtonGadget(#mbox_button_cancel, 160, 110, 70, 30, mbox_button_cancel_text$)
          ImageGadget(#mbox_imagegadget,  10, 10, 32, 32, ImageID(#mbox_image_info))
           
        Case #mbox_yesnocancel+#mbox_info 
          ButtonGadget(#mbox_button_yes, 10, 110, 70, 30, mbox_button_yes_text$)
          ButtonGadget(#mbox_button_no, 85, 110, 70, 30, mbox_button_no_text$)
          ButtonGadget(#mbox_button_cancel, 160, 110, 70, 30, mbox_button_cancel_text$)
          ImageGadget(#mbox_imagegadget,  10, 10, 32, 32, ImageID(#mbox_image_info))
           
        Case #mbox_yesnocancel+#mbox_warning
          ButtonGadget(#mbox_button_yes, 10, 110, 70, 30, mbox_button_yes_text$)
          ButtonGadget(#mbox_button_no, 85, 110, 70, 30, mbox_button_no_text$)
          ButtonGadget(#mbox_button_cancel, 160, 110, 70, 30, mbox_button_cancel_text$)
          ImageGadget(#mbox_imagegadget,  10, 10, 32, 32, ImageID(#mbox_image_warning))
 
        Case #mbox_yesnocancel+#mbox_error
          ButtonGadget(#mbox_button_yes, 10, 110, 70, 30, mbox_button_yes_text$)
          ButtonGadget(#mbox_button_no, 85, 110, 70, 30, mbox_button_no_text$)
          ButtonGadget(#mbox_button_cancel, 160, 110, 70, 30, mbox_button_cancel_text$)
          ImageGadget(#mbox_imagegadget,  10, 10, 32, 32, ImageID(#mbox_image_error))         
      EndSelect   
     
      result=0
      quit=0
      Repeat

        Select WaitWindowEvent()
           
          Case #PB_Event_Gadget
            Select EventGadget()
              Case #mbox_button_ok
                mbox_result=#mbox_ok           
                quit=1
           
              Case #mbox_button_no
                mbox_result=#mbox_no
                quit=1
           
              Case #mbox_button_yes
                mbox_result=#mbox_yes
                quit=1
           
              Case #mbox_button_cancel
                mbox_result=#mbox_cancel
                quit=1       
               
            EndSelect 
           
        EndSelect 
      Until quit=1

      CloseWindow(#mbox_window)
    EndIf

    ;ProcedureReturn result
  EndProcedure

EndModule

;***********************************************************
; Test module code
;***********************************************************
UseModule mbox

mbox::mbox_button_ok_text$="Ok" ; you can change it to "D'accord"
mbox::mbox_button_yes_text$="Yes" ; you can change it to "Oui"
mbox::mbox_button_no_text$="No" ; you can change it to "Non"
mbox::mbox_button_cancel_text$="Cancel" ; you can change it to "Annuler"

mbox::mbox_messagebox("Area 51 - Warning","Alien life form is contained in dark chamber. Go to night vision mode ?",mbox::#mbox_yesno+mbox::#mbox_warning)

If mbox::mbox_result=mbox::#mbox_ok
  Debug("ok")
EndIf

If mbox::mbox_result=mbox::#mbox_yes
  Debug("yes")
EndIf

If mbox::mbox_result=mbox::#mbox_no
  Debug("no")
EndIf

If mbox::mbox_result=mbox::#mbox_cancel
  Debug("cancel")
EndIf

Image Image Image

Image
walbus
Addict
Addict
Posts: 929
Joined: Sat Mar 02, 2013 9:17 am

Re: Project "Give a Pure Example"

Post by walbus »

More tipps

Make it so :

Code: Select all

mbox_button_ok=ButtonGadget(#PB_any, 10, 110, 70, 30, mbox_button_ok_text$)

; Not so
ButtonGadget(#mbox_button_ok, 10, 110, 70, 30, mbox_button_ok_text$)
Add ever to the Dec part EnableExplicit for modules
Primary you should use ever EnableExplicit, for each code

Create the icons self with PB graphic functions
Its not a good idea for preload this little and simple icons
User avatar
TI-994A
Addict
Addict
Posts: 2512
Joined: Sat Feb 19, 2011 3:47 am
Location: Singapore
Contact:

Re: Project "Give a Pure Example"

Post by TI-994A »

As used in an application:

Code: Select all

;*************************************************
; PROJECT DATA
;*************************************************
; Project name: Module mbox
; Project works on: Windows 7
;*************************************************
; Features
; - You can write text in the buttons
; - Don't need to define a result variable in main program
; - Project code and comments are all written in english
;*************************************************

DeclareModule mbox
  
  ; creating independent OS text for buttons
  Global mbox_button_ok_text$="OK"
  Global mbox_button_yes_text$="Yes"
  Global mbox_button_no_text$="No"
  Global mbox_button_cancel_text$="Cancel"
  
  Global mbox_result ; stores return value
  
  ; contants to represent flags (must be declared here for you to use it outside module)
  #mbox_noflags=0
  #mbox_ok=1
  #mbox_yesno=2
  #mbox_yesnocancel=3
  #mbox_info=11
  #mbox_warning=22
  #mbox_error=33
  
  ; constants for result of buttons press (must be declared here for you to use it outside module)
  #mbox_ok=1
  #mbox_yes=2
  #mbox_no=3
  #mbox_cancel=4
  
  Declare mbox_messagebox(boxtitle$,boxtext$,flags)
  
EndDeclareModule

Module mbox
  ; so what do we need ... hum ... a window, a text message, an image and some buttons ... let's enumerate this idea
  Enumeration mbox #PB_Compiler_EnumerationValue
    #mbox_window
    #mbox_textgadget_message
    #mbox_imagegadget
    #mbox_button_ok
    #mbox_button_cancel
    #mbox_button_yes
    #mbox_button_no
    
    #mbox_image_info
    #mbox_image_warning
    #mbox_image_error
    
    #mbox_font
    
  EndEnumeration
  
  ; $boxtitle - put the box title
  ; $boxtitle - put the box text
  ; flags - put the flags
  ; procedure will return something to variable mbox_result when you press buttons
  
  Procedure mbox_messagebox(boxtitle$,boxtext$,flags)
    Protected quit
    Protected backcolor=RGB(64,62,73)
    Protected forecolor=RGB(255,255,255)
    Protected fieldforecolor=RGB(0,0,0)
    Protected fieldbackcolor=RGB(181,230,29)
    
    ;need to create a dir called images
    Protected pathmoduleimages.s="images/"
    ;Protected pathmoduleimages.s=GetPathPart(ProgramFilename())+"modules/mbox/images/"
    
    UsePNGImageDecoder()
    
    ;get the 32x32 pixels images down there and give them this names
    LoadImage(#mbox_image_info,pathmoduleimages+"messagebox_info.png")
    LoadImage(#mbox_image_warning,pathmoduleimages+"messagebox_warning.png")
    LoadImage(#mbox_image_error,pathmoduleimages+"messagebox_error.png")
    
    ; let's make a window
    ;
    If OpenWindow(#mbox_window, 0, 0, 300, 150, boxtitle$, #PB_Window_ScreenCentered)
      
      SetWindowColor(#mbox_window, BackColor)
      
      StickyWindow(#mbox_window, #True) ; stay on top
      
      If LoadFont(#mbox_font, "Consolas", 10)
        SetGadgetFont(#PB_Default, FontID(#mbox_font))
      EndIf
      
      TextGadget(#mbox_textgadget_message,10,50,280,40,boxtext$)
      SetGadgetColor(#mbox_textgadget_message, #PB_Gadget_FrontColor, fieldforecolor)
      SetGadgetColor(#mbox_textgadget_message, #PB_Gadget_BackColor, fieldbackcolor)
      
      Select flags
        Case #mbox_ok
          ButtonGadget(#mbox_button_ok, 10, 110, 70, 30, "OK")
          
        Case #mbox_ok+#mbox_info
          ButtonGadget(#mbox_button_ok, 10, 110, 70, 30, mbox_button_ok_text$)
          ImageGadget(#mbox_imagegadget, 10, 10, 32, 32, ImageID(#mbox_image_info))
          
        Case #mbox_ok+#mbox_warning
          ButtonGadget(#mbox_button_ok, 10, 110, 70, 30, mbox_button_ok_text$)
          ImageGadget(#mbox_imagegadget, 10, 10, 32, 32, ImageID(#mbox_image_warning))
          
        Case #mbox_ok+#mbox_error
          ButtonGadget(#mbox_button_ok, 10, 110, 70, 30, mbox_button_ok_text$)
          ImageGadget(#mbox_imagegadget, 10, 10, 32, 32, ImageID(#mbox_image_error))
          
        Case #mbox_yesno
          ButtonGadget(#mbox_button_yes, 10, 110, 70, 30, mbox_button_yes_text$)
          ButtonGadget(#mbox_button_no, 85, 110, 70, 30, mbox_button_no_text$)
          ImageGadget(#mbox_imagegadget, 10, 10, 32, 32, ImageID(#mbox_image_info))
          
        Case #mbox_yesno+#mbox_info
          ButtonGadget(#mbox_button_yes, 10, 110, 70, 30, mbox_button_yes_text$)
          ButtonGadget(#mbox_button_no, 85, 110, 70, 30, mbox_button_no_text$)
          ImageGadget(#mbox_imagegadget, 10, 10, 32, 32, ImageID(#mbox_image_info))
          
        Case #mbox_yesno+#mbox_warning
          ButtonGadget(#mbox_button_yes, 10, 110, 70, 30, mbox_button_yes_text$)
          ButtonGadget(#mbox_button_no, 85, 110, 70, 30, mbox_button_no_text$)
          ImageGadget(#mbox_imagegadget, 10, 10, 32, 32, ImageID(#mbox_image_warning))
          
        Case #mbox_yesno+#mbox_error
          ButtonGadget(#mbox_button_yes, 10, 110, 70, 30, mbox_button_yes_text$)
          ButtonGadget(#mbox_button_no, 85, 110, 70, 30, mbox_button_no_text$)
          ImageGadget(#mbox_imagegadget, 10, 10, 32, 32, ImageID(#mbox_image_error)) 
          
        Case #mbox_yesnocancel
          ButtonGadget(#mbox_button_yes, 10, 110, 70, 30, mbox_button_yes_text$)
          ButtonGadget(#mbox_button_no, 85, 110, 70, 30, mbox_button_no_text$)
          ButtonGadget(#mbox_button_cancel, 160, 110, 70, 30, mbox_button_cancel_text$)
          ImageGadget(#mbox_imagegadget,  10, 10, 32, 32, ImageID(#mbox_image_info))
          
        Case #mbox_yesnocancel+#mbox_info 
          ButtonGadget(#mbox_button_yes, 10, 110, 70, 30, mbox_button_yes_text$)
          ButtonGadget(#mbox_button_no, 85, 110, 70, 30, mbox_button_no_text$)
          ButtonGadget(#mbox_button_cancel, 160, 110, 70, 30, mbox_button_cancel_text$)
          ImageGadget(#mbox_imagegadget,  10, 10, 32, 32, ImageID(#mbox_image_info))
          
        Case #mbox_yesnocancel+#mbox_warning
          ButtonGadget(#mbox_button_yes, 10, 110, 70, 30, mbox_button_yes_text$)
          ButtonGadget(#mbox_button_no, 85, 110, 70, 30, mbox_button_no_text$)
          ButtonGadget(#mbox_button_cancel, 160, 110, 70, 30, mbox_button_cancel_text$)
          ImageGadget(#mbox_imagegadget,  10, 10, 32, 32, ImageID(#mbox_image_warning))
          
        Case #mbox_yesnocancel+#mbox_error
          ButtonGadget(#mbox_button_yes, 10, 110, 70, 30, mbox_button_yes_text$)
          ButtonGadget(#mbox_button_no, 85, 110, 70, 30, mbox_button_no_text$)
          ButtonGadget(#mbox_button_cancel, 160, 110, 70, 30, mbox_button_cancel_text$)
          ImageGadget(#mbox_imagegadget,  10, 10, 32, 32, ImageID(#mbox_image_error))         
      EndSelect   
      
      result=0
      quit=0
      Repeat
        
        Select WaitWindowEvent()
            
          Case #PB_Event_Gadget
            Select EventGadget()
              Case #mbox_button_ok
                mbox_result=#mbox_ok           
                quit=1
                
              Case #mbox_button_no
                mbox_result=#mbox_no
                quit=1
                
              Case #mbox_button_yes
                mbox_result=#mbox_yes
                quit=1
                
              Case #mbox_button_cancel
                mbox_result=#mbox_cancel
                quit=1       
                
            EndSelect 
            
        EndSelect 
      Until quit=1
      
      CloseWindow(#mbox_window)
    EndIf
    
    ;ProcedureReturn result
  EndProcedure
  
EndModule

appWin = OpenWindow(#PB_Any, 100, 100, 400, 200, "Test Message Box", 
           #PB_Window_SystemMenu | #PB_Window_ScreenCentered)
button = ButtonGadget(#PB_Any, 150, 60, 100, 30, "Show Message")

Repeat  
  event = WaitWindowEvent()  
  Select event
    Case #PB_Event_CloseWindow
      appQuit = 1
    Case #PB_Event_Gadget
      If EventGadget() = button
        DisableWindow(appWin, #True)
        
        UseModule mbox           
        ;with the UseModule keyboard the module prefix can be omitted        
        
        mbox_button_ok_text$="Ok"
        mbox_button_yes_text$="Yes"
        mbox_button_no_text$="No"
        mbox_button_cancel_text$="Cancel"        
        mbox_messagebox("Area 51 - Warning","Alien life form is contained in dark chamber. Go to night vision mode ?",mbox::#mbox_yesno+mbox::#mbox_warning)
        
        Select mbox_result            
          Case #mbox_ok
            Debug "OK!"
          Case #mbox_yes
            Debug "Yes!"
          Case #mbox_no
            Debug "No!"
          Case #mbox_cancel            
            Debug "Cancel!"
        EndSelect 
        
        DisableWindow(appWin, #False)
        SetActiveWindow(appWin)
        
      EndIf      
  EndSelect  
Until appQuit
Note: When the module function UseModule is called, the module prefix can be safely omitted.
Texas Instruments TI-99/4A Home Computer: the first home computer with a 16bit processor, crammed into an 8bit architecture. Great hardware - Poor design - Wonderful BASIC engine. And it could talk too! Please visit my YouTube Channel :D
User avatar
PedroMartins
User
User
Posts: 47
Joined: Sat Sep 02, 2017 7:30 pm

Re: Project "Give a Pure Example"

Post by PedroMartins »

Section: Gadget

Instruction/Procedure: ScrollAreaGadget()

Based on program from user: Rashad

Example:

Code: Select all


Enumeration
#Win
#Panel
#Scrl
#Canv
EndEnumeration

Global scrollgadget_width=376 ; it works if you change to this
;Global scrollgadget_width=200 ; it works if you change to this
Global scrollgadget_height=570 ; it works if you change to this
;Global scrollgadget_height=300 ; it works if you change to this

If OpenWindow(#Win, 0, 0, 700, 650, "ScrollArea scrollbar positions", #PB_Window_SystemMenu | #PB_Window_ScreenCentered)

SetWindowColor(#Win, RGB(240,240,240))

PanelGadget(#Panel, 1, 1, 698, 648)

AddGadgetItem(#Panel, -1, "Tab 0")

;ScrollAreaGadget(#Scrl, 5,  40,  376,  570, 1000, 1000, 10, #PB_ScrollArea_Center) ; Don't need #PB_ScrollArea_Center
ScrollAreaGadget(#Scrl, 5,  40,  scrollgadget_width,  scrollgadget_height, 1000, 1000, 10)

   ;CanvasGadget(#Canv, 0,   0, 1000, 1000, #PB_Canvas_Container) ; it works if you change to this
   CanvasGadget(#Canv, 0,   0, 1500, 1500, #PB_Canvas_Container) ; it works if you change to this. In this case Canvas is bigger than scrollarea.
   ;CanvasGadget(#Canv, 0,   0, 500, 500, #PB_Canvas_Container) ; it works if you change to this
   
CloseGadgetList() ;#Canv
CloseGadgetList() ;#Scrl

StartDrawing(CanvasOutput(#Canv))
  Box(0, 0, GadgetWidth(#Canv), GadgetHeight(#Canv), RGB(192,192,192)) ; background

  LineXY(GadgetWidth(#Canv)/2,   0,  GadgetWidth(#Canv)/2, GadgetHeight(#Canv), RGB(200,000,000))
  LineXY(  0, GadgetHeight(#Canv)/2, GadgetWidth(#Canv),  GadgetHeight(#Canv)/2, RGB(200,000,000))
  DrawingMode(#PB_2DDrawing_Outlined)
 
  ;put box in center of scroll area
  Box(GadgetWidth(#Canv)/2-50,GadgetHeight(#Canv)/2-50, 100, 100, RGB(000,000,200))
 
  ; ajust visualization center in scrollarea
  SetGadgetAttribute(#Scrl, #PB_ScrollArea_X, GadgetWidth(#Canv)/2-scrollgadget_width/2)
  SetGadgetAttribute(#Scrl, #PB_ScrollArea_Y, GadgetHeight(#Canv)/2-scrollgadget_height/2)
 
StopDrawing()
   
    ;SetGadgetAttribute(#Scrl, #PB_ScrollArea_X, 500)
    ;hpos = GetGadgetAttribute(#Scrl, #PB_ScrollArea_X)
   
    ;SetGadgetAttribute(#Scrl, #PB_ScrollArea_Y, 500)
    ;vpos = GetGadgetAttribute(#Scrl, #PB_ScrollArea_Y)             

    ;SetGadgetAttribute(#Scrl, #PB_ScrollArea_X, hpos/2)
    ;SetGadgetAttribute(#Scrl, #PB_ScrollArea_Y, vpos/2)

Repeat
Until WaitWindowEvent(1) = #PB_Event_CloseWindow
EndIf

User avatar
PedroMartins
User
User
Posts: 47
Joined: Sat Sep 02, 2017 7:30 pm

Re: Project "Give a Pure Example"

Post by PedroMartins »

Section: Enumerations

Instruction/Procedure: Enumeration

Example:

Code: Select all

EnableExplicit
;**********************************************************************************************************************
; FUNCTIONS
;**********************************************************************************************************************
Declare m1_window()
Declare m2_window()

;**********************************************************************************************************************
; Enumeration
;**********************************************************************************************************************
Enumeration m1
  #m1_window=1
  #m1_menu=2
  #m1_menu_app_module2=3
  #m1_menu_app_quit=4
EndEnumeration 

Enumeration m2
  ;#m2_window=1 ; application will fail if you put this. Just remove comment in the beginnig of line and comment the good one
  #m2_window=100 ; application will work
  #m2_button=2
EndEnumeration 

;**********************************************************************************************************************
; BEGIN PROGRAM
;**********************************************************************************************************************
m1_window()
;**********************************************************************************************************************
; END PROGRAM
;**********************************************************************************************************************



Procedure m1_window()
  Protected quit
  Protected event
 
  If OpenWindow(#m1_window, 0, 0, 800, 600, "Module 1", #PB_Window_ScreenCentered)
 
  If CreateImageMenu(#m1_menu, WindowID(#m1_window))
    MenuTitle("APP")
      MenuItem(#m1_menu_app_module2, "Module2 Window")
      MenuItem(#m1_menu_app_quit, "Quit")
    EndIf 
 
    quit=0
    Repeat
      event=WaitWindowEvent()
   
      Select event
        Case #PB_Event_Menu
          Select EventMenu()
            Case #m1_menu_app_module2
              m2_window()
            Case #m1_menu_app_quit   
              quit=1
          EndSelect   
      EndSelect
    Until quit = 1
    CloseWindow(#m1_window)
  EndIf 
EndProcedure


Procedure m2_window()
  Protected quit
  Protected event
 
  If OpenWindow(#m2_window, 0, 0, 200, 200, "Module 2", #PB_Window_ScreenCentered)
    ButtonGadget(#m2_button,10,10,40,40,"OK")
 
    quit=0
    Repeat
      event=WaitWindowEvent()
   
      Select event
        Case #PB_Event_Gadget
          Select EventGadget()
            Case #m2_button
              quit=1
          EndSelect
      EndSelect
    Until quit = 1
    CloseWindow(#m2_window)
  EndIf 
EndProcedure

User avatar
PedroMartins
User
User
Posts: 47
Joined: Sat Sep 02, 2017 7:30 pm

Re: Project "Give a Pure Example"

Post by PedroMartins »

Section: Debugger

Instruction/Procedure: Debug()

Example:

Code: Select all


Define x.d = 10
Define y.d = 0
Define a.d = 0

y = x / y ; Works correctly.

;a = 1.0 / a ; Invalid memory access.

; the problem is that you have to convert the float to
; double again because the result variable a is double. :)
a = ValD(StrD(1.0)) / a

Debug("y: "+y)
Debug("a; "+a)

Fred
Administrator
Administrator
Posts: 16621
Joined: Fri May 17, 2002 4:39 pm
Location: France
Contact:

Re: Project "Give a Pure Example"

Post by Fred »

Please Pedro, your examples are not helping anyone here. Worste, your code on Enumeration is just plainly wrong, you don't even use the enumeration feature as you affect number to every constant. I would suggest to relax, learn how to use PureBasic and then come back with posts which are actually useful for the other users on this forums. Thank you.

Locked as you continue to post non-senses (just by the time I wrote my post which is pretty incredible :) ).
Locked