Skip to content

Commit

Permalink
Merge pull request #1 from MarkYav/develop
Browse files Browse the repository at this point in the history
v1.0.0
  • Loading branch information
MarkYav authored Apr 1, 2023
2 parents e86512a + 5a47943 commit 59fc2ef
Show file tree
Hide file tree
Showing 25 changed files with 970 additions and 0 deletions.
42 changes: 42 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
.gradle
build/
!gradle/wrapper/gradle-wrapper.jar
!**/src/main/**/build/
!**/src/test/**/build/

### IntelliJ IDEA ###
.idea/modules.xml
.idea/jarRepositories.xml
.idea/compiler.xml
.idea/libraries/
*.iws
*.iml
*.ipr
out/
!**/src/main/**/out/
!**/src/test/**/out/

### Eclipse ###
.apt_generated
.classpath
.factorypath
.project
.settings
.springBeans
.sts4-cache
bin/
!**/src/main/**/bin/
!**/src/test/**/bin/

### NetBeans ###
/nbproject/private/
/nbbuild/
/dist/
/nbdist/
/.nb-gradle/

### VS Code ###
.vscode/

### Mac OS ###
.DS_Store
43 changes: 43 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
# DrawBox
DrawBox is a multipurpose tool to draw anything on canvas, written completely on Compose Multiplatform.
This is the first multiplatform drawing library!

## Features

- Cross-platform!
- Customisable stoke size, color and opacity
- Inbuilt Undo and Redo options
- Reset option
- Background with color/image
- Custom opacity of drawing/background
- Different subscriptions (dynamic update/after each drawing)
- Easy Implementations

**Next releases:**
- Optimizing rendering (convert drawn PATHes)

**Planned:**
- Different image rations
- Erase tool
- Filling tool
- Migrate from Compose dependencies in DrawController

## Usage

```kotlin
val controller = remember { DrawController() }
DrawBox(drawController = controller, modifier = Modifier.fillMaxSize())
```

## Download

Using Gradle Kotlin DSL:
```kotlin
repository {
implementation("io.github.markyav.drawbox:drawbox:1.0.0")
}
```

## License

Licensed under the Apache License, Version 2.0, [click here for the full license](LICENSE.txt).
18 changes: 18 additions & 0 deletions build.gradle.kts
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
group = Library.group
version = Library.version

allprojects {
repositories {
google()
mavenCentral()
maven("https://maven.pkg.jetbrains.space/public/p/compose/dev")
}
}

plugins {
kotlin("multiplatform") apply false
kotlin("android") apply false
id("com.android.application") apply false
id("com.android.library") apply false
id("org.jetbrains.compose") apply false
}
8 changes: 8 additions & 0 deletions buildSrc/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
plugins {
`kotlin-dsl`
}

repositories {
gradlePluginPortal() // To use 'maven-publish' and 'signing' plugins in our own plugin
}

5 changes: 5 additions & 0 deletions buildSrc/src/main/kotlin/Android.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
object Android {
val compileSdk = 33
val minSdk = 24
val targetSdk = 33
}
20 changes: 20 additions & 0 deletions buildSrc/src/main/kotlin/Library.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
object Library {
val name = "DrawBox"
val description = "Multiplatform drawing library based on Compose Multiplatform!"
val url = "https://github.com/MarkYav/DrawBox"

val group = "io.github.markyav.drawbox"
val artifact = "drawbox"
val version = "1.0.0"

object License {
val name = "Apache-2.0"
val url = "https://opensource.org/license/apache-2-0/"
}

object Author {
val id = "MarkYav"
val name = "Mark Yavorskyi"
val email = "[email protected]"
}
}
90 changes: 90 additions & 0 deletions buildSrc/src/main/kotlin/convention-publication.gradle.kts
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
import org.gradle.api.publish.maven.MavenPublication
import org.gradle.api.tasks.bundling.Jar
import org.gradle.kotlin.dsl.`maven-publish`
import org.gradle.kotlin.dsl.signing
import java.util.*

plugins {
`maven-publish`
signing
}

// Stub secrets to let the project sync and build without the publication values set up
ext["signing.keyId"] = null
ext["signing.password"] = null
ext["signing.secretKeyRingFile"] = null
ext["ossrhUsername"] = null
ext["ossrhPassword"] = null

