composite.vue 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179
  1. <template>
  2. <div>
  3. <el-table :data="tableData" style="width: 100%" class="elementTable">
  4. <el-table-column prop="val" label="值" width="180"></el-table-column>
  5. <el-table-column prop="desc" label="描述"></el-table-column>
  6. </el-table>
  7. <div style="margin: 14px 0;">
  8. <span style="font-size: 14px;">选择融合方式</span>
  9. <el-select v-model="value" placeholder="请选择" @change="changeCom" size="small">
  10. <el-option v-for="item in options" :key="item.value" :label="item.label"
  11. :value="item.value"></el-option>
  12. </el-select>
  13. </div>
  14. <canvas :id="id" width="740" height="400" tabindex="0"/>
  15. </div>
  16. </template>
  17. <script lang="ts">
  18. import { SGraphItem, SGraphScene, SGraphView } from "@persagy-web/graph/lib";
  19. import { SColor, SCompositeType, SPainter, SRect } from "@persagy-web/draw/lib"
  20. import { Component, Vue } from "vue-property-decorator";
  21. import { v1 as uuid } from "uuid";
  22. class Circle extends SGraphItem {
  23. /** 融合方式 默认。在目标图像上显示源图像。 */
  24. _composite = SCompositeType.SourceOver;
  25. get composite(): SCompositeType {
  26. return this._composite;
  27. }
  28. set composite(v: SCompositeType) {
  29. this._composite = v;
  30. this.update();
  31. }
  32. /**
  33. * 构造函数
  34. *
  35. * @param parent Item 图像引擎
  36. * @param com 融合方式
  37. */
  38. constructor(parent: SGraphItem | null, com: SCompositeType) {
  39. super(parent);
  40. this.composite = com ? SCompositeType.SourceOver : com;
  41. }
  42. /**
  43. * 矩形数据类型绘制
  44. */
  45. boundingRect(): SRect {
  46. return new SRect(-500, -500, 1500, 1500);
  47. }
  48. /**
  49. * Item 绘制操作
  50. *
  51. * @param painter 绘制对象
  52. */
  53. onDraw(painter: SPainter): void {
  54. painter.brush.color = SColor.Blue;
  55. painter.pen.color = SColor.Transparent;
  56. painter.drawRect(0, 0, 1000, 1000);
  57. //融合属性
  58. painter.composite = this.composite;
  59. painter.brush.color = SColor.Red;
  60. //绘制圆形
  61. painter.drawCircle(0, 0, 500);
  62. }
  63. }
  64. @Component
  65. export default class CompositeCanvas extends Vue {
  66. view: SGraphView | undefined;
  67. id: string = uuid();
  68. value: SCompositeType = SCompositeType.SourceOver;
  69. options = [{
  70. value: SCompositeType.DestinationAtop,
  71. label: 'DestinationAtop'
  72. }, {
  73. value: SCompositeType.DestinationIn,
  74. label: 'DestinationIn'
  75. }, {
  76. value: SCompositeType.DestinationOut,
  77. label: 'DestinationOut'
  78. }, {
  79. value: SCompositeType.DestinationOver,
  80. label: 'DestinationOver'
  81. }, {
  82. value: SCompositeType.SourceAtop,
  83. label: 'SourceAtop'
  84. }, {
  85. value: SCompositeType.SourceIn,
  86. label: 'SourceIn'
  87. }, {
  88. value: SCompositeType.SourceOver,
  89. label: 'SourceOver'
  90. }, {
  91. value: SCompositeType.SourceOut,
  92. label: 'SourceOut'
  93. }, {
  94. value: SCompositeType.Xor,
  95. label: 'Xor'
  96. }, {
  97. value: SCompositeType.Lighter,
  98. label: 'Lighter'
  99. }, {
  100. value: SCompositeType.Copy,
  101. label: 'Copy'
  102. }];
  103. circle: Circle | undefined;
  104. tableData = [{
  105. val: 'source-over',
  106. desc: '默认。在目标图像上显示源图像。'
  107. }, {
  108. val: 'source-atop',
  109. desc: '在目标图像顶部显示源图像。源图像位于目标图像之外的部分是不可见的。'
  110. },
  111. {
  112. val: 'source-in',
  113. desc: '在目标图像中显示源图像。只有目标图像之内的源图像部分会显示,目标图像是透明的。'
  114. },
  115. {
  116. val: 'source-out',
  117. desc: '在目标图像之外显示源图像。只有目标图像之外的源图像部分会显示,目标图像是透明的。'
  118. },
  119. {
  120. val: 'destination-over',
  121. desc: '在源图像上显示目标图像。'
  122. },
  123. {
  124. val: 'destination-atop',
  125. desc: '在源图像顶部显示目标图像。目标图像位于源图像之外的部分是不可见的。'
  126. },
  127. {
  128. val: 'destination-in',
  129. desc: '在源图像中显示目标图像。只有源图像之内的目标图像部分会被显示,源图像是透明的。'
  130. },
  131. {
  132. val: 'destination-out',
  133. desc: '在源图像之外显示目标图像。只有源图像之外的目标图像部分会被显示,源图像是透明的。'
  134. },
  135. {
  136. val: 'lighter',
  137. desc: '显示源图像 + 目标图像。'
  138. },
  139. {
  140. val: 'copy',
  141. desc: '显示源图像。忽略目标图像。'
  142. },
  143. {
  144. val: 'xor',
  145. desc: '使用异或操作对源图像与目标图像进行组合。'
  146. }
  147. ];
  148. /**
  149. * 页面挂载
  150. */
  151. mounted(): void {
  152. this.init()
  153. };
  154. init(): void {
  155. this.view = new SGraphView(this.id);
  156. const scene = new SGraphScene();
  157. this.circle = new Circle(null, SCompositeType.SourceOut);
  158. scene.addItem(this.circle);
  159. this.view.scene = scene;
  160. this.view.fitSceneToView();
  161. this.view.scalable = false;
  162. };
  163. changeCom(val: SCompositeType): void {
  164. if (this.circle) {
  165. this.circle.composite = val;
  166. }
  167. }
  168. }
  169. </script>