Fixed scrolling ui component

This commit is contained in:
austin 2022-03-17 00:05:28 -04:00
parent 1f00532448
commit af0a54b336
13 changed files with 543 additions and 171 deletions

28
.vscode/launch.json vendored Normal file
View File

@ -0,0 +1,28 @@
{
// Use IntelliSense to learn about possible attributes.
// Hover to view descriptions of existing attributes.
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"type": "java",
"name": "Launch Current File",
"request": "launch",
"mainClass": "${file}"
},
{
"type": "java",
"name": "Launch TerrainGen",
"request": "launch",
"mainClass": "electrosphere.game.server.terrain.generation.TerrainGen",
"projectName": "Renderer"
},
{
"type": "java",
"name": "Launch Main",
"request": "launch",
"mainClass": "electrosphere.main.Main",
"projectName": "Renderer"
}
]
}

Binary file not shown.

View File

@ -18,17 +18,18 @@ void main() {
for(float y = 0; y < 5; y++){
float xPos = x / 10.0;
float yPos = y / 10.0;
origCoord = (triangle1Pos + vec4( 0.0 + xPos, 0.0, 0.0 + yPos, 0.0)).xyz;
origCoord = (triangle1Pos + vec4( 0.0 + xPos, 0.5, 0.0 + yPos, 0.0)).xyz;
gl_Position = projection * view * model * (triangle1Pos + vec4( 0.0 + xPos, 0.0, 0.0 + yPos, 0.0));
EmitVertex();
origCoord = (triangle1Pos + vec4( 0.1 + xPos, 0.5, 0.0 + yPos, 0.0)).xyz;
gl_Position = projection * view * model * (triangle1Pos + vec4( 0.1 + xPos, 0.5, 0.0 + yPos, 0.0));
EmitVertex();
origCoord = (triangle1Pos + vec4( 0.0 + xPos, 1.0, 0.0 + yPos, 0.0)).xyz;
origCoord = (triangle1Pos + vec4( 0.05 + xPos, 1.0, 0.0 + yPos, 0.0)).xyz;
gl_Position = projection * view * model * (triangle1Pos + vec4( 0.0 + xPos, 1.0, 0.0 + yPos, 0.0));
EmitVertex();
EndPrimitive();
}
EndPrimitive();
// EndPrimitive();
}

View File

