Gui Window

Übersicht BlitzMax, BlitzMax NG Allgemein

Neue Antwort erstellen

Mathias-Kwiatkowski

Betreff: Gui Window

BeitragSo, Mai 20, 2012 20:04
Antworten mit Zitat
Benutzer-Profile anzeigen
hi ich habe hier nun ein dummes problem mit den Gui fenstern... für einige projekte möchte ich "meine" grafischen fenster benutzen. naja das problem is das man durch die fenster durchklicken kann.

hier der code. ich weiss nun nich genau was ich machen muss um genau dieses durchklicken zu verhindern...

Code: [AUSKLAPPEN]
Global ScreenX:Int = DesktopWidth()
Global ScreenY:Int = DesktopHeight()

Global WindowList:TList = New TList
Global Window:TWindow
Global WindowID:Int = 0
Type TWindow
   Field Name:String
   Field ID:Int
   Field X:Int, Y:Int, W:Int, H:Int
   Field Scalable:Int
   Field Activ:Int
   
   Function Create(Name:String, X:Int, Y:Int, W:Int, H:Int, Scalable:Int = 0)
      Window:TWindow = New TWindow
      Window.Name = Name
      Window.X = X
      Window.Y = Y
      Window.W = W
      Window.H = H
      Window.Scalable = Scalable
      Window.id = WindowID
      
      WindowID = WindowID + 1
      
      WindowList.Addlast Window
   End Function
   
   Method Draw()
      If Self.Activ = 0 Then
         SetColor 80, 80, 80
      Else
         SetColor 255, 255, 255
      EndIf
      SetScale Float(Window.w) / WindowIMG.width, Float(Window.h - 26 * 2) / WindowIMG.height
      DrawImage WindowIMG, Window.x, Window.y + 26, 4
      SetScale Float(Window.w - 65 * 2) / WindowIMG.width, 1
      DrawImage WindowIMG, Window.x + 65, Window.y, 1
      SetScale Float(Window.w - 65 * 2) / WindowIMG.width, 1
      DrawImage WindowIMG, Window.x + 65, Window.y + Window.h - ImageHeight(WindowIMG), 7
      SetScale 1, Float(Window.h - 26 - 26) / WindowIMG.height
      DrawImage WindowIMG, Window.x, Window.y + 26, 3
      SetScale 1, Float(Window.h - 26 - 26) / WindowIMG.height
      DrawImage WindowIMG, Window.x + Window.w - ImageWidth(WindowIMG), Window.y + 26, 5
      SetScale 1, 1
      DrawImage WindowIMG, Window.x, Window.y, 0
      DrawImage WindowIMG, Window.x + Window.w - ImageWidth(WindowIMG), Window.y, 2
      DrawImage WindowIMG, Window.x, Window.y + Window.h - ImageHeight(WindowIMG), 6
      DrawImage WindowIMG, Window.X + Window.W - ImageWidth(WindowIMG), Window.Y + Window.H - ImageHeight(WindowIMG), 8
   
      SetColor 255, 255, 255
   End Method
   
   Method Check()
      If MBL = 1 And GUI_MouseX() > Self.X And GUI_MouseX() < Self.X + Self.W And GUI_MouseY() > Self.Y And GUI_MouseY() < Self.Y + Self.H And CheckWinodw(Self.X, Self.Y, Self.W, Self.H, Self.id) = 0 Then
         TargetID = Self.id
         TargetWas = 1
         WindowList.Remove Self
         WindowList.Addlast Self
         For Xwindow:TWindow = EachIn WindowList
            Xwindow.Activ = 0
         Next
         Self.Activ = 1
      End If
   End Method
EndType

Function CheckWinodw:Int(x:Int, y:Int, w:Int, h:Int, id:Int)
   For Window:TWindow = EachIn WindowList
      If GUI_MouseX() > Window.x And GUI_MouseX() < Window.x + Window.w And GUI_MouseY() > Window.y And GUI_MouseY() < Window.y + Window.h Then
         If id = Window.id Then
         Else
             Return 1
         EndIf
      EndIf
   Next
   Return 0
