Skip to content

Commit 15e087b

Browse files
committed
feat: add new filter examples and enhance documentation with blur, color matrix, and displacement filters
1 parent d4e9a29 commit 15e087b

24 files changed

+621
-77
lines changed

docs/.vitepress/config.ts

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ const themeConfig: DefaultTheme.Config = {
3030
{ text: 'Assets', link: '/examples/assets/async' },
3131
{ text: 'Dom Container', link: '/examples/dom-container/html_text-area' },
3232
{ text: 'Events', link: '/examples/events/buttons' },
33+
{ text: 'Filters', link: '/examples/filters/blur' },
3334
// { text: 'Text', link: '/examples/text/bitmap-text' },
3435
// { text: 'Graphics', link: '/examples/graphics/advanced' },
3536
// { text: 'Events', link: '/examples/events/click' },
@@ -170,6 +171,18 @@ const themeConfig: DefaultTheme.Config = {
170171
{ text: 'Slider', link: '/examples/events/slider' },
171172
],
172173
},
174+
{
175+
text: 'Filters',
176+
collapsed: true,
177+
items: [
178+
{ text: 'Blur', link: '/examples/filters/blur' },
179+
{ text: 'Color Matrix', link: '/examples/filters/color-matrix' },
180+
{ text: 'Custom shader / Glsl', link: '/examples/filters/custom-shader_glsl' },
181+
{ text: 'Custom / Interactive / Blending', link: '/examples/filters/custom_interactive_blending' },
182+
{ text: 'Displacement', link: '/examples/filters/displacement' },
183+
{ text: 'Displacement / Interactive', link: '/examples/filters/displacement_interactive' },
184+
],
185+
},
173186
// {
174187
// text: 'Container',
175188
// collapsed: true,