@ -0,0 +1,234 @@
/*
MIT License
Copyright (c) 2022 railgunSR
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
*/
/*
THIS MAKES USE OF OPENSIMPLEX2, A NOISE ALGORITHM CREATED BY THE FINE FOLKS
OVER AT https://github.com/KdotJPG/OpenSimplex2
PLEASE GIVE THEM SOME LOVE.
THE FLAME FUNCTION IS ONE CREATED BY ME BLENDING A LOG2 INTO A EXPONENTIAL.
*/
//version
#version 330 core
//macros
#extension GL_ARB_explicit_uniform_location : enable
//output
out vec4 fragColor;
//input
in vec3 FragPos;
in vec3 Normal;
in vec2 TexCoord;
in vec4 projCoord;
in vec4 modelCoord;
//uniforms
uniform float time;
//layout uniforms
layout (location = 5) uniform sampler2D volumeDepthFrontface;
layout (location = 6) uniform sampler2D volumeDepthBackface;
//function declarations
vec4 openSimplex2_Conventional(vec3 X);
vec4 openSimplex2_ImproveXY(vec3 X);
float flameTex(float x, float y);
float getNoise(float scale, float timeScale);
/*
Main method
*/
void main(){
float timeS = time * 0.01;
// Normalized pixel coordinates (from 0 to 1)
vec3 projCoordNorm = projCoord.xyz / projCoord.w / 2.0 + 0.5;
//make vec2
vec2 finalProd = projCoordNorm.xy;
//grab depth values
float closeDepth = texture(volumeDepthFrontface, finalProd.xy).r;
float farDepth = texture(volumeDepthBackface, finalProd.xy).r;
//distance between the two
float volume = abs(farDepth - closeDepth);
//based on distance of model coords from center
float dist = length(modelCoord.xyz);
//noise
// float noiseInX = modelCoord.x * 7.0;
// float noiseInZ = FragPos.y * 7.0 - timeS;
// float noiseInY = modelCoord.y * 7.0;
// float noise = openSimplex2_ImproveXY(vec3(noiseInX,noiseInY,noiseInZ)).x;
float noise = (getNoise(7.0,1.5 * timeS) + getNoise(10.0,1.5 * (timeS + 0.1)) + getNoise(14.0,1.5 * (timeS + 0.2)) + getNoise(20.0,3.0 * timeS)) / 4.0;
// float noise = getNoise(10.0,1.5);
// float noise = getNoise(14.0,2.0);
float vertical = -modelCoord.z;
float amountOfFire = volume * 50.0 + vertical * 2.0 + noise * 0.1;// + dist * 0.1; //should be a function of volume + noise + dist from center
// if(amountOfFire < 0.1){
// discard;
// }
amountOfFire = amountOfFire * 2.0;
float red = 0.1984;
float green = 0.6464;
float blue = 0.7366;
float alpha = volume * 10.0;
// float red = volume * 10.0;
// float green = volume * 10.0;
// float blue = volume * 10.0;
// float alpha = 1.0;
vec4 color = vec4(
red,
green,
blue,
alpha
);
// if(val < 0.3){
// discard;
// }
// Output to screen
fragColor = color;
}
float getNoise(float scale, float time){
float noiseInX = modelCoord.x * scale;
float noiseInZ = FragPos.y * scale - time;
float noiseInY = modelCoord.y * scale;
float noise = openSimplex2_ImproveXY(vec3(noiseInX,noiseInY,noiseInZ)).x;
return noise;
}
//////////////// K.jpg's Re-oriented 4-Point BCC Noise (OpenSimplex2) ////////////////
////////////////////// Output: vec4(dF/dx, dF/dy, dF/dz, value) //////////////////////
// Inspired by Stefan Gustavson's noise
vec4 permute(vec4 t) {
return t * (t * 34.0 + 133.0);
}
// Gradient set is a normalized expanded rhombic dodecahedron
vec3 grad(float hash) {
// Random vertex of a cube, +/- 1 each
vec3 cube = mod(floor(hash / vec3(1.0, 2.0, 4.0)), 2.0) * 2.0 - 1.0;
// Random edge of the three edges connected to that vertex
// Also a cuboctahedral vertex
// And corresponds to the face of its dual, the rhombic dodecahedron
vec3 cuboct = cube;
cuboct[int(hash / 16.0)] = 0.0;
// In a funky way, pick one of the four points on the rhombic face
float type = mod(floor(hash / 8.0), 2.0);
vec3 rhomb = (1.0 - type) * cube + type * (cuboct + cross(cube, cuboct));
// Expand it so that the new edges are the same length
// as the existing ones
vec3 grad = cuboct * 1.22474487139 + rhomb;
// To make all gradients the same length, we only need to shorten the
// second type of vector. We also put in the whole noise scale constant.
// The compiler should reduce it into the existing floats. I think.
grad *= (1.0 - 0.042942436724648037 * type) * 32.80201376986577;
return grad;
}
// BCC lattice split up into 2 cube lattices
vec4 openSimplex2Base(vec3 X) {
// First half-lattice, closest edge
vec3 v1 = round(X);
vec3 d1 = X - v1;
vec3 score1 = abs(d1);
vec3 dir1 = step(max(score1.yzx, score1.zxy), score1);
vec3 v2 = v1 + dir1 * sign(d1);
vec3 d2 = X - v2;
// Second half-lattice, closest edge
vec3 X2 = X + 144.5;
vec3 v3 = round(X2);
vec3 d3 = X2 - v3;
vec3 score2 = abs(d3);
vec3 dir2 = step(max(score2.yzx, score2.zxy), score2);
vec3 v4 = v3 + dir2 * sign(d3);
vec3 d4 = X2 - v4;
// Gradient hashes for the four points, two from each half-lattice
vec4 hashes = permute(mod(vec4(v1.x, v2.x, v3.x, v4.x), 289.0));
hashes = permute(mod(hashes + vec4(v1.y, v2.y, v3.y, v4.y), 289.0));
hashes = mod(permute(mod(hashes + vec4(v1.z, v2.z, v3.z, v4.z), 289.0)), 48.0);
// Gradient extrapolations & kernel function
vec4 a = max(0.5 - vec4(dot(d1, d1), dot(d2, d2), dot(d3, d3), dot(d4, d4)), 0.0);
vec4 aa = a * a; vec4 aaaa = aa * aa;
vec3 g1 = grad(hashes.x); vec3 g2 = grad(hashes.y);
vec3 g3 = grad(hashes.z); vec3 g4 = grad(hashes.w);
vec4 extrapolations = vec4(dot(d1, g1), dot(d2, g2), dot(d3, g3), dot(d4, g4));
// Derivatives of the noise
vec3 derivative = -8.0 * mat4x3(d1, d2, d3, d4) * (aa * a * extrapolations)
+ mat4x3(g1, g2, g3, g4) * aaaa;
// Return it all as a vec4
return vec4(derivative, dot(aaaa, extrapolations));
}
// Use this if you don't want Z to look different from X and Y
vec4 openSimplex2_Conventional(vec3 X) {
// Rotate around the main diagonal. Not a skew transform.
vec4 result = openSimplex2Base(dot(X, vec3(2.0/3.0)) - X);
return vec4(dot(result.xyz, vec3(2.0/3.0)) - result.xyz, result.w);
}
// Use this if you want to show X and Y in a plane, then use Z for time, vertical, etc.
vec4 openSimplex2_ImproveXY(vec3 X) {
// Rotate so Z points down the main diagonal. Not a skew transform.
mat3 orthonormalMap = mat3(
0.788675134594813, -0.211324865405187, -0.577350269189626,
-0.211324865405187, 0.788675134594813, -0.577350269189626,
0.577350269189626, 0.577350269189626, 0.577350269189626);
vec4 result = openSimplex2Base(orthonormalMap * X);
return vec4(result.xyz * orthonormalMap, result.w);
}
//////////////////////////////// End noise code ////////////////////////////////

