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

[둘리] 뷰 챌린지 미션 2단계 제출합니다. #38

Merged
merged 28 commits into from
Oct 11, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
dc16a7d
feat: button bindingAdapter로 isSelected 생성
hyemdooly Oct 9, 2023
dee7ae1
feat: 선택된 버튼 색깔 생성
hyemdooly Oct 9, 2023
74f09cb
feat: 브러쉬 요소 추가
hyemdooly Oct 9, 2023
4e324fd
feat: 브러쉬 선택 기능 UI 추가
hyemdooly Oct 9, 2023
2e8ae10
feat: 함수 일부 네이밍 변경 및 Circle, Rectangle 그리기 기능 추가
hyemdooly Oct 9, 2023
4c813d6
refactor: 함수 분리 및 중복 코드 삭제
hyemdooly Oct 9, 2023
c56475f
feat: 지우개 기능 구현
hyemdooly Oct 9, 2023
dc53032
refactor: Drawing 클래스에서 Path, Paint 복사하도록 수정
hyemdooly Oct 9, 2023
7da23af
feat: 전체 삭제, undo, redo 구현
hyemdooly Oct 9, 2023
e22dfd6
refactor: 함수 순서 수정
hyemdooly Oct 9, 2023
87daa31
refactor: SettingState sealed class -> enum class로 변경, 상수 위치 이동
hyemdooly Oct 9, 2023
0b210df
refactor: width로 굵기 네이밍 통일
hyemdooly Oct 9, 2023
943e72c
refactor: Brush -> Tool로 네이밍 변경
hyemdooly Oct 10, 2023
1cf3673
refactor: enum class 상수 네이밍 변경
hyemdooly Oct 10, 2023
316933e
refactor: Drawing 클래스 세분화
hyemdooly Oct 10, 2023
2d10fa3
refactor: tool이 drawing 객체를 리턴하도록 수정
hyemdooly Oct 10, 2023
f67b8ac
refactor: CanvasView가 하던 일을 Drawing 클래스로 이동
hyemdooly Oct 11, 2023
ee553e0
refactor: undo, redo 코드 줄 수 줄이기
hyemdooly Oct 11, 2023
cd6ff78
design: 도구에 따른 설정 화면 변경
hyemdooly Oct 11, 2023
dd8e201
refactor: 도구에 따라 버튼 동적 생성
hyemdooly Oct 11, 2023
26e18fe
refactor: brushes -> tools로 네이밍 수정
hyemdooly Oct 11, 2023
f412171
refactor: 함수명 수정
hyemdooly Oct 11, 2023
acb317f
refactor: tool 바꿀 때 설정창 닫도록 수정
hyemdooly Oct 11, 2023
f55275e
fix: Rectangle 버그 수정
hyemdooly Oct 11, 2023
b10fda7
refactor: 도구 모음 일치
hyemdooly Oct 11, 2023
d4a46c4
refactor: tool -> drawingTool로 네이밍 변경
hyemdooly Oct 11, 2023
1d90521
refactor: Drawings 일급컬렉션 생성
hyemdooly Oct 11, 2023
1264668
refactor: 팩토리 함수 삭제
hyemdooly Oct 11, 2023
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
Prev Previous commit
Next Next commit
feat: 브러쉬 선택 기능 UI 추가
  • Loading branch information
hyemdooly committed Oct 9, 2023
commit 4e324fd5843197c649fb6dca12d7b16852274640
17 changes: 17 additions & 0 deletions app/src/main/java/woowacourse/paint/MainViewModel.kt
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import androidx.lifecycle.LiveData
import androidx.lifecycle.MutableLiveData
import androidx.lifecycle.Transformations
import androidx.lifecycle.ViewModel
import woowacourse.paint.canvas.Brush
import woowacourse.paint.canvas.PaletteColor
import woowacourse.paint.model.ColorUiModel