End Function

Function GUI_MouseX()
   Return MouseX()
End Function

Function GUI_MouseY()
   Return MouseY()
End Function

Function GUI_MouseMBL()
   If MouseDown(1) Then MBL = 1
   If Not MouseDown(1) Then MBL = 0 TargetWas = 0
End Function

Function GUI_Update()
   GUI_MouseMBL()
   For Window:TWindow = EachIn WindowList
      Window.draw()
      Window.Check()
   Next
   
   
End Function

Graphics ScreenX, ScreenY, 1
SetMaskColor 255, 0, 255
Global WindowIMG:TImage = LoadAnimImage ("Data\Window.BMP", 65, 26, 0, 9)




TWindow.Create("Mathias", 20, 20, 230, 270)
TWindow.Create("TTT", 120, 120, 230, 270)
TWindow.Create("XXX", 220, 220, 230, 270)
 

Repeat
   Cls
   
   GUI_Update()
   
   Flip
Until KeyDown(KEY_ESCAPE)
End

Propellator

BeitragSo, Mai 20, 2012 21:51
Antworten mit Zitat
Benutzer-Profile anzeigen
Du solltest sie in der TList entweder nach "tiefe" sortieren oder eine Variable Z hinzufügen. Die "Tiefe" ist hierbei wie sehr das Fenster in relation zu anderen Fenstern steht, ob es nun hinter ihnen oder vorne an ihnen steht. Also eine art dritte Dimension.
Nur das höchste Fenster soll dann den Mausklick empfangen.
Propellator - Alles andere ist irrelephant.
Elefanten sind die Könige der Antarktis.

Mathias-Kwiatkowski

BeitragSo, Mai 20, 2012 23:23
Antworten mit Zitat
Benutzer-Profile anzeigen
ok danke sehr, wäre der code so nun richtig? also es funktioniert alles. aber die frage ist ob es so auch effektiv ist.

Code: [AUSKLAPPEN]
Global MBL:Int            'MouseLeft Button

Global ScreenX:Int = DesktopWidth()
Global ScreenY:Int = DesktopHeight()

