v1.2.0: added custom cursor visuals
This commit is contained in:
parent
83c83e7b25
commit
1f50f74d73
88
SPD-classes/src/main/java/com/watabou/noosa/ui/Cursor.java
Normal file
88
SPD-classes/src/main/java/com/watabou/noosa/ui/Cursor.java
Normal file
|
@ -0,0 +1,88 @@
|
|||
/*
|
||||
* Pixel Dungeon
|
||||
* Copyright (C) 2012-2015 Oleg Dolya
|
||||
*
|
||||
* Shattered Pixel Dungeon
|
||||
* Copyright (C) 2014-2022 Evan Debenham
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>
|
||||
*/
|
||||
|
||||
package com.watabou.noosa.ui;
|
||||
|
||||
import com.badlogic.gdx.Files;
|
||||
import com.badlogic.gdx.Gdx;
|
||||
import com.badlogic.gdx.graphics.Pixmap;
|
||||
import com.watabou.utils.FileUtils;
|
||||
|
||||
public class Cursor {
|
||||
|
||||
private static com.badlogic.gdx.graphics.Cursor currentCursor;
|
||||
|
||||
public enum Type {
|
||||
|
||||
//TODO if we ever add more cursors, should cache their pixmaps rather than always remaking
|
||||
DEFAULT("gdx/cursor.png");
|
||||
|
||||
private String file;
|
||||
|
||||
Type(String file){
|
||||
this.file = file;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private static Type lastType;
|
||||
private static int lastZoom;
|
||||
|
||||
public static void setCustomCursor(Type type, int zoom){
|
||||
|
||||
if (currentCursor != null){
|
||||
if (lastType == type && lastZoom == zoom){
|
||||
return;
|
||||
}
|
||||
|
||||
currentCursor.dispose();
|
||||
currentCursor = null;
|
||||
}
|
||||
|
||||
Pixmap cursorImg = new Pixmap(FileUtils.getFileHandle(Files.FileType.Internal, type.file));
|
||||
|
||||
int scaledWidth = cursorImg.getWidth()*zoom;
|
||||
int width2 = 2;
|
||||
while (width2 < scaledWidth) {
|
||||
width2 <<= 1;
|
||||
}
|
||||
|
||||
int scaledHeight = cursorImg.getHeight()*zoom;
|
||||
int height2 = 2;
|
||||
while (height2 < scaledHeight) {
|
||||
height2 <<= 1;
|
||||
}
|
||||
|
||||
Pixmap scaledImg = new Pixmap(width2, height2, cursorImg.getFormat());
|
||||
scaledImg.setFilter(Pixmap.Filter.NearestNeighbour);
|
||||
scaledImg.drawPixmap(cursorImg, 0, 0, cursorImg.getWidth(), cursorImg.getHeight(), 0, 0, scaledWidth, scaledHeight);
|
||||
|
||||
currentCursor = Gdx.graphics.newCursor(scaledImg, 0, 0);
|
||||
Gdx.graphics.setCursor(currentCursor);
|
||||
scaledImg.dispose();
|
||||
cursorImg.dispose();
|
||||
|
||||
lastType = type;
|
||||
lastZoom = zoom;
|
||||
|
||||
}
|
||||
|
||||
}
|
|
@ -42,6 +42,7 @@ import com.watabou.noosa.Gizmo;
|
|||
import com.watabou.noosa.Scene;
|
||||
import com.watabou.noosa.Visual;
|
||||
import com.watabou.noosa.ui.Component;
|
||||
import com.watabou.noosa.ui.Cursor;
|
||||
import com.watabou.utils.GameMath;
|
||||
import com.watabou.utils.Reflection;
|
||||
|
||||
|
@ -151,6 +152,8 @@ public class PixelScene extends Scene {
|
|||
|
||||
Tooltip.resetLastUsedTime();
|
||||
|
||||
Cursor.setCustomCursor(Cursor.Type.DEFAULT, defaultZoom);
|
||||
|
||||
}
|
||||
|
||||
//FIXME this system currently only works for a subset of windows
|
||||
|
|
Loading…
Reference in New Issue
Block a user