erm
This commit is contained in:
		
							parent
							
								
									df6d9b91d0
								
							
						
					
					
						commit
						f8f78dc59b
					
				
					 3 changed files with 53 additions and 42 deletions
				
			
		
							
								
								
									
										1
									
								
								other.go
									
										
									
									
									
								
							
							
						
						
									
										1
									
								
								other.go
									
										
									
									
									
								
							|  | @ -5,3 +5,4 @@ import rl "github.com/gen2brain/raylib-go/raylib" | |||
| func DrawTextureFlipped(rentex *rl.Texture2D, posx, posy int32) { | ||||
| 	rl.DrawTexturePro(*rentex, rl.NewRectangle(0, 0, float32(rentex.Width), -float32(rentex.Height)), rl.NewRectangle(float32(posx), float32(posy), float32(rentex.Width), float32(rentex.Height)), rl.NewVector2(0, 0), 0, rl.White) | ||||
| } | ||||
| 
 | ||||
|  |  | |||
							
								
								
									
										12
									
								
								window.go
									
										
									
									
									
								
							
							
						
						
									
										12
									
								
								window.go
									
										
									
									
									
								
							|  | @ -32,6 +32,14 @@ func NewRayGuiWindow(x, y, w, h int) RayGuiWindow { | |||
| 	return RayGuiWindow{Texture: &texture, Pos: rl.Vector2{X: float32(x), Y: float32(y)}, Size: rl.Vector2{X: float32(w), Y: float32(h)}, DrawBorder: true, AcceptingInput: false} | ||||
| } | ||||
| 
 | ||||
| func (win *RayGuiWindow) GetBorderRect() rl.Rectangle { | ||||
| 	if win.DrawBorder { | ||||
| 		return rl.NewRectangle(0, 0, win.Size.X, 20) | ||||
| 	} else { | ||||
| 		return rl.NewRectangle(0, 0, 0, 0) | ||||
| 	} | ||||
| } | ||||
| 
 | ||||
