Java Code Examples for com.google.common.primitives.Ints#constrainToRange()
The following examples show how to use
com.google.common.primitives.Ints#constrainToRange() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: HuePanel.java From runelite with BSD 2-Clause "Simplified" License | 6 votes |
/** * Moves the selector to a specified y coordinate. */ private void moveSelector(int y) { y = Ints.constrainToRange(y, 0, height - 1); if (y == this.selectedY) { return; } this.selectedY = y; paintImmediately(0, 0, PANEL_WIDTH, height); if (this.onColorChange != null) { this.onColorChange.accept(y); } }
Example 2
Source File: ColorValueSlider.java From runelite with BSD 2-Clause "Simplified" License | 5 votes |
private void moveTarget(int x, boolean shouldUpdate) { value = Ints.constrainToRange(x, ColorUtil.MIN_RGB_VALUE + KNOB_WIDTH, ColorUtil.MAX_RGB_VALUE + KNOB_WIDTH); paintImmediately(0, 0, this.getWidth(), this.getHeight()); if (shouldUpdate && onValueChanged != null) { onValueChanged.accept(getValue()); } }
Example 3
Source File: CameraPlugin.java From runelite with BSD 2-Clause "Simplified" License | 5 votes |
@Override public void keyReleased(KeyEvent e) { if (e.getKeyCode() == KeyEvent.VK_CONTROL) { controlDown = false; if (config.controlFunction() == ControlFunction.CONTROL_TO_RESET) { final int zoomValue = Ints.constrainToRange(config.ctrlZoomValue(), CameraConfig.OUTER_LIMIT_MIN, CameraConfig.INNER_ZOOM_LIMIT); clientThread.invokeLater(() -> client.runScript(ScriptID.CAMERA_DO_ZOOM, zoomValue, zoomValue)); } } }
Example 4
Source File: GpuPlugin.java From plugins with GNU General Public License v3.0 | 4 votes |
private int getDrawDistance() { final int limit = useComputeShaders ? MAX_DISTANCE : DEFAULT_DISTANCE; return Ints.constrainToRange(config.drawDistance(), 0, limit); }
Example 5
Source File: OptionSetting.java From mylizzie with GNU General Public License v3.0 | 4 votes |
public ColorSetting(int red, int green, int blue, int alpha) { this.red = Ints.constrainToRange(red, 0, 255); this.green = Ints.constrainToRange(green, 0, 255); this.blue = Ints.constrainToRange(blue, 0, 255); this.alpha = Ints.constrainToRange(alpha, 0, 255); }
Example 6
Source File: ChatboxItemSearch.java From runelite with BSD 2-Clause "Simplified" License | 4 votes |
@Override public void keyPressed(KeyEvent ev) { switch (ev.getKeyCode()) { case KeyEvent.VK_ENTER: ev.consume(); if (index > -1) { if (onItemSelected != null) { onItemSelected.accept(results.keySet().toArray(new Integer[results.size()])[index]); } chatboxPanelManager.close(); } break; case KeyEvent.VK_TAB: case KeyEvent.VK_RIGHT: ev.consume(); if (!results.isEmpty()) { index++; if (index >= results.size()) { index = 0; } clientThread.invokeLater(this::update); } break; case KeyEvent.VK_LEFT: ev.consume(); if (!results.isEmpty()) { index--; if (index < 0) { index = results.size() - 1; } clientThread.invokeLater(this::update); } break; case KeyEvent.VK_UP: ev.consume(); if (results.size() >= (MAX_RESULTS / 2)) { index -= MAX_RESULTS / 2; if (index < 0) { if (results.size() == MAX_RESULTS) { index += results.size(); } else { index += MAX_RESULTS; } index = Ints.constrainToRange(index, 0, results.size() - 1); } clientThread.invokeLater(this::update); } break; case KeyEvent.VK_DOWN: ev.consume(); if (results.size() >= (MAX_RESULTS / 2)) { index += MAX_RESULTS / 2; if (index >= MAX_RESULTS) { if (results.size() == MAX_RESULTS) { index -= results.size(); } else { index -= MAX_RESULTS; } index = Ints.constrainToRange(index, 0, results.size() - 1); } clientThread.invokeLater(this::update); } break; default: super.keyPressed(ev); } }
Example 7
Source File: ColorPanel.java From runelite with BSD 2-Clause "Simplified" License | 4 votes |
private Color colorAt(int x, int y) { x = Ints.constrainToRange(x, 0, size - 1); y = Ints.constrainToRange(y, 0, size - 1); return new Color(image.getRGB(x, y)); }
Example 8
Source File: GpuPlugin.java From runelite with BSD 2-Clause "Simplified" License | 4 votes |
private int getDrawDistance() { final int limit = useComputeShaders ? MAX_DISTANCE : DEFAULT_DISTANCE; return Ints.constrainToRange(config.drawDistance(), 0, limit); }
Example 9
Source File: ColorUtil.java From runelite with BSD 2-Clause "Simplified" License | 2 votes |
/** * Limits an int to the rgba value range (0-255) * * @param value The value for the r, g, b, or a. * @return An int between 0 - 255. */ public static int constrainValue(int value) { return Ints.constrainToRange(value, MIN_RGB_VALUE, MAX_RGB_VALUE); }