@@ -2,51 +2,71 @@ package api
22
33import (
44 "image"
5+ "math"
56 "time"
67)
78
89type LcdBackgrounder interface {
910 GetTouchPanelBackground () string
1011 GetTouchPanelBackgroundBuff () []image.Image
1112 SetTouchPanelBackgroundBuff (img []image.Image )
12- GetTouchPanelBackgroundHandler () TouchPanelBackgroundHandler
13- SetTouchPanelBackgroundHandler (handler TouchPanelBackgroundHandler )
13+ GetTouchPanelBackgroundHandler () BackgroundHandler
14+ SetTouchPanelBackgroundHandler (handler BackgroundHandler )
1415 GetTouchPanelBackgroundHandlerFields () map [string ]any
1516}
1617
1718type KeyGridBackgrounder interface {
1819 GetKeyGridBackground () string
1920 GetKeyGridBackgroundBuff () []image.Image
2021 SetKeyGridBackgroundBuff (img []image.Image )
21- GetKeyGridBackgroundHandler () KeyGridBackgroundHandler
22- SetKeyGridBackgroundHandler (handler KeyGridBackgroundHandler )
22+ GetKeyGridBackgroundHandler () BackgroundHandler
23+ SetKeyGridBackgroundHandler (handler BackgroundHandler )
2324 GetKeyGridBackgroundHandlerFields () map [string ]any
2425}
2526
27+ type InputActions interface {
28+ GetSwitchPage () int
29+ GetKeyBind () string
30+ GetCommand () string
31+ GetBrightness () int
32+ GetUrl () string
33+ GetObsCommand () string
34+ GetObsCommandParams () map [string ]string
35+ }
36+
37+ type ForegroundActions interface {
38+ GetIcon () string
39+ GetText () string
40+ GetTextSize () int
41+ GetTextAlignment () VerticalAlignment
42+ GetFontFace () string
43+ GetTextColour () string
44+ }
45+
2646type ConfigV3 struct {
2747 Modules []string `json:"modules,omitempty"`
2848 Decks []DeckV3 `json:"decks"`
2949 ObsConnectionInfo ObsConnectionInfoV2 `json:"obs_connection_info,omitempty"`
3050}
3151
3252type DeckV3 struct {
33- Serial string `json:"serial"`
34- Pages []PageV3 `json:"pages"`
35- TouchPanelBackground string `json:"touch_panel_background"`
36- TouchPanelBackgroundBuff []image.Image `json:"-"`
37- TouchPanelBackgroundHandler TouchPanelBackgroundHandler `json:"-"`
38- TouchPanelBackgroundHandlerFields map [string ]any `json:"touch_panel_background_handler_fields"`
39- KeyGridBackground string `json:"key_grid_background"`
40- KeyGridBackgroundBuff []image.Image `json:"-"`
41- KeyGridBackgroundHandler KeyGridBackgroundHandler `json:"-"`
42- KeyGridBackgroundHandlerFields map [string ]any `json:"key_grid_background_handler_fields"`
43- }
44-
45- func (d * DeckV3 ) SetTouchPanelBackgroundHandler (handler TouchPanelBackgroundHandler ) {
53+ Serial string `json:"serial"`
54+ Pages []PageV3 `json:"pages"`
55+ TouchPanelBackground string `json:"touch_panel_background"`
56+ TouchPanelBackgroundBuff []image.Image `json:"-"`
57+ TouchPanelBackgroundHandler BackgroundHandler `json:"-"`
58+ TouchPanelBackgroundHandlerFields map [string ]any `json:"touch_panel_background_handler_fields"`
59+ KeyGridBackground string `json:"key_grid_background"`
60+ KeyGridBackgroundBuff []image.Image `json:"-"`
61+ KeyGridBackgroundHandler BackgroundHandler `json:"-"`
62+ KeyGridBackgroundHandlerFields map [string ]any `json:"key_grid_background_handler_fields"`
63+ }
64+
65+ func (d * DeckV3 ) SetTouchPanelBackgroundHandler (handler BackgroundHandler ) {
4666 d .TouchPanelBackgroundHandler = handler
4767}
4868
49- func (d * DeckV3 ) GetTouchPanelBackgroundHandler () TouchPanelBackgroundHandler {
69+ func (d * DeckV3 ) GetTouchPanelBackgroundHandler () BackgroundHandler {
5070 return d .TouchPanelBackgroundHandler
5171}
5272
@@ -78,11 +98,11 @@ func (d *DeckV3) SetKeyGridBackgroundBuff(img []image.Image) {
7898 d .KeyGridBackgroundBuff = img
7999}
80100
81- func (d * DeckV3 ) SetKeyGridBackgroundHandler (handler KeyGridBackgroundHandler ) {
101+ func (d * DeckV3 ) SetKeyGridBackgroundHandler (handler BackgroundHandler ) {
82102 d .KeyGridBackgroundHandler = handler
83103}
84104
85- func (d * DeckV3 ) GetKeyGridBackgroundHandler () KeyGridBackgroundHandler {
105+ func (d * DeckV3 ) GetKeyGridBackgroundHandler () BackgroundHandler {
86106 return d .KeyGridBackgroundHandler
87107}
88108
@@ -91,23 +111,23 @@ func (d *DeckV3) GetKeyGridBackgroundHandlerFields() map[string]any {
91111}
92112
93113type PageV3 struct {
94- Keys []KeyV3 `json:"keys"`
95- Knobs []KnobV3 `json:"knobs"`
96- TouchPanelBackground string `json:"touch_panel_background"`
97- TouchPanelBackgroundBuff []image.Image `json:"-"`
98- TouchPanelBackgroundHandler TouchPanelBackgroundHandler `json:"-"`
99- TouchPanelBackgroundHandlerFields map [string ]any `json:"touch_panel_background_handler_fields"`
100- KeyGridBackground string `json:"key_grid_background"`
101- KeyGridBackgroundBuff []image.Image `json:"-"`
102- KeyGridBackgroundHandler KeyGridBackgroundHandler `json:"-"`
103- KeyGridBackgroundHandlerFields map [string ]any `json:"key_grid_background_handler_fields"`
104- }
105-
106- func (p * PageV3 ) SetTouchPanelBackgroundHandler (handler TouchPanelBackgroundHandler ) {
114+ Keys []KeyV3 `json:"keys"`
115+ Knobs []KnobV3 `json:"knobs"`
116+ TouchPanelBackground string `json:"touch_panel_background"`
117+ TouchPanelBackgroundBuff []image.Image `json:"-"`
118+ TouchPanelBackgroundHandler BackgroundHandler `json:"-"`
119+ TouchPanelBackgroundHandlerFields map [string ]any `json:"touch_panel_background_handler_fields"`
120+ KeyGridBackground string `json:"key_grid_background"`
121+ KeyGridBackgroundBuff []image.Image `json:"-"`
122+ KeyGridBackgroundHandler BackgroundHandler `json:"-"`
123+ KeyGridBackgroundHandlerFields map [string ]any `json:"key_grid_background_handler_fields"`
124+ }
125+
126+ func (p * PageV3 ) SetTouchPanelBackgroundHandler (handler BackgroundHandler ) {
107127 p .TouchPanelBackgroundHandler = handler
108128}
109129
110- func (p * PageV3 ) GetTouchPanelBackgroundHandler () TouchPanelBackgroundHandler {
130+ func (p * PageV3 ) GetTouchPanelBackgroundHandler () BackgroundHandler {
111131 return p .TouchPanelBackgroundHandler
112132}
113133
@@ -139,11 +159,11 @@ func (p *PageV3) SetKeyGridBackgroundBuff(img []image.Image) {
139159 p .KeyGridBackgroundBuff = img
140160}
141161
142- func (p * PageV3 ) SetKeyGridBackgroundHandler (handler KeyGridBackgroundHandler ) {
162+ func (p * PageV3 ) SetKeyGridBackgroundHandler (handler BackgroundHandler ) {
143163 p .KeyGridBackgroundHandler = handler
144164}
145165
146- func (p * PageV3 ) GetKeyGridBackgroundHandler () KeyGridBackgroundHandler {
166+ func (p * PageV3 ) GetKeyGridBackgroundHandler () BackgroundHandler {
147167 return p .KeyGridBackgroundHandler
148168}
149169
@@ -152,21 +172,66 @@ func (p *PageV3) GetKeyGridBackgroundHandlerFields() map[string]any {
152172}
153173
154174type StreamDeckInfoV1 struct {
155- Cols int `json:"cols,omitempty"`
156- Rows int `json:"rows,omitempty"`
157- IconSize int `json:"icon_size,omitempty"`
158- Page int `json:"page"`
159- Serial string `json:"serial,omitempty"`
160- Name string `json:"name,omitempty"`
161- Connected bool `json:"connected"`
162- LastConnected time.Time `json:"last_connected,omitempty"`
163- LastDisconnected time.Time `json:"last_disconnected,omitempty"`
164- LcdWidth int `json:"lcd_width,omitempty"`
165- LcdHeight int `json:"lcd_height,omitempty"`
166- LcdCols int `json:"lcd_cols,omitempty"`
167- KnobCols int `json:"knob_cols,omitempty"`
168- PaddingX int `json:"padding_x"`
169- PaddingY int `json:"padding_y"`
175+ Cols int `json:"cols,omitempty"`
176+ Rows int `json:"rows,omitempty"`
177+ IconSize int `json:"icon_size,omitempty"`
178+ Page int `json:"page"`
179+ Serial string `json:"serial,omitempty"`
180+ Name string `json:"name,omitempty"`
181+ Connected bool `json:"connected"`
182+ LastConnected time.Time `json:"last_connected,omitempty"`
183+ LastDisconnected time.Time `json:"last_disconnected,omitempty"`
184+ LcdWidth int `json:"lcd_width,omitempty"`
185+ LcdHeight int `json:"lcd_height,omitempty"`
186+ LcdCols int `json:"lcd_cols,omitempty"`
187+ KnobCols int `json:"knob_cols,omitempty"`
188+ PaddingX int `json:"padding_x"`
189+ PaddingY int `json:"padding_y"`
190+ KeyGridBackgroundWidth int `json:"key_grid_background_width"`
191+ KeyGridBackgroundHeight int `json:"key_grid_background_height"`
192+ LcdBackgroundWidth int `json:"lcd_background_width"`
193+ LcdBackgroundHeight int `json:"lcd_background_height"`
194+ }
195+
196+ func (info StreamDeckInfoV1 ) GetDimensions (handlerType HandlerType ) (int , int ) {
197+ if handlerType == LCD {
198+ return info .LcdWidth , info .LcdHeight
199+ }
200+ return info .IconSize , info .IconSize
201+ }
202+
203+ func (info StreamDeckInfoV1 ) GetGridDimensions (handlerType HandlerType ) (int , int ) {
204+ if handlerType == LCD {
205+ return info .LcdBackgroundWidth , info .LcdBackgroundHeight
206+ }
207+ return info .KeyGridBackgroundWidth , info .KeyGridBackgroundHeight
208+ }
209+
210+ func (info StreamDeckInfoV1 ) SplitBackgroundImage (background image.Image , handlerType HandlerType ) []image.Image {
211+ var frameArr []image.Image
212+
213+ if handlerType == KEY {
214+ for keyIndex := range info .Cols * info .Rows {
215+ keyX := keyIndex % info .Cols
216+ keyY := int (math .Floor (float64 (keyIndex ) / float64 (info .Cols )))
217+
218+ x0 , y0 := keyX * (info .IconSize + info .PaddingX ), keyY * (info .IconSize + info .PaddingY )
219+ x1 , y1 := keyX * (info .IconSize + info .PaddingX )+ info .IconSize , keyY * (info .IconSize + info .PaddingY )+ info .IconSize
220+
221+ frameArr = append (frameArr , SubImage (background , x0 , y0 , x1 , y1 ))
222+ }
223+ } else {
224+ for lcdIndex := range info .LcdCols {
225+ x0 , y0 := info .LcdWidth * lcdIndex , 0
226+ x1 , y1 := info .LcdWidth * (lcdIndex + 1 ), info .LcdHeight
227+
228+ subImage := SubImage (background , x0 , y0 , x1 , y1 )
229+
230+ frameArr = append (frameArr , subImage )
231+ }
232+ }
233+
234+ return frameArr
170235}
171236
172237type ObsConnectionInfoV2 struct {
0 commit comments