Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 17 additions & 10 deletions app/src/main/java/com/ethran/notable/data/datastore/AppSettings.kt
Original file line number Diff line number Diff line change
Expand Up @@ -23,33 +23,40 @@ object GlobalAppSettings {

@Serializable
data class AppSettings(
// General
val version: Int,
val monitorBgFiles: Boolean = false,
val showWelcome: Boolean = true,
val defaultNativeTemplate: String = "blank",
val quickNavPages: List<String> = listOf(),
val debugMode: Boolean = false,
val neoTools: Boolean = false,
val scribbleToEraseEnabled: Boolean = false,
val toolbarPosition: Position = Position.Top,
val smoothScroll: Boolean = true,
val monochromeMode: Boolean = false,
val continuousZoom: Boolean = false,
val visualizePdfPagination: Boolean = false,
val continuousStrokeSlider: Boolean = false,
val monochromeMode: Boolean = false,
val paginatePdf: Boolean = true,
val scribbleToEraseEnabled: Boolean = false,
val simpleRendering: Boolean = false,
val openGLRendering: Boolean = true,
val muPdfRendering: Boolean = true,
val destructiveMigrations: Boolean = false,
val visualizePdfPagination: Boolean = false,

// Gestures
val doubleTapAction: GestureAction? = defaultDoubleTapAction,
val twoFingerTapAction: GestureAction? = defaultTwoFingerTapAction,
val swipeLeftAction: GestureAction? = defaultSwipeLeftAction,
val swipeRightAction: GestureAction? = defaultSwipeRightAction,
val twoFingerSwipeLeftAction: GestureAction? = defaultTwoFingerSwipeLeftAction,
val twoFingerSwipeRightAction: GestureAction? = defaultTwoFingerSwipeRightAction,
val holdAction: GestureAction? = defaultHoldAction,
val continuousStrokeSlider: Boolean = false,
val enableQuickNav: Boolean = true,


// Debug
val showWelcome: Boolean = true,
// [system information -- does not have a setting]
val debugMode: Boolean = false,
val simpleRendering: Boolean = false,
val openGLRendering: Boolean = true,
val muPdfRendering: Boolean = true,
val destructiveMigrations: Boolean = false,

) {
companion object {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,15 +1,11 @@
package com.ethran.notable.editor.ui

import android.graphics.Rect
import androidx.compose.foundation.background
import androidx.compose.foundation.border
import androidx.compose.foundation.gestures.awaitEachGesture
import androidx.compose.foundation.gestures.awaitFirstDown
import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.fillMaxHeight
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.offset
import androidx.compose.foundation.layout.size
import androidx.compose.runtime.Composable
import androidx.compose.runtime.getValue
import androidx.compose.runtime.mutableStateOf
Expand All @@ -18,18 +14,14 @@ import androidx.compose.runtime.rememberCoroutineScope
import androidx.compose.runtime.setValue
import androidx.compose.ui.Modifier
import androidx.compose.ui.geometry.Offset
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.input.pointer.PointerType
import androidx.compose.ui.input.pointer.pointerInput
import androidx.compose.ui.platform.LocalDensity
import androidx.compose.ui.platform.LocalView
import androidx.compose.ui.unit.Density
import androidx.compose.ui.unit.IntOffset
import androidx.compose.ui.unit.dp
import com.ethran.notable.data.datastore.AppSettings
import com.ethran.notable.data.datastore.GlobalAppSettings
import com.ethran.notable.editor.canvas.CanvasEventBus
import com.ethran.notable.editor.EditorControlTower
import com.ethran.notable.editor.canvas.CanvasEventBus
import com.ethran.notable.editor.state.DOUBLE_TAP_MIN_MS
import com.ethran.notable.editor.state.DOUBLE_TAP_TIMEOUT_MS
import com.ethran.notable.editor.state.GestureMode
Expand Down Expand Up @@ -66,8 +58,10 @@ fun EditorGestureReceiver(
val down = awaitFirstDown()

// We should not get any stylus events
require(down.type != PointerType.Stylus ||
down.type == PointerType.Eraser)
require(
down.type != PointerType.Stylus ||
down.type == PointerType.Eraser
)


// testing if it will fixed exception:
Expand Down Expand Up @@ -291,67 +285,12 @@ fun EditorGestureReceiver(
}
}
}

.fillMaxWidth()
.fillMaxHeight()
) {
val density = LocalDensity.current
// Draw cross where finger is touching
DrawCross(crossPosition, density)
// Draw the rectangle while dragging
DrawRectangle(rectangleBounds, density)
}
}

@Composable
private fun DrawRectangle(rectangleBounds: Rect?, density: Density) {
rectangleBounds?.let { bounds ->
// Draw the rectangle
Box(
Modifier
.offset { IntOffset(bounds.left, bounds.top) }
.size(
width = with(density) { (bounds.right - bounds.left).toDp() },
height = with(density) { (bounds.bottom - bounds.top).toDp() }
)
// Is there rendering speed difference between colors?
.background(Color(0x55000000))
.border(1.dp, Color.Black)
)
}

)
SelectionVisualCues(crossPosition, rectangleBounds)
}

