Skip to content

Commit

Permalink
wip: rework style properties
Browse files Browse the repository at this point in the history
  • Loading branch information
Julusian committed Oct 17, 2023
1 parent 448a869 commit 77a3cd4
Show file tree
Hide file tree
Showing 8 changed files with 24 additions and 10 deletions.
2 changes: 1 addition & 1 deletion lib/Cloud/Controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -665,7 +665,7 @@ class CloudController extends CoreBase {
*/
updateBank(location, render) {
const bank = xyToOldBankIndex(location.column, location.row)
if (!render.style?.cloud && bank) {
if (typeof render.style === 'object' && !render.style.cloud && bank) {
const updateId = v4()
for (let region in this.regionInstances) {
if (!!this.regionInstances[region]?.socketTransmit) {
Expand Down
16 changes: 14 additions & 2 deletions lib/Graphics/ImageResult.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
/**
* @typedef {import("../Data/Model/StyleModel.js").DrawStyleButtonModel | 'pagenum' | 'pageup' | 'pagedown'} ImageResultStyle
*/

export class ImageResult {
/**
* Image data-url for socket.io clients
Expand All @@ -16,15 +20,15 @@ export class ImageResult {

/**
* Image draw style
* @type {any}
* @type {ImageResultStyle | undefined}
* @access public
* @readonly
*/
style

/**
* @param {Buffer} buffer
* @param {any} style
* @param {ImageResultStyle | undefined} style
*/
constructor(buffer, style) {
this.buffer = buffer
Expand Down Expand Up @@ -80,4 +84,12 @@ export class ImageResult {

return bmpHeader
}

get bgcolor() {
if (typeof this.style === 'object') {
return this.style.bgcolor ?? 0
} else {
return 0
}
}
}
3 changes: 2 additions & 1 deletion lib/Graphics/Renderer.js
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ export default class GraphicsRenderer {
// console.time('drawBankImage')
const img = new Image(72, 72, 4)

/** @type {import('./ImageResult.js').ImageResultStyle | undefined} */
let draw_style = undefined

// special button types
Expand Down Expand Up @@ -137,7 +138,7 @@ export default class GraphicsRenderer {
} else {
img.drawAlignedText(0, 0, 72, 72, pagename, colorWhite, 18, 'center', 'center')
}
} else if (bankStyle.style) {
} else if (bankStyle.style === 'button') {
draw_style = bankStyle

// @ts-ignore
Expand Down
3 changes: 2 additions & 1 deletion lib/Internal/Controls.js
Original file line number Diff line number Diff line change
Expand Up @@ -654,7 +654,7 @@ export default class Controls {
}

const render = theLocation && this.#graphicsController.getBank(theLocation)
if (render?.style) {
if (render?.style && typeof render.style === 'object') {
if (!feedback.options.properties) {
// TODO populate these properties instead
return {
Expand All @@ -666,6 +666,7 @@ export default class Controls {
const newStyle = {}

for (const prop of feedback.options.properties) {
// @ts-ignore
newStyle[prop] = render.style[prop]
}

Expand Down
4 changes: 2 additions & 2 deletions lib/Surface/Handler.js
Original file line number Diff line number Diff line change
Expand Up @@ -381,7 +381,7 @@ class SurfaceHandler extends CoreBase {
this.panelconfig.config.rotation
)

this.panel.drawColor(pageOffset, transformedX, transformedY, render.style?.bgcolor || 0)
this.panel.drawColor(pageOffset, transformedX, transformedY, render.bgcolor)
}
} else if (location.pageNumber == this.currentPage) {
// normal mode
Expand Down Expand Up @@ -581,7 +581,7 @@ class SurfaceHandler extends CoreBase {
this.panelconfig.config.rotation
)

this.panel.drawColor(page, transformedX, transformedY, render.style?.bgcolor || 0)
this.panel.drawColor(page, transformedX, transformedY, render.bgcolor)
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion lib/Surface/USB/LoupedeckCt.js
Original file line number Diff line number Diff line change
Expand Up @@ -467,7 +467,7 @@ class SurfaceUSBLoupedeckCt extends EventEmitter {
let color = { r: 0, g: 0, b: 0 }
if (render.style === 'pageup') color = { r: 255, g: 255, b: 255 }
else if (render.style === 'pagedown') color = { r: 0, g: 0, b: 255 }
else if (render.style) color = colorToRgb(render.style.bgcolor)
else if (render.style) color = colorToRgb(render.bgcolor)

this.#loupedeck
.setButtonColor({
Expand Down
2 changes: 1 addition & 1 deletion lib/Surface/USB/LoupedeckLive.js
Original file line number Diff line number Diff line change
Expand Up @@ -409,7 +409,7 @@ class SurfaceUSBLoupedeckLive extends EventEmitter {

const buttonIndex = this.#modelInfo.buttons.findIndex((btn) => btn[0] == x && btn[1] == y)
if (buttonIndex >= 0) {
const color = render.style ? colorToRgb(render.style.bgcolor) : { r: 0, g: 0, b: 0 }
const color = render.style ? colorToRgb(render.bgcolor) : { r: 0, g: 0, b: 0 }

this.#loupedeck
.setButtonColor({
Expand Down
2 changes: 1 addition & 1 deletion lib/Surface/USB/XKeys.js
Original file line number Diff line number Diff line change
Expand Up @@ -344,7 +344,7 @@ class SurfaceUSBXKeys extends EventEmitter {
if (x < 0 || y < 0 || x >= gridSize.columns || y >= gridSize.rows) return

const buttonIndex = x * gridSize.rows + y + 1
const color = render?.style?.bgcolor ?? 0
const color = render.bgcolor
this.#drawColorAtIndex(buttonIndex, color)
}

Expand Down

0 comments on commit 77a3cd4

Please sign in to comment.