This repository has been archived by the owner on Feb 16, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
CubeWhy
committed
Jul 31, 2023
1 parent
a1b9ac5
commit ac41481
Showing
4 changed files
with
143 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
51 changes: 51 additions & 0 deletions
51
src/main/java/org/cubewhy/lunarcn/gui/elements/CopyButton.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
package org.cubewhy.lunarcn.gui.elements; | ||
|
||
import net.minecraft.client.gui.Gui; | ||
import net.minecraft.client.gui.GuiButton; | ||
import net.minecraft.client.renderer.entity.Render; | ||
import net.minecraft.util.ResourceLocation; | ||
import org.cubewhy.lunarcn.utils.ClientUtils; | ||
import org.cubewhy.lunarcn.utils.MSTimer; | ||
import org.cubewhy.lunarcn.utils.RenderUtils; | ||
import org.lwjgl.input.Mouse; | ||
|
||
import java.awt.*; | ||
import java.awt.datatransfer.Clipboard; | ||
import java.awt.datatransfer.StringSelection; | ||
|
||
import static org.cubewhy.lunarcn.utils.ClientUtils.*; | ||
|
||
public class CopyButton { | ||
public static boolean hasPressed = false; | ||
|
||
public static final ResourceLocation imageCopy = new ResourceLocation("lunarcn/icons/copy.png"); | ||
|
||
public boolean hovered = false; | ||
public int x; | ||
public int y; | ||
|
||
public String text; | ||
|
||
public CopyButton(int x, int y, String text) { | ||
this.x = x; | ||
this.y = y; | ||
this.text = text; | ||
} | ||
|
||
public void drawButton(int mouseX, int mouseY) { | ||
hovered = RenderUtils.isHovering(mouseX, mouseY, this.x, this.y, this.x + 10, this.y + 10); | ||
// draw image | ||
RenderUtils.drawImage(imageCopy, this.x, this.y, 10, 10); | ||
|
||
if (Mouse.isButtonDown(0) ^ hasPressed) { | ||
try { | ||
Clipboard clipboard = Toolkit.getDefaultToolkit().getSystemClipboard(); | ||
clipboard.setContents(new StringSelection(this.text), null); | ||
logger.info("Copied text: " + this.text); | ||
hasPressed = Mouse.isButtonDown(0); | ||
} catch (Exception e) { | ||
logger.catching(e); // copy failed | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.