mirror of
https://gitea.sffempire.ru/Kolyah35/minecraft-pe-0.6.1.git
synced 2026-03-19 22:43:32 +00:00
Added mouse wheel support to the world selection screen.
This commit is contained in:
@@ -78,6 +78,14 @@ void Screen::updateEvents()
|
|||||||
void Screen::mouseEvent()
|
void Screen::mouseEvent()
|
||||||
{
|
{
|
||||||
const MouseAction& e = Mouse::getEvent();
|
const MouseAction& e = Mouse::getEvent();
|
||||||
|
// forward wheel events to subclasses
|
||||||
|
if (e.action == MouseAction::ACTION_WHEEL) {
|
||||||
|
int xm = e.x * width / minecraft->width;
|
||||||
|
int ym = e.y * height / minecraft->height - 1;
|
||||||
|
mouseWheel(e.dx, e.dy, xm, ym);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
if (!e.isButton())
|
if (!e.isButton())
|
||||||
return;
|
return;
|
||||||
|
|
||||||
|
|||||||
@@ -57,6 +57,9 @@ protected:
|
|||||||
virtual void mouseClicked(int x, int y, int buttonNum);
|
virtual void mouseClicked(int x, int y, int buttonNum);
|
||||||
virtual void mouseReleased(int x, int y, int buttonNum);
|
virtual void mouseReleased(int x, int y, int buttonNum);
|
||||||
|
|
||||||
|
// mouse wheel movement (dx/dy are wheel deltas, xm/ym are GUI coords)
|
||||||
|
virtual void mouseWheel(int dx, int dy, int xm, int ym) {}
|
||||||
|
|
||||||
virtual void keyPressed(int eventKey);
|
virtual void keyPressed(int eventKey);
|
||||||
virtual void keyboardNewChar(char inputChar) {}
|
virtual void keyboardNewChar(char inputChar) {}
|
||||||
public:
|
public:
|
||||||
|
|||||||
@@ -548,6 +548,14 @@ void ScrollingPane::stepThroughDecelerationAnimation(bool noAnimation) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void ScrollingPane::scrollBy(float dx, float dy) {
|
||||||
|
// adjust the translation offsets fpx/fpy by the requested amount
|
||||||
|
float nfpx = fpx + dx;
|
||||||
|
float nfpy = fpy + dy;
|
||||||
|
// convert back to content offset (fpx = -contentOffset.x)
|
||||||
|
setContentOffset(Vec3(-nfpx, -nfpy, 0));
|
||||||
|
}
|
||||||
|
|
||||||
void ScrollingPane::setContentOffset(float x, float y) {
|
void ScrollingPane::setContentOffset(float x, float y) {
|
||||||
this->setContentOffsetWithAnimation(Vec3(x, y, 0), false);
|
this->setContentOffsetWithAnimation(Vec3(x, y, 0), false);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -51,6 +51,10 @@ public:
|
|||||||
void tick();
|
void tick();
|
||||||
void render(int xm, int ym, float alpha);
|
void render(int xm, int ym, float alpha);
|
||||||
|
|
||||||
|
// scroll the content by the given amount (dx horizontal, dy vertical)
|
||||||
|
// positive values move content downward/rightward
|
||||||
|
void scrollBy(float dx, float dy);
|
||||||
|
|
||||||
bool getGridItemFor_slow(int itemIndex, GridItem& out);
|
bool getGridItemFor_slow(int itemIndex, GridItem& out);
|
||||||
|
|
||||||
void setSelected(int id, bool selected);
|
void setSelected(int id, bool selected);
|
||||||
|
|||||||
@@ -202,6 +202,25 @@ void IngameBlockSelectionScreen::keyPressed(int eventKey)
|
|||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//------------------------------------------------------------------------------
|
||||||
|
// wheel support for creative inventory; scroll moves selection vertically
|
||||||
|
void IngameBlockSelectionScreen::mouseWheel(int dx, int dy, int xm, int ym)
|
||||||
|
{
|
||||||
|
if (dy == 0) return;
|
||||||
|
// just move selection up/down one row; desktop UI doesn't have a pane
|
||||||
|
int cols = InventoryCols;
|
||||||
|
int maxIndex = InventorySize - 1;
|
||||||
|
int idx = selectedItem;
|
||||||
|
if (dy > 0) {
|
||||||
|
// wheel up -> previous row
|
||||||
|
if (idx >= cols) idx -= cols;
|
||||||
|
} else {
|
||||||
|
// wheel down -> next row
|
||||||
|
if (idx + cols <= maxIndex) idx += cols;
|
||||||
|
}
|
||||||
|
selectedItem = idx;
|
||||||
|
}
|
||||||
|
|
||||||
int IngameBlockSelectionScreen::getSelectedSlot(int x, int y)
|
int IngameBlockSelectionScreen::getSelectedSlot(int x, int y)
|
||||||
{
|
{
|
||||||
int left = width / 2 - InventoryCols * 10;
|
int left = width / 2 - InventoryCols * 10;
|
||||||
|
|||||||
@@ -23,6 +23,9 @@ protected:
|
|||||||
|
|
||||||
virtual void buttonClicked(Button* button);
|
virtual void buttonClicked(Button* button);
|
||||||
|
|
||||||
|
// wheel input for creative inventory scrolling
|
||||||
|
virtual void mouseWheel(int dx, int dy, int xm, int ym) override;
|
||||||
|
|
||||||
virtual void keyPressed(int eventKey);
|
virtual void keyPressed(int eventKey);
|
||||||
private:
|
private:
|
||||||
void renderSlots();
|
void renderSlots();
|
||||||
|
|||||||
@@ -356,7 +356,7 @@ void SelectWorldScreen::render( int xm, int ym, float a )
|
|||||||
worldsList->setComponentSelected(bWorldView.selected);
|
worldsList->setComponentSelected(bWorldView.selected);
|
||||||
// #ifdef PLATFORM_DESKTOP
|
// #ifdef PLATFORM_DESKTOP
|
||||||
|
|
||||||
// We should add scrolling with mouse wheel but currently i dont know how to implement it
|
// desktop: render the list normally (mouse wheel handled separately below)
|
||||||
if (_mouseHasBeenUp)
|
if (_mouseHasBeenUp)
|
||||||
worldsList->render(xm, ym, a);
|
worldsList->render(xm, ym, a);
|
||||||
else {
|
else {
|
||||||
@@ -412,6 +412,28 @@ std::string SelectWorldScreen::getUniqueLevelName( const std::string& level )
|
|||||||
|
|
||||||
bool SelectWorldScreen::isInGameScreen() { return true; }
|
bool SelectWorldScreen::isInGameScreen() { return true; }
|
||||||
|
|
||||||
|
void SelectWorldScreen::mouseWheel(int dx, int dy, int xm, int ym)
|
||||||
|
{
|
||||||
|
if (!worldsList)
|
||||||
|
return;
|
||||||
|
if (dy == 0)
|
||||||
|
return;
|
||||||
|
int num = worldsList->getNumberOfItems();
|
||||||
|
int idx = worldsList->selectedItem;
|
||||||
|
if (dy > 0) {
|
||||||
|
if (idx > 0) {
|
||||||
|
idx--;
|
||||||
|
worldsList->stepLeft();
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
if (idx < num - 1) {
|
||||||
|
idx++;
|
||||||
|
worldsList->stepRight();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
worldsList->selectedItem = idx;
|
||||||
|
}
|
||||||
|
|
||||||
void SelectWorldScreen::keyPressed( int eventKey )
|
void SelectWorldScreen::keyPressed( int eventKey )
|
||||||
{
|
{
|
||||||
if (bWorldView.selected) {
|
if (bWorldView.selected) {
|
||||||
|
|||||||
@@ -90,6 +90,9 @@ public:
|
|||||||
|
|
||||||
void render(int xm, int ym, float a);
|
void render(int xm, int ym, float a);
|
||||||
|
|
||||||
|
// mouse wheel scroll (new in desktop implementation)
|
||||||
|
virtual void mouseWheel(int dx, int dy, int xm, int ym);
|
||||||
|
|
||||||
bool isInGameScreen();
|
bool isInGameScreen();
|
||||||
private:
|
private:
|
||||||
void loadLevelSource();
|
void loadLevelSource();
|
||||||
|
|||||||
@@ -153,6 +153,11 @@ int IngameBlockSelectionScreen::getSlotPosY(int slotY) {
|
|||||||
return height - 16 - 3 - 22 * 2 - 22 * slotY;
|
return height - 16 - 3 - 22 * 2 - 22 * slotY;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int IngameBlockSelectionScreen::getSlotHeight() {
|
||||||
|
// same as non-touch implementation
|
||||||
|
return 22;
|
||||||
|
}
|
||||||
|
|
||||||
void IngameBlockSelectionScreen::mouseClicked(int x, int y, int buttonNum) {
|
void IngameBlockSelectionScreen::mouseClicked(int x, int y, int buttonNum) {
|
||||||
_pendingClose = _blockList->_clickArea->isInside((float)x, (float)y);
|
_pendingClose = _blockList->_clickArea->isInside((float)x, (float)y);
|
||||||
if (!_pendingClose)
|
if (!_pendingClose)
|
||||||
@@ -166,6 +171,24 @@ void IngameBlockSelectionScreen::mouseReleased(int x, int y, int buttonNum) {
|
|||||||
super::mouseReleased(x, y, buttonNum);
|
super::mouseReleased(x, y, buttonNum);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void IngameBlockSelectionScreen::mouseWheel(int dx, int dy, int xm, int ym)
|
||||||
|
{
|
||||||
|
if (dy == 0) return;
|
||||||
|
if (_blockList) {
|
||||||
|
float amount = -dy * getSlotHeight();
|
||||||
|
_blockList->scrollBy(0, amount);
|
||||||
|
}
|
||||||
|
int cols = InventoryColumns;
|
||||||
|
int maxIndex = InventorySize - 1;
|
||||||
|
int idx = selectedItem;
|
||||||
|
if (dy > 0) {
|
||||||
|
if (idx >= cols) idx -= cols;
|
||||||
|
} else {
|
||||||
|
if (idx + cols <= maxIndex) idx += cols;
|
||||||
|
}
|
||||||
|
selectedItem = idx;
|
||||||
|
}
|
||||||
|
|
||||||
bool IngameBlockSelectionScreen::addItem(const InventoryPane* pane, int itemId)
|
bool IngameBlockSelectionScreen::addItem(const InventoryPane* pane, int itemId)
|
||||||
{
|
{
|
||||||
Inventory* inventory = minecraft->player->inventory;
|
Inventory* inventory = minecraft->player->inventory;
|
||||||
|
|||||||
@@ -39,12 +39,16 @@ public:
|
|||||||
protected:
|
protected:
|
||||||
virtual void mouseClicked(int x, int y, int buttonNum);
|
virtual void mouseClicked(int x, int y, int buttonNum);
|
||||||
virtual void mouseReleased(int x, int y, int buttonNum);
|
virtual void mouseReleased(int x, int y, int buttonNum);
|
||||||
|
|
||||||
|
// also support wheel scrolling
|
||||||
|
virtual void mouseWheel(int dx, int dy, int xm, int ym) override;
|
||||||
private:
|
private:
|
||||||
void renderDemoOverlay();
|
void renderDemoOverlay();
|
||||||
|
|
||||||
//int getLinearSlotId(int x, int y);
|
//int getLinearSlotId(int x, int y);
|
||||||
int getSlotPosX(int slotX);
|
int getSlotPosX(int slotX);
|
||||||
int getSlotPosY(int slotY);
|
int getSlotPosY(int slotY);
|
||||||
|
int getSlotHeight();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
int selectedItem;
|
int selectedItem;
|
||||||
|
|||||||
@@ -389,6 +389,26 @@ static char ILLEGAL_FILE_CHARACTERS[] = {
|
|||||||
'/', '\n', '\r', '\t', '\0', '\f', '`', '?', '*', '\\', '<', '>', '|', '\"', ':'
|
'/', '\n', '\r', '\t', '\0', '\f', '`', '?', '*', '\\', '<', '>', '|', '\"', ':'
|
||||||
};
|
};
|
||||||
|
|
||||||
|
void SelectWorldScreen::mouseWheel(int dx, int dy, int xm, int ym)
|
||||||
|
{
|
||||||
|
if (!worldsList) return;
|
||||||
|
if (dy == 0) return;
|
||||||
|
int num = worldsList->getNumberOfItems();
|
||||||
|
int idx = worldsList->selectedItem;
|
||||||
|
if (dy > 0) {
|
||||||
|
if (idx > 0) {
|
||||||
|
idx--;
|
||||||
|
worldsList->stepLeft();
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
if (idx < num - 1) {
|
||||||
|
idx++;
|
||||||
|
worldsList->stepRight();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
worldsList->selectedItem = idx;
|
||||||
|
}
|
||||||
|
|
||||||
void SelectWorldScreen::tick()
|
void SelectWorldScreen::tick()
|
||||||
{
|
{
|
||||||
#if 0
|
#if 0
|
||||||
|
|||||||
@@ -97,6 +97,9 @@ public:
|
|||||||
virtual void buttonClicked(Button* button);
|
virtual void buttonClicked(Button* button);
|
||||||
virtual void keyPressed(int eventKey);
|
virtual void keyPressed(int eventKey);
|
||||||
|
|
||||||
|
// support for mouse wheel when desktop code uses touch variant
|
||||||
|
virtual void mouseWheel(int dx, int dy, int xm, int ym) override;
|
||||||
|
|
||||||
bool isInGameScreen();
|
bool isInGameScreen();
|
||||||
private:
|
private:
|
||||||
void loadLevelSource();
|
void loadLevelSource();
|
||||||
|
|||||||
@@ -113,6 +113,14 @@ LRESULT WINAPI windowProc ( HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam )
|
|||||||
Multitouch::feed(0, 0, GET_X_LPARAM(lParam), GET_Y_LPARAM(lParam), 0);
|
Multitouch::feed(0, 0, GET_X_LPARAM(lParam), GET_Y_LPARAM(lParam), 0);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
case WM_MOUSEWHEEL: {
|
||||||
|
// wheel delta is multiples of WHEEL_DELTA (120); convert to +/-1
|
||||||
|
int delta = GET_WHEEL_DELTA_WPARAM(wParam) / WHEEL_DELTA;
|
||||||
|
short x = GET_X_LPARAM(lParam);
|
||||||
|
short y = GET_Y_LPARAM(lParam);
|
||||||
|
Mouse::feed(MouseAction::ACTION_WHEEL, 0, x, y, 0, delta);
|
||||||
|
break;
|
||||||
|
}
|
||||||
default:
|
default:
|
||||||
if (uMsg == WM_NCDESTROY) g_running = false;
|
if (uMsg == WM_NCDESTROY) g_running = false;
|
||||||
else {
|
else {
|
||||||
|
|||||||
Reference in New Issue
Block a user