Global WindowList:TList = New TList
Global Window:TWindow
Global WindowID:Int = 0
Type TWindow
   Field Name:String
   Field ID:Int
   Field X:Int, Y:Int, W:Int, H:Int
   Field Scalable:Int
   Field Activ:Int
   Field OldX:Int, OldY:Int
   Field MaxW:Int, MaxH:Int
   Field Close:Int
   
   Function Create(Name:String, X:Int, Y:Int, W:Int, H:Int, Scalable:Int = 0, MaxW:Int = 195, MaxH:Int = 225)
      Window:TWindow = New TWindow
      Window.Name = Name
      Window.X = X
      Window.Y = Y
      Window.W = W
      Window.H = H
      Window.Scalable = Scalable
      Window.id = WindowID
      Window.MaxW = MaxW
      Window.MaxH = MaxH
      
      WindowID = WindowID + 1
      
      WindowList.Addlast Window
   End Function
   
   Method Draw()
      If Self.Activ = 0 Then
         SetColor 80, 80, 80
      Else
         SetColor 255, 255, 255
      EndIf
      SetScale Float(Window.w) / WindowIMG.width, Float(Window.h - 26 * 2) / WindowIMG.height
      DrawImage WindowIMG, Window.x, Window.y + 26, 4
      SetScale Float(Window.w - 65 * 2) / WindowIMG.width, 1
      DrawImage WindowIMG, Window.x + 65, Window.y, 1
      SetScale Float(Window.w - 65 * 2) / WindowIMG.width, 1
      DrawImage WindowIMG, Window.x + 65, Window.y + Window.h - ImageHeight(WindowIMG), 7
      SetScale 1, Float(Window.h - 26 - 26) / WindowIMG.height
      DrawImage WindowIMG, Window.x, Window.y + 26, 3
      SetScale 1, Float(Window.h - 26 - 26) / WindowIMG.height
      DrawImage WindowIMG, Window.x + Window.w - ImageWidth(WindowIMG), Window.y + 26, 5
      SetScale 1, 1
      DrawImage WindowIMG, Window.X, Window.Y, 10
      If Self.Close = 1 Then DrawImage WindowIMG, Self.X, Self.Y, 11
      DrawImage WindowIMG, Window.X + Window.W - ImageWidth(WindowIMG), Window.Y, 2
      DrawImage WindowIMG, Window.x, Window.y + Window.h - ImageHeight(WindowIMG), 6
      If Self.Scalable = 0 Then DrawImage WindowIMG, Window.X + Window.W - ImageWidth(WindowIMG), Window.Y + Window.H - ImageHeight(WindowIMG), 8
      If Self.Scalable = 1 Then DrawImage WindowIMG, Window.X + Window.W - ImageWidth(WindowIMG), Window.Y + Window.H - ImageHeight(WindowIMG), 9
   
      If Self.Activ = 0 Then
         SetColor 0, 0, 0
         DrawText Window.Name, Window.X + 36 - 1, Window.Y + 7 - 1
         SetColor 0, 120, 0
         DrawText Window.Name, Window.X + 36, Window.Y + 7
      ElseIf Self.Activ = 1
            SetColor 0, 0, 0
         DrawText Window.Name, Window.X + 36 - 1, Window.Y + 7 - 1
         SetColor 0, 255, 0
         DrawText Window.Name, Window.X + 36, Window.Y + 7
      EndIf
      
      SetColor 255, 255, 255
   End Method
   
   Method Check()
      'Window Aktivieren
      If MBL = 1 And GUI_MouseX() > Self.X And GUI_MouseX() < Self.X + Self.W And GUI_MouseY() > Self.Y And GUI_MouseY() < Self.Y + Self.H And CheckWinodw(Self.id) = 0 And Self.Activ = 0 Then
         TargetID = Self.id
         TargetWas = 1
         WindowList.Remove Self
         WindowList.Addlast Self
         For Xwindow:TWindow = EachIn WindowList
            Xwindow.Activ = 0
         Next
         Self.Activ = 1
         Self.id = WindowID WindowID = WindowID + 1
      End If
      'Window Verschieben
      If MBL = 1 And GUI_MouseX() > Self.X + 13 And GUI_MouseX() < Self.X + Self.W And GUI_MouseY() > Self.Y And GUI_MouseY() < Self.Y + 23 And Self.Activ = 1 Then
         Self.OldX = GUI_MouseX() - Self.X
         Self.OldY = GUI_MouseY() - Self.Y
         MBL = 2   'mbl=2 = verschieben aktiviert
      EndIf
      If MBL = 2 And Self.Activ = 1Then
         Self.X = GUI_MouseX() - Self.OldX
         Self.Y = GUI_MouseY() - Self.OldY
         
         If Self.X > ScreenX - Self.W Then Self.X = ScreenX - Self.W
         If Self.Y > ScreenY - Self.H Then Self.Y = ScreenY - Self.H
         If Self.X < 0 Then Self.X = 0
         If Self.Y < 0 Then Self.Y = 0
      End If
      'Vergrössern
      If MBL = 1 And GUI_MouseX() > Self.X + Self.W - 10 And GUI_MouseX() < Self.X + Self.W And GUI_MouseY() > Self.Y + Self.H - 10 And GUI_MouseY() < Self.Y + Self.H And Self.Activ = 1 And Self.Scalable = 1 Then
         MBL = 3 'Vergrössern
      End If
      If MBL = 3 And Self.Activ = 1 Then
         Self.W = GUI_MouseX () - Self.X
         Self.H = GUI_MouseY () - Self.Y
         
         If Self.W < Self.MaxW Then Self.W = Self.MaxW
         If Self.H < Self.MaxH Then Self.H = Self.MaxH
      End If
      'Schliessen
      If GUI_MouseX() > Self.X + 6 And GUI_MouseX () < Self.X + 12 And GUI_MouseY () > Self.Y + 8 And GUI_MouseY () < Self.Y + 17 And Self.Activ = 1 Then
         Self.Close = 1
         If MBL = 1 Then WindowList.Remove Self
      Else
         Self.Close = 0
      EndIf
   End Method
