use of com.spinyowl.legui.component.ImageView in project legui by SpinyOwl.
the class ExampleGui method createImageWrapperWidgetWithImage.
private Widget createImageWrapperWidgetWithImage() {
Widget imageWrapper = new Widget(20, 30, 100, 100);
imageWrapper.setAscendible(true);
imageWrapper.setTitleEnabled(true);
imageView = new ImageView(ImageLoader.loadImage("com/spinyowl/legui/demo/1.jpg"));
imageView.setPosition(15, 5);
imageView.setSize(70, 70);
imageView.getStyle().setBorderRadius(10f);
imageWrapper.getTitle().getTextState().setText("Ascendible widget");
imageWrapper.getContainer().add(imageView);
imageWrapper.setCloseable(false);
return imageWrapper;
}
use of com.spinyowl.legui.component.ImageView in project legui by SpinyOwl.
the class FBOImageExample method main.
public static void main(String[] args) throws IOException {
System.setProperty("joml.nounsafe", Boolean.TRUE.toString());
System.setProperty("java.awt.headless", Boolean.TRUE.toString());
if (!GLFW.glfwInit()) {
throw new RuntimeException("Can't initialize GLFW");
}
long window = glfwCreateWindow(WIDTH, HEIGHT, "FBO Image example", NULL, NULL);
glfwShowWindow(window);
glfwMakeContextCurrent(window);
GL.createCapabilities();
glfwSwapInterval(0);
// Firstly we need to create frame component for window.
Frame frame = new Frame(WIDTH, HEIGHT);
// We need to create legui context which shared by renderer and event processor.
// Also we need to pass event processor for ui events such as click on component, key typing and etc.
Context context = new Context(window);
// We need to create callback keeper which will hold all of callbacks.
// These callbacks will be used in initialization of system event processor
// (will be added callbacks which will push system events to event queue and after that processed by SystemEventProcessor)
CallbackKeeper keeper = new DefaultCallbackKeeper();
// register callbacks for window. Note: all previously binded callbacks will be unbinded.
CallbackKeeper.registerCallbacks(window, keeper);
GLFWKeyCallbackI glfwKeyCallbackI = (w1, key, code, action, mods) -> running = !(key == GLFW_KEY_ESCAPE && action != GLFW_RELEASE);
GLFWWindowCloseCallbackI glfwWindowCloseCallbackI = w -> running = false;
// if we want to create some callbacks for system events you should create and put them to keeper
//
// Wrong:
// glfwSetKeyCallback(window, glfwKeyCallbackI);
// glfwSetWindowCloseCallback(window, glfwWindowCloseCallbackI);
//
// Right:
keeper.getChainKeyCallback().add(glfwKeyCallbackI);
keeper.getChainWindowCloseCallback().add(glfwWindowCloseCallbackI);
// Event processor for system events. System events should be processed and translated to gui events.
SystemEventProcessor systemEventProcessor = new SystemEventProcessorImpl();
SystemEventProcessor.addDefaultCallbacks(keeper, systemEventProcessor);
// Also we need to create renderer provider
// and create renderer which will render our ui components.
Renderer renderer = new NvgRenderer();
// Initialization finished, so we can start render loop.
running = true;
// Everything can be done in one thread as well as in separated threads.
// Here is one-thread example.
// before render loop we need to initialize renderer
renderer.initialize();
// //// rendering to texture and use this texture as image
long nvgContext = 0;
FBOImage fboTexture = null;
boolean isVersionNew = (glGetInteger(GL_MAJOR_VERSION) > 3) || (glGetInteger(GL_MAJOR_VERSION) == 3 && glGetInteger(GL_MINOR_VERSION) >= 2);
if (isVersionNew) {
int flags = NanoVGGL3.NVG_STENCIL_STROKES | NanoVGGL3.NVG_ANTIALIAS;
nvgContext = NanoVGGL3.nvgCreate(flags);
} else {
int flags = NanoVGGL2.NVG_STENCIL_STROKES | NanoVGGL2.NVG_ANTIALIAS;
nvgContext = NanoVGGL2.nvgCreate(flags);
}
if (nvgContext != 0) {
fboTexture = createFBOTexture(textureWidth, textureHeight);
Widget widget = new Widget(10, 10, 100, 100);
widget.setCloseable(false);
widget.setMinimizable(false);
widget.setResizable(true);
widget.getContainer().getStyle().setDisplay(DisplayType.FLEX);
ImageView imageView = new ImageView(fboTexture);
imageView.setPosition(10, 10);
imageView.getStyle().setPosition(PositionType.RELATIVE);
imageView.getStyle().getFlexStyle().setFlexGrow(1);
imageView.getStyle().setMargin(10f);
imageView.getStyle().setMinimumSize(50, 50);
widget.getContainer().add(imageView);
frame.getContainer().add(widget);
}
while (running) {
if (fboTexture != null) {
renderToFBO(nvgContext);
}
// Before rendering we need to update context with window size and window framebuffer size
// {
// int[] windowWidth = {0}, windowHeight = {0};
// GLFW.glfwGetWindowSize(window, windowWidth, windowHeight);
// int[] frameBufferWidth = {0}, frameBufferHeight = {0};
// GLFW.glfwGetFramebufferSize(window, frameBufferWidth, frameBufferHeight);
// int[] xpos = {0}, ypos = {0};
// GLFW.glfwGetWindowPos(window, xpos, ypos);
// double[] mx = {0}, my = {0};
// GLFW.glfwGetCursorPos(window, mx, my);
//
// context.update(windowWidth[0], windowHeight[0],
// frameBufferWidth[0], frameBufferHeight[0],
// xpos[0], ypos[0],
// mx[0], my[0]
// );
// }
// Also we can do it in one line
context.updateGlfwWindow();
Vector2i windowSize = context.getFramebufferSize();
glClearColor(1, 1, 1, 1);
// Set viewport size
glViewport(0, 0, windowSize.x, windowSize.y);
// Clear screen
glClear(GL_COLOR_BUFFER_BIT | GL_STENCIL_BUFFER_BIT);
// render frame
renderer.render(frame, context);
// poll events to callbacks
glfwPollEvents();
glfwSwapBuffers(window);
// Now we need to process events. Firstly we need to process system events.
systemEventProcessor.processEvents(frame, context);
// When system events are translated to GUI events we need to process them.
// This event processor calls listeners added to ui components
EventProcessorProvider.getInstance().processEvents();
// When everything done we need to relayout components.
LayoutManager.getInstance().layout(frame);
// Run animations. Should be also called cause some components use animations for updating state.
AnimatorProvider.getAnimator().runAnimations();
}
if (nvgContext != 0) {
glDeleteRenderbuffers(renderBufferID);
glDeleteTextures(textureID);
glDeleteFramebuffers(frameBufferID);
if (isVersionNew) {
NanoVGGL3.nnvgDelete(nvgContext);
} else {
NanoVGGL2.nnvgDelete(nvgContext);
}
}
// And when rendering is ended we need to destroy renderer
renderer.destroy();
glfwDestroyWindow(window);
glfwTerminate();
}
use of com.spinyowl.legui.component.ImageView in project legui by SpinyOwl.
the class SingleClassExampleImageRendering method createGuiElements.
private static void createGuiElements(Frame frame) {
Widget widget = new Widget("video", 10, 40, WIDTH - 20, HEIGHT - 50);
widget.getContainer().getStyle().setDisplay(Style.DisplayType.FLEX);
widget.setCloseable(false);
ImageView imageView = new ImageView();
imageView.getStyle().setPosition(Style.PositionType.ABSOLUTE);
imageView.getStyle().setTop(0);
imageView.getStyle().setBottom(0);
imageView.getStyle().setLeft(0);
imageView.getStyle().setRight(0);
imageView.getStyle().getBackground().setColor(ColorConstants.lightGray());
if (imageView.getImage() == null) {
textureWidth = WIDTH / 2;
textureHeight = HEIGHT / 2;
byteBuffer = generateEmptyImage(ByteBuffer.allocate(textureWidth * textureHeight * 4));
img = new BufferedImageRGBA(textureWidth, textureHeight);
img.updateImageData(generateEmptyImage(byteBuffer));
imageView.setImage(img);
}
;
widget.getContainer().add(imageView);
frame.getContainer().add(widget);
}
Aggregations