View File

@ -0,0 +1,44 @@
//Vertex Shader
#version 330 core
//input buffers
layout (location = 0) in vec3 aPos;
layout (location = 1) in vec3 aNormal;
layout (location = 4) in vec2 aTex;
//coordinate space transformation matrices
uniform mat4 model;
uniform mat4 view;
uniform mat4 projection;
uniform float time;
//output buffers
out vec3 FragPos;
out vec3 Normal;
out vec2 TexCoord;
out vec4 projCoord;
out vec4 modelCoord;
void main() {
//normalize posiiton and normal
vec4 FinalVertex = vec4(aPos, 1.0);
vec4 FinalNormal = vec4(aNormal, 1.0);
//push frag, normal, and texture positions to fragment shader
FragPos = vec3(model * FinalVertex);
Normal = mat3(transpose(inverse(model))) * aNormal;
TexCoord = aTex;
projCoord = projection * view * model * FinalVertex;
modelCoord = FinalVertex;
//set final position with opengl space
gl_Position = projection * view * model * FinalVertex;
}

View File

@ -806,7 +806,7 @@ public class ControlHandler {
void setInGameDebugControls(){
mainGameDebugControlList.add(controls.get(DATA_STRING_INPUT_CODE_DEBUG_SPAWN_ITEM));
controls.get(DATA_STRING_INPUT_CODE_DEBUG_SPAWN_ITEM).setOnPress(new ControlMethod(){public void execute(){
RenderingEngine.incrementOutputFramebuffer();
// RenderingEngine.incrementOutputFramebuffer();
// Entity bow = ItemUtils.spawnBasicItem("shorts1");
// EntityUtils.getPosition(bow).set(1, 5, 2);
// CollisionObjUtils.positionCharacter(bow, new Vector3f(1, 5, 2));

View File

@ -704,32 +704,35 @@ public class LoadingThread extends Thread {
EntityUtils.getPosition(cube).set(1,0.08f,1);
EntityUtils.getRotation(cube).rotationX(-(float)Math.PI/2.0f);
//texture mask
List<Texture> textureList = new LinkedList<Texture>();
textureList.add(Globals.renderingEngine.getVolumeFrontfaceTexture());
textureList.add(Globals.renderingEngine.getVolumeBackfaceTexture());
List<String> uniformList = new LinkedList<String>();
uniformList.add("volumeDepthFrontface");
uniformList.add("volumeDepthBackface");
ActorTextureMask textureMask = new ActorTextureMask("Sphere",textureList,uniformList);
EntityUtils.getActor(cube).addTextureMask(textureMask);
EntityUtils.getActor(cube).addTextureMask(RenderUtils.generateVolumetricTextureMask("Sphere"));
//set draw volumetric
cube.putData(EntityDataStrings.DRAW_VOLUMETRIC, true);
//queue grass shader
Globals.assetManager.addShaderToQueue("Shaders/grass1/grass1.vs", "Shaders/grass1/grass1.gs", "Shaders/grass1/grass1.fs");
for(int x = 0; x < 10; x++){
for(int y = 0; y < 10; y++){
Entity grass = EntityUtils.spawnDrawableEntity("Models/grass1.fbx");
//shader mask
EntityUtils.getActor(grass).maskShader("Cube", "Shaders/grass1/grass1.vs", "Shaders/grass1/grass1.gs", "Shaders/grass1/grass1.fs");
EntityUtils.getPosition(grass).set(2 + x / 2.0f,0.0,2 + y / 2.0f);
}
}
// //queue grass shader
// Globals.assetManager.addShaderToQueue("Shaders/grass1/grass1.vs", "Shaders/grass1/grass1.gs", "Shaders/grass1/grass1.fs");
// for(int x = 0; x < 10; x++){
// for(int y = 0; y < 10; y++){
// Entity grass = EntityUtils.spawnDrawableEntity("Models/grass1.fbx");
// //shader mask
// EntityUtils.getActor(grass).maskShader("Cube", "Shaders/grass1/grass1.vs", "Shaders/grass1/grass1.gs", "Shaders/grass1/grass1.fs");
// EntityUtils.getPosition(grass).set(3 + x / 2.0f,0.0,1 + y / 2.0f);
// }
// }
//water cube
Entity water = EntityUtils.spawnDrawableEntity("Models/watercube1.fbx");
EntityUtils.getActor(water).maskShader("Cube", "Shaders/water1/water.vs", "Shaders/water1/water.fs");
Globals.assetManager.addShaderToQueue("Shaders/water1/water.vs", "Shaders/water1/water.fs");
EntityUtils.getPosition(water).set(5,0.51,5);
//texture mask
EntityUtils.getActor(water).addTextureMask(RenderUtils.generateVolumetricTextureMask("Cube"));
//set draw volumetric
water.putData(EntityDataStrings.DRAW_VOLUMETRIC, true);
// goblin = CreatureUtils.spawnBasicCreature("Goblin");
// CollisionObjUtils.positionCharacter(goblin, new Vector3f(3, 0, 4));

View File

@ -13,6 +13,7 @@ import electrosphere.game.server.saves.SaveUtils;
import electrosphere.main.Globals;
import electrosphere.main.Main;
import electrosphere.net.NetUtils;
import electrosphere.renderer.RenderingEngine;
import electrosphere.renderer.ui.ClickableElement;
import electrosphere.renderer.ui.DrawableElement;
import electrosphere.renderer.ui.Element;
@ -505,11 +506,15 @@ public class MenuGenerators {
float fontSize = 0.4f;
Window rVal = new Window(0,0,width,height);
// int screenLeft = (Globals.WINDOW_WIDTH - width)/2;
Div div = new Div();
// Div div = new Div();
// div.setPositionX(0);
// div.setPositionY(0);
// div.setWidth(500);
// div.setHeight(500);
ScrollableContainer scrollable = new ScrollableContainer(0, 0, width, height);
rVal.addChild(scrollable);
scrollable.addChild(div);
div.setOnNavigationCallback(new NavigationEventCallback() {public boolean execute(NavigationEvent event){
// scrollable.addChild(div);
rVal.setOnNavigationCallback(new NavigationEventCallback() {public boolean execute(NavigationEvent event){
WindowUtils.replaceWindow(WindowStrings.WINDOW_MENU_INGAME_MAIN, createInGameMainMenu());
return false;
}});
@ -519,14 +524,14 @@ public class MenuGenerators {
// imagePanel.setWidth(width);
// imagePanel.setHeight(height);
// imagePanel.setTexture(Globals.assetManager.fetchTexture(Globals.blackTexture));
div.addChild(imagePanel);
scrollable.addChild(imagePanel);
//label 1 (back)
Button backButton = new Button();
Label backLabel = new Label(100,50,fontSize);
backLabel.setText("Back");
backButton.addChild(backLabel);
div.addChild(backButton);
scrollable.addChild(backButton);
backButton.setOnClick(new ClickableElement.ClickEventCallback(){public boolean execute(ClickEvent event){
WindowUtils.replaceWindow(WindowStrings.WINDOW_MENU_INGAME_MAIN, createInGameMainMenu());
return false;
@ -538,7 +543,7 @@ public class MenuGenerators {
Label quitLabel = new Label(100,150,fontSize);
quitLabel.setText("debug or smthn");
quitButton.addChild(quitLabel);
div.addChild(quitButton);
scrollable.addChild(quitButton);
quitButton.setOnClick(new ClickableElement.ClickEventCallback(){public boolean execute(ClickEvent event){
// Main.running = false;
return false;
@ -547,15 +552,27 @@ public class MenuGenerators {
for(int i = 0; i < 10; i++){
Button someButton = new Button();
Label someLabel = new Label(100,250 + i * 100,fontSize);
someLabel.setText("aaaaaa");
someLabel.setText("aaaaaa" + i);
someButton.addChild(someLabel);
div.addChild(someButton);
scrollable.addChild(someButton);
someButton.setOnClick(new ClickableElement.ClickEventCallback(){public boolean execute(ClickEvent event){
// Main.running = false;
return false;
}});
}
//label (switch framebuffer)
Button switchFramebufferButton = new Button();
Label switchFramebufferLabel = new Label(100,1250,fontSize);
switchFramebufferLabel.setText("Switch Active Framebuffer");
switchFramebufferButton.addChild(switchFramebufferLabel);
scrollable.addChild(switchFramebufferButton);
switchFramebufferButton.setOnClick(new ClickableElement.ClickEventCallback(){public boolean execute(ClickEvent event){
// Main.running = false;
RenderingEngine.incrementOutputFramebuffer();
return false;
}});
return rVal;
}

View File

@ -11,6 +11,9 @@ import java.util.LinkedList;
import java.util.List;
import electrosphere.main.Globals;
import electrosphere.renderer.actor.ActorTextureMask;
import electrosphere.renderer.texture.Texture;
import org.joml.Matrix4f;
import org.joml.Vector3f;
import org.lwjgl.BufferUtils;
@ -1776,5 +1779,16 @@ public class RenderUtils {
}
public static ActorTextureMask generateVolumetricTextureMask(String meshName){
List<Texture> textureList = new LinkedList<Texture>();
textureList.add(Globals.renderingEngine.getVolumeFrontfaceTexture());
textureList.add(Globals.renderingEngine.getVolumeBackfaceTexture());
List<String> uniformList = new LinkedList<String>();
uniformList.add("volumeDepthFrontface");
uniformList.add("volumeDepthBackface");
return new ActorTextureMask(meshName,textureList,uniformList);
}
}

View File

@ -19,11 +19,11 @@ public class Button implements DrawableElement, FocusableElement, ContainerEleme
List<Element> childList = new LinkedList<Element>();
int width = 1;
int height = 1;
int width = -1;
int height = -1;
int positionX = 0;
int positionY = 0;
int positionX = -1;
int positionY = -1;
int parentWidth = 1;
int parentHeight = 1;
@ -36,81 +36,97 @@ public class Button implements DrawableElement, FocusableElement, ContainerEleme
ClickEventCallback clickCallback;
public int getWidth() {
int minX = -1;
int maxX = -1;
for(Element child : childList){
if(width == -1){
int minX = -1;
int maxX = -1;
for(Element child : childList){
if(minX == -1){
minX = child.getPositionX();
} else if(child.getPositionX() < minX){
minX = child.getPositionX();
}
if(maxX == -1){
maxX = child.getPositionX() + child.getWidth();
} else if(child.getPositionX() + child.getWidth() > maxX){
maxX = child.getPositionX() + child.getWidth();
}
}
if(minX == -1){
minX = child.getPositionX();
} else if(child.getPositionX() < minX){
minX = child.getPositionX();
minX = 0;
}
if(maxX == -1){
maxX = child.getPositionX() + child.getWidth();
} else if(child.getPositionX() + child.getWidth() > maxX){
maxX = child.getPositionX() + child.getWidth();
maxX = 0;
}
return maxX - minX;
} else {
return width;
}
if(minX == -1){
minX = 0;
}
if(maxX == -1){
maxX = 0;
}
return maxX - minX;
}
public int getHeight() {
int minY = -1;
int maxY = -1;
for(Element child : childList){
if(height == -1){
int minY = -1;
int maxY = -1;
for(Element child : childList){
if(minY == -1){
minY = child.getPositionY();
} else if(child.getPositionY() < minY){
minY = child.getPositionY();
}
if(maxY == -1){
maxY = child.getPositionY() + child.getHeight();
} else if(child.getPositionY() + child.getHeight() > maxY){
maxY = child.getPositionY() + child.getHeight();
}
}
if(minY == -1){
minY = child.getPositionY();
} else if(child.getPositionY() < minY){
minY = child.getPositionY();
minY = 0;
}
if(maxY == -1){
maxY = child.getPositionY() + child.getHeight();
} else if(child.getPositionY() + child.getHeight() > maxY){
maxY = child.getPositionY() + child.getHeight();
maxY = 0;
}
return maxY - minY;
} else {
return height;
}
if(minY == -1){
minY = 0;
}
if(maxY == -1){
maxY = 0;
}
return maxY - minY;
}
public int getPositionX() {
int minX = -1;
for(Element child : childList){
if(minX == -1){
minX = child.getPositionX();
} else if(child.getPositionX() < minX){
minX = child.getPositionX();
if(positionX == -1){
int minX = -1;
for(Element child : childList){
if(minX == -1){
minX = child.getPositionX();
} else if(child.getPositionX() < minX){
minX = child.getPositionX();
}
}
if(minX == -1){
minX = 0;
}
return minX;
} else {
return positionX;
}
if(minX == -1){
minX = 0;
}
return minX;
}
public int getPositionY() {
int minY = -1;
for(Element child : childList){
if(minY == -1){
minY = child.getPositionY();
} else if(child.getPositionY() < minY){
minY = child.getPositionY();
if(positionY == -1){
int minY = -1;
for(Element child : childList){
if(minY == -1){
minY = child.getPositionY();
} else if(child.getPositionY() < minY){
minY = child.getPositionY();
}
}
if(minY == -1){
minY = 0;
}
return minY;
} else {
return positionY;
}
if(minY == -1){
minY = 0;
}
return minY;
}
public boolean getVisible() {
@ -125,17 +141,17 @@ public class Button implements DrawableElement, FocusableElement, ContainerEleme
this.height = height;
}
public void setPositionX(int positionX) {
int deltaX = this.positionX - positionX;
this.positionX = positionX;
public void setPositionX(int posX) {
int deltaX = posX - getPositionX();
this.positionX = posX;
for(Element child : childList){
child.setPositionX(child.getPositionX() + deltaX);
}
}
public void setPositionY(int positionY) {
int deltaY = this.positionY - positionY;
this.positionY = positionY;
public void setPositionY(int posY) {
int deltaY = posY - getPositionY();
this.positionY = posY;
for(Element child : childList){
child.setPositionY(child.getPositionY() + deltaY);
}

View File

@ -30,11 +30,11 @@ public class Div implements ClickableElement,ContainerElement,DraggableElement,F
List<Element> childList = new LinkedList<Element>();
public int width = 1;
public int height = 1;
public int width = -1;
public int height = -1;
public int positionX = 0;
public int positionY = 0;
public int positionX = -1;
public int positionY = -1;
public int parentWidth = 1;
public int parentHeight = 1;
@ -43,28 +43,32 @@ public class Div implements ClickableElement,ContainerElement,DraggableElement,F
@Override
public int getWidth() {
if(childList.size() > 0){
int minX = -1;
int maxX = -1;
for(Element child : childList){
if(width == -1){
if(childList.size() > 0){
int minX = -1;
int maxX = -1;
for(Element child : childList){
if(minX == -1){
minX = child.getPositionX();
} else if(child.getPositionX() < minX){
minX = child.getPositionX();
}
if(maxX == -1){
maxX = child.getPositionX() + child.getWidth();
} else if(child.getPositionX() + child.getWidth() > maxX){
maxX = child.getPositionX() + child.getWidth();
}
}
if(minX == -1){
minX = child.getPositionX();
} else if(child.getPositionX() < minX){
minX = child.getPositionX();
minX = 0;
}
if(maxX == -1){
maxX = child.getPositionX() + child.getWidth();
} else if(child.getPositionX() + child.getWidth() > maxX){
maxX = child.getPositionX() + child.getWidth();
maxX = 0;
}
return maxX - minX;
} else {
return 1;
}
if(minX == -1){
minX = 0;
}
if(maxX == -1){
maxX = 0;
}
return maxX - minX;
} else {
return width;
}
@ -72,28 +76,32 @@ public class Div implements ClickableElement,ContainerElement,DraggableElement,F
@Override
public int getHeight() {
if(childList.size() > 0){
int minY = -1;
int maxY = -1;
for(Element child : childList){
if(height == -1){
if(childList.size() > 0){
int minY = -1;
int maxY = -1;
for(Element child : childList){
if(minY == -1){
minY = child.getPositionY();
} else if(child.getPositionY() < minY){
minY = child.getPositionY();
}
if(maxY == -1){
maxY = child.getPositionY() + child.getHeight();
} else if(child.getPositionY() + child.getHeight() > maxY){
maxY = child.getPositionY() + child.getHeight();
}
}
if(minY == -1){
minY = child.getPositionY();
} else if(child.getPositionY() < minY){
minY = child.getPositionY();
minY = 0;
}
if(maxY == -1){
maxY = child.getPositionY() + child.getHeight();
} else if(child.getPositionY() + child.getHeight() > maxY){
maxY = child.getPositionY() + child.getHeight();
maxY = 0;
}
return maxY - minY;
} else {
return 1;
}
if(minY == -1){
minY = 0;
}
if(maxY == -1){
maxY = 0;
}
return maxY - minY;
} else {
return height;
}
@ -101,19 +109,23 @@ public class Div implements ClickableElement,ContainerElement,DraggableElement,F
@Override
public int getPositionX() {
if(childList.size() > 0){
int minX = -1;
for(Element child : childList){
if(minX == -1){
minX = child.getPositionX();
} else if(child.getPositionX() < minX){
minX = child.getPositionX();
if(positionX == -1){
if(childList.size() > 0){
int minX = -1;
for(Element child : childList){
if(minX == -1){
minX = child.getPositionX();
} else if(child.getPositionX() < minX){
minX = child.getPositionX();
}
}
if(minX == -1){
minX = 0;
}
return minX;
} else {
return 0;
}
if(minX == -1){
minX = 0;
}
return minX;
} else {
return positionX;
}
@ -121,19 +133,23 @@ public class Div implements ClickableElement,ContainerElement,DraggableElement,F
@Override
public int getPositionY() {
if(childList.size() > 0){
int minY = -1;
for(Element child : childList){
if(minY == -1){
minY = child.getPositionY();
} else if(child.getPositionY() < minY){
minY = child.getPositionY();
if(positionY == -1){
if(childList.size() > 0){
int minY = -1;
for(Element child : childList){
if(minY == -1){
minY = child.getPositionY();
} else if(child.getPositionY() < minY){
minY = child.getPositionY();
}
}
if(minY == -1){
minY = 0;
}
return minY;
} else {
return 0;
}
if(minY == -1){
minY = 0;
}
return minY;
} else {
return positionY;
}
@ -152,18 +168,18 @@ public class Div implements ClickableElement,ContainerElement,DraggableElement,F
}
@Override
public void setPositionX(int positionX) {
int deltaX = this.positionX - positionX;
this.positionX = positionX;
public void setPositionX(int posX) {
int deltaX = posX - getPositionX();
this.positionX = posX;
for(Element child : childList){
child.setPositionX(child.getPositionX() + deltaX);
}
}
@Override
public void setPositionY(int positionY) {
int deltaY = this.positionY - positionY;
this.positionY = positionY;
public void setPositionY(int posY) {
int deltaY = posY - getPositionY();
this.positionY = posY;
for(Element child : childList){
child.setPositionY(child.getPositionY() + deltaY);
}

View File

@ -172,17 +172,17 @@ public class Label implements DrawableElement {
this.height = height;
}
public void setPositionX(int positionX) {
int deltaX = this.positionX - positionX;
this.positionX = positionX;
public void setPositionX(int posX) {
int deltaX = posX - this.positionX;
this.positionX = posX;
for(Element child : childrenElements){
child.setPositionX(child.getPositionX() + deltaX);
}
}
public void setPositionY(int positionY) {
int deltaY = this.positionY - positionY;
this.positionY = positionY;
public void setPositionY(int posY) {
int deltaY = posY - this.positionY;
this.positionY = posY;
for(Element child : childrenElements){
child.setPositionY(child.getPositionY() + deltaY);
}

View File

@ -227,17 +227,16 @@ public class ScrollableContainer implements DrawableElement, ContainerElement {
neededOffsetY = -focused.getPositionY();
} else {
neededOffsetY = -((focused.getPositionY() - this.height) + focused.getHeight());
System.out.println(focused.getPositionY() + " " + this.height + " " + focused.getHeight());
// System.out.println(focused.getPositionY() + " " + this.height + " " + focused.getHeight());
}
}
//apply offset to all children
System.out.println(focused);
for(Element child : childList){
int currentX = child.getPositionX();
int currentY = child.getPositionY();
child.setPositionX(currentX + neededOffsetX);
child.setPositionY(currentY + neededOffsetY);
System.out.println(currentX + " " + currentY);
int newX = child.getPositionX() + neededOffsetX;
int newY = child.getPositionY() + neededOffsetY;
child.setPositionX(newX);
child.setPositionY(newY);
// System.out.println(currentX + " " + currentY);
}
}
}