EndType

Function CheckWinodw:Int(id:Int)
   WKlick:Int = 0
   For Window:TWindow = EachIn WindowList
      If GUI_MouseX() > Window.x And GUI_MouseX() < Window.x + Window.w And GUI_MouseY() > Window.y And GUI_MouseY() < Window.y + Window.h Then
         WKlick = 1
      EndIf
   Next
   If WKlick = 0 Then
      'Kein fenster angeklickt
      Return 2
   End If
   For Window:TWindow = EachIn WindowList
      If GUI_MouseX() > Window.x And GUI_MouseX() < Window.x + Window.w And GUI_MouseY() > Window.y And GUI_MouseY() < Window.y + Window.h Then
         If id = Window.id Then
         Else
             If Window.id > id Return 1
         EndIf
      EndIf
   Next
   Return 0
End Function

Function GUI_MouseX()
   Return MouseX()
End Function

Function GUI_MouseY()
   Return MouseY()
End Function

Function GUI_MouseMBL()
   If MouseDown(1) And MBL = 0 Then MBL = 1
   If Not MouseDown(1) Then MBL = 0 TargetWas = 0
End Function

Function GUI_Update()
   GUI_MouseMBL()
   If MBL = 1 And CheckWinodw(0) = 2 Then
      For Window:TWindow = EachIn WindowList
         Window.Activ = 0
      Next
   End If
   For Window:TWindow = EachIn WindowList
      Window.draw()
      Window.Check()
   Next
   
   
End Function

Graphics ScreenX, ScreenY, 1
SetMaskColor 255, 0, 255
Global WindowIMG:TImage = LoadAnimImage ("Data\Window.BMP", 65, 26, 0, 12)




TWindow.Create("Mathias", 20, 20, 230, 270, 1)
TWindow.Create("TTT", 120, 120, 230, 270)
TWindow.Create("XXX", 220, 220, 230, 270)
 

Repeat
   Cls
   DrawText MBL, 10, 500
   
   GUI_Update()
   
   Flip
Until KeyDown(KEY_ESCAPE)
End

Xeres

Moderator

BeitragSo, Mai 20, 2012 23:41
Antworten mit Zitat
Benutzer-Profile anzeigen
Warum wrappst du MouseY() nochmal in GUI_MouseY()? Wären Variablen nicht kürzer und schneller als die Funktionsaufrufe? Die langen Bedingungen könnte man dagegen mit einer Funktion ersetzen.
Statt des Activ Fields würde ich eine Globale Activ:TWindow Variable benutzen. Die ganzen reinen Zahlen sollten auch zumindest durch Konstanten ersetzt werden.
Und CheckWinodw hat nicht nur einen Buchstabendreher, es sollte auch im Type enthalten sein.
Edit: Gleiches für die anderen Window-Globalen.
Win10 Prof.(x64)/Ubuntu 16.04|CPU 4x3Ghz (Intel i5-4590S)|RAM 8 GB|GeForce GTX 960
Wie man Fragen richtig stellt || "Es geht nicht" || Video-Tutorial: Sinus & Cosinus
T
HERE IS NO FAIR. THERE IS NO JUSTICE. THERE IS JUST ME. (Death, Discworld)

Neue Antwort erstellen


Übersicht BlitzMax, BlitzMax NG Allgemein

Gehe zu:

Powered by phpBB © 2001 - 2006, phpBB Group