// Grabbing secrets from local.properties file or from environment variables, which could be used on CI
val secretPropsFile = project.rootProject.file("local.properties")
if (secretPropsFile.exists()) {
secretPropsFile.reader().use {
Properties().apply {
load(it)
}
}.onEach { (name, value) ->
ext[name.toString()] = value
}
} else {
ext["signing.keyId"] = System.getenv("SIGNING_KEY_ID")
ext["signing.password"] = System.getenv("SIGNING_PASSWORD")
ext["signing.secretKeyRingFile"] = System.getenv("SIGNING_SECRET_KEY_RING_FILE")
ext["ossrhUsername"] = System.getenv("OSSRH_USERNAME")
ext["ossrhPassword"] = System.getenv("OSSRH_PASSWORD")
}

val javadocJar by tasks.registering(Jar::class) {
archiveClassifier.set("javadoc")
}

fun getExtraString(name: String) = ext[name]?.toString()

publishing {
// Configure maven central repository
repositories {
maven {
name = "sonatype"
setUrl("https://s01.oss.sonatype.org/service/local/staging/deploy/maven2/")
credentials {
username = getExtraString("ossrhUsername")
password = getExtraString("ossrhPassword")
}
}
}

// Configure all publications
publications.withType<MavenPublication> {
// Stub javadoc.jar artifact
artifact(javadocJar.get())

// Provide artifacts information requited by Maven Central
pom {
name.set(Library.name)
description.set(Library.description)
url.set(Library.url)

licenses {
license {
name.set(Library.License.name)
url.set(Library.License.url)
}
}
developers {
developer {
id.set(Library.Author.id)
name.set(Library.Author.name)
email.set(Library.Author.email)
}
}
scm {
url.set(Library.url)
}
}
}
}

// Signing artifacts. Signing.* extra properties values will be used
signing {
sign(publishing.publications)
}
44 changes: 44 additions & 0 deletions drawbox/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
plugins {
kotlin("multiplatform")
id("org.jetbrains.compose")
id("com.android.library")
id("convention-publication")
}

group = Library.group
version = Library.version

kotlin {
android {
publishLibraryVariants("release")
}
jvm("desktop") {
jvmToolchain(11)
}
sourceSets {
val commonMain by getting {
dependencies {
api(compose.runtime)
api(compose.foundation)
}
}
val commonTest by getting
val androidMain by getting
val androidTest by getting
val desktopMain by getting
val desktopTest by getting
}
}

android {
compileSdk = Android.compileSdk
sourceSets["main"].manifest.srcFile("src/androidMain/AndroidManifest.xml")
defaultConfig {
minSdk = Android.minSdk
targetSdk = Android.targetSdk
}
compileOptions {
sourceCompatibility = JavaVersion.VERSION_1_8
targetCompatibility = JavaVersion.VERSION_1_8
}
}
2 changes: 2 additions & 0 deletions drawbox/src/androidMain/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android" package="io.github.markyav.drawbox"/>
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
package io.github.markyav.drawbox.box

import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.runtime.Composable
import androidx.compose.ui.Modifier
import io.github.markyav.drawbox.controller.DrawBoxBackground
import io.github.markyav.drawbox.controller.DrawController
import io.github.markyav.drawbox.model.PathWrapper

@Composable
fun DrawBox(
controller: DrawController,
modifier: Modifier = Modifier.fillMaxSize(),
) {
val path: List<PathWrapper>? = controller.pathToDrawOnCanvas
val background: DrawBoxBackground = controller.background
val canvasAlpha: Float = controller.canvasOpacity

Box(modifier = modifier) {
DrawBoxBackground(
background = background,
modifier = Modifier.fillMaxSize(),
)
DrawBoxCanvas(
path = path ?: emptyList(),
alpha = canvasAlpha,
onSizeChanged = controller::connectToDrawBox,
onTap = controller::insertNewPath,
onDragStart = controller::insertNewPath,
onDrag = controller::updateLatestPath,
onDragEnd = controller::finalizePath,
modifier = Modifier.fillMaxSize(),
)
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
package io.github.markyav.drawbox.box

import androidx.compose.foundation.Image
import androidx.compose.foundation.background
import androidx.compose.foundation.layout.Box
import androidx.compose.runtime.Composable
import androidx.compose.ui.Modifier
import androidx.compose.ui.draw.alpha
import io.github.markyav.drawbox.controller.DrawBoxBackground

@Composable
fun DrawBoxBackground(
background: DrawBoxBackground,
modifier: Modifier,
) {
when (background) {
is DrawBoxBackground.ColourBackground -> Box(
modifier = modifier
.alpha(alpha = background.alpha)
.background(color = background.color)
)
is DrawBoxBackground.ImageBackground -> Image(
bitmap = background.bitmap,
alpha = background.alpha,
modifier = modifier,
contentDescription = null
)
is DrawBoxBackground.NoBackground -> { }
}
}
Loading

0 comments on commit 59fc2ef

Please sign in to comment.