Please wait. This can take some minutes ...
Many resources are needed to download a project. Please understand that we have to compensate our server costs. Thank you in advance.
Project price only 1 $
You can buy this project and download/modify it how often you want.
io.docops.asciidoc.buttons.ButtonMaker.kt Maven / Gradle / Ivy
/*
* Copyright 2020 The DocOps Consortium
*
* 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 io.docops.asciidoc.buttons
import io.docops.asciidoc.buttons.models.Button
import io.docops.asciidoc.buttons.theme.Theme
abstract class ButtonMaker {
abstract fun makeButtons(buttons: MutableList>, theme: Theme): String
protected val types = mutableMapOf()
private var startLegendHeight = 0
private fun height(
buttons: MutableList>,
heightFactor: Int,
defaultHeight: Int,
theme: Theme
): Int {
var height = defaultHeight
if (buttons.size > 1) {
height = heightFactor * buttons.size
}
if (theme.legendOn) {
startLegendHeight = height + 30
val unique = buttonTypes(buttons = buttons, theme = theme)
height += 20 * (unique.size)
height += 20
}
return height
}
private fun buttonTypes(buttons: MutableList>, theme: Theme): MutableMap {
buttons.forEach {
it.forEach { btn ->
types[theme.buttonColor(btn)] = (btn.type)
}
}
return types
}
fun makeSvgHead(
buttons: MutableList>,
heightFactor: Int = 170,
defaultHeight: Int = 250,
widthFactor: Int = 100,
theme: Theme
): String {
val height = height(buttons, heightFactor = heightFactor, defaultHeight = defaultHeight, theme = theme)
val maxWidth = theme.columns * widthFactor + theme.columns * 10
// language=svg
return """
"""
}
fun makeDefs(buttons: MutableList>, theme: Theme): String {
var linear = ""
theme.gradientStyle?.let { linear = it.gradientIdToXml() }
val btnDef = StringBuilder("")
buttons.forEach {
btn -> btn.forEach {
btnDef.append(theme.buildGradientDef(it))
}
}
// language=svg
return """
$linear
$btnDef
${theme.defs}
"""
}
fun makeSvgEnd(): String {
return " "
}
fun drawLegend(types: MutableMap): String {
val sb = StringBuilder("")
var recXpos = "10"
var textXPos = "30"
var yPos = startLegendHeight - 20
val size = types.size/2
var count = 0
types.forEach { (color, desc) ->
if(count == size) {
recXpos = "50%"
yPos = startLegendHeight - 20
textXPos = "54%"
}
// language=svg
sb.append(
"""
$desc
""".trimIndent()
)
yPos += 20
count++
}
sb.append(" ")
return sb.toString()
}
fun glassStyle() = """
.glass {
overflow: hidden;
color: white;
text-shadow: 0 1px 2px rgba(0, 0, 0, 0.7);
background-image: radial-gradient(circle at center, rgba(0, 167, 225, 0.25), rgba(0, 110, 149, 0.5));
box-shadow: 0 5px 10px rgba(0, 0, 0, 0.75), inset 0 0 0 2px rgba(0, 0, 0, 0.3), inset 0 -6px 6px -3px rgba(0, 129, 174, 0.2);
position: relative;
}
.glass:after {
content: "";
background: rgba(0, 167, 225, 0.2);
display: block;
position: absolute;
z-index: 0;
height: 100%;
width: 100%;
top: 0;
left: 0;
backdrop-filter: blur(3px) saturate(400%);
-webkit-backdrop-filter: blur(3px) saturate(400%);
}
.glass:before {
content: "";
display: block;
position: absolute;
width: calc(100% - 4px);
height: 35px;
background-image: linear-gradient(rgba(255, 255, 255, 0.7), rgba(255, 255, 255, 0));
top: 2px;
left: 2px;
border-radius: 30px 30px 200px 200px;
opacity: 0.7;
}
.glass:hover {
text-shadow: 0 1px 2px rgba(0, 0, 0, 0.9);
}
.glass:hover:before {
opacity: 1;
}
.glass:active {
text-shadow: 0 0 2px rgba(0, 0, 0, 0.9);
box-shadow: 0 3px 8px rgba(0, 0, 0, 0.75), inset 0 0 0 2px rgba(0, 0, 0, 0.3), inset 0 -6px 6px -3px rgba(0, 129, 174, 0.2);
}
.glass:active:before {
height: 25px;
}
""".trimIndent()
}