Skip to content

Commit d13148e

Browse files
authored
Merge pull request #9 from CactiChameleon9/master
Add a relative brush size option
2 parents 0f46f79 + 2abc584 commit d13148e

7 files changed

Lines changed: 44 additions & 1 deletion

File tree

app/src/main/kotlin/org/fossify/paint/activities/MainActivity.kt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -170,6 +170,7 @@ class MainActivity : SimpleActivity(), CanvasListener {
170170
strokeWidthBar.beVisibleIf(isShowBrushSizeEnabled)
171171
strokeWidthPreview.beVisibleIf(isShowBrushSizeEnabled)
172172
myCanvas.setAllowZooming(config.allowZoomingCanvas)
173+
myCanvas.setRelativeBrushSize(config.relativeBrushSize)
173174
updateTextColors(mainHolder)
174175
if (isBlackAndWhiteTheme()) {
175176
strokeWidthBar.setColors(0, config.canvasBackgroundColor.getContrastColor(), 0)

app/src/main/kotlin/org/fossify/paint/activities/SettingsActivity.kt

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ class SettingsActivity : SimpleActivity() {
4040
setupPreventPhoneFromSleeping()
4141
setupBrushSize()
4242
setupAllowZoomingCanvas()
43+
setupRelativeBrushSize()
4344
setupForcePortraitMode()
4445
updateTextColors(binding.settingsHolder)
4546

@@ -109,6 +110,16 @@ class SettingsActivity : SimpleActivity() {
109110
}
110111
}
111112

113+
private fun setupRelativeBrushSize() {
114+
binding.apply {
115+
settingsRelativeBrushSize.isChecked = config.relativeBrushSize
116+
settingsRelativeBrushSizeHolder.setOnClickListener {
117+
settingsRelativeBrushSize.toggle()
118+
config.relativeBrushSize = settingsRelativeBrushSize.isChecked
119+
}
120+
}
121+
}
122+
112123
private fun setupForcePortraitMode() {
113124
binding.apply {
114125
settingsForcePortrait.isChecked = config.forcePortraitMode

app/src/main/kotlin/org/fossify/paint/helpers/Config.kt

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,11 @@ class Config(context: Context) : BaseConfig(context) {
4141
set(allowZoomingCanvas) = prefs.edit().putBoolean(ALLOW_ZOOMING_CANVAS, allowZoomingCanvas)
4242
.apply()
4343

44+
var relativeBrushSize: Boolean
45+
get() = prefs.getBoolean(RELATIVE_BRUSH_SIZE, true)
46+
set(relativeBrushSize) = prefs.edit().putBoolean(RELATIVE_BRUSH_SIZE, relativeBrushSize)
47+
.apply()
48+
4449
var forcePortraitMode: Boolean
4550
get() = prefs.getBoolean(FORCE_PORTRAIT_MODE, false)
4651
set(forcePortraitMode) = prefs.edit().putBoolean(FORCE_PORTRAIT_MODE, forcePortraitMode)

app/src/main/kotlin/org/fossify/paint/helpers/Constants.kt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ const val BRUSH_SIZE = "brush_size_2"
77
const val LAST_SAVE_FOLDER = "last_save_folder"
88
const val LAST_SAVE_EXTENSION = "last_save_extension"
99
const val ALLOW_ZOOMING_CANVAS = "allow_zooming_canvas"
10+
const val RELATIVE_BRUSH_SIZE = "relative_brush_size"
1011
const val FORCE_PORTRAIT_MODE = "force_portrait_mode"
1112

1213
const val PNG = "png"

app/src/main/kotlin/org/fossify/paint/views/MyCanvas.kt

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@ class MyCanvas(context: Context, attrs: AttributeSet) : View(context, attrs) {
6363
private var mCurrBrushSize = 0f
6464
private var mAllowMovingZooming = true
6565
private var mIsEraserOn = false
66+
private var mRelativeBrushSize = true
6667
private var mIsBucketFillOn = false
6768
private var mWasMultitouch = false
6869
private var mIgnoreTouches = false
@@ -291,13 +292,21 @@ class MyCanvas(context: Context, attrs: AttributeSet) : View(context, attrs) {
291292

292293
fun setBrushSize(newBrushSize: Float) {
293294
mCurrBrushSize = newBrushSize
294-
mPaintOptions.strokeWidth = resources.getDimension(R.dimen.full_brush_size) * (mCurrBrushSize / mScaleFactor / 100f)
295+
mPaintOptions.strokeWidth = resources.getDimension(R.dimen.full_brush_size) * (mCurrBrushSize / 100f)
296+
if (mRelativeBrushSize) {
297+
mPaintOptions.strokeWidth /= mScaleFactor
298+
}
295299
}
296300

297301
fun setAllowZooming(allowZooming: Boolean) {
298302
mAllowMovingZooming = allowZooming
299303
}
300304

305+
fun setRelativeBrushSize(relativeBrushSize: Boolean) {
306+
mRelativeBrushSize = relativeBrushSize
307+
setBrushSize(mCurrBrushSize)
308+
}
309+
301310
fun getBitmap(): Bitmap {
302311
val bitmap = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888)
303312
val canvas = Canvas(bitmap)

app/src/main/res/layout/activity_settings.xml

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -146,6 +146,21 @@
146146

147147
</RelativeLayout>
148148

149+
<RelativeLayout
150+
android:id="@+id/settings_relative_brush_size_holder"
151+
style="@style/SettingsHolderCheckboxStyle"
152+
android:layout_width="match_parent"
153+
android:layout_height="wrap_content">
154+
155+
<org.fossify.commons.views.MyMaterialSwitch
156+
android:id="@+id/settings_relative_brush_size"
157+
style="@style/SettingsSwitchStyle"
158+
android:layout_width="match_parent"
159+
android:layout_height="wrap_content"
160+
android:text="@string/use_relative_brush_size" />
161+
162+
</RelativeLayout>
163+
149164
<RelativeLayout
150165
android:id="@+id/settings_force_portrait_holder"
151166
style="@style/SettingsHolderSwitchStyle"

app/src/main/res/values/strings.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
<!-- Settings -->
1111
<string name="show_brush_size">Show brush size tool</string>
1212
<string name="allow_zooming_moving_canvas">Allow zooming and moving the canvas with gestures</string>
13+
<string name="use_relative_brush_size">Adjust brush size based on zoom level</string>
1314
<string name="clear">Clear</string>
1415
<string name="change_background_color">Change background color</string>
1516
<!--

0 commit comments

Comments
 (0)