<commit_before>/*
 * Copyright 2012 <NAME> <<EMAIL>>
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package org.terasology.rendering.gui.framework;

import org.lwjgl.opengl.Display;
import org.terasology.asset.AssetManager;
import org.terasology.input.BindButtonEvent;
import org.terasology.input.events.KeyEvent;
import org.terasology.rendering.gui.framework.style.UIStyle;
import org.terasology.rendering.gui.framework.style.UIStyleBackgroundColor;
import org.terasology.rendering.gui.framework.style.UIStyleBackgroundImage;
import org.terasology.rendering.gui.framework.style.UIStyleBorderImage;
import org.terasology.rendering.gui.framework.style.UIStyleBorderSolid;

import javax.vecmath.Vector2f;
import javax.vecmath.Vector4f;
import java.util.ArrayList;
import java.util.List;

import static org.lwjgl.opengl.GL11.*;

/**
 * Composition of multiple display elements.
 *
 * @author <NAME> <<EMAIL>>
 * @author <NAME> <<EMAIL>>
 */
public abstract class UIDisplayContainer extends UIDisplayElement {

    //child elements
    private final ArrayList<UIDisplayElement> displayElements = new ArrayList<UIDisplayElement>();
    private final List<UIStyle> styles = new ArrayList<UIStyle>();
    
    //cropping
    private boolean cropContainer = false;
    protected Vector4f cropMargin = new Vector4f(0.0f, 0.0f,0.0f, 0.0f);

    public UIDisplayContainer() {
        super();
    }

    public void render() {
        boolean allowsCrop = false;
        int cropX = 0;
        int cropY = 0;
        int cropWidth = 0;
        int cropHeight = 0;

        if (!isVisible())
            return;

        //Cut the elements
        if (cropContainer) {
            cropX = (int) getAbsolutePosition().x - (int) (cropMargin.w);
            cropY = Display.getHeight() - (int) getAbsolutePosition().y - (int) getSize().y - (int) cropMargin.z;
            cropWidth = (int) getSize().x + (int) cropMargin.y;
            cropHeight = (int) getSize().y + (int) cropMargin.x;
            glEnable(GL_SCISSOR_TEST);
            glScissor(cropX, cropY, cropWidth, cropHeight);
        }

        // Render all display elements
        for (int i = 0; i < displayElements.size(); i++) {
            allowsCrop = cropContainer && !displayElements.get(i).isCrop();
            if (allowsCrop) {
                glDisable(GL_SCISSOR_TEST);
            }
            displayElements.get(i).renderTransformed();
            if (allowsCrop) {
                glEnable(GL_SCISSOR_TEST);
                glScissor(cropX, cropY, cropWidth, cropHeight);
            }
        }

        if (cropContainer) {
            glDisable(GL_SCISSOR_TEST);
        }
    }

    public void update() {
        if (!isVisible())
            return;

        // Update all display elements
        for (int i = 0; i < displayElements.size(); i++) {
            displayElements.get(i).update();
        }
    }
    
    public void layout() {
        if (!isVisible())
            return;
        
        super.layout();

        // Update layout of all display elements
        for (int i = 0; i < displayElements.size(); i++) {
            displayElements.get(i).layout();
        }
    }
    
    @Override
    public void processBindButton(BindButtonEvent event) {
        if (!isVisible())
            return;
        
        super.processBindButton(event);
        
        // Pass the bind key to all display elements
        for (int i = 0; i < displayElements.size(); i++) {
            displayElements.get(i).processBindButton(event);
        }
    }

    @Override
    public void processKeyboardInput(KeyEvent event) {
        if (!isVisible())
            return;

        super.processKeyboardInput(event);

        // Pass the pressed key to all display elements
        for (int i = 0; i < displayElements.size(); i++) {
            displayElements.get(i).processKeyboardInput(event);
        }
    }

    @Override
    public boolean processMouseInput(int button, boolean state, int wheelMoved, boolean consumed) {
        if (!isVisible())
            return consumed;

        // Pass the mouse event to all display elements
        for (int i = displayElements.size() - 1; i >= 0; i--) {
            consumed = displayElements.get(i).processMouseInput(button, state, wheelMoved, consumed);
        }
        
        consumed = super.processMouseInput(button, state, wheelMoved, consumed);<commit_msg>Fix for disable mouse click event out of cropped areas<commit_after>/*
 * Copyright 2012 <NAME> <<EMAIL>>
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package org.terasology.rendering.gui.framework;

import org.lwjgl.input.Mouse;
import org.lwjgl.opengl.Display;
import org.terasology.asset.AssetManager;
import org.terasology.input.BindButtonEvent;
import org.terasology.input.events.KeyEvent;
import org.terasology.rendering.gui.framework.style.UIStyle;
import org.terasology.rendering.gui.framework.style.UIStyleBackgroundColor;
import org.terasology.rendering.gui.framework.style.UIStyleBackgroundImage;
import org.terasology.rendering.gui.framework.style.UIStyleBorderImage;
import org.terasology.rendering.gui.framework.style.UIStyleBorderSolid;

import javax.vecmath.Vector2f;
import javax.vecmath.Vector4f;
import java.util.ArrayList;
import java.util.List;

import static org.lwjgl.opengl.GL11.*;

/**
 * Composition of multiple display elements.
 *
 * @author <NAME> <<EMAIL>>
 * @author <NAME> <<EMAIL>>
 */
public abstract class UIDisplayContainer extends UIDisplayElement {

    //child elements
    private final ArrayList<UIDisplayElement> displayElements = new ArrayList<UIDisplayElement>();
    private final List<UIStyle> styles = new ArrayList<UIStyle>();
    
    //cropping
    private boolean cropContainer = false;
    protected Vector4f cropMargin = new Vector4f(0.0f, 0.0f,0.0f, 0.0f);

    public UIDisplayContainer() {
        super();
    }

    public void render() {
        boolean allowsCrop = false;
        int cropX = 0;
        int cropY = 0;
        int cropWidth = 0;
        int cropHeight = 0;

        if (!isVisible())
            return;

        //Cut the elements
        if (cropContainer) {
            cropX = (int) getAbsolutePosition().x - (int) (cropMargin.w);
            cropY = Display.getHeight() - (int) getAbsolutePosition().y - (int) getSize().y - (int) cropMargin.z;
            cropWidth = (int) getSize().x + (int) cropMargin.y;
            cropHeight = (int) getSize().y + (int) cropMargin.x;
            glEnable(GL_SCISSOR_TEST);
            glScissor(cropX, cropY, cropWidth, cropHeight);
        }

        // Render all display elements
        for (int i = 0; i < displayElements.size(); i++) {
            allowsCrop = cropContainer && !displayElements.get(i).isCrop();
            if (allowsCrop) {
                glDisable(GL_SCISSOR_TEST);
            }
            displayElements.get(i).renderTransformed();
            if (allowsCrop) {
                glEnable(GL_SCISSOR_TEST);
                glScissor(cropX, cropY, cropWidth, cropHeight);
            }
        }

        if (cropContainer) {
            glDisable(GL_SCISSOR_TEST);
        }
    }

    public void update() {
        if (!isVisible())
            return;

        // Update all display elements
        for (int i = 0; i < displayElements.size(); i++) {
            displayElements.get(i).update();
        }
    }
    
    public void layout() {
        if (!isVisible())
            return;
        
        super.layout();

        // Update layout of all display elements
        for (int i = 0; i < displayElements.size(); i++) {
            displayElements.get(i).layout();
        }
    }
    
    @Override
    public void processBindButton(BindButtonEvent event) {
        if (!isVisible())
            return;
        
        super.processBindButton(event);
        
        // Pass the bind key to all display elements
        for (int i = 0; i < displayElements.size(); i++) {
            displayElements.get(i).processBindButton(event);
        }
    }

    @Override
    public void processKeyboardInput(KeyEvent event) {
        if (!isVisible())
            return;

        super.processKeyboardInput(event);

        // Pass the pressed key to all display elements
        for (int i = 0; i < displayElements.size(); i++) {
            displayElements.get(i).processKeyboardInput(event);
        }
    }

    @Override
    public boolean processMouseInput(int button, boolean state, int wheelMoved, boolean consumed) {
        if (!isVisible())
            return consumed;
        
        //cancel mouse click event if the click is out of the cropped area
        if (cropContainer) {
            if (!intersects(new Vector2f(Mouse.getX(), Display.getHeight() - Mouse.getY()))) {
                state = false;
            }
        }

        // Pass the mouse event to all display elements
        for (int i = displayElements.size() - 1; i >= 0; i--) {
            consumed = displayElements.get(i).processMouseInput(button, state, wheelMoved, consumed);
        }
        
        consumed = super.processMouseInput(button, state, wheelMoved, consumed);
{'fraction_non_alphanumeric': 0.10791650256006302, 'fraction_numerical': 0.006597085466719181, 'mean_word_length': 2.3924515698062794, 'pattern_counts': {'":': 0, '<': 39, '<?xml version=': 0, '>': 31, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3143193', 'n_tokens_mistral': 2924, 'n_tokens_neox': 2879, 'n_words': 776}