Can drag scrollbar in block select screen.

This commit is contained in:
UnknownShadow200 2015-12-25 14:44:28 +11:00
parent 5d65eca0b8
commit 0f95d6d92f
2 changed files with 17 additions and 3 deletions

View File

@ -1,4 +1,5 @@
using System;
using OpenTK.Input;
namespace ClassicalSharp {
@ -11,8 +12,8 @@ namespace ClassicalSharp {
graphicsApi.Draw2DQuad( TableX, TableY, scrollbarWidth,
TableHeight, scrollCol );
float scale = TableHeight / (float)rows;
int yOffset = (int)Math.Ceiling(scrollY * scale);
int height = (int)Math.Ceiling(maxRows * scale);
int yOffset = (int)Math.Ceiling( scrollY * scale );
int height = (int)Math.Ceiling( maxRows * scale );
if( yOffset + height > TableHeight )
height = TableHeight - yOffset;
@ -53,5 +54,12 @@ namespace ClassicalSharp {
scrollY = (int)(mouseY / scale);
ClampScrollY();
}
bool draggingMouse = false;
public override bool HandlesMouseUp( int mouseX, int mouseY, MouseButton button ) {
draggingMouse = false;
return true;
}
}
}

View File

@ -218,6 +218,11 @@ namespace ClassicalSharp {
}
public override bool HandlesMouseMove( int mouseX, int mouseY ) {
if( draggingMouse ) {
ScrollbarClick( mouseY );
return true;
}
selIndex = -1;
if( Contains( startX, startY, blocksPerRow * blockSize,
maxRows * blockSize, mouseX, mouseY ) ) {
@ -236,10 +241,11 @@ namespace ClassicalSharp {
}
public override bool HandlesMouseClick( int mouseX, int mouseY, MouseButton button ) {
if( game.hudScreen.hotbar.HandlesMouseClick( mouseX, mouseY, button ) )
if( draggingMouse || game.hudScreen.hotbar.HandlesMouseClick( mouseX, mouseY, button ) )
return true;
if( button == MouseButton.Left && mouseX >= TableX && mouseX < TableX + scrollbarWidth ) {
ScrollbarClick( mouseY );
draggingMouse = true;
} else if( button == MouseButton.Left && selIndex != -1 ) {
game.Inventory.HeldBlock = blocksTable[selIndex];
game.SetNewScreen( null );