Skip to content

Commit

Permalink
feat(color-picker): adds custom color picker
Browse files Browse the repository at this point in the history
Adds a custom color picker for alpha value selection

re #372 and #373
  • Loading branch information
2xAA committed Sep 18, 2020
1 parent 2dfff4d commit f29f05b
Show file tree
Hide file tree
Showing 9 changed files with 203 additions and 3 deletions.
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@
"uuid": "^3.3.3",
"vue": "^2.6.10",
"vue-class-component": "^7.2.3",
"vue-color": "^2.7.1",
"vue-golden-layout": "^2.0.8",
"vue-property-decorator": "^8.3.0",
"vue-smooth-dnd": "^0.8.1",
Expand Down
8 changes: 8 additions & 0 deletions src/application/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,14 @@ export default class ModV {
this.store.dispatch("windows/createWindow");
});

ipcRenderer.on("input-update", (event, { moduleId, prop, data }) => {
this.store.dispatch("modules/updateProp", {
moduleId,
prop,
data
});
});

this.ready = true;
ipcRenderer.send("modv-ready");
ipcRenderer.send("get-media-manager-state");
Expand Down
17 changes: 17 additions & 0 deletions src/background.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,23 @@ let projectNames = ["default"];
let currentProject = "default";

const windowPrefs = {
colorPicker: {
devPath: "colorPicker",
prodPath: "colorPicker.html",
options: {
webPreferences: {
nodeIntegration: true
},
transparent: true,
frame: false,
alwaysOnTop: true,
resizable: false,
skipTaskbar: true,
fullscreenable: false
},
unique: true
},

mainWindow: {
devPath: "",
prodPath: "index.html",
Expand Down
6 changes: 4 additions & 2 deletions src/components/Control.vue
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
<input type="checkbox" v-model="value" />
</div>
<div class="input" v-else-if="type === 'color'">
<input type="color" v-model="value" />
<ColorControl v-model="value" :moduleId="id" :prop="prop" />
</div>
<div class="input" v-else-if="type === 'texture'">
<TextureControl v-model="value" />
Expand Down Expand Up @@ -60,6 +60,7 @@ import TweenControl from "./Controls/TweenControl";
import PaletteControl from "./Controls/PaletteControl";
import TextureControl from "./Controls/TextureControl";
import FontControl from "./Controls/FontControl";
import ColorControl from "./Controls/ColorControl";
import hasLink from "./mixins/has-input-link";
import inputIsFocused from "./mixins/input-is-focused";
Expand All @@ -74,7 +75,8 @@ export default {
TweenControl,
PaletteControl,
TextureControl,
FontControl
FontControl,
ColorControl
},
data() {
Expand Down
49 changes: 49 additions & 0 deletions src/components/Controls/ColorControl.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
<template>
<div class="color-well">
<input @click.prevent="openColorPicker" type="color" v-model="value" />
</div>
</template>

<script>
import { ipcRenderer } from "electron";
export default {
props: {
value: {
type: String,
required: true
},
moduleId: {
type: String,
required: true
},
prop: {
type: String,
required: true
}
},
methods: {
openColorPicker() {
ipcRenderer.send("open-window", "colorPicker");
ipcRenderer.once("window-ready", (event, { window: windowName, id }) => {
if (windowName !== "colorPicker") {
return;
}
ipcRenderer.sendTo(id, "return-format");
ipcRenderer.sendTo(id, "module-info", {
moduleId: this.moduleId,
prop: this.prop,
data: this.value
});
});
}
}
};
</script>

<style></style>
85 changes: 85 additions & 0 deletions src/subpages/color-picker/App.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
<template>
<div>
<Sketch :value="color" @input="updateValue" ref="picker" />
</div>
</template>

<script>
import { ipcRenderer } from "electron";
import { Sketch } from "vue-color";
export default {
components: {
Sketch
},
data() {
return {
color: "#ff0000ff",
moduleId: null,
prop: null,
// hex, hsl, hsv, rgba
returnFormat: "hex"
};
},
created() {
ipcRenderer.on("module-info", (event, { moduleId, prop, data }) => {
this.moduleId = moduleId;
this.prop = prop;
this.color = data;
});
ipcRenderer.on("value", (event, message) => {
this.color = message;
});
ipcRenderer.on("return-format", (event, message) => {
this.returnFormat = message;
});
},
mounted() {
window.addEventListener("resize", this.resize);
this.resize();
},
beforeDestroy() {
window.removeEventListener("resize", this.resize);
},
methods: {
resize(e) {
const pickerRect = this.$refs.picker.$el.getBoundingClientRect();
if (e) {
e.preventDefault();
}
window.resizeTo(pickerRect.width, pickerRect.height);
},
updateValue(color) {
this.color = color;
ipcRenderer.send("input-update", {
moduleId: this.moduleId,
prop: this.prop,
data: color[this.returnFormat]
});
}
}
};
</script>

<style>
body {
margin: 0;
-webkit-app-region: drag;
font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto,
"Helvetica Neue", "微軟雅黑", "Microsoft YaHei", "微軟正黑體",
"Microsoft JhengHei", Verdana, Arial, sans-serif !important;
}
.vc-sketch > * {
-webkit-app-region: no-drag;
}
</style>
7 changes: 7 additions & 0 deletions src/subpages/color-picker/main.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import Vue from "vue";

import App from "./App.vue";

window.Vue = new Vue({
render: h => h(App)
}).$mount("#app");
3 changes: 2 additions & 1 deletion vue.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@ const publishingOptions = {
module.exports = {
// https://cli.vuejs.org/config/#pages
pages: {
index: "src/main.js"
index: "src/main.js",
colorPicker: "src/subpages/color-picker/main.js"
},

configureWebpack: {
Expand Down
30 changes: 30 additions & 0 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -2792,6 +2792,11 @@ circular-json@^0.3.1:
resolved "https://registry.yarnpkg.com/circular-json/-/circular-json-0.3.3.tgz#815c99ea84f6809529d2f45791bdf82711352d66"
integrity sha512-UZK3NBx2Mca+b5LsG7bY183pHWt5Y1xts4P3Pz7ENTwGVnJOUWbRb3ocjvX7hx9tq/yTAdclXm9sZ38gNuem4A==

clamp@^1.0.1:
version "1.0.1"
resolved "https://registry.yarnpkg.com/clamp/-/clamp-1.0.1.tgz#66a0e64011816e37196828fdc8c8c147312c8634"
integrity sha1-ZqDmQBGBbjcZaCj9yMjBRzEshjQ=

class-utils@^0.3.5:
version "0.3.6"
resolved "https://registry.yarnpkg.com/class-utils/-/class-utils-0.3.6.tgz#f93369ae8b9a7ce02fd41faad0ca83033190c463"
Expand Down Expand Up @@ -7434,6 +7439,11 @@ lodash.merge@^4.6.1:
resolved "https://registry.yarnpkg.com/lodash.merge/-/lodash.merge-4.6.2.tgz#558aa53b43b661e1925a0afdfa36a9a1085fe57a"
integrity sha512-0KpjqXRVvrYyCsX1swR/XTK0va6VQkQM6MNo7PqW77ByjAhoARA8EfrP1N4+KlKj8YS0ZUCtRT/YUuhyYDujIQ==

lodash.throttle@^4.0.0:
version "4.1.1"
resolved "https://registry.yarnpkg.com/lodash.throttle/-/lodash.throttle-4.1.1.tgz#c23e91b710242ac70c37f1e1cda9274cc39bf2f4"
integrity sha1-wj6RtxAkKscMN/HhzaknTMOb8vQ=

lodash.transform@^4.6.0:
version "4.6.0"
resolved "https://registry.yarnpkg.com/lodash.transform/-/lodash.transform-4.6.0.tgz#12306422f63324aed8483d3f38332b5f670547a0"
Expand Down Expand Up @@ -7614,6 +7624,11 @@ matcher@^3.0.0:
dependencies:
escape-string-regexp "^4.0.0"

material-colors@^1.0.0:
version "1.2.6"
resolved "https://registry.yarnpkg.com/material-colors/-/material-colors-1.2.6.tgz#6d1958871126992ceecc72f4bcc4d8f010865f46"
integrity sha512-6qE4B9deFBIa9YSpOc9O0Sgc43zTeVYbgDT5veRKSlB2+ZuHNoVVxA1L/ckMUayV9Ay9y7Z/SZCLcGteW9i7bg==

mathjs-expression-parser@^1.0.2:
version "1.0.2"
resolved "https://registry.yarnpkg.com/mathjs-expression-parser/-/mathjs-expression-parser-1.0.2.tgz#7f59984cad711d766a1032f0900b01755c5cbc81"
Expand Down Expand Up @@ -11682,6 +11697,11 @@ tiny-relative-date@^1.3.0:
resolved "https://registry.yarnpkg.com/tiny-relative-date/-/tiny-relative-date-1.3.0.tgz#fa08aad501ed730f31cc043181d995c39a935e07"
integrity sha512-MOQHpzllWxDCHHaDno30hhLfbouoYlOI8YlMNtvKe1zXbjEVhbcEovQxvZrPvtiYW630GQDoMMarCnjfyfHA+A==

tinycolor2@^1.1.2:
version "1.4.1"
resolved "https://registry.yarnpkg.com/tinycolor2/-/tinycolor2-1.4.1.tgz#f4fad333447bc0b07d4dc8e9209d8f39a8ac77e8"
integrity sha1-9PrTM0R7wLB9TcjpIJ2POaisd+g=

tmp@^0.0.33:
version "0.0.33"
resolved "https://registry.yarnpkg.com/tmp/-/tmp-0.0.33.tgz#6d34335889768d21b2bcda0aa277ced3b1bfadf9"
Expand Down Expand Up @@ -12288,6 +12308,16 @@ vue-cli-plugin-electron-builder@^1.4.2:
webpack-chain "^5.0.0"
yargs "^14.0.0"

vue-color@^2.7.1:
version "2.7.1"
resolved "https://registry.yarnpkg.com/vue-color/-/vue-color-2.7.1.tgz#ca035109ea0010f0d60b889b97d63d37ac712f2d"
integrity sha512-u3yl46B2eEej9zfAOIRRSphX1QfeNQzMwO82EIA+aoi0AKX3o1KcfsmMzm4BFkkj2ukCxLVfQ41k7g1gSI7SlA==
dependencies:
clamp "^1.0.1"
lodash.throttle "^4.0.0"
material-colors "^1.0.0"
tinycolor2 "^1.1.2"

vue-eslint-parser@^2.0.3:
version "2.0.3"
resolved "https://registry.yarnpkg.com/vue-eslint-parser/-/vue-eslint-parser-2.0.3.tgz#c268c96c6d94cfe3d938a5f7593959b0ca3360d1"
Expand Down

0 comments on commit f29f05b

Please sign in to comment.