mirror of
https://github.com/curioustorvald/Terrarum.git
synced 2026-06-10 02:24:05 +09:00
code tag wip
This commit is contained in:
BIN
assets/mods/basegame/fonts/composer_gui.tga
LFS
Normal file
BIN
assets/mods/basegame/fonts/composer_gui.tga
LFS
Normal file
Binary file not shown.
@@ -300,7 +300,14 @@ class BTeXPage(
|
|||||||
if (drawCall.isNotBlank()) drawCalls.add(drawCall)
|
if (drawCall.isNotBlank()) drawCalls.add(drawCall)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private var prerender = false
|
||||||
|
|
||||||
fun render(frameDelta: Float, batch: SpriteBatch, x: Int, y: Int, marginH: Int, marginV: Int) {
|
fun render(frameDelta: Float, batch: SpriteBatch, x: Int, y: Int, marginH: Int, marginV: Int) {
|
||||||
|
if (!prerender) {
|
||||||
|
prerender = true
|
||||||
|
drawCalls.sortBy { if (it.text != null) 16 else 0 }
|
||||||
|
}
|
||||||
|
|
||||||
batch.color = back.cpy().also { it.a = 0.93f }
|
batch.color = back.cpy().also { it.a = 0.93f }
|
||||||
Toolkit.fillArea(batch, x, y, width, height)
|
Toolkit.fillArea(batch, x, y, width, height)
|
||||||
batch.color = Color.WHITE
|
batch.color = Color.WHITE
|
||||||
|
|||||||
@@ -79,6 +79,7 @@ object BTeXParser {
|
|||||||
|
|
||||||
private var currentTheme = ""
|
private var currentTheme = ""
|
||||||
private var spanColour: String? = null
|
private var spanColour: String? = null
|
||||||
|
private var codeMode: Boolean = false
|
||||||
|
|
||||||
|
|
||||||
private val elemOpeners: HashMap<String, KFunction<*>> = HashMap()
|
private val elemOpeners: HashMap<String, KFunction<*>> = HashMap()
|
||||||
@@ -175,6 +176,26 @@ object BTeXParser {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private fun getOrPutCodeTagRef(width: Int): ((BTeXDrawCall) -> BTeXBatchDrawCall)? {
|
||||||
|
val tagname = "TAG@CODE-$width"
|
||||||
|
if (!objDict.contains(tagname)) {
|
||||||
|
objWidthDict[tagname] = 0
|
||||||
|
objDict[tagname] = { text: BTeXDrawCall ->
|
||||||
|
object : BTeXBatchDrawCall(0, 0, text) {
|
||||||
|
override fun draw(doc: BTeXDocument, batch: SpriteBatch, x: Float, y: Float, font: TerrarumSansBitmap?) {
|
||||||
|
val oldcol = batch.color.cpy()
|
||||||
|
batch.color = Color(0xccccccff.toInt())
|
||||||
|
Toolkit.fillArea(batch, x - 2, y - 1, width + 4f, doc.lineHeightInPx + 2f)
|
||||||
|
batch.color = Color(0x999999ff.toInt())
|
||||||
|
Toolkit.drawBoxBorder(batch, x - 2, y - 1, width + 4f, doc.lineHeightInPx + 2f)
|
||||||
|
batch.color = oldcol
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return objDict[tagname]
|
||||||
|
}
|
||||||
|
|
||||||
fun dispose() {
|
fun dispose() {
|
||||||
if (::testFont.isInitialized) testFont.tryDispose()
|
if (::testFont.isInitialized) testFont.tryDispose()
|
||||||
if (::titleFont.isInitialized) titleFont.tryDispose()
|
if (::titleFont.isInitialized) titleFont.tryDispose()
|
||||||
@@ -262,12 +283,14 @@ object BTeXParser {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private var oldSpanColour: String? = null
|
private var oldSpanColour: String? = null
|
||||||
|
private var oldCodeMode = false
|
||||||
|
|
||||||
override fun characters(ch: CharArray, start: Int, length: Int) {
|
override fun characters(ch: CharArray, start: Int, length: Int) {
|
||||||
val str =
|
val str =
|
||||||
String(ch.sliceArray(start until start + length)).replace('\n', ' ').replace(Regex(" +"), " ")//.trim()
|
String(ch.sliceArray(start until start + length)).replace('\n', ' ').replace(Regex(" +"), " ")//.trim()
|
||||||
|
|
||||||
if (str.isNotEmpty()) {
|
if (str.isNotEmpty()) {
|
||||||
|
// process span request
|
||||||
if (spanColour != oldSpanColour || spanColour != null) {
|
if (spanColour != oldSpanColour || spanColour != null) {
|
||||||
// printdbg("Characters [col:${spanColour}] \t\"$str\"")
|
// printdbg("Characters [col:${spanColour}] \t\"$str\"")
|
||||||
|
|
||||||
@@ -283,12 +306,22 @@ object BTeXParser {
|
|||||||
spanGdxCol.b.times(15f).roundToInt()
|
spanGdxCol.b.times(15f).roundToInt()
|
||||||
))
|
))
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// process code request
|
||||||
|
if (codeMode != oldCodeMode && codeMode) {
|
||||||
|
println("CODE tag for str '$str'")
|
||||||
|
val w = getFont().getWidth(str)
|
||||||
|
getOrPutCodeTagRef(w)
|
||||||
|
paragraphBuffer.appendObjectPlaceholder("TAG@CODE-$w")
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
paragraphBuffer.append(str)
|
paragraphBuffer.append(str)
|
||||||
|
|
||||||
oldSpanColour = spanColour
|
oldSpanColour = spanColour
|
||||||
|
oldCodeMode = codeMode
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -636,6 +669,15 @@ object BTeXParser {
|
|||||||
handler.paragraphBuffer.appendObjectPlaceholder("TAG@TEX")
|
handler.paragraphBuffer.appendObjectPlaceholder("TAG@TEX")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@OpenTag // reflective access is impossible with 'private'
|
||||||
|
fun processElemCODE(handler: BTeXHandler, doc: BTeXDocument, uri: String, attribs: HashMap<String, String>) {
|
||||||
|
handler.codeMode = true
|
||||||
|
}
|
||||||
|
@CloseTag
|
||||||
|
fun closeElemCODE(handler: BTeXHandler, doc: BTeXDocument, uri: String, siblingIndex: Int) {
|
||||||
|
handler.codeMode = false
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
@OpenTag // reflective access is impossible with 'private'
|
@OpenTag // reflective access is impossible with 'private'
|
||||||
fun processElemCOVER(handler: BTeXHandler, doc: BTeXDocument, uri: String, attribs: HashMap<String, String>) {
|
fun processElemCOVER(handler: BTeXHandler, doc: BTeXDocument, uri: String, attribs: HashMap<String, String>) {
|
||||||
|
|||||||
Reference in New Issue
Block a user