Seite 1 von 1
Buttongadget auf nem windowedscreen??
Verfasst: 29.08.2023 19:09
von 3dhubiflieger
Code: Alles auswählen
If InitSprite() = 0
MessageRequester("Error", "Can't open screen & sprite environment!", 0)
End
EndIf
If OpenWindow(0, 0, 0, 220, 160, "A screen in a window...", #PB_Window_SystemMenu | #PB_Window_ScreenCentered)
ButtonGadget(0, 70, 135, 45, 20, "Quit")
If OpenWindowedScreen(WindowID(0), 0, 0, 160, 160)
CreateSprite(0, 20, 20)
If StartDrawing(SpriteOutput(0))
Box(0, 0, 20, 20, RGB(255, 0, 155))
Box(5, 5, 10, 10, RGB(155, 0, 255))
StopDrawing()
EndIf
Else
MessageRequester("Error", "Can't open windowed screen!", 0)
End
EndIf
EndIf
direction = 2
Repeat
; Es ist sehr wichtig, alle im Queue befindlichen Ereignisse während jedes Frames abzuarbeiten
;
Repeat
Event = WindowEvent()
Select Event
Case #PB_Event_Gadget
If EventGadget() = 0
End
EndIf
Case #PB_Event_CloseWindow
End
EndSelect
Until Event = 0
FlipBuffers()
ClearScreen(RGB(0, 0, 0))
DisplaySprite(0, x, x)
x + direction
If x > 140 : direction = -2 : EndIf
If x < 0 : direction = 2 : EndIf
Delay(1)
ForEver
Wie bekommt man es hin das das buttongadget auf dem windowedscreen angezeigt wird ???
// Code-Tags hinzugefügt (Kiffi)
Re: Buttongadget auf nem windowedscreen??
Verfasst: 29.08.2023 19:22
von mk-soft
WindowedScreen und Window sind zwei unterschiedliche Bereiche oder Ausgaben
Siehe dir die Hilfe für "PureBasic - Gadget3D" an
Re: Buttongadget auf nem windowedscreen??
Verfasst: 29.08.2023 19:48
von 3dhubiflieger
Also das kapier ich nicht. Hab mir die Hilfe angeschaut. Das mit start und stopdrawing funktioniert dann irgendwie nicht. Bekomme es dann auch nicht hin mit >Line< ne Linie zu zeichnen. Gibts da echt nix ohne das komische 3d ? Davon abgesehn müsste ich mein Programm komplett umstrukturieren was ein Mega Aufwand wäre.
Re: Buttongadget auf nem windowedscreen??
Verfasst: 29.08.2023 21:44
von mk-soft
CanvasGadget
Code: Alles auswählen
;-TOP
#ProgramTitle = "Main Window"
#ProgramVersion = "v1.01.2"
Enumeration Windows
#Main
EndEnumeration
Enumeration MenuBar
#MainMenu
EndEnumeration
Enumeration MenuItems
#MainMenuAbout
#MainMenuExit
EndEnumeration
Enumeration Gadgets
#MainCanvas
#MainButton
EndEnumeration
Enumeration StatusBar
#MainStatusBar
EndEnumeration
Procedure DoDrawCanvas()
Protected dx, dy
dx = GadgetWidth(#MainCanvas)
dy = GadgetHeight(#MainCanvas)
If StartDrawing(CanvasOutput(0))
Box(0, 0, dx, dy, #White)
DrawingMode(#PB_2DDrawing_Outlined)
Box(2, 2, dx - 4, dy - 4, #Blue)
DrawingMode(#PB_2DDrawing_Default)
Box(5, 5, 130, 35, #Red)
StopDrawing()
EndIf
EndProcedure
Procedure UpdateWindow()
Protected dx, dy
dx = WindowWidth(#Main)
dy = WindowHeight(#Main) - StatusBarHeight(#MainStatusBar) - MenuHeight()
; Resize gadgets
ResizeGadget(#MainCanvas, 0, 0, dx, dy)
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, #ProgramTitle , #MainStyle)
; Menu
CreateMenu(#MainMenu, WindowID(#Main))
MenuTitle("&File")
CompilerIf #PB_Compiler_OS = #PB_OS_MacOS
MenuItem(#PB_Menu_About, "")
CompilerElse
MenuItem(#MainMenuAbout, "About")
CompilerEndIf
; Menu File Items
CompilerIf Not #PB_Compiler_OS = #PB_OS_MacOS
MenuBar()
MenuItem(#MainMenuExit, "E&xit")
CompilerEndIf
; StatusBar
CreateStatusBar(#MainStatusBar, WindowID(#Main))
AddStatusBarField(#PB_Ignore)
; Gadgets
dx = WindowWidth(#Main)
dy = WindowHeight(#Main) - StatusBarHeight(#MainStatusBar) - MenuHeight()
CanvasGadget(#MainCanvas, 0, 0, dx, dy, #PB_Canvas_Container)
ButtonGadget(#MainButton, 10, 10, 120, 25, "Button")
CloseGadgetList()
DoDrawCanvas()
; Bind Events
BindEvent(#PB_Event_SizeWindow, @UpdateWindow(), #Main)
BindGadgetEvent(#MainCanvas, @DoDrawCanvas(), #PB_EventType_Resize)
; Event Loop
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
PostEvent(#PB_Event_Menu, #Main, #MainMenuAbout)
Case #PB_Menu_Preferences
Case #PB_Menu_Quit
PostEvent(#PB_Event_CloseWindow, #Main, #Null)
CompilerEndIf
Case #MainMenuAbout
MessageRequester("About", #ProgramTitle + #LF$ + #ProgramVersion, #PB_MessageRequester_Info)
Case #MainMenuExit
PostEvent(#PB_Event_CloseWindow, #Main, #Null)
EndSelect
Case #PB_Event_Gadget
Select EventGadget()
EndSelect
EndSelect
ForEver
EndIf
EndProcedure : Main()
Re: Buttongadget auf nem windowedscreen??
Verfasst: 30.08.2023 07:42
von 3dhubiflieger
vielen Dank für den Code. Jedoch muss das Buttongadget bei einem Windowed screen mit Flipbuffers angezeigt werden sonst bringt mirs nix, da mein Programm komplett darauf beruht. Echt schade das es da keine simple Lösung gibt.
Re: Buttongadget auf nem windowedscreen??
Verfasst: 30.08.2023 14:13
von mk-soft
Es können keine Standard Gadgets auf einem Screen Dargestellt werden. Diese Screen sind für Spiele gedacht.
Du kannst aber den Screen kleiner darstellen als das Window Fenster und die Gadgets ausserhalb vom Screen platzieren.