Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add a relative brush size option #9

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,7 @@ class MainActivity : SimpleActivity(), CanvasListener {
strokeWidthBar.beVisibleIf(isShowBrushSizeEnabled)
strokeWidthPreview.beVisibleIf(isShowBrushSizeEnabled)
myCanvas.setAllowZooming(config.allowZoomingCanvas)
myCanvas.setRelativeBrushSize(config.relativeBrushSize)
updateTextColors(mainHolder)
if (isBlackAndWhiteTheme()) {
strokeWidthBar.setColors(0, config.canvasBackgroundColor.getContrastColor(), 0)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ class SettingsActivity : SimpleActivity() {
setupPreventPhoneFromSleeping()
setupBrushSize()
setupAllowZoomingCanvas()
setupRelativeBrushSize()
setupForcePortraitMode()
updateTextColors(binding.settingsHolder)

Expand Down Expand Up @@ -101,6 +102,16 @@ class SettingsActivity : SimpleActivity() {
}
}

private fun setupRelativeBrushSize() {
binding.apply {
settingsRelativeBrushSize.isChecked = config.relativeBrushSize
settingsRelativeBrushSizeHolder.setOnClickListener {
settingsRelativeBrushSize.toggle()
config.relativeBrushSize = settingsRelativeBrushSize.isChecked
}
}
}

private fun setupForcePortraitMode() {
binding.apply {
settingsForcePortrait.isChecked = config.forcePortraitMode
Expand Down
4 changes: 4 additions & 0 deletions app/src/main/kotlin/org/fossify/draw/helpers/Config.kt
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,10 @@ class Config(context: Context) : BaseConfig(context) {
get() = prefs.getBoolean(ALLOW_ZOOMING_CANVAS, true)
set(allowZoomingCanvas) = prefs.edit().putBoolean(ALLOW_ZOOMING_CANVAS, allowZoomingCanvas).apply()

var relativeBrushSize: Boolean
get() = prefs.getBoolean(RELATIVE_BRUSH_SIZE, true)
set(relativeBrushSize) = prefs.edit().putBoolean(RELATIVE_BRUSH_SIZE, relativeBrushSize).apply()

var forcePortraitMode: Boolean
get() = prefs.getBoolean(FORCE_PORTRAIT_MODE, false)
set(forcePortraitMode) = prefs.edit().putBoolean(FORCE_PORTRAIT_MODE, forcePortraitMode).apply()
Expand Down
1 change: 1 addition & 0 deletions app/src/main/kotlin/org/fossify/draw/helpers/Constants.kt
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ const val BRUSH_SIZE = "brush_size_2"
const val LAST_SAVE_FOLDER = "last_save_folder"
const val LAST_SAVE_EXTENSION = "last_save_extension"
const val ALLOW_ZOOMING_CANVAS = "allow_zooming_canvas"
const val RELATIVE_BRUSH_SIZE = "relative_brush_size"
const val FORCE_PORTRAIT_MODE = "force_portrait_mode"

const val PNG = "png"
Expand Down
11 changes: 10 additions & 1 deletion app/src/main/kotlin/org/fossify/draw/views/MyCanvas.kt
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ class MyCanvas(context: Context, attrs: AttributeSet) : View(context, attrs) {

private var mCurrBrushSize = 0f
private var mAllowMovingZooming = true
private var mRelativeBrushSize = true
private var mIsEraserOn = false
private var mIsBucketFillOn = false
private var mWasMultitouch = false
Expand Down Expand Up @@ -282,13 +283,21 @@ class MyCanvas(context: Context, attrs: AttributeSet) : View(context, attrs) {

fun setBrushSize(newBrushSize: Float) {
mCurrBrushSize = newBrushSize
mPaintOptions.strokeWidth = resources.getDimension(R.dimen.full_brush_size) * (mCurrBrushSize / mScaleFactor / 100f)
mPaintOptions.strokeWidth = resources.getDimension(R.dimen.full_brush_size) * (mCurrBrushSize / 100f)
if (mRelativeBrushSize) {
mPaintOptions.strokeWidth /= mScaleFactor
}
}

fun setAllowZooming(allowZooming: Boolean) {
mAllowMovingZooming = allowZooming
}

fun setRelativeBrushSize(relativeBrushSize: Boolean) {
mRelativeBrushSize = relativeBrushSize
setBrushSize(mCurrBrushSize)
}

fun getBitmap(): Bitmap {
val bitmap = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888)
val canvas = Canvas(bitmap)
Expand Down
15 changes: 15 additions & 0 deletions app/src/main/res/layout/activity_settings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,21 @@

</RelativeLayout>

<RelativeLayout
android:id="@+id/settings_relative_brush_size_holder"
style="@style/SettingsHolderCheckboxStyle"
android:layout_width="match_parent"
android:layout_height="wrap_content">

<org.fossify.commons.views.MyAppCompatCheckbox
android:id="@+id/settings_relative_brush_size"
style="@style/SettingsCheckboxStyle"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="@string/use_relative_brush_size" />

</RelativeLayout>

<RelativeLayout
android:id="@+id/settings_force_portrait_holder"
style="@style/SettingsHolderCheckboxStyle"
Expand Down
1 change: 1 addition & 0 deletions app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
<!-- Settings -->
<string name="show_brush_size">Show brush size tool</string>
<string name="allow_zooming_moving_canvas">Allow zooming and moving the canvas with gestures</string>
<string name="use_relative_brush_size">Use a relative (to zoom) brush size</string>
<string name="clear">Clear</string>
<string name="change_background_color">Change background color</string>
<!--
Expand Down