@Composable
private fun DrawCross(crossPosition: IntOffset?, density: Density) {

// Draw cross where finger is touching
crossPosition?.let { pos ->
val crossSizePx = with(density) { 100.dp.toPx() }
Box(
Modifier
.offset {
IntOffset(
pos.x - (crossSizePx / 2).toInt(),
pos.y
)
} // Horizontal bar centered
.size(width = 100.dp, height = 2.dp)
.background(Color.Black)
)
Box(
Modifier
.offset {
IntOffset(
pos.x,
pos.y - (crossSizePx / 2).toInt()
)
} // Vertical bar centered
.size(width = 2.dp, height = 100.dp)
.background(Color.Black)
)
}
}

private fun resolveGesture(
settings: AppSettings?,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
package com.ethran.notable.editor.ui

import android.graphics.Rect
import androidx.compose.foundation.background
import androidx.compose.foundation.border
import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.fillMaxHeight
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.offset
import androidx.compose.foundation.layout.size
import androidx.compose.runtime.Composable
import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.platform.LocalDensity
import androidx.compose.ui.unit.Density
import androidx.compose.ui.unit.IntOffset
import androidx.compose.ui.unit.dp
import androidx.compose.ui.zIndex

@Composable
fun SelectionVisualCues(crossPosition: IntOffset?, rectangleBounds: Rect?) {
// Box for showing visual cues for selection
// separated from pointerInput box, as it has to be on top of everything.
Box(
modifier = Modifier
.fillMaxWidth()
.fillMaxHeight()
.zIndex(1f)
)
{
val density = LocalDensity.current
// Draw cross where finger is touching
DrawCross(crossPosition, density)
// Draw the rectangle while dragging
DrawRectangle(rectangleBounds, density)
}
}


@Composable
private fun DrawRectangle(rectangleBounds: Rect?, density: Density) {
rectangleBounds?.let { bounds ->
// Draw the rectangle
Box(
Modifier
.offset { IntOffset(bounds.left, bounds.top) }
.size(
width = with(density) { (bounds.right - bounds.left).toDp() },
height = with(density) { (bounds.bottom - bounds.top).toDp() }
)
// Is there rendering speed difference between colors?
.background(Color(0x55000000))
.border(1.dp, Color.Black)
)
}

}

@Composable
private fun DrawCross(crossPosition: IntOffset?, density: Density) {

// Draw cross where finger is touching
crossPosition?.let { pos ->
val crossSizePx = with(density) { 100.dp.toPx() }
Box(
Modifier
.offset {
IntOffset(
pos.x - (crossSizePx / 2).toInt(),
pos.y
)
} // Horizontal bar centered
.size(width = 100.dp, height = 2.dp)
.background(Color.Black)
)
Box(
Modifier
.offset {
IntOffset(
pos.x,
pos.y - (crossSizePx / 2).toInt()
)
} // Vertical bar centered
.size(width = 2.dp, height = 100.dp)
.background(Color.Black)
)
}
}
3 changes: 2 additions & 1 deletion app/src/main/java/com/ethran/notable/ui/Router.kt
Original file line number Diff line number Diff line change
Expand Up @@ -215,7 +215,8 @@ fun Router() {
*/
private fun Modifier.detectThreeFingerTouchToOpenQuickNav(
onOpen: () -> Unit
): Modifier = this.pointerInput(Unit) {
): Modifier = this.pointerInput(GlobalAppSettings.current.enableQuickNav) {
if(!GlobalAppSettings.current.enableQuickNav) return@pointerInput
while (true) {
try {
awaitPointerEventScope {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
package com.ethran.notable.ui.components

import androidx.compose.foundation.layout.Column
import androidx.compose.runtime.Composable
import androidx.navigation.NavController
import com.ethran.notable.data.datastore.AppSettings
import com.ethran.notable.data.db.KvProxy


@Composable
fun DebugSettings(kv: KvProxy, settings: AppSettings, navController: NavController) {
Column {
SettingToggleRow(
label = "Show welcome screen", value = settings.showWelcome, onToggle = { isChecked ->
kv.setAppSettings(settings.copy(showWelcome = isChecked))
})
SettingToggleRow(
label = "Show System Information", value = false, onToggle = {
navController.navigate("SystemInformationView")
})
SettingToggleRow(
label = "Debug Mode (show changed area)",
value = settings.debugMode,
onToggle = { isChecked ->
kv.setAppSettings(settings.copy(debugMode = isChecked))
})
SettingToggleRow(
label = "Use simple rendering for scroll and zoom -- uses more resources.",
value = settings.simpleRendering,
onToggle = { isChecked ->
kv.setAppSettings(settings.copy(simpleRendering = isChecked))
})
SettingToggleRow(
label = "Use openGL rendering for eraser.",
value = settings.openGLRendering,
onToggle = { isChecked ->
kv.setAppSettings(settings.copy(openGLRendering = isChecked))
})
SettingToggleRow(
label = "Use MuPdf as a renderer for pdfs.",
value = settings.muPdfRendering,
onToggle = { isChecked ->
kv.setAppSettings(settings.copy(muPdfRendering = isChecked))
})
SettingToggleRow(
label = "Allow destructive migrations",
value = settings.destructiveMigrations,
onToggle = { isChecked ->
kv.setAppSettings(settings.copy(destructiveMigrations = isChecked))
})
}
}
Loading
Loading