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) { | 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) | 	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} | 	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) { | func (win *RayGuiWindow) Resize(x, y int) { | ||||||
| 	rl.UnloadRenderTexture(*win.Texture) | 	rl.UnloadRenderTexture(*win.Texture) | ||||||
| 	win.Size.X += float32(x) | 	win.Size.X += float32(x) | ||||||
|  | @ -84,7 +92,9 @@ func (window RayGuiWindow) IsTouchingRegion(posvec rl.Vector2, rect rl.Rectangle | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| func (window *RayGuiWindow) Draw() { | 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) | 	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) | 	//fmt.Printf("WindowDraw at %i, %i\n", window.X, window.Y) | ||||||
| 	DrawTextureFlipped(&window.Texture.Texture, int32(window.Pos.X), int32(window.Pos.Y)) | 	DrawTextureFlipped(&window.Texture.Texture, int32(window.Pos.X), int32(window.Pos.Y)) | ||||||
|  |  | ||||||
|  | @ -7,77 +7,77 @@ import ( | ||||||
| type managewindowfunc func(*RayGuiWindowManager, *RayGuiWindow) | type managewindowfunc func(*RayGuiWindowManager, *RayGuiWindow) | ||||||
| 
 | 
 | ||||||
| type RayGuiWindowManager struct { | type RayGuiWindowManager struct { | ||||||
| 	winlist          []*RayGuiWindow | 	Winlist          []*RayGuiWindow | ||||||
| 	movingwindow     *RayGuiWindow // the currently moving (resize, drag, etc...) | 	Movingwindow     *RayGuiWindow // the currently moving (resize, drag, etc...) | ||||||
| 	movingwindowmode int | 	Movingwindowmode int | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| func NewRayGuiWindowManager() RayGuiWindowManager { | func NewRayGuiWindowManager() RayGuiWindowManager { | ||||||
| 	var windowlist []*RayGuiWindow | 	var windowlist []*RayGuiWindow | ||||||
| 	return RayGuiWindowManager{winlist: windowlist, movingwindow: nil} | 	return RayGuiWindowManager{Winlist: windowlist, Movingwindow: nil} | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| func (winman *RayGuiWindowManager) ManageWindowlist() { | func (winman *RayGuiWindowManager) ManageWindowlist() { | ||||||
| 	var windowtomovetofront *RayGuiWindow = nil | 	var windowtomovetofront *RayGuiWindow = nil | ||||||
| 	for i := 0; i < len(winman.winlist); i++ { | 	for i := 0; i < len(winman.Winlist); i++ { | ||||||
| 		if winman.winlist[i].isLeftClicked() { | 		if winman.Winlist[i].isLeftClicked() { | ||||||
| 			windowtomovetofront = winman.winlist[i] | 			windowtomovetofront = winman.Winlist[i] | ||||||
| 		} | 		} | ||||||
| 	} | 	} | ||||||
| 	if windowtomovetofront != nil { | 	if windowtomovetofront != nil { | ||||||
| 		windowtomovetofront.ManageFunc = MoveToTopOfWindowlist | 		windowtomovetofront.ManageFunc = MoveToTopOfWindowlist | ||||||
| 	} | 	} | ||||||
| 	for i := 0; i < len(winman.winlist); i++ { | 	for i := 0; i < len(winman.Winlist); i++ { | ||||||
| 		if winman.winlist[i].ManageFunc != nil { | 		if winman.Winlist[i].ManageFunc != nil { | ||||||
| 			winman.winlist[i].ManageFunc(winman, winman.winlist[i]) | 			winman.Winlist[i].ManageFunc(winman, winman.Winlist[i]) | ||||||
| 		} | 		} | ||||||
| 	} | 	} | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| func (winman *RayGuiWindowManager) ProcessUserWindowMovement() { | func (winman *RayGuiWindowManager) ProcessUserWindowMovement() { | ||||||
| 	currentmovingwindow := winman.movingwindow | 	currentmovingwindow := winman.Movingwindow | ||||||
| 
 | 
 | ||||||
| 	for i := 0; i < len(winman.winlist); i++ { | 	for i := 0; i < len(winman.Winlist); i++ { | ||||||
| 		if winman.winlist[i].DidStartMoveDrag() && currentmovingwindow == nil { | 		if winman.Winlist[i].DidStartMoveDrag() && currentmovingwindow == nil { | ||||||
| 			winman.movingwindow = winman.winlist[i] | 			winman.Movingwindow = winman.Winlist[i] | ||||||
| 			winman.movingwindowmode = WINDOW_MODE_DRAG | 			winman.Movingwindowmode = WINDOW_MODE_DRAG | ||||||
| 		} | 		} | ||||||
| 		if winman.winlist[i].DidStartResizeDrag() && currentmovingwindow == nil { | 		if winman.Winlist[i].DidStartResizeDrag() && currentmovingwindow == nil { | ||||||
| 			winman.movingwindow = winman.winlist[i] | 			winman.Movingwindow = winman.Winlist[i] | ||||||
| 			winman.movingwindowmode = WINDOW_MODE_RESZIE | 			winman.Movingwindowmode = WINDOW_MODE_RESZIE | ||||||
| 		} | 		} | ||||||
| 		if rl.IsMouseButtonReleased(rl.MouseButtonLeft) || rl.IsMouseButtonReleased(rl.MouseButtonRight) { | 		if rl.IsMouseButtonReleased(rl.MouseButtonLeft) || rl.IsMouseButtonReleased(rl.MouseButtonRight) { | ||||||
| 			winman.movingwindow = nil | 			winman.Movingwindow = nil | ||||||
| 		} | 		} | ||||||
| 
 | 
 | ||||||
| 	} | 	} | ||||||
| 	if winman.movingwindow != nil { | 	if winman.Movingwindow != nil { | ||||||
| 		if winman.movingwindowmode == WINDOW_MODE_DRAG { | 		if winman.Movingwindowmode == WINDOW_MODE_DRAG { | ||||||
| 			winman.movingwindow.Pos.X += (rl.GetMouseDelta().X) | 			winman.Movingwindow.Pos.X += (rl.GetMouseDelta().X) | ||||||
| 			winman.movingwindow.Pos.Y += (rl.GetMouseDelta().Y) | 			winman.Movingwindow.Pos.Y += (rl.GetMouseDelta().Y) | ||||||
| 		} | 		} | ||||||
| 		if winman.movingwindowmode == WINDOW_MODE_RESZIE { | 		if winman.Movingwindowmode == WINDOW_MODE_RESZIE { | ||||||
| 			winman.movingwindow.Resize(int(rl.GetMouseDelta().X), int(rl.GetMouseDelta().Y)) | 			winman.Movingwindow.Resize(int(rl.GetMouseDelta().X), int(rl.GetMouseDelta().Y)) | ||||||
| 		} | 		} | ||||||
| 	} | 	} | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| func (winman RayGuiWindowManager) DrawInternalWindowList() { | func (winman RayGuiWindowManager) DrawInternalWindowList() { | ||||||
| 	for i := 0; i < len(winman.winlist); i++ { | 	for i := 0; i < len(winman.Winlist); i++ { | ||||||
| 		winman.winlist[i].DrawInternals() | 		winman.Winlist[i].DrawInternals() | ||||||
| 	} | 	} | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| func (winman RayGuiWindowManager) DrawWindowlist() { | func (winman RayGuiWindowManager) DrawWindowlist() { | ||||||
| 	for i := 0; i < len(winman.winlist); i++ { | 	for i := 0; i < len(winman.Winlist); i++ { | ||||||
| 		winman.winlist[i].Draw() | 		winman.Winlist[i].Draw() | ||||||
| 	} | 	} | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| func (winman *RayGuiWindowManager) WinlistUnlistWindow(windowtoremove *RayGuiWindow) { | func (winman *RayGuiWindowManager) WinlistUnlistWindow(windowtoremove *RayGuiWindow) { | ||||||
| 	indextoremove := -1 | 	indextoremove := -1 | ||||||
| 	for i := 0; i < len(winman.winlist); i++ { | 	for i := 0; i < len(winman.Winlist); i++ { | ||||||
| 		if winman.winlist[i] == windowtoremove { | 		if winman.Winlist[i] == windowtoremove { | ||||||
| 			indextoremove = i | 			indextoremove = i | ||||||
| 			break | 			break | ||||||
| 		} | 		} | ||||||
|  | @ -85,31 +85,31 @@ func (winman *RayGuiWindowManager) WinlistUnlistWindow(windowtoremove *RayGuiWin | ||||||
| 	if indextoremove == -1 { | 	if indextoremove == -1 { | ||||||
| 		return | 		return | ||||||
| 	} | 	} | ||||||
| 	copy(winman.winlist[indextoremove:], winman.winlist[indextoremove+1:]) | 	copy(winman.Winlist[indextoremove:], winman.Winlist[indextoremove+1:]) | ||||||
| 	winman.winlist[len(winman.winlist)-1] = nil | 	winman.Winlist[len(winman.Winlist)-1] = nil | ||||||
| 	winman.winlist = winman.winlist[:len(winman.winlist)-1] | 	winman.Winlist = winman.Winlist[:len(winman.Winlist)-1] | ||||||
| 	return | 	return | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| func CloseWindow(winman *RayGuiWindowManager, windowtoremove *RayGuiWindow) { | func CloseWindow(winman *RayGuiWindowManager, windowtoremove *RayGuiWindow) { | ||||||
| 	winman.WinlistUnlistWindow(windowtoremove) | 	winman.WinlistUnlistWindow(windowtoremove) | ||||||
| 	rl.UnloadRenderTexture(*windowtoremove.Texture) | 	rl.UnloadRenderTexture(*windowtoremove.Texture) | ||||||
| 	if winman.movingwindow == windowtoremove { | 	if winman.Movingwindow == windowtoremove { | ||||||
| 		winman.movingwindow = nil | 		winman.Movingwindow = nil | ||||||
| 	} | 	} | ||||||
| 	return | 	return | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| func (winman *RayGuiWindowManager) AddWindow(windowtoadd *RayGuiWindow) { | func (winman *RayGuiWindowManager) AddWindow(windowtoadd *RayGuiWindow) { | ||||||
| 	if len(winman.winlist) > 0 { | 	if len(winman.Winlist) > 0 { | ||||||
| 		winman.winlist[len(winman.winlist)-1].AcceptingInput = false | 		winman.Winlist[len(winman.Winlist)-1].AcceptingInput = false | ||||||
| 	} | 	} | ||||||
| 	winman.winlist = append(winman.winlist, windowtoadd) | 	winman.Winlist = append(winman.Winlist, windowtoadd) | ||||||
| 	winman.winlist[len(winman.winlist)-1].AcceptingInput = true | 	winman.Winlist[len(winman.Winlist)-1].AcceptingInput = true | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| func MoveToTopOfWindowlist(winman *RayGuiWindowManager, windowtomove *RayGuiWindow) { | 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.WinlistUnlistWindow(windowtomove) | ||||||
| 	winman.AddWindow(windowtomove) | 	winman.AddWindow(windowtomove) | ||||||
| 	windowtomove.ManageFunc = nil | 	windowtomove.ManageFunc = nil | ||||||
|  |  | ||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue