Linear Programmer looking for a clue

Just starting out? Need help? Post your questions and find answers here.
User avatar
mk-soft
Always Here
Always Here
Posts: 6209
Joined: Fri May 12, 2006 6:51 pm
Location: Germany

Re: Linear Programmer looking for a clue

Post 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()
My Projects ThreadToGUI / OOP-BaseClass / EventDesigner V3
PB v3.30 / v5.75 - OS Mac Mini OSX 10.xx - VM Window Pro / Linux Ubuntu
Downloads on my Webspace / OneDrive
glennj.0158
User
User
Posts: 21
Joined: Tue Mar 31, 2020 4:43 pm
Location: Lawrenceville, NJ, USA

Re: Linear Programmer looking for a clue

Post 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
glennj.0158
User
User
Posts: 21
Joined: Tue Mar 31, 2020 4:43 pm
Location: Lawrenceville, NJ, USA

2D graphics - When do things happen

Post 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
User avatar
netmaestro
PureBasic Bullfrog
PureBasic Bullfrog
Posts: 8451
Joined: Wed Jul 06, 2005 5:42 am
Location: Fort Nelson, BC, Canada

Re: Linear Programmer looking for a clue

Post 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.
BERESHEIT
User avatar
netmaestro
PureBasic Bullfrog
PureBasic Bullfrog
Posts: 8451
Joined: Wed Jul 06, 2005 5:42 am
Location: Fort Nelson, BC, Canada

Re: Linear Programmer looking for a clue

Post 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
BERESHEIT
glennj.0158
User
User
Posts: 21
Joined: Tue Mar 31, 2020 4:43 pm
Location: Lawrenceville, NJ, USA

Re: Linear Programmer looking for a clue

Post 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
User avatar
netmaestro
PureBasic Bullfrog
PureBasic Bullfrog
Posts: 8451
Joined: Wed Jul 06, 2005 5:42 am
Location: Fort Nelson, BC, Canada

Re: Linear Programmer looking for a clue

Post by netmaestro »

Just remember that when you assign an image to an image gadget, it needs the handle, (ImageID()) not the image#.
BERESHEIT
User avatar
mk-soft
Always Here
Always Here
Posts: 6209
Joined: Fri May 12, 2006 6:51 pm
Location: Germany

Re: Linear Programmer looking for a clue

Post by mk-soft »

Hello Glenn,

Please read PB Help 'Various Topics' -> 'PureBasic objects overview' and 'Arrays, Lists & Structures' -> 'Enumerations' (Named enumeration)
My Projects ThreadToGUI / OOP-BaseClass / EventDesigner V3
PB v3.30 / v5.75 - OS Mac Mini OSX 10.xx - VM Window Pro / Linux Ubuntu
Downloads on my Webspace / OneDrive
User avatar
chikega
User
User
Posts: 38
Joined: Fri Dec 04, 2020 3:19 am

Re: Linear Programmer looking for a clue

Post 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
Gary E Chike DMD MS
'Experience is what you get when you don't get what you want' Image
Bitblazer
Enthusiast
Enthusiast
Posts: 761
Joined: Mon Apr 10, 2017 6:17 pm
Location: Germany
Contact:

Re: Linear Programmer looking for a clue

Post 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.
Post Reply