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

depth에 따른 노드 색 구현, 불필요한 코드 제거 #41

Merged
merged 3 commits into from
Nov 16, 2023
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
20 changes: 6 additions & 14 deletions AOS/app/src/main/java/boostcamp/and07/mindsync/data/SampleNode.kt
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package boostcamp.and07.mindsync.data

import boostcamp.and07.mindsync.data.model.CircleNode
import boostcamp.and07.mindsync.data.model.CirclePath
import boostcamp.and07.mindsync.data.model.ColorRGB
import boostcamp.and07.mindsync.data.model.Node
import boostcamp.and07.mindsync.data.model.RectangleNode
import boostcamp.and07.mindsync.data.model.RectanglePath
Expand All @@ -15,47 +14,40 @@ object SampleNode {
Dp(100f),
Dp(50f),
),
ColorRGB(100, 100, 100),
"Root",
listOf(
RectangleNode(
RectanglePath(Dp(200f), Dp(100f), Dp(50f), Dp(50f)),
ColorRGB(200, 200, 200),
"Child1",
listOf(
RectangleNode(
RectanglePath(Dp(250f), Dp(200f), Dp(50f), Dp(50f)),
ColorRGB(30, 30, 30),
"Child3",
listOf(
RectangleNode(
RectanglePath(Dp(350f), Dp(450f), Dp(50f), Dp(50f)),
ColorRGB(50, 70, 80),
"Child5",
listOf(),
),
RectangleNode(
RectanglePath(Dp(350f), Dp(550f), Dp(50f), Dp(50f)),
ColorRGB(100, 200, 100),
"Child6",
listOf(),
)
)
),
),
),
RectangleNode(
RectanglePath(Dp(250f), Dp(400f), Dp(50f), Dp(50f)),
ColorRGB(10, 23, 40),
"Child4",
listOf(),
)
)
),
),
),
RectangleNode(
RectanglePath(Dp(200f), Dp(300f), Dp(50f), Dp(50f)),
ColorRGB(0, 0, 0),
"Child2",
listOf(),
)
)
),
),
)
}

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -2,21 +2,18 @@ package boostcamp.and07.mindsync.data.model

sealed class Node(
open val path: NodePath,
open val color: ColorRGB,
open val description: String,
open val nodes: List<Node>,
)

data class CircleNode(
override val path: CirclePath,
override val color: ColorRGB,
override val description: String,
override val nodes: List<Node>,
) : Node(path, color, description, nodes)
) : Node(path, description, nodes)

data class RectangleNode(
override val path: RectanglePath,
override val color: ColorRGB,
override val description: String,
override val nodes: List<Node>,
) : Node(path, color, description, nodes)
) : Node(path, description, nodes)
24 changes: 14 additions & 10 deletions AOS/app/src/main/java/boostcamp/and07/mindsync/ui/view/NodeView.kt
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,10 @@ package boostcamp.and07.mindsync.ui.view

import android.content.Context
import android.graphics.Canvas
import android.graphics.Color
import android.graphics.Paint
import android.util.AttributeSet
import android.util.Log
import android.view.View
import boostcamp.and07.mindsync.R
import boostcamp.and07.mindsync.data.SampleNode
import boostcamp.and07.mindsync.data.model.CircleNode
import boostcamp.and07.mindsync.data.model.Node
Expand All @@ -16,9 +15,16 @@ import boostcamp.and07.mindsync.ui.util.toPx
class NodeView constructor(context: Context, attrs: AttributeSet?) : View(context, attrs) {
private val head = SampleNode.head
private val circlePaint = Paint().apply {
color = Color.rgb(head.color.red, head.color.green, head.color.blue)
color = context.getColor(R.color.mindmap1)
}
private val rectanglePaint = Paint()
private val nodeColors = listOf(
context.getColor(R.color.main3),
context.getColor(R.color.mindmap2),
context.getColor(R.color.mindmap3),
context.getColor(R.color.mindmap4),
context.getColor(R.color.mindmap5),
)

override fun onDraw(canvas: Canvas) {
super.onDraw(canvas)
Expand All @@ -31,21 +37,19 @@ class NodeView constructor(context: Context, attrs: AttributeSet?) : View(contex

private fun traverseNode(canvas: Canvas, node: Node, depth: Int) {
drawNode(canvas, node, depth)
if (node.nodes.isNotEmpty()) {
node.nodes.forEach { node ->
traverseNode(canvas, node, depth + 1)
}
node.nodes.forEach { node ->
traverseNode(canvas, node, depth + 1)
}
}

private fun drawNode(canvas: Canvas, node: Node, depth: Int) {
when (node) {
is CircleNode -> drawCircleNode(canvas, node, depth)
is CircleNode -> drawCircleNode(canvas, node)
is RectangleNode -> drawRectangleNode(canvas, node, depth)
}
}

private fun drawCircleNode(canvas: Canvas, node: CircleNode, depth: Int) {
private fun drawCircleNode(canvas: Canvas, node: CircleNode) {
canvas.drawCircle(
node.path.centerX.toPx(context).toFloat(),
node.path.centerY.toPx(context).toFloat(),
Expand All @@ -55,7 +59,7 @@ class NodeView constructor(context: Context, attrs: AttributeSet?) : View(contex
}

private fun drawRectangleNode(canvas: Canvas, node: RectangleNode, depth: Int) {
rectanglePaint.color = Color.rgb(node.color.red, node.color.green, node.color.blue)
rectanglePaint.color = nodeColors[(depth - 1) % nodeColors.size]
canvas.drawRect(
node.path.leftX().toPx(context).toFloat(),
node.path.topY().toPx(context).toFloat(),
Expand Down
7 changes: 7 additions & 0 deletions AOS/app/src/main/res/values/colors.xml
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,11 @@

<color name="sub2">#49AA95</color>
<color name="sub1">#FB5D67</color>


<color name="mindmap1">#D7558A</color>
<color name="mindmap2">#B9BC81</color>
<color name="mindmap3">#7AA37D</color>
<color name="mindmap4">#4B877B</color>
<color name="mindmap5">#336770</color>
</resources>