docs/examples/events/demo/buttons.vue

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ type RecordSprite = SpriteElement & Record<string, any>
99
const screen = useScreen()
1010
const textures = reactive<Record<string, Texture>>({})
1111
12-
// 根据 screen 计算按钮位置和尺寸
12+
// calculate button positions and sizes based on screen
1313
const buttons = computed(() => {
1414
const { width, height } = screen.value
1515
return [
@@ -61,7 +61,7 @@ function onButtonOut(this: RecordSprite) {
6161
@loaded="Object.assign(textures, $event)"
6262
>
6363
<!-- create a background... -->
64-
<Sprite texture="bg" :width="screen.width" :height="screen.height" />
64+
<sprite texture="bg" :width="screen.width" :height="screen.height" />
6565
<!-- add it to the stage -->
6666
<sprite
6767
v-for="(p, i) in buttons"

docs/examples/events/demo/custom-hitarea.vue

Lines changed: 19 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
<script lang="ts" setup>
2-
import { Graphics, Polygon, Sprite } from 'pixi.js'
2+
import type { Sprite as SpriteElement } from 'pixi.js'
3+
import { Graphics, Polygon } from 'pixi.js'
34
45
const hitArea = new Polygon([
56
80,
@@ -24,21 +25,16 @@ const hitArea = new Polygon([
2425
50,
2526
])
2627
27-
const square = new Graphics()
28-
.rect(400, 200, 75, 200)
29-
.fill()
28+
const square = new Graphics().rect(400, 200, 75, 200).fill()
29+
const squareHit = new Graphics().rect(550, 200, 75, 200).fill()
3030
31-
const squareHit = new Graphics()
32-
.rect(550, 200, 75, 200)
33-
.fill()
34-
35-
function onClick(this: Sprite) {
31+
function onClick(this: SpriteElement) {
3632
this.tint = 0x333333
3733
}
38-
function onPointerOver(this: Sprite) {
34+
function onPointerOver(this: SpriteElement) {
3935
this.tint = 0x666666
4036
}
41-
function onPointerOut(this: Sprite) {
37+
function onPointerOut(this: SpriteElement) {
4238
this.tint = 0xFFFFFF
4339
}
4440
@@ -57,21 +53,21 @@ const tBind = {
5753

5854
<template>
5955
<assets alias="star" entry="https://pixijs.com/assets/yellowstar.png">
60-
<Sprite v-bind="sBind" :x="0" texture="star" />
61-
<Text v-bind="tBind" :x="25">
56+
<sprite v-bind="sBind" :x="0" texture="star" />
57+
<text v-bind="tBind" :x="25">
6258
Standard
63-
</Text>
64-
<Sprite v-bind="sBind" :x="200" :hit-area="hitArea" texture="star" />
65-
<Text v-bind="tBind" :x="200 + 35">
59+
</text>
60+
<sprite v-bind="sBind" :x="200" :hit-area="hitArea" texture="star" />
61+
<text v-bind="tBind" :x="200 + 35">
6662
Hit Area
67-
</Text>
68-
<Sprite v-bind="sBind" :x="400" :mask="square" texture="star" />
69-
<Text v-bind="tBind" :x="400 + 10">
63+
</text>
64+
<sprite v-bind="sBind" :x="400" :mask="square" texture="star" />
65+
<text v-bind="tBind" :x="400 + 10">
7066
Mask
71-
</Text>
72-
<Sprite v-bind="sBind" :x="550" :hit-area="hitArea" :mask="squareHit" texture="star" />
73-
<Text v-bind="tBind" :x="550 + 10">
67+
</text>
68+
<sprite v-bind="sBind" :x="550" :hit-area="hitArea" :mask="squareHit" texture="star" />
69+
<text v-bind="tBind" :x="550 + 10">
7470
Mask\nHit Area
75-
</Text>
71+
</text>
7672
</assets>
7773
</template>

docs/examples/events/demo/custom-pointer.vue

Lines changed: 20 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,47 +1,50 @@
11
<script lang="ts" setup>
2-
import type { Sprite as SpriteElement, SpriteOptions, Texture } from 'pixi.js'
2+
import type { Sprite as SpriteElement, Texture } from 'pixi.js'
33
4-
import { reactive } from 'vue'
4+
import { computed, reactive } from 'vue'
55
import { onReady, useScreen } from 'vue3-pixi'
66
77
type RecordSprite = SpriteElement & Record<string, any>
88
99
const screen = useScreen()
1010
const textures = reactive<Record<string, Texture>>({})
1111
12-
// set some silly values...
13-
const buttons: any[] = [
14-
{ x: 175, y: 75, scale: 1.2 },
15-
{ x: 655, y: 75 },
16-
{ x: 410, y: 325, rotation: Math.PI / 10 },
17-
{ x: 150, y: 465, scale: 0.8 },
18-
{ x: 685, y: 445, scale: { x: 0.8, y: 1.2 }, rotation: Math.PI },
19-
]
12+
// calculate button positions and sizes based on screen
13+
const buttons = computed(() => {
14+
const { width, height } = screen.value
15+
return [
16+
{ x: width * 0.25, y: height * 0.15, scale: 1.2 },
17+
{ x: width * 0.75, y: height * 0.15 },
18+
{ x: width * 0.5, y: height * 0.5, rotation: Math.PI / 10 },
19+
{ x: width * 0.2, y: height * 0.85, scale: 0.8 },
20+
{ x: width * 0.8, y: height * 0.85, scale: { x: 0.8, y: 1.2 }, rotation: Math.PI },
21+
]
22+
})
2023
2124
function onButtonDown(this: RecordSprite) {
22-
this._is_down = true
25+
this.isDown = true
2326
this.texture = textures.buttonDown
2427
this.alpha = 1
2528
}
2629
2730
function onButtonUp(this: RecordSprite) {
28-
this._is_down = false
29-
if (this._is_over)
31+
this.isDown = false
32+
if (this.isOver)
3033
this.texture = textures.buttonOver
3134
else
3235
this.texture = textures.button
3336
}
3437
3538
function onButtonOver(this: RecordSprite) {
36-
this._is_over = true
37-
if (this._is_down)
39+
this.isOver = true
40+
if (this.isDown)
3841
return
3942
this.texture = textures.buttonOver
4043
}
4144
4245
function onButtonOut(this: RecordSprite) {
43-
this._is_over = false
44-
if (this._is_down)
46+
this.isOver = false
47+
if (this.isDown)
4548
return
4649
this.texture = textures.button
4750
}

docs/examples/events/demo/dragging.vue

Lines changed: 16 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -22,11 +22,11 @@ function onDragStart(this: SpriteElement) {
2222
}
2323
2424
function onDragMove(event: FederatedPointerEvent) {
25-
if (target.value) {
26-
// Directly update the sprite's position
27-
target.value.x = event.global.x
28-
target.value.y = event.global.y
29-
}
25+
if (!target.value)
26+
return
27+
// Directly update the sprite's position
28+
target.value.x = event.global.x
29+
target.value.y = event.global.y
3030
}
3131
3232
function onDragEnd() {
@@ -40,14 +40,17 @@ function onDragEnd() {
4040
function onLoaded(texture: Texture) {
4141
texture.source.scaleMode = 'nearest'
4242
43-
sprites.value = Array.from({ length: 10 }).fill(undefined).map(() => ({
44-
x: Math.floor(Math.random() * screen.value.width),
45-
y: Math.floor(Math.random() * screen.value.height),
46-
onPointerdown: onDragStart,
47-
texture,
48-
scale: 3,
49-
anchor: 0.5,
50-
}))
43+
sprites.value = Array
44+
.from({ length: 10 })
45+
.fill(undefined)
46+
.map(() => ({
47+
x: Math.floor(Math.random() * screen.value.width),
48+
y: Math.floor(Math.random() * screen.value.height),
49+
onPointerdown: onDragStart,
50+
texture,
51+
scale: 3,
52+
anchor: 0.5,
53+
}))
5154
}
5255
5356
onReady((app) => {

docs/examples/events/demo/order.vue

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,11 @@ for (const r of [stageRef, whiteBoxRef, blackBoxRef]) {
4444

4545
<template>
4646
<text :x="2" :style="{ fontSize: 14 }">
47-
Move your mouse slowly over the boxes to\nsee the order of pointerenter, pointerleave,\npointerover, pointerout events on each target!
47+
Move your mouse slowly over the boxes to
48+
\n
49+
see the order of pointerenter, pointerleave,
50+
\n
51+
pointerover, pointerout events on each target!
4852
</text>
4953
<text :x="2" :y="80" :style="{ fontSize: 12 }">
5054
{{ logs.join('\n') }}

docs/examples/filters/blur.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
<demo mode="full" :background-alpha="0" src="./demo/blur.vue" />
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
<demo mode="full" :background-alpha="0" src="./demo/color-matrix.vue" />
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
<demo mode="full" :background-alpha="0" src="./demo/custom-shader_glsl.vue" />
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
<demo mode="full" src="./demo/custom_interactive_blending.vue" />

0 commit comments

Comments
 (0)