Page 2 of 2

Re: Linear Programmer looking for a clue

Posted: Tue Feb 08, 2022 4:28 pm
by mk-soft
Simple base window save into toolbox templates

Update

Code: Select all

;-TOP

EnableExplicit

Enumeration Windows
  #Main
EndEnumeration

Enumeration Menus
  #MainMenu
EndEnumeration

Enumeration MenuItems
  #MainMenuExitApplication
EndEnumeration

Enumeration Gadgets
  
EndEnumeration

Enumeration Status
  #MainStatusBar
EndEnumeration

; ----

Procedure UpdateWindow()
  Protected dx, dy
  dx = WindowWidth(#Main)
  dy = WindowHeight(#Main) - MenuHeight() - StatusBarHeight(#MainStatusBar)
  ;ResizeGadget
EndProcedure

Procedure Main()
  Protected dx, dy
  
  #MainStyle = #PB_Window_SystemMenu | #PB_Window_SizeGadget | #PB_Window_MaximizeGadget | #PB_Window_MinimizeGadget
  
  If OpenWindow(#Main, #PB_Ignore, #PB_Ignore, 800, 600, "Main Window" , #MainStyle)
    ; Menu
    CreateMenu(#MainMenu, WindowID(#Main))
    MenuTitle("File")
    MenuItem(#MainMenuExitApplication, "E&xit")
    
    ; For Mac
    CompilerIf #PB_Compiler_OS = #PB_OS_MacOS
      ; Mac default menu
      MenuItem(#PB_Menu_About, "")
      MenuItem(#PB_Menu_Preferences, "")
    CompilerEndIf
    
    ; Statusbar
    CreateStatusBar(#MainStatusBar, WindowID(#Main))
    AddStatusBarField(#PB_Ignore)
    StatusBarText(#MainStatusBar, 0, " Status")
    
    ; Gadgets
    dx = WindowWidth(#Main)
    dy = WindowHeight(#Main) - MenuHeight() - StatusBarHeight(#MainStatusBar)
    
    ; Bind events
    BindEvent(#PB_Event_SizeWindow, @UpdateWindow(), #Main)
    
    Repeat
      Select WaitWindowEvent()
        Case #PB_Event_CloseWindow
          Select EventWindow()
            Case #Main
              Break
              
          EndSelect
          
        Case #PB_Event_Menu
          Select EventMenu()
            CompilerIf #PB_Compiler_OS = #PB_OS_MacOS   
              Case #PB_Menu_About
                MessageRequester("Info", "Main Window v1.0")
                
              Case #PB_Menu_Preferences
                
              Case #PB_Menu_Quit
                PostEvent(#PB_Event_CloseWindow, #Main, #Null)
                
            CompilerEndIf
              
            Case #MainMenuExitApplication
              PostEvent(#PB_Event_CloseWindow, #Main, #Null)
                
          EndSelect
        
        Case #PB_Event_Gadget
          Select EventGadget()
              
          EndSelect
          
      EndSelect
    ForEver
    
  EndIf
  
EndProcedure : Main()

Re: Linear Programmer looking for a clue

Posted: Wed Feb 09, 2022 2:40 am
by glennj.0158
Thanks all for the help. I got the gadgets into the order I wanted and life is good.

On a more philosophical note -- I use the Form Designer tool when I'm starting a new language or using new project tools to get a feel for the mechanical requirements. This get me to "something that works". I usually start making tweaks to the generated code to figure out what works better. Once I have that sorted I'll either move to coding from scratch (I agree that easy projects are often easier to just create) or use the tools depending.

I do agree strongly that you need to understand what the application needs in order to have effective and efficient designs. I find that my ASM background often points me to solving a coding problem (e.g. why is 1/2 == 0) that the "kids" who never suffered through numerical methods don't get.

Regards
Glenn

2D graphics - When do things happen

Posted: Mon Feb 14, 2022 12:44 am
by glennj.0158
I'm working on a program which displays a quilting block part by part. I think the code below should create a window, project a black background,
and display 6 squares on the diagonal with a one-second delay between squares. What I get is a grey window with banner and nothing else.

I copied the diagonal line example from the Survival Guide and it works BUT the display of the image is disconnected in time from the execution of the code. My intention is to provide both the illustration of the pattern and, through delaying the projection of each additional component, a sense of how the block is assembled.

Your guidance is, as always, appreciated

hDisplayBlockWin = OpenWindow(#PB_Any, 0, 0, 600, 600, "Test Window",
#PB_Window_SystemMenu | #PB_Window_ScreenCentered)
Bitmap1_num = 1001
Bitmap1_han = CreateImage(Bitmap1_num, 600, 600) ; *********** Create an image area with a black (color 0) background

GadgetImage_1_num =1002
ImageGadget (GadgetImage_1_num, 0, 0, 600, 600, Bitmap1_han)

For iTemp = 1 To 6
StartDrawing (ImageOutput (Bitmap1_num))
X = (Temp-1 ) * 50
y = x
Box( x, y, 50, 50, $00FF00 ) ; ************* I expected this to add a new box to the image
DrawText(x, y, " Log " + iTemp)
StopDrawing()
SetGadgetState (GadgetImage_1_num, 1) ; ********** I expected this to display the image-to-date on the screen
Next iTemp

MessageRequester ("Stall", "Really Stall")
End

Re: Linear Programmer looking for a clue

Posted: Mon Feb 14, 2022 12:51 am
by netmaestro
Did you mean x = (iTemp-1) * 50 ? EnableExplicit can help with this type of oversight.
Also, by assigning the static Image# of Bitmap1_num to 1001, you are reserving space for 1000 images along with the image you create.
And where's your windowevents loop? Nothing works unless you process window events.

Re: Linear Programmer looking for a clue

Posted: Mon Feb 14, 2022 1:13 am
by netmaestro
Try this:

Code: Select all

hDisplayBlockWin = OpenWindow(#PB_Any, 0, 0, 600, 600, "Test Window",
                              #PB_Window_SystemMenu | #PB_Window_ScreenCentered)
Bitmap1_num = 1
Bitmap1_han = CreateImage(Bitmap1_num, 600, 600, 24, #Black) ; *********** Create an image area with a black (color 0) background
GadgetImage_1_num = 2
ImageGadget (GadgetImage_1_num, 0, 0, 600, 600, Bitmap1_han)

iTemp=1
Repeat
  Ev=WaitWindowEvent()
  If itemp<7
    StartDrawing (ImageOutput (Bitmap1_num))
    X = (iTemp-1 ) * 50
    y = x
    Box( x, y, 50, 50, $00FF00 ) ; ************* I expected this to add a new box to the image
    DrawText(x, y, " Log " + iTemp)
    StopDrawing()
    SetGadgetState (GadgetImage_1_num, ImageID(Bitmap1_num)) ; ********** I expected this to display the image-to-date on the screen
    iTemp+1
  EndIf
Until Ev=#PB_Event_CloseWindow

Re: Linear Programmer looking for a clue

Posted: Mon Feb 14, 2022 2:19 am
by glennj.0158
Thanks for the catch on Temp vs iTemp. This code fragment was extracted from a larger unit and then simplified to show the structure of the problem.

Also thanks for your snippet. I'm in the process of figuring out how this works.

-Glenn

Re: Linear Programmer looking for a clue

Posted: Mon Feb 14, 2022 2:22 am
by netmaestro
Just remember that when you assign an image to an image gadget, it needs the handle, (ImageID()) not the image#.

Re: Linear Programmer looking for a clue

Posted: Mon Feb 14, 2022 9:36 am
by mk-soft
Hello Glenn,

Please read PB Help 'Various Topics' -> 'PureBasic objects overview' and 'Arrays, Lists & Structures' -> 'Enumerations' (Named enumeration)

Re: Linear Programmer looking for a clue

Posted: Mon Mar 28, 2022 2:45 pm
by chikega
It looks like the Discord link has expired. And I can't seem to find PureBasic in Discord when doing a search. Thanks in advance for an invite. :D

Re: Linear Programmer looking for a clue

Posted: Mon Mar 28, 2022 6:03 pm
by Bitblazer
chikega wrote: Mon Mar 28, 2022 2:45 pm It looks like the Discord link has expired. And I can't seem to find PureBasic in Discord when doing a search. Thanks in advance for an invite. :D
Purebasic Discord

This discord invitation link should be permanent now and can be copied to websites and signatures.