Expand All @@ -18,6 +19,10 @@ class MainViewModel : ViewModel() {
val colors: LiveData<List<ColorUiModel>>
get() = _colors

private var _selectedBrush = MutableLiveData(Brush.PEN)
val selectedBrush: LiveData<Brush>
get() = _selectedBrush

val selectedColor: LiveData<PaletteColor>
get() = Transformations.map(_colors) { colors ->
colors.firstOrNull { it.isPicked }?.color ?: DEFAULT_SELECTED_COLOR
Expand All @@ -27,6 +32,14 @@ class MainViewModel : ViewModel() {
val width: LiveData<Float>
get() = _width

fun setBrushSettingState() {
if (_paintChangingState.value == PaintChangingState.BrushChanging) {
_paintChangingState.value = PaintChangingState.Nothing
return
}
_paintChangingState.value = PaintChangingState.BrushChanging
}

fun setColorSettingState() {
if (_paintChangingState.value == PaintChangingState.ColorChanging) {
_paintChangingState.value = PaintChangingState.Nothing
Expand All @@ -43,6 +56,10 @@ class MainViewModel : ViewModel() {
_paintChangingState.value = PaintChangingState.WidthChanging
}

fun pickBrush(brush: Brush) {
_selectedBrush.value = brush
}

fun pickColor(model: ColorUiModel) {
val colors = _colors.value ?: return
_colors.value = colors.map { it.copy(isPicked = it.color == model.color) }
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
package woowacourse.paint.canvas

enum class Brushes {
enum class Brush {
Copy link

@tmdgh1592 tmdgh1592 Oct 9, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

개인적으로 Brush 라는 단어를 들었을 때 붓이 연상되는데요!
도형과 지우개는 브러시랑은 조금 거리가 있는 것처럼 느껴집니다.

스크린샷 2023-10-10 오전 12 57 22

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tool로 수정했습니다~

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

이게 무슨 Tool 인지도 부가적인 설명이 있으면 좋겠네요~

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

DrawingTool로 수정했습니다~

PEN, RECTANGLE, CIRCLE, ERASER
tmdgh1592 marked this conversation as resolved.
Show resolved Hide resolved
}
73 changes: 69 additions & 4 deletions app/src/main/res/layout/activity_main.xml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@

<import type="woowacourse.paint.PaintChangingState" />

<import type="woowacourse.paint.canvas.Brush" />

<import type="android.view.View" />
</data>

Expand Down Expand Up @@ -43,11 +45,75 @@
android:orientation="horizontal"
android:visibility="@{viewModel.paintChangingState instanceof PaintChangingState.ColorChanging ? View.VISIBLE : View.GONE}"
app:layoutManager="androidx.recyclerview.widget.LinearLayoutManager"
app:layout_constraintBottom_toTopOf="@id/ll_brushes"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/rs_thickness_changer"
tools:listitem="@layout/item_color_palette" />

<LinearLayout
android:id="@+id/ll_brushes"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:gravity="center_horizontal"
android:orientation="horizontal"
android:visibility="@{viewModel.paintChangingState instanceof PaintChangingState.BrushChanging ? View.VISIBLE : View.GONE}"
app:layout_constraintBottom_toTopOf="@id/btn_change_brush"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent">

<Button
android:id="@+id/btn_pen"
isSelected="@{viewModel.selectedBrush == Brush.PEN}"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="5dp"
android:backgroundTint="@color/brush_selected"
android:onClick="@{() -> viewModel.pickBrush(Brush.PEN)}"
android:text="@string/pen" />

<Button
android:id="@+id/btn_rectangle"
tmdgh1592 marked this conversation as resolved.
Show resolved Hide resolved
isSelected="@{viewModel.selectedBrush == Brush.RECTANGLE}"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="5dp"
android:backgroundTint="@color/brush_selected"
android:onClick="@{() -> viewModel.pickBrush(Brush.RECTANGLE)}"
android:text="@string/rectangle" />

<Button
android:id="@+id/btn_circle"
isSelected="@{viewModel.selectedBrush == Brush.CIRCLE}"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="5dp"
android:backgroundTint="@color/brush_selected"
android:onClick="@{() -> viewModel.pickBrush(Brush.CIRCLE)}"
android:text="@string/circle" />

<Button
android:id="@+id/btn_eraser"
isSelected="@{viewModel.selectedBrush == Brush.ERASER}"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="5dp"
android:backgroundTint="@color/brush_selected"
android:onClick="@{() -> viewModel.pickBrush(Brush.ERASER)}"
android:text="@string/eraser" />
</LinearLayout>


<Button
android:id="@+id/btn_change_brush"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_margin="10dp"
android:onClick="@{() -> viewModel.setBrushSettingState()}"
android:text="@string/main_change_brush"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toStartOf="@id/btn_change_color"
app:layout_constraintStart_toStartOf="parent" />

<Button
android:id="@+id/btn_change_color"
android:layout_width="0dp"
Expand All @@ -58,7 +124,7 @@
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toStartOf="@id/btn_change_thickness"
app:layout_constraintHorizontal_chainStyle="packed"
app:layout_constraintStart_toStartOf="parent" />
app:layout_constraintStart_toEndOf="@id/btn_change_brush" />

<Button
android:id="@+id/btn_change_thickness"
Expand All @@ -69,8 +135,7 @@
android:text="@string/main_change_thickness"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toEndOf="@id/btn_change_color"
app:layout_constraintTop_toBottomOf="@id/rv_colors" />
app:layout_constraintStart_toEndOf="@id/btn_change_color" />


</androidx.constraintlayout.widget.ConstraintLayout>
Expand Down