| func (win *RayGuiWindow) Resize(x, y int) { | ||||
| 	rl.UnloadRenderTexture(*win.Texture) | ||||
| 	win.Size.X += float32(x) | ||||
|  | @ -84,7 +92,9 @@ func (window RayGuiWindow) IsTouchingRegion(posvec rl.Vector2, rect rl.Rectangle | |||
| } | ||||
| 
 | ||||
| func (window *RayGuiWindow) Draw() { | ||||
| 	rl.DrawRectangle(int32(window.Pos.X), int32(window.Pos.Y)-20, int32(window.Size.X), 20, rl.Gray) | ||||
| 	rl.DrawRectangle(int32(window.Pos.X), int32(window.Pos.Y)-int32(window.GetBorderRect().Height, int32(window.Size.X), int32(window.GetBorderRect().Height), rl.Gray) | ||||
| 
 | ||||
| 	 | ||||
| 	rl.DrawText(fmt.Sprint(window.AcceptingInput), int32(window.Pos.X-20), int32(window.Pos.Y)-20, 12, rl.Blue) | ||||
| 	//fmt.Printf("WindowDraw at %i, %i\n", window.X, window.Y) | ||||
| 	DrawTextureFlipped(&window.Texture.Texture, int32(window.Pos.X), int32(window.Pos.Y)) | ||||
|  |  | |||
|  | @ -7,77 +7,77 @@ import ( | |||
| type managewindowfunc func(*RayGuiWindowManager, *RayGuiWindow) | ||||
| 
 | ||||
| type RayGuiWindowManager struct { | ||||
| 	winlist          []*RayGuiWindow | ||||
| 	movingwindow     *RayGuiWindow // the currently moving (resize, drag, etc...) | ||||
| 	movingwindowmode int | ||||
| 	Winlist          []*RayGuiWindow | ||||
| 	Movingwindow     *RayGuiWindow // the currently moving (resize, drag, etc...) | ||||
| 	Movingwindowmode int | ||||
| } | ||||
| 
 | ||||
| func NewRayGuiWindowManager() RayGuiWindowManager { | ||||
| 	var windowlist []*RayGuiWindow | ||||
| 	return RayGuiWindowManager{winlist: windowlist, movingwindow: nil} | ||||
| 	return RayGuiWindowManager{Winlist: windowlist, Movingwindow: nil} | ||||
| } | ||||
| 
 | ||||
| func (winman *RayGuiWindowManager) ManageWindowlist() { | ||||
| 	var windowtomovetofront *RayGuiWindow = nil | ||||
| 	for i := 0; i < len(winman.winlist); i++ { | ||||
| 		if winman.winlist[i].isLeftClicked() { | ||||
| 			windowtomovetofront = winman.winlist[i] | ||||
| 	for i := 0; i < len(winman.Winlist); i++ { | ||||
| 		if winman.Winlist[i].isLeftClicked() { | ||||
| 			windowtomovetofront = winman.Winlist[i] | ||||
| 		} | ||||
| 	} | ||||
| 	if windowtomovetofront != nil { | ||||
| 		windowtomovetofront.ManageFunc = MoveToTopOfWindowlist | ||||
| 	} | ||||
| 	for i := 0; i < len(winman.winlist); i++ { | ||||
| 		if winman.winlist[i].ManageFunc != nil { | ||||
| 			winman.winlist[i].ManageFunc(winman, winman.winlist[i]) | ||||
| 	for i := 0; i < len(winman.Winlist); i++ { | ||||
| 		if winman.Winlist[i].ManageFunc != nil { | ||||
| 			winman.Winlist[i].ManageFunc(winman, winman.Winlist[i]) | ||||
| 		} | ||||
| 	} | ||||
| } | ||||
| 
 | ||||
| func (winman *RayGuiWindowManager) ProcessUserWindowMovement() { | ||||
| 	currentmovingwindow := winman.movingwindow | ||||
| 	currentmovingwindow := winman.Movingwindow | ||||
| 
 | ||||
| 	for i := 0; i < len(winman.winlist); i++ { | ||||
| 		if winman.winlist[i].DidStartMoveDrag() && currentmovingwindow == nil { | ||||
| 			winman.movingwindow = winman.winlist[i] | ||||
| 			winman.movingwindowmode = WINDOW_MODE_DRAG | ||||
| 	for i := 0; i < len(winman.Winlist); i++ { | ||||
| 		if winman.Winlist[i].DidStartMoveDrag() && currentmovingwindow == nil { | ||||
| 			winman.Movingwindow = winman.Winlist[i] | ||||
| 			winman.Movingwindowmode = WINDOW_MODE_DRAG | ||||
| 		} | ||||
| 		if winman.winlist[i].DidStartResizeDrag() && currentmovingwindow == nil { | ||||
| 			winman.movingwindow = winman.winlist[i] | ||||
| 			winman.movingwindowmode = WINDOW_MODE_RESZIE | ||||
| 		if winman.Winlist[i].DidStartResizeDrag() && currentmovingwindow == nil { | ||||
| 			winman.Movingwindow = winman.Winlist[i] | ||||
| 			winman.Movingwindowmode = WINDOW_MODE_RESZIE | ||||
| 		} | ||||
| 		if rl.IsMouseButtonReleased(rl.MouseButtonLeft) || rl.IsMouseButtonReleased(rl.MouseButtonRight) { | ||||
| 			winman.movingwindow = nil | ||||
| 			winman.Movingwindow = nil | ||||
| 		} | ||||
| 
 | ||||
| 	} | ||||
| 	if winman.movingwindow != nil { | ||||
| 		if winman.movingwindowmode == WINDOW_MODE_DRAG { | ||||
| 			winman.movingwindow.Pos.X += (rl.GetMouseDelta().X) | ||||
| 			winman.movingwindow.Pos.Y += (rl.GetMouseDelta().Y) | ||||
| 	if winman.Movingwindow != nil { | ||||
| 		if winman.Movingwindowmode == WINDOW_MODE_DRAG { | ||||
| 			winman.Movingwindow.Pos.X += (rl.GetMouseDelta().X) | ||||
| 			winman.Movingwindow.Pos.Y += (rl.GetMouseDelta().Y) | ||||
| 		} | ||||
| 		if winman.movingwindowmode == WINDOW_MODE_RESZIE { | ||||
| 			winman.movingwindow.Resize(int(rl.GetMouseDelta().X), int(rl.GetMouseDelta().Y)) | ||||
| 		if winman.Movingwindowmode == WINDOW_MODE_RESZIE { | ||||
| 			winman.Movingwindow.Resize(int(rl.GetMouseDelta().X), int(rl.GetMouseDelta().Y)) | ||||
| 		} | ||||
| 	} | ||||
| } | ||||
| 
 | ||||
| func (winman RayGuiWindowManager) DrawInternalWindowList() { | ||||
| 	for i := 0; i < len(winman.winlist); i++ { | ||||
| 		winman.winlist[i].DrawInternals() | ||||
| 	for i := 0; i < len(winman.Winlist); i++ { | ||||
| 		winman.Winlist[i].DrawInternals() | ||||
| 	} | ||||
| } | ||||
| 
 | ||||
| func (winman RayGuiWindowManager) DrawWindowlist() { | ||||
| 	for i := 0; i < len(winman.winlist); i++ { | ||||
| 		winman.winlist[i].Draw() | ||||
| 	for i := 0; i < len(winman.Winlist); i++ { | ||||
| 		winman.Winlist[i].Draw() | ||||
| 	} | ||||
| } | ||||
| 
 | ||||
| func (winman *RayGuiWindowManager) WinlistUnlistWindow(windowtoremove *RayGuiWindow) { | ||||
| 	indextoremove := -1 | ||||
| 	for i := 0; i < len(winman.winlist); i++ { | ||||
| 		if winman.winlist[i] == windowtoremove { | ||||
| 	for i := 0; i < len(winman.Winlist); i++ { | ||||
| 		if winman.Winlist[i] == windowtoremove { | ||||
| 			indextoremove = i | ||||
| 			break | ||||
| 		} | ||||
|  | @ -85,31 +85,31 @@ func (winman *RayGuiWindowManager) WinlistUnlistWindow(windowtoremove *RayGuiWin | |||
| 	if indextoremove == -1 { | ||||
| 		return | ||||
| 	} | ||||
| 	copy(winman.winlist[indextoremove:], winman.winlist[indextoremove+1:]) | ||||
| 	winman.winlist[len(winman.winlist)-1] = nil | ||||
| 	winman.winlist = winman.winlist[:len(winman.winlist)-1] | ||||
| 	copy(winman.Winlist[indextoremove:], winman.Winlist[indextoremove+1:]) | ||||
| 	winman.Winlist[len(winman.Winlist)-1] = nil | ||||
| 	winman.Winlist = winman.Winlist[:len(winman.Winlist)-1] | ||||
| 	return | ||||
| } | ||||
| 
 | ||||
| func CloseWindow(winman *RayGuiWindowManager, windowtoremove *RayGuiWindow) { | ||||
| 	winman.WinlistUnlistWindow(windowtoremove) | ||||
| 	rl.UnloadRenderTexture(*windowtoremove.Texture) | ||||
| 	if winman.movingwindow == windowtoremove { | ||||
| 		winman.movingwindow = nil | ||||
| 	if winman.Movingwindow == windowtoremove { | ||||
| 		winman.Movingwindow = nil | ||||
| 	} | ||||
| 	return | ||||
| } | ||||
| 
 | ||||
| func (winman *RayGuiWindowManager) AddWindow(windowtoadd *RayGuiWindow) { | ||||
| 	if len(winman.winlist) > 0 { | ||||
| 		winman.winlist[len(winman.winlist)-1].AcceptingInput = false | ||||
| 	if len(winman.Winlist) > 0 { | ||||
| 		winman.Winlist[len(winman.Winlist)-1].AcceptingInput = false | ||||
| 	} | ||||
| 	winman.winlist = append(winman.winlist, windowtoadd) | ||||
| 	winman.winlist[len(winman.winlist)-1].AcceptingInput = true | ||||
| 	winman.Winlist = append(winman.Winlist, windowtoadd) | ||||
| 	winman.Winlist[len(winman.Winlist)-1].AcceptingInput = true | ||||
| } | ||||
| 
 | ||||
| func MoveToTopOfWindowlist(winman *RayGuiWindowManager, windowtomove *RayGuiWindow) { | ||||
| 	winman.winlist[len(winman.winlist)-1].AcceptingInput = false | ||||
| 	winman.Winlist[len(winman.Winlist)-1].AcceptingInput = false | ||||
| 	winman.WinlistUnlistWindow(windowtomove) | ||||
| 	winman.AddWindow(windowtomove) | ||||
| 	windowtomove.ManageFunc = nil | ||||
|  |  | |||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue