GraphyFmItem.kt 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  1. package com.ys.bdtp.cad.test
  2. import android.graphics.Bitmap
  3. import android.graphics.Canvas
  4. import android.graphics.Color
  5. import android.graphics.Matrix
  6. import android.graphics.Paint
  7. import android.graphics.RectF
  8. import android.util.Log
  9. import com.ys.bdtp.graph.SGraphyItem
  10. import com.ys.bdtp.graph.SMotionEvent
  11. import com.ys.bdtp.graph.enums.SGraphyItemFlag
  12. import java.util.*
  13. /**
  14. * 设备
  15. * @author Andy
  16. */
  17. class GraphyFmItem(parent: SGraphyItem? = null) : SGraphyItem(parent) {
  18. // 画笔
  19. private var pen = Paint()
  20. var flag:Boolean = false
  21. var isClick:Boolean = false
  22. /** 当前设备 */
  23. var isCurrent:Boolean=false
  24. private lateinit var bitmapdianbiao:Bitmap
  25. private lateinit var bitmapequipment:Bitmap
  26. private lateinit var decodeResource:Bitmap
  27. private var bitheight = 0
  28. private var bitwidth = 0
  29. /** png图数据 */
  30. private var pngWidth = 16
  31. private var pngHeight = 16
  32. /** png定位点的坐标 */
  33. private val pngLocatX = 8
  34. private val pngLocatY = 14
  35. /** 原始宽 */
  36. private var originalWidth = 0
  37. /** 原始高 */
  38. private var originalHeight = 0
  39. private var rate = 1f
  40. var color = Color.BLACK
  41. /**
  42. * 默认构造函数
  43. */
  44. init {
  45. // hide()
  46. isClick=true
  47. isCurrent=false
  48. pen.color = color
  49. pen.strokeWidth = 5f
  50. pen.isAntiAlias=false
  51. /** item获取焦点ItemIsFocusable,移动ItemIsMovable */
  52. flags= EnumSet.of(SGraphyItemFlag.ItemIsFocusable)
  53. } // init
  54. /**
  55. * Item对象边界区域
  56. */
  57. override fun boundingRect(): RectF {
  58. return RectF(0f,0f,600f,300f)
  59. } // Function boundingRect()
  60. /**
  61. * @param canvas 画布对象
  62. */
  63. override fun onDraw(canvas: Canvas) {
  64. try {
  65. canvas.drawRect(0f,0f,600f,300f,pen)
  66. invalidate()
  67. } catch (e: Exception) {
  68. e.printStackTrace()
  69. }
  70. return
  71. } // Function paint()
  72. /**
  73. * 点击
  74. */
  75. override fun onSingleTapUp(e: SMotionEvent): Boolean {
  76. Log.e("被点击1","**************************************")
  77. return true
  78. }
  79. /**
  80. *
  81. * @param bm 传入的bitmap
  82. * @param newWidth 指定的图片宽
  83. * @param newHeight 指定的图片高
  84. * @return newbm 返回 bitmap类型
  85. */
  86. private fun setImgSize(bm: Bitmap?, newWidth: Int, newHeight: Int): Bitmap {
  87. // 获得图片的宽高.
  88. val width = bm!!.width
  89. val height = bm.height
  90. // 计算缩放比例.
  91. val scaleWidth = newWidth.toFloat() / width
  92. val scaleHeight = newHeight.toFloat() / height
  93. // 取得想要缩放的matrix参数.
  94. val matrix = Matrix()
  95. matrix.postScale(scaleWidth, scaleHeight)
  96. // bm.config = Bitmap.Config.RGB_565
  97. // 得到新的图片.
  98. return Bitmap.createBitmap(bm, 0, 0, width, height, matrix, true)
  99. }
  100. } // Class GraphyWallItem