mirror of
https://gitlab.com/cc-ru/ocelot/ocelot-desktop.git
synced 2025-12-20 02:59:19 +01:00
Allow magnifying the screen
This commit is contained in:
parent
a46dd42f2e
commit
b6b238666f
Binary file not shown.
|
Before Width: | Height: | Size: 154 B After Width: | Height: | Size: 546 B |
Binary file not shown.
|
Before Width: | Height: | Size: 61 KiB After Width: | Height: | Size: 53 KiB |
@ -5,7 +5,7 @@ import ocelot.desktop.color.{IntColor, RGBAColor}
|
||||
import ocelot.desktop.geometry.{Rect2D, Size2D, Vector2D}
|
||||
import ocelot.desktop.graphics.Graphics
|
||||
import ocelot.desktop.ui.UiHandler
|
||||
import ocelot.desktop.ui.event.sources.MouseEvents
|
||||
import ocelot.desktop.ui.event.sources.{KeyEvents, MouseEvents}
|
||||
import ocelot.desktop.ui.event.{DragEvent, KeyEvent, MouseEvent, ScrollEvent}
|
||||
import ocelot.desktop.ui.widget.window.BasicWindow
|
||||
import ocelot.desktop.util.{DrawUtils, Logging}
|
||||
@ -93,14 +93,18 @@ class ScreenWindow(screenNode: ScreenNode) extends BasicWindow with Logging {
|
||||
if (sx.abs > sy.abs) {
|
||||
val newWidth = startingWidth - sx
|
||||
val maxWidth = screenWidth * fontWidth
|
||||
val midScale = (newWidth / maxWidth).min(1f).max(0f)
|
||||
var midScale = (newWidth / maxWidth).max(0f)
|
||||
if (!KeyEvents.isDown(Keyboard.KEY_LSHIFT) && scale <= 1.001)
|
||||
midScale = midScale.min(1f)
|
||||
val lowScale = (fontWidth * midScale).floor / fontWidth
|
||||
val highScale = (fontWidth * midScale).ceil / fontWidth
|
||||
scale = if (midScale - lowScale > highScale - midScale) highScale else lowScale
|
||||
} else {
|
||||
val newHeight = startingWidth * (screenHeight * fontHeight / screenWidth / fontWidth) - sy
|
||||
val maxHeight = screenHeight * fontHeight
|
||||
val midScale = (newHeight / maxHeight).min(1f).max(0f)
|
||||
var midScale = (newHeight / maxHeight).max(0f)
|
||||
if (!KeyEvents.isDown(Keyboard.KEY_LSHIFT) && scale <= 1.001)
|
||||
midScale = midScale.min(1f)
|
||||
val lowScale = (fontHeight * midScale).floor / fontHeight
|
||||
val highScale = (fontHeight * midScale).ceil / fontHeight
|
||||
scale = if (midScale - lowScale > highScale - midScale) highScale else lowScale
|
||||
@ -161,6 +165,11 @@ class ScreenWindow(screenNode: ScreenNode) extends BasicWindow with Logging {
|
||||
override def update(): Unit = {
|
||||
super.update()
|
||||
|
||||
if (scaleDragRegion.contains(UiHandler.mousePosition)) {
|
||||
root.get.statusBar.addMouseEntry("icons/DragLMB", "Scale screen")
|
||||
root.get.statusBar.addKeyMouseEntry("icons/DragLMB", "SHIFT", "Scale screen (magnify)")
|
||||
}
|
||||
|
||||
val currentMousePos = convertMousePos(UiHandler.mousePosition)
|
||||
if (!checkBounds(currentMousePos) || currentMousePos == lastMousePos) return
|
||||
|
||||
|
||||
@ -0,0 +1,28 @@
|
||||
package ocelot.desktop.ui.widget.statusbar
|
||||
|
||||
import ocelot.desktop.ColorScheme
|
||||
import ocelot.desktop.color.Color
|
||||
import ocelot.desktop.geometry.Size2D
|
||||
import ocelot.desktop.graphics.Graphics
|
||||
import ocelot.desktop.ui.widget.Widget
|
||||
import ocelot.desktop.util.{DrawUtils, Spritesheet}
|
||||
|
||||
class KeyMouseEntry(val icon: String, val key: String, val text: String) extends Widget {
|
||||
private val iconSize = Spritesheet.spriteSize(icon)
|
||||
|
||||
override def minimumSize: Size2D = Size2D(iconSize.width + key.length * 8 + 40 + text.length * 8, 16)
|
||||
override def maximumSize: Size2D = minimumSize
|
||||
|
||||
override def draw(g: Graphics): Unit = {
|
||||
g.sprite(icon, position + Size2D(8, height / 2 - iconSize.height / 2), ColorScheme("StatusBarIcon"))
|
||||
|
||||
g.background = Color.Transparent
|
||||
g.foreground = ColorScheme("StatusBarKey")
|
||||
g.setSmallFont()
|
||||
DrawUtils.borderedText(g, position.x + iconSize.width + 8, position.y + 5, "+" + key)
|
||||
|
||||
g.foreground = ColorScheme("StatusBarForeground")
|
||||
g.setNormalFont()
|
||||
g.text(position.x + iconSize.width + key.length * 8 + 24, position.y, text)
|
||||
}
|
||||
}
|
||||
@ -16,9 +16,11 @@ class StatusBar extends Widget {
|
||||
|
||||
private val mouseEntries = new Widget
|
||||
private val keyEntries = new Widget
|
||||
private val keyMouseEntries = new Widget
|
||||
|
||||
children :+= new ScrollView(new Widget {
|
||||
children :+= mouseEntries
|
||||
children :+= keyMouseEntries
|
||||
children :+= keyEntries
|
||||
})
|
||||
{
|
||||
@ -38,6 +40,11 @@ class StatusBar extends Widget {
|
||||
mouseEntries.children :+= new MouseEntry(icon, text)
|
||||
}
|
||||
|
||||
def addKeyMouseEntry(icon: String, key: String, text: String): Unit = {
|
||||
if (!keyMouseEntries.children.map(_.asInstanceOf[KeyMouseEntry]).exists(v => v.icon == icon && v.key == key))
|
||||
keyMouseEntries.children :+= new KeyMouseEntry(icon, key, text)
|
||||
}
|
||||
|
||||
def addKeyEntry(key: String, text: String): Unit = {
|
||||
if (!keyEntries.children.map(_.asInstanceOf[KeyEntry]).exists(_.key == key))
|
||||
keyEntries.children :+= new KeyEntry(key, text)
|
||||
@ -48,6 +55,7 @@ class StatusBar extends Widget {
|
||||
g.line(position, position + Size2D(width, 0), 1, ColorScheme("StatusBarBorder"))
|
||||
drawChildren(g)
|
||||
mouseEntries.children = Array()
|
||||
keyMouseEntries.children = Array()
|
||||
keyEntries.children = Array()
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user