colour picker wip

This commit is contained in:
minjaesong
2022-02-21 16:29:35 +09:00
parent 46b15c3d95
commit f5b6a3e22a

View File

@@ -7,12 +7,14 @@ import com.badlogic.gdx.backends.lwjgl3.Lwjgl3Application
import com.badlogic.gdx.backends.lwjgl3.Lwjgl3ApplicationConfiguration import com.badlogic.gdx.backends.lwjgl3.Lwjgl3ApplicationConfiguration
import com.badlogic.gdx.graphics.Color import com.badlogic.gdx.graphics.Color
import com.badlogic.gdx.graphics.OrthographicCamera import com.badlogic.gdx.graphics.OrthographicCamera
import com.badlogic.gdx.graphics.Pixmap
import com.badlogic.gdx.graphics.Texture
import com.badlogic.gdx.graphics.g2d.SpriteBatch import com.badlogic.gdx.graphics.g2d.SpriteBatch
import com.badlogic.gdx.graphics.glutils.ShaderProgram import com.badlogic.gdx.graphics.glutils.ShaderProgram
import net.torvald.terrarum.App import com.badlogic.gdx.utils.GdxRuntimeException
import net.torvald.terrarum.Terrarum import net.torvald.colourutil.HUSLColorConverter
import net.torvald.terrarum.Yaml import net.torvald.terrarum.*
import net.torvald.terrarum.inUse import net.torvald.terrarum.gamecontroller.TerrarumKeyboardEvent
import net.torvald.terrarum.modulebasegame.TerrarumIngame import net.torvald.terrarum.modulebasegame.TerrarumIngame
import net.torvald.terrarum.ui.Toolkit import net.torvald.terrarum.ui.Toolkit
import net.torvald.terrarum.ui.UINSMenu import net.torvald.terrarum.ui.UINSMenu
@@ -23,57 +25,26 @@ val UITEST1_HEIGHT = 720
/** /**
* Created by minjaesong on 2018-12-09. * Created by minjaesong on 2018-12-09.
*/ */
class UITestPad1 : ScreenAdapter() { class UITestPad1 : TerrarumGamescreen {
val treeStr = """
- File
- New
- Open
- Open Recent
- yaml_example.yaml
- Yaml.kt
- Close
- Settings
- Line Separators
- CRLF
- CR
- LF
- Edit
- Undo
- Redo
- Cut
- Copy
- Paste
- Find
- Find
- Replace
- Convert Indents
- To Spaces
- Set Project Indentation
- To Tabs
- Refactor
- Refactor This
- Rename
- Extract
- Variable
- Property
- Function
"""
lateinit var nsMenu: UINSMenu
lateinit var batch: SpriteBatch lateinit var batch: SpriteBatch
lateinit var camera: OrthographicCamera lateinit var camera: OrthographicCamera
override fun inputStrobed(e: TerrarumKeyboardEvent) {
}
lateinit var colourPickerPixmap: Pixmap
lateinit var colourPickerTex: Texture
private var hue = 0f
override fun show() { override fun show() {
Gdx.input.inputProcessor = UITestPad1Controller(this) Gdx.input.inputProcessor = UITestPad1Controller(this)
nsMenu = UINSMenu(
"Menu", batch = FlippingSpriteBatch()
96,
Yaml(treeStr)
)
batch = SpriteBatch()
camera = OrthographicCamera(UITEST1_WIDTH.toFloat(), UITEST1_HEIGHT.toFloat()) camera = OrthographicCamera(UITEST1_WIDTH.toFloat(), UITEST1_HEIGHT.toFloat())
camera.setToOrtho(true, UITEST1_WIDTH.toFloat(), UITEST1_HEIGHT.toFloat()) camera.setToOrtho(true, UITEST1_WIDTH.toFloat(), UITEST1_HEIGHT.toFloat())
@@ -82,58 +53,63 @@ class UITestPad1 : ScreenAdapter() {
resize(UITEST1_WIDTH, UITEST1_HEIGHT) resize(UITEST1_WIDTH, UITEST1_HEIGHT)
nsMenu.setPosition(0, 0) colourPickerPixmap = Pixmap(cmapSize, cmapSize, Pixmap.Format.RGBA8888)
nsMenu.setAsAlwaysVisible() colourPickerTex = Texture(colourPickerPixmap)
} }
val bgCol = Color(.62f, .79f, 1f, 1f) val bgCol = Color(.62f, .79f, 1f, 1f)
var _dct = 0f
private val cmapSize = 16
private val cmapSize2 = cmapSize * 2f
private val cmapDrawSize = 256f
override fun render(delta: Float) { override fun render(delta: Float) {
Gdx.graphics.setTitle(TerrarumIngame.getCanonicalTitle()) Gdx.graphics.setTitle(TerrarumIngame.getCanonicalTitle())
// UPDATE hue += delta * 8f
nsMenu.update(delta) if (hue > 360f) hue -= 360f
for (y in 0 until cmapSize) { for (x in 0 until cmapSize) {
val saturation = x * 100f / (cmapSize - 1f)
val luma = 100f - y * 100f / (cmapSize - 1f)
val rgb = HUSLColorConverter.hsluvToRgb(floatArrayOf(hue, saturation, luma))
colourPickerPixmap.setColor(rgb[0], rgb[1], rgb[2], 1f)
colourPickerPixmap.drawPixel(x, y)
}}
// RENDER
batch.inUse { batch.inUse {
batch.color = bgCol colourPickerTex.dispose()
Toolkit.fillArea(batch, 0, 0, 2048, 2048) colourPickerTex = Texture(colourPickerPixmap)
colourPickerTex.setFilter(Texture.TextureFilter.Linear, Texture.TextureFilter.Linear)
nsMenu.render(batch, camera) batch.draw(colourPickerTex, 10f, 10f,
cmapDrawSize, cmapDrawSize,
batch.color = if (nsMenu.mouseOnTitleBar()) 1f / cmapSize2, 1f - 1f / cmapSize2,
Color.LIME 1f - 1f / cmapSize2, 1f / cmapSize2
else )
Color.FIREBRICK
App.fontGame.draw(batch, "Mouse: ${Terrarum.mouseScreenX}, ${Terrarum.mouseScreenY}", 8f, 740 - 28f)
} }
_dct = (_dct + delta*2) % 10f
//nsMenu.setPosition(_dct.toInt(), _dct.toInt())
}
override fun pause() {
super.pause()
}
override fun resume() {
super.resume()
} }
override fun resize(width: Int, height: Int) { override fun resize(width: Int, height: Int) {
super.resize(width, height) }
override fun pause() {
}
override fun resume() {
}
override fun hide() {
} }
override fun dispose() { override fun dispose() {
super.dispose() try { colourPickerTex.dispose() } catch (e: GdxRuntimeException) {}
try { colourPickerPixmap.dispose() } catch (e: GdxRuntimeException) {}
} }
@@ -141,12 +117,10 @@ class UITestPad1 : ScreenAdapter() {
class UITestPad1Controller(val host: UITestPad1) : InputAdapter() { class UITestPad1Controller(val host: UITestPad1) : InputAdapter() {
override fun touchDragged(screenX: Int, screenY: Int, pointer: Int): Boolean { override fun touchDragged(screenX: Int, screenY: Int, pointer: Int): Boolean {
host.nsMenu.touchDragged(screenX, screenY, pointer)
return true return true
} }
override fun touchDown(screenX: Int, screenY: Int, pointer: Int, button: Int): Boolean { override fun touchDown(screenX: Int, screenY: Int, pointer: Int, button: Int): Boolean {
host.nsMenu.touchDown(screenX, screenY, pointer, button)
return true return true
} }
} }
@@ -159,6 +133,9 @@ fun main(args: Array<String>) {
appConfig.useVsync(false) appConfig.useVsync(false)
appConfig.setResizable(false) appConfig.setResizable(false)
appConfig.setWindowedMode(UITEST1_WIDTH, UITEST1_HEIGHT) appConfig.setWindowedMode(UITEST1_WIDTH, UITEST1_HEIGHT)
appConfig.useOpenGL3(true, 3, 2)
App.scr = TerrarumScreenSize(UITEST1_WIDTH, UITEST1_HEIGHT)
Lwjgl3Application(App(appConfig, UITestPad1()), appConfig) Lwjgl3Application(App(appConfig, UITestPad1()), appConfig)
} }