styleSet.ts 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. import Point from '../core/point'
  2. import FixedPoint from '../core/fixedpoint'
  3. import {AttachCAD as CAD} from '../index'
  4. import Line from '../core/fixedline'
  5. interface pointStyle {
  6. storkeColor?: string,
  7. fillColor?: string,
  8. hoverStorkeColor?: string,
  9. hoverFillColor?: string
  10. }
  11. interface lineStyle {
  12. width: number,
  13. color: string
  14. }
  15. export interface Style {
  16. setDefaultPointStyle: (args: pointStyle) => void,
  17. setDefaultLineStyle: (args: lineStyle) => void,
  18. }
  19. // 给cad点设置默认样式
  20. export const attachStyle = (cad: CAD) => {
  21. let fixedPointStyle = {
  22. fillColor: 'rgb(0, 200, 175)',
  23. storkeColor: 'green'
  24. }
  25. let pointStyle = {
  26. fillColor: 'rgba(245, 255, 0, 0.7)',
  27. storkeColor: 'rgba(245, 255, 255, 0.3)'
  28. }
  29. cad.setDefaultPointStyle = (args) => {
  30. args.storkeColor && (fixedPointStyle.storkeColor = args.storkeColor)
  31. args.fillColor && (fixedPointStyle.fillColor = args.fillColor)
  32. args.hoverStorkeColor && (pointStyle.storkeColor = args.hoverStorkeColor)
  33. args.hoverFillColor && (pointStyle.fillColor = args.hoverFillColor)
  34. setTimeout(() => {
  35. cad.loadData(cad.getData());
  36. }, 100)
  37. }
  38. let lineStyle = {
  39. width: 3,
  40. color: 'rgb(255,255,255)'
  41. }
  42. const addProcessing = cad.addProcessing
  43. cad.addProcessing = (...args) => {
  44. let processing = addProcessing.call(cad, ...args)
  45. FixedPoint.Setting.set(processing.render, fixedPointStyle)
  46. Point.Setting.set(processing.render, pointStyle)
  47. Line.Setting.set(processing.render, lineStyle)
  48. return processing
  49. }
  50. cad.setDefaultLineStyle = args => {
  51. args.width && (lineStyle.width = args.width)
  52. args.color && (lineStyle.color = args.color)
  53. setTimeout(() => {
  54. cad.loadData(cad.getData());
  55. }, 100)
  56. }
  57. }