|
| 1 | +//package main; |
| 2 | +// |
| 3 | +//import org.lwjgl.PointerBuffer; |
| 4 | +//import org.lwjgl.glfw.GLFWErrorCallback; |
| 5 | +//import org.lwjgl.glfw.GLFWVidMode; |
| 6 | +//import org.lwjgl.opengl.GL; |
| 7 | +//import org.lwjgl.system.MemoryStack; |
| 8 | +// |
| 9 | +//import java.nio.*; |
| 10 | +//import java.util.*; |
| 11 | +// |
| 12 | +//import static org.lwjgl.glfw.Callbacks.*; |
| 13 | +//import static org.lwjgl.glfw.GLFW.*; |
| 14 | +//import static org.lwjgl.opengl.GL11C.*; |
| 15 | +//import static org.lwjgl.system.MemoryStack.*; |
| 16 | +//import static org.lwjgl.system.MemoryUtil.*; |
| 17 | +//import static org.lwjgl.util.tinyfd.TinyFileDialogs.*; |
| 18 | +// |
| 19 | +//public final class HelloTinyFD { |
| 20 | +// |
| 21 | +// private HelloTinyFD() { |
| 22 | +// } |
| 23 | +// |
| 24 | +// public static void main(String[] args) { |
| 25 | +// GLFWErrorCallback.createPrint().set(); |
| 26 | +// if (!glfwInit()) { |
| 27 | +// throw new IllegalStateException("Unable to initialize GLFW"); |
| 28 | +// } |
| 29 | +// |
| 30 | +// long window = glfwCreateWindow(300, 300, "Hello tiny file dialogs!", NULL, NULL); |
| 31 | +// if (window == NULL) { |
| 32 | +// throw new RuntimeException("Failed to create the GLFW window"); |
| 33 | +// } |
| 34 | +// |
| 35 | +// glfwSetKeyCallback(window, (windowHnd, key, scancode, action, mods) -> { |
| 36 | +// if (action == GLFW_RELEASE) { |
| 37 | +// return; |
| 38 | +// } |
| 39 | +// |
| 40 | +// switch (key) { |
| 41 | +// case GLFW_KEY_ESCAPE: |
| 42 | +// glfwSetWindowShouldClose(windowHnd, true); |
| 43 | +// break; |
| 44 | +// case GLFW_KEY_B: |
| 45 | +// tinyfd_beep(); |
| 46 | +// break; |
| 47 | +// case GLFW_KEY_N: |
| 48 | +// System.out.println("\nOpening notification popup..."); |
| 49 | +// System.out.println(tinyfd_notifyPopup("Please read...", "...this message.", "info")); |
| 50 | +// break; |
| 51 | +// case GLFW_KEY_1: |
| 52 | +// System.out.println("\nOpening message dialog..."); |
| 53 | +// System.out.println(tinyfd_messageBox("Please read...", "...this message.", "okcancel", "info", true) ? "OK" : "Cancel"); |
| 54 | +// break; |
| 55 | +// case GLFW_KEY_2: |
| 56 | +// System.out.println("\nOpening input box dialog..."); |
| 57 | +// System.out.println(tinyfd_inputBox("Input Value", "How old are you?", "30")); |
| 58 | +// break; |
| 59 | +// case GLFW_KEY_3: |
| 60 | +// System.out.println("\nOpening file open dialog..."); |
| 61 | +// System.out.println(tinyfd_openFileDialog("Open File(s)", "", null, null, true)); |
| 62 | +// break; |
| 63 | +// case GLFW_KEY_4: |
| 64 | +// try (MemoryStack stack = stackPush()) { |
| 65 | +// PointerBuffer aFilterPatterns = stack.mallocPointer(2); |
| 66 | +// |
| 67 | +// aFilterPatterns.put(stack.UTF8("*.jpg")); |
| 68 | +// aFilterPatterns.put(stack.UTF8("*.png")); |
| 69 | +// |
| 70 | +// aFilterPatterns.flip(); |
| 71 | +// |
| 72 | +// System.out.println("\nOpening file save dialog..."); |
| 73 | +// System.out.println(tinyfd_saveFileDialog("Save Image", "", aFilterPatterns, "Image files (*.jpg, *.png)")); |
| 74 | +// } |
| 75 | +// break; |
| 76 | +// case GLFW_KEY_5: |
| 77 | +// System.out.println("\nOpening folder select dialog..."); |
| 78 | +// System.out.println(tinyfd_selectFolderDialog("Select Folder", "")); |
| 79 | +// break; |
| 80 | +// case GLFW_KEY_6: |
| 81 | +// System.out.println("\nOpening color chooser dialog..."); |
| 82 | +// try (MemoryStack stack = stackPush()) { |
| 83 | +// ByteBuffer color = stack.malloc(3); |
| 84 | +// String hex = tinyfd_colorChooser("Choose Color", "#FF00FF", null, color); |
| 85 | +// System.out.println(hex); |
| 86 | +// if (hex != null) { |
| 87 | +// System.out.println("\tR: " + (color.get(0) & 0xFF)); |
| 88 | +// System.out.println("\tG: " + (color.get(1) & 0xFF)); |
| 89 | +// System.out.println("\tB: " + (color.get(2) & 0xFF)); |
| 90 | +// } |
| 91 | +// } |
| 92 | +// break; |
| 93 | +// } |
| 94 | +// }); |
| 95 | +// |
| 96 | +// // Center window |
| 97 | +// GLFWVidMode vidmode = Objects.requireNonNull(glfwGetVideoMode(glfwGetPrimaryMonitor())); |
| 98 | +// glfwSetWindowPos( |
| 99 | +// window, |
| 100 | +// (vidmode.width() - 300) / 2, |
| 101 | +// (vidmode.height() - 300) / 2 |
| 102 | +// ); |
| 103 | +// |
| 104 | +// glfwMakeContextCurrent(window); |
| 105 | +// GL.createCapabilities(); |
| 106 | +// |
| 107 | +// glfwSwapInterval(1); |
| 108 | +// |
| 109 | +// tinyfd_messageBox("tinyfd_query", "", "ok", "info", true); |
| 110 | +// System.out.println("tiny file dialogs " + tinyfd_version + " (" + tinyfd_response() + ")"); |
| 111 | +// System.out.println(); |
| 112 | +// System.out.println(tinyfd_needs); |
| 113 | +// System.out.println(); |
| 114 | +// System.out.println("Press 1 to launch a message dialog."); |
| 115 | +// System.out.println("Press 2 to launch an input box fialog."); |
| 116 | +// System.out.println("Press 3 to launch a file open dialog."); |
| 117 | +// System.out.println("Press 4 to launch a file save dialog."); |
| 118 | +// System.out.println("Press 5 to launch a folder select dialog."); |
| 119 | +// System.out.println("Press 6 to launch a color chooser dialog."); |
| 120 | +// while (!glfwWindowShouldClose(window)) { |
| 121 | +// glfwPollEvents(); |
| 122 | +// |
| 123 | +// glClear(GL_COLOR_BUFFER_BIT); |
| 124 | +// glfwSwapBuffers(window); |
| 125 | +// } |
| 126 | +// |
| 127 | +// GL.setCapabilities(null); |
| 128 | +// |
| 129 | +// glfwFreeCallbacks(window); |
| 130 | +// glfwDestroyWindow(window); |
| 131 | +// glfwTerminate(); |
| 132 | +// |
| 133 | +// Objects.requireNonNull(glfwSetErrorCallback(null)).free(); |
| 134 | +// } |
| 135 | +// |
| 136 | +//} |
0 commit comments