-
Notifications
You must be signed in to change notification settings - Fork 2
/
main.lua
1652 lines (1477 loc) · 46.1 KB
/
main.lua
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
require "gooi"
require "AnAL"
require "palette"
require "animManager"
require "colorManager"
function width()
return love.graphics.getWidth()
end
function height()
return love.graphics.getHeight()
end
function love.load()
save_dir = love.filesystem.getSaveDirectory()
print("GÖÖi save directory: "..save_dir)
gr = love.graphics
kb = love.keyboard
mo = love.mouse
fs = love.filesystem
-----------------------------------------------
STATE_EDITING = 1
STATE_SAVING = 2
STATE_NEW = 3
STATE_OPENING = 4
STATE_OPTIONS = 5
state = STATE_EDITING
-----------------------------------------------
MOUSE_LEFT = 1
MOUSE_RIGHT = 2
MOUSE_MIDDLE = 3
-----------------------------------------------
states = {}-- For Ctrl + Z
indexStates = 1
timerCopied = 0
-----------------------------------------------
win = {}
win.smaller = function()
if width() < height() then return width() end
return height()
end
bgC1 = {31, 21, 10}
bgC2 = {22, 48, 0}
bgC3 = {18, 41, 54}
gr.setBackgroundColor(bgC1)
loadFrames()
imagesDir = "/images/"
bgImage1 = gr.newImage(imagesDir.."bgImage1.png")
bgImage2 = gr.newImage(imagesDir.."bgImage2.png")
bgImage3 = gr.newImage(imagesDir.."bgImage3.png")
bgDude1 = gr.newImage(imagesDir.."bgDude1.png")
bgDude2 = gr.newImage(imagesDir.."bgDude2.png")
bgDude3 = gr.newImage(imagesDir.."bgDude3.png")
imgAlpha = gr.newImage(imagesDir.."alpha.png")
imgStop = gr.newImage(imagesDir.."square.png")
imgSave = gr.newImage(imagesDir.."save.png")
imgSaveAs = gr.newImage(imagesDir.."saveAs.png")
imgFill = gr.newImage(imagesDir.."fill.png")
imgFill4 = gr.newImage(imagesDir.."fill4.png")
imgFill8 = gr.newImage(imagesDir.."fill8.png")
imgLeft = gr.newImage(imagesDir.."left.png")
imgRight = gr.newImage(imagesDir.."right.png")
imgAAArrow = gr.newImage(imagesDir.."aAarrow.png")
imgPalette1 = gr.newImage(imagesDir.."palette1.png")
imgPalette2 = gr.newImage(imagesDir.."palette2.png")
imgPalette3 = gr.newImage(imagesDir.."palette3.png")
imgContrast = gr.newImage(imagesDir.."contrast.png")
imgContrastSmall = gr.newImage(imagesDir.."contrastSmall.png")
bgDude1:setFilter("nearest", "nearest")
bgDude2:setFilter("nearest", "nearest")
bgDude3:setFilter("nearest", "nearest")
imgPalette1:setFilter("nearest", "nearest")
imgPalette2:setFilter("nearest", "nearest")
imgPalette3:setFilter("nearest", "nearest")
bgImage1:setWrap("repeat", "repeat")
bgImage2:setWrap("repeat", "repeat")
bgImage3:setWrap("repeat", "repeat")
------------------------------------------------------------------------
love.window.setIcon(love.image.newImageData(imagesDir.."icon.png"))
------------------------------------------------------------------------
setBoundsPixel()
setBoundsCanvas()
lineAnchor = nil
-----------------------------------------------
mirrorX = false
mirrorY = false
playing = false
animSaved = true
savedOnce = false
just_copied = false
-----------------------------------------------
fillMode = nil
brush = {}
brush.color = {0, 0, 0, 255}
colorIndicator = {0, 0, 0, 255}
currentFrameIndex = 1
aaDirection = 1-- Right.
aaRotation = 0
palette.change(1)
---------------------------------------------------------------------------
---------------------------------------------------------------------------
-- gooi:
---------------------------------------------------------------------------
---------------------------------------------------------------------------
font = gr.newFont("fonts/HussarPrintA.otf", 16)
fontLetter = gr.newFont(30)
style = {
font = font,
bgColor = "218AB8cc",
radius = 2,
innerRadius = 3,
showBorder = true
--mode3d = true,
--glass = true
}
gooi.setStyle(style)
debugFont = gr.newFont(width() / 70)
finalW, finalH = 0, 0
-- Edit gooi:
btnNew = gooi.newButton({icon = imagesDir.."new.png"}):setTooltip("Create a new animation")
btnOpen = gooi.newButton({icon = imagesDir.."open.png"}):setTooltip("Open an animation")
btnPlay = gooi.newButton({icon = imgRight}):bg("#00ff0088"):setTooltip("Play the animation")
btnSave = gooi.newButton({icon = imgSave}):setTooltip("Save current animation")
btnSaveAs = gooi.newButton("as.."):setTooltip("Save as...")
btnPrev = gooi.newButton({icon = imgLeft}):bg("#ff880088"):setTooltip("Change to the previous frame")
btnNext = gooi.newButton({icon = imgRight}):bg("#ff880088"):setTooltip("Change to the next frame")
btnDel = gooi.newButton({icon = imagesDir.."del.png"}):setTooltip("Deletes the last frame (Shift to delete current)")
btnAdd = gooi.newButton({icon = imagesDir.."add.png"}):setTooltip("Add a new frame (Shift to add in current position)")
chbLoop = gooi.newCheck("Loop"):change():bg("#FFFF0088"):setTooltip("Loop animation")
sliSpeed = gooi.newSlider(0.1):setTooltip("Delay in seconds for each frame"):setTooltip("Speed in seconds for each frame")
lblSpeed = gooi.newLabel("0.1"):setAlign("center")
chbGrid = gooi.newCheck("Grid"):change():setTooltip("Show/Hide grid")
btnMX = gooi.newButton({icon = imagesDir.."mX.png"}):bg("#88888888"):setTooltip("Mirror in X axis")
btnMY = gooi.newButton({icon = imagesDir.."mY.png"}):bg("#88888888"):setTooltip("Mirror in Y axis")
btnCopyL = gooi.newButton({icon = imagesDir.."copyL.png"}):setTooltip("Copy frame from the left")
btnCopyR = gooi.newButton({icon = imagesDir.."copyR.png"}):setTooltip("Copy frame from the left")
------------
spinAlpha = gooi.newSpinner(0, 255, 255):setTooltip("Alpha of picked color")
chbAA = gooi.newCheck("Autoanimate"):setTooltip("'Moves' the drawn pixels to the indicated direction, with the given step size")
btnAA = gooi.newButton(""):setTooltip("Direction of the autoanimation")
chbCyclic = gooi.newCheck("Turn"):bg("#ff880088"):setTooltip("Makes the pixels to 'return' from the opposite side")
spiStep = gooi.newSpinner(0, 5, 1):setTooltip("Step size for the autoanimation")
--lblInd = gooi.newLabel("255"):setAlign("center")
btnFill = gooi.newButton({icon = imgFill}):bg("#88888888"):setTooltip("Fill in 4 or 8 directions")
--[[
btnFS = gooi.newButton({icon = imagesDir.."fs.png"}):onRelease(function(c)
love.window.setFullscreen(not love.window.getFullscreen())
c.image = love.graphics.newImage(imagesDir.."fs.png")
if love.window.getFullscreen() then
c.image = love.graphics.newImage(imagesDir.."nofs.png")
end
--btnOptions:setBounds(width() - 60, 10, 50, 30)
--btnReturn:setBounds(width() - 120, height() - 40, 110, 30)
end
):bg({127, 0, 127, 127}):setTooltip("Fullscreen")
]]
--gooi.newButton("btnOptions", "", width() - 60, 10, 50, 30, imagesDir.."spanner.png", "editing").bgColor = {127, 0, 127, 127}
btnOptions = gooi.newButton({icon = imagesDir.."spanner.png"}):setTooltip("See options")
--gooi.newButton("btnQuit", "", width() - 60, 50, 50, 30, imagesDir.."quit.png", "editing").bgColor = {255, 0, 0, 127}
--btnQuit = gooi.newButton({icon = imagesDir.."quit.png"}):bg("#ff000088")
btnCopyCB = gooi.newButton("Copy SD", 110, height() - 30, 110, 25):onRelease(function(c)
c:setText("Copied!"):bg("#FF880088")
just_copied = true
love.system.setClipboardText(lblCopySD.text)
end):setGroup("editing")
lblCopySD = gooi.newLabel(save_dir, 230, height() - 30, width() - 235, 25):setGroup("editing"):setAlign("left")
:setOpaque(true):bg("#000000BB")
-- Put them in the panel:
panelEdit = gooi.newPanel(3, 3, 100, 550, "grid 16x2")
:setColspan(2, 1, 2)-- Play
:setColspan(6, 1, 2)
:setColspan(7, 1, 2)
:setColspan(8, 1, 2)
:setColspan(9, 1, 2)
:setColspan(12, 1, 2)
:add(
btnNew,
btnOpen,
btnPlay,
btnSave,
btnSaveAs,
btnPrev,
btnNext,
btnDel,
btnAdd,
chbLoop,
sliSpeed,
lblSpeed,
chbGrid,
btnMX,
btnMY,
btnCopyL,
btnCopyR,
btnCopyCB
):setGroup("editing")
panelEdit2 = gooi.newPanel(510, 3, 400, 70, "grid 2x8")
panelEdit2.layout.debug = false
panelEdit2
:setColspan(1, 1, 4)-- Autoanimate
:setColspan(1, 5, 2)-- Turn
:setColspan(2, 1, 3)-- Alpha
:setColspan(2, 5, 2)-- Step
--[[
:setColspan(1, 1, 2)-- 255
:setColspan(1, 3, 4)-- Autoanimate
:setColspan(1, 7, 2)-- Turn
:setColspan(2, 1, 3)-- Slider alpha
:setColspan(2, 4, 2)-- Step
:setColspan(2, 6, 2)-- Fill
:add(
--lblInd,
chbAA,
chbCyclic,
btnAA,
--btnChangePalette,
--spiStep,
btnFill,
spinAlpha
--btnFS,
--btnOptions
)
]]
:add(
chbAA,
chbCyclic,
btnAA,
btnOptions,
spinAlpha,
btnFill,
spiStep
)
:setGroup("editing")
--panelEdit2.layout.debug = true
radiosPalette = {
gooi.newRadio(" ", "g_palettes"):onRelease(function(c)
palette.change(1)
brush.color = palette.getColor(palette.xColor, palette.yColor)
end):select(),
gooi.newRadio(" ", "g_palettes"):onRelease(function(c)
palette.change(2)
brush.color = palette.getColor(palette.xColor, palette.yColor)
end),
gooi.newRadio(" ", "g_palettes"):onRelease(function(c)
palette.change(3)
brush.color = palette.getColor(palette.xColor, palette.yColor)
end)
}
panelPalettes = gooi.newPanel(435, 3, 70, 70, "grid 3x1"):add(
radiosPalette[1],
radiosPalette[2],
radiosPalette[3]):setGroup("editing")
local function getColor(c)
if shiftDown() then
local bg = {brush.color[1], brush.color[2], brush.color[3], brush.color[4] or 255}
c:bg(bg)
c.hasColor = true
c.showBorder = true
else
if c.hasColor then
brush.color = {c.bgColor[1], c.bgColor[2], c.bgColor[3], c.bgColor[4] or 255}
spinAlpha.bg(brush.color)
end
end
end
local ttfc = "Shift + click to pick, normal click to use"
radioPicked1 = gooi.newRadio(" ", "grp_frequent"):bg("#888888"):onRelease(getColor):setTooltip(ttfc)
radioPicked2 = gooi.newRadio(" ", "grp_frequent"):bg("#888888"):onRelease(getColor):setTooltip(ttfc)
radioPicked3 = gooi.newRadio(" ", "grp_frequent"):bg("#888888"):onRelease(getColor):setTooltip(ttfc)
radioPicked4 = gooi.newRadio(" ", "grp_frequent"):bg("#888888"):onRelease(getColor):setTooltip(ttfc)
radioPicked5 = gooi.newRadio(" ", "grp_frequent"):bg("#888888"):onRelease(getColor):setTooltip(ttfc)
radioPicked6 = gooi.newRadio(" ", "grp_frequent"):bg("#888888"):onRelease(getColor):setTooltip(ttfc)
radioPicked1:border(3).showBorder = false
radioPicked2:border(3).showBorder = false
radioPicked3:border(3).showBorder = false
radioPicked4:border(3).showBorder = false
radioPicked5:border(3).showBorder = false
radioPicked6:border(3).showBorder = false
panelColors = gooi.newPanel(103, 3, 70, 70, "grid 3x2"):add(
radioPicked1,
radioPicked2,
radioPicked3,
radioPicked4,
radioPicked5,
radioPicked6
):setGroup("editing")
--panelColors.layout.debug = true
btnAA:bg({0, 255, 0, 127})
btnAA:setEnabled(false)
chbCyclic:setEnabled(false)
spiStep:setEnabled(false)
--palette.changeSquare()
-- Saving gooi:
sliderSave = gooi.newSlider(0, 50, 50, 600, 30):setGroup("saving")
btnCancelSave = gooi.newButton("Cancel", width() - 220, height() - 40, 100, 30):setGroup("saving"):bg("#ff000088")
btnConfirmSave = gooi.newButton("Save", width() - 110, height() - 40, 100, 30):setGroup("saving")
lblName = gooi.newLabel("Name:", width() - 540, height() - 40, 100, 30):setGroup("saving")
textName = gooi.newText("new.png", width() - 430, height() - 40, 200, 30):setGroup("saving")
-- New animation gooi:
gooi.newLabel ("Width:", 420, 440, 120, 30):setGroup("new")
gooi.newLabel ("Height:",420, 480, 120, 30):setGroup("new")
lblFrameNum = gooi.newLabel("Frames", 420, 520, 120, 30):setGroup("new")
spiNewW = gooi.newSpinner(1, 32, 16, 540, 440, 120, 30):setGroup("new")
spiNewH = gooi.newSpinner(1, 32, 16, 540, 480, 120, 30):setGroup("new")
spiFramesNum = gooi.newSpinner(1, 50, 10, 540, 520, 120, 30):setGroup("new")
--textNameNew = gooi.newText("", width() - 450, height() - 40, 220, 30):setGroup("new")
btnCancelNew = gooi.newButton("Cancel", width() - 220, height() - 40, 100, 30):setGroup("new"):bg("#ff000088")
btnOkNew = gooi.newButton("OK", width() - 110, height() - 40, 100, 30):setGroup("new")
--gooi.get("btnCancelNew").bgColor = {255, 0, 0, 127}
-- Options gooi:
radTheme1 = gooi.newRadio("Theme 1", "grpTheme", 50, 50, 150, 30):setGroup("options")
radTheme2 = gooi.newRadio("Theme 2", "grpTheme", 50, 90, 150, 30):setGroup("options"):select()
radTheme3 = gooi.newRadio("Theme 3", "grpTheme", 50, 130, 150, 30):setGroup("options")
btnReturn = gooi.newButton("Return", width() - 110, height() - 40, 100, 30):setGroup("options")
radBg1 = gooi.newRadio("Background 1", "grpBG", 220, 50, 200, 30):setGroup("options"):select()
radBg2 = gooi.newRadio("Background 2", "grpBG", 220, 90, 200, 30):setGroup("options")
radBg3 = gooi.newRadio("Background 3", "grpBG", 220, 130, 200, 30):setGroup("options")
chbAutosave = gooi.newCheck("Save animation when playing", 50, 170, 370, 30):setGroup("options"):change()
-- Open gooi:
btnOpenThis = gooi.newButton("Open this", width() - 110, height() - 40, 100, 30):setGroup("opening")
btnCancelOpen = gooi.newButton("Cancel", width() - 220, height() - 40, 100, 30):setGroup("opening"):bg("#ff000088")
availableAnims = {}
gooi.setGroupEnabled("saving", false)
gooi.setGroupEnabled("opening", false)
gooi.setGroupEnabled("new", false)
gooi.setGroupEnabled("options", false)
---------------------------------------------------------------------------
---------------------------------------------------------------------------
-- Events:
---------------------------------------------------------------------------
---------------------------------------------------------------------------
local function checkAutoAnim()
btnAA:setEnabled(chbAA.checked)
chbCyclic:setEnabled(chbAA.checked)
spiStep:setEnabled(chbAA.checked)
end
local function returnFromOpening()
gooi.setGroupEnabled("open", false)
gooi.setGroupEnabled("new", false)
gooi.setGroupEnabled("options", false)
gooi.setGroupEnabled("editing", true)
btnAA:setEnabled(chbAA.checked)
chbCyclic:setEnabled(chbAA.checked)
checkAutoAnim()
state = STATE_EDITING
end
function playOrStop(c)
playing = not playing
c:bg({0, 255, 0, 127})
c.icon = imgRight
currentFrameIndex = 1
analAnim:reset()
if playing then
analAnim:play()
c:bg({255, 0, 0, 127})
c.icon = imgStop
end
end
function callSave(c)
gooi.setGroupEnabled("saving", true)
gooi.setGroupVisible("saving", true)
gooi.setGroupEnabled("editing", false)
state = STATE_SAVING
end
function performSave(c)
--print(finalW, finalH)
imgAnalAnim, info = animManager.saveAnimation(textName.text, frames, finalW, finalH)
local millis = sliSpeed.value
analAnim = newAnimation(imgAnalAnim, info.fW, info.fH, millis, #frames)
gooi.setGroupEnabled("saving", false)
gooi.setGroupEnabled("editing", true)
checkAutoAnim()
btnSave:setEnabled(false)
animSaved = true
savedOnce = true
state = STATE_EDITING
end
function setFillMode4(c)
fillMode = "4"
c:bg({255, 127, 0, 127})
c.icon = imgFill4
end
function setFillMode8(c)
fillMode = "8"
c:bg({255, 255, 0, 127})
c.icon = imgFill8
end
function setNoFillMode(c)
fillMode = nil
c:bg({127, 127, 127, 127})
c.icon = imgFill
end
btnCopyL:onRelease(function(c) copyPrevious() end)
btnCopyR:onRelease(function(c) copyNext() end)
btnPrev:onRelease(function(c) frameLeft() end)
btnNext:onRelease(function(c) frameRight() end)
btnPlay:onRelease(function(c)
playOrStop(c)
--print(tostring(chbAutosave.checked))
if chbAutosave.checked then
--if animSaved then
performSave()
--end
end
end)
chbLoop:onRelease(function(c)
analAnim.mode = 1
if not c.checked then
analAnim.mode = 2
end
end)
btnSave:onRelease(function(c)
if savedOnce then
performSave(c)
else
callSave(c)
end
end)
btnSaveAs:onRelease(function(c)
callSave(c)
end)
btnDel:onRelease(function(c)
deleteFrame()
notifyNotSaved()
end)
btnAdd:onRelease(function(c)
addNewFrame()
notifyNotSaved()
end)
btnNew:onRelease(function(c)
gooi.setGroupEnabled("new", true)
gooi.setGroupEnabled("saving", true)
gooi.setGroupEnabled("editing", false)
lblName:setVisible(false)
textName:setVisible(false)
btnCancelSave:setVisible(false)
btnConfirmSave:setVisible(false)
state = STATE_NEW
end)
btnOpen:onRelease(function(c)
gooi.setGroupEnabled("editing", false)
gooi.setGroupEnabled("opening", true)
availableAnims = animManager.loadAvailable()
btnOpenThis:setEnabled(not (#availableAnims == 0))
state = STATE_OPENING
end)
btnCancelSave:onRelease(function(c)
gooi.setGroupEnabled("saving", false)
gooi.setGroupEnabled("editing", true)
checkAutoAnim()
state = STATE_EDITING
end)
btnCancelOpen:onRelease(function(c)
returnFromOpening()
end)
btnOpenThis:onRelease(function(c)
setOpenedAnim()
returnFromOpening()
end)
btnConfirmSave:onRelease(function(c)
performSave(c)
end)
-- Mirrors:
btnMX:onRelease(function(c)
mirrorX = not mirrorX
c:bg({127, 127, 127, 127})
if mirrorX then
c:bg({0, 255, 0, 127})
end
end)
btnMY:onRelease(function(c)
mirrorY = not mirrorY
c:bg({127, 127, 127, 127})
if mirrorY then
c:bg({0, 255, 0, 127})
end
end)
btnCancelNew:onRelease(function(c)
gooi.setGroupEnabled("new", false)
gooi.setGroupEnabled("saving", false)
gooi.setGroupEnabled("editing", true)
checkAutoAnim()
state = STATE_EDITING
end)
btnOkNew:onRelease(function(c)
setNewAnim(spiFramesNum.value, spiNewW.value, spiNewH.value)
checkAutoAnim()
state = STATE_EDITING
savedOnce = false
end)
btnAA:onRelease(function(c)
local sense = 1
if shiftDown() then sense = -1 end
aaRotation = aaRotation + 45 * sense
aaDirection = aaDirection + 1 * sense
if aaRotation >= 360 then aaRotation = 0 end
if aaDirection > 8 then aaDirection = 1 end
if aaDirection < 1 then aaDirection = 8 end
end)
chbAA:onRelease(function(c)
checkAutoAnim()
end)
btnReturn:onRelease(function(c)
gooi.setGroupEnabled("options", false)
gooi.setGroupEnabled("editing", true)
checkAutoAnim()
state = STATE_EDITING
end)
btnFill:onRelease(function(c)
if not fillMode then
setFillMode4(c)
elseif fillMode == "4" then
setFillMode8(c)
elseif fillMode == "8" then
setNoFillMode(c)
end
end)
--[[
btnChangePalette:onRelease(function(c)
palette.change()
c.label = "Palette "..palette.which
brush.color = palette.getColor(palette.xColor, palette.yColor)
c:bg({r(), r(), r(), 127})
end)
]]
btnOptions:onRelease(function(c)
gooi.setGroupEnabled("editing", false)
gooi.setGroupEnabled("options", true)
state = STATE_OPTIONS
end)
--btnQuit:onRelease(function(c) exit() end)
-- Load first "ctrl+z" state:
table.insert(states, {
frame = copyCurrent()
})
btnSave:setEnabled(false)
gooi.desktopMode()
end
---------------------------------------------------------------------------
---------------------------------------------------------------------------
-- love.update()
---------------------------------------------------------------------------
---------------------------------------------------------------------------
function love.update(dt)
gooi.update(dt)
if state == STATE_EDITING then
if mo.isDown(MOUSE_LEFT) and not gooi.showingDialog then
setPixel(mo.getX(), mo.getY(), brush.color, true)
updateAnchor(mo.getPosition())
end
spinAlpha:bg(brush.color)
local a = math.floor(spinAlpha.value)
spinAlpha.bgColor[4] = a
--lblInd.text = tostring(a)
lblCopySD:setVisible(btnCopyCB:overIt())
local btn = btnSave
btn.image = imgSave
if shiftDown() then
btn.image = imgSaveAs
end
if just_copied then
timerCopied = timerCopied + dt
if timerCopied >= 1 then
timerCopied = 0
just_copied = false
btnCopyCB:setText("Copy SD"):bg(component.style.bgColor)
end
end
-- Update color picked:
if palette.mouseInside() then
if mo.isDown(MOUSE_LEFT) then
palette.pressed = true
palette.changeSquare(mo.getX(), mo.getY())
brush.color = palette.getColor()
end
elseif palette.pressed then
local x = mo.getX()
local y = mo.getY()
if x >= palette.x + palette.w() then
x = palette.x + palette.w() - palette.scale()
end
if x <= palette.x then x = palette.x end
if y >= palette.y + palette.h() then
y = palette.y + palette.h() - palette.scale()
end
if y <= palette.y then y = palette.y end
palette.changeSquare(x, y)
brush.color = palette.getColor(palette.xColor, palette.yColor)
end
-- Update color indicator:
for i = 1, 3 do
colorIndicator[i] = colorIndicator[i] - 500 * dt
if colorIndicator[i] < 0 then colorIndicator[i] = 255 end
end
-- Update canvas position:
if mo.isDown(MOUSE_MIDDLE) and not gooi.showingDialog then
xCanvas = mo.getX() - dispCX
yCanvas = mo.getY() - dispCY
end
-- Update analAnim:
if playing then
analAnim:update(dt)
currentFrameIndex = analAnim.position
if not analAnim.playing then
playOrStop(btnPlay)
end
end
-- Animation:
analAnim:setFramesDelay(sliSpeed.value)
lblSpeed:setText(string.sub(tostring(sliSpeed.value), 0, 4))
elseif state == STATE_SAVING then
elseif state == STATE_OPENING then
end
end
---------------------------------------------------------------------------
---------------------------------------------------------------------------
-- love.draw()
---------------------------------------------------------------------------
---------------------------------------------------------------------------
function love.draw()
-- Background dude:
gr.setColor(255, 255, 255)
if radTheme1.selected then
gr.setBackgroundColor(bgC1)
gr.draw(bgDude1, 135, height() - bgDude1:getHeight() * 30, 0, 30, 30)
elseif radTheme2.selected then
gr.setBackgroundColor(bgC2)
gr.draw(bgDude2, 400, 200, 0, 20, 20)
elseif radTheme3.selected then
gr.setBackgroundColor(bgC3)
gr.draw(bgDude3, width() - bgDude3:getWidth() * 16, 0, 0, 16, 16)
end
if v then gr.print("file saved", 10, 70) end
if state == STATE_EDITING then
drawCurrentFrame()
-- Grid:
if chbGrid.checked then
gr.setLineStyle("rough")
gr.setColor(127, 127, 127, 150)
for i = 1, w - 1 do-- Vertical lines:
gr.line(xCanvas + i * pS, yCanvas, xCanvas + i * pS, yCanvas + h * pS - 1)
end
for i = 1, h - 1 do-- Horizonal:
gr.line(xCanvas, yCanvas + i * pS - 1, xCanvas + w * pS - 1, yCanvas + i * pS)
end
gr.setLineStyle("smooth")
end
-- Mirror lines:
gr.setColor(0, 255, 0)
if mirrorX then
gr.line(xCanvas + w * pS / 2, yCanvas, xCanvas + w * pS / 2, yCanvas + h * pS)
end
if mirrorY then
gr.line(xCanvas, yCanvas + h * pS / 2, xCanvas + w * pS, yCanvas + h * pS / 2)
end
-- Cursor:
local x, y = getFixedPosition(mo.getPosition())
if insideCanvas(mo.getPosition()) then
gr.setColor(127, 127, 127, 127)
gr.rectangle("fill", xCanvas + ((x - 1) * pS), yCanvas + ((y - 1) * pS), pS, pS)
gr.rectangle("fill", xCanvas + ((x - 1) * pS) + pS / 4, yCanvas + ((y - 1) * pS) + pS / 4, pS / 2, pS / 2)
end
-- Line (if drawing a rect):
if lineAnchor and shiftDown() and insideCanvas(mo.getPosition()) then
local cF = frames[currentFrameIndex]
bresenham(lineAnchor[1], lineAnchor[2],
x, y, #cF[1], #cF, cF, {127, 127, 127, 127}, true)
end
-------------------------------
local p = palette
-------------------------------
gr.setColor(12, 183, 242)
--gr.rectangle("line", p.x - 1, p.y - 1, p.w() + 2, p.h() + 2)
-- Toolbar margin:
gr.setColor(0, 0, 0, 180)
gr.rectangle("fill", 0, 0, width(), tbUpLimit)
gr.rectangle("fill", 0, tbUpLimit, tbLeftLimit, height() - tbUpLimit)
-- Contrast images:
gr.setColor(255, 255, 255)
gr.draw(imgContrast, spinAlpha.x, spinAlpha.y)
gr.draw(imgContrastSmall, 106, 7)
gr.draw(imgContrastSmall, 141, 7)
gr.draw(imgContrastSmall, 106, 30)
gr.draw(imgContrastSmall, 141, 30)
gr.draw(imgContrastSmall, 106, 53)
gr.draw(imgContrastSmall, 141, 53)
gr.setColor(6, 96, 128)
-- Palette:
gr.setColor(255, 255, 255)
gr.draw(p.img(), p.x, p.y, 0, p.scale(), p.scale())
-- Little indicator:
gr.setLineStyle("rough")
gr.setColor(colorIndicator)
gr.rectangle("line", p.xColor, p.yColor, p.scale(), p.scale())
gr.setLineStyle("smooth")
-- Autoanimation:
local btn = btnAA
-- Mini map:
if w * pS > width() or h * pS > height() then
gr.setLineStyle("rough")
local mmPS = 4
local mmX = width() - w * mmPS - 30
local mmY = height() - h * mmPS - 30
gr.setColor(0, 0, 0, 127)
gr.rectangle("fill", mmX, mmY, w * mmPS, h * mmPS)
gr.setColor(colorIndicator)
gr.rectangle("line", mmX, mmY, w * mmPS + 1, h * mmPS + 1)
-- frame of the animation:
gr.setColor(255, 255, 255, 255)
gr.draw(analAnim.img, analAnim.frames[currentFrameIndex], mmX, mmY, 0, mmPS, mmPS)
local xMask = mmX - (mmPS * xCanvas / pS)
local yMask = mmY - (mmPS * yCanvas / pS)
local wMask = (w * mmPS) * width() / (w * pS)
local hMask = (h * mmPS) * height() / (h * pS)
gr.setColor(colorIndicator)
gr.rectangle("line", xMask, yMask, wMask, hMask)
end
gr.setColor(255, 255, 255)
-- Frame indicator:
prevFont = gr.getFont()
gr.setFont(fontLetter)
local wFontLetter = fontLetter:getWidth(""..currentFrameIndex) + 10
local hFontLetter = fontLetter:getHeight()
gr.setColor(255, 255, 255)
gr.print(currentFrameIndex.."/"..#frames, 10, height() - hFontLetter)
gr.setFont(prevFont)
---------------------------------------------
---------------------------------------------
gooi.draw("editing")
---------------------------------------------
---------------------------------------------
gr.setColor(255, 255, 255)
if not chbAA.checked then
gr.setColor(127, 127, 127)
end
gr.draw(imgAAArrow, btn.x + btn.w / 2, btn.y + btn.h / 2,
math.rad(aaRotation), 1, 1, imgAAArrow:getWidth() / 2, imgAAArrow:getHeight() / 2)
gr.setColor(255, 0, 0)
-- Palette radios:
gr.setColor(255, 255, 255)
if gooi.showingDialog then
gr.setColor(127, 127, 127)
end
gr.draw(imgPalette1, 460, 11, 0, 1, 1)
gr.draw(imgPalette2, 460, 34, 0, 4, 4)
gr.draw(imgPalette3, 460, 57, 0, 4, 4)
elseif state == STATE_SAVING then
gooi.draw("saving")
drawMatrixFrame()
elseif state == STATE_NEW then
gooi.draw("saving")
gooi.draw("new")
drawMatrixFrame()
elseif state == STATE_OPENING then
gooi.draw("opening")
gr.print("Your animations:", 10, 10)
local prevFont = gr.getFont()
gr.setFont(gooi.getFont())
gr.setLineStyle("smooth")
for i = 1, #availableAnims do
local item = availableAnims[i]
gr.setColor(12, 183, 242, 127)
local w, h = 200, 25
if item.selected then
gr.rectangle("fill",
item.x,
item.y,
w,
h, 10, 10)
end
gr.rectangle("line",
item.x,
item.y,
w,
h, 10, 10)
gr.setColor(255, 255, 255)
gr.print(item.name,
math.floor(item.x + w / 2 - gooi.getFont():getWidth(item.name) / 2),
math.floor(item.y + h / 2 - gooi.getFont():getHeight() / 2))
end
gr.setFont(prevFont)
elseif state == STATE_OPTIONS then
gr.print("Select a theme:", radTheme1.x, 10)
gr.print("Anim background:", radBg1.x, 10)
gr.draw(sBgImage(), 450, 32)
gooi.draw("options")
end
gr.setColor(255, 255, 255)
--gr.print(aaDirection, 200,200)
gr.setFont(debugFont)
local fpsText = "FPS: "..love.timer.getFPS()
gr.print(fpsText, width() - debugFont:getWidth(fpsText), height() - debugFont:getHeight())
--gr.print("dispCX: "..dispCX..", dispCY: "..dispCY, 0, height() - debugFont:getHeight() * 2)
end
----------------------------------------------------------------------------------------------------------
----------------------------------------------------------------------------------------------------------
----------------------------------------------------------------------------------------------------------
function drawCurrentFrame()
gr.setLineWidth(1)
gr.setCanvas(bgC)
gr.clear(0, 0, 0, 1)
-- Draw background for the canvas:
gr.draw(
sBgImage(),
gr.newQuad(
xCanvas,
yCanvas,
w * pS,
h * pS,
sBgImage():getWidth(),
sBgImage():getHeight()
)
)
gr.setCanvas()
gr.setColor(255, 255, 255)
gr.draw(bgC, xCanvas, yCanvas)
gr.setColor(255, 255, 255)
-- Draw AnAL animation or grid of pixels:
if playing then
analAnim:draw(xCanvas, yCanvas, 0, pS, pS)
else
local f = frames[currentFrameIndex]
for i = 1, #f do
for j = 1, #f[i] do
local n, m = 0, 0
if i == #f then m = 1 end
if j == #f[i] then n = 1 end
local p = f[i][j]
gr.setColor(p.color)
gr.rectangle("fill",
(xCanvas) + (j - 1) * pS,
(yCanvas) + (i - 1) * pS, pS - n, pS - m)
end
end
end
end
function sBgImage()
if radBg1.selected then return bgImage1 end
if radBg2.selected then return bgImage2 end
if radBg3.selected then return bgImage3 end
end
function drawMatrixFrame()
-- Draw matrix of frames:
local theW, theH = w, h
local theFNumber = #frames
if state == STATE_NEW then
theW, theH = spiNewW.value, spiNewH.value
theFNumber = spiFramesNum.value
end
local smaller, scale = theW, 1
--[[if theH < theW then smaller = theH end
if smaller <= 16 then
scale = 2
if smaller <= 8 then
scale = 4
if smaller <= 4 then
scale = 8
end
end
end]]
local s = sliderSave
local widthDesired = s.value * (s.w - s.h)
local xDisp, yDisp = 0, 0
local x0, y0, indexX, indexY = s.x + s.h / 2, s.y + s.h * 2, 1, 1
local nW, nH = 1, 1
for i = 1, theFNumber do
if xDisp > (widthDesired) / scale then
xDisp, indexX = 0, 0
yDisp = yDisp + theH
indexY = indexY + 1
nH = nH + 1
else
indexX = indexX + 1
if indexX > nW then nW = indexX - 1 end
end
gr.setColor(12, 183, 242)
if (indexX + indexY) % 2 == 0 then gr.setColor(12, 183, 242, 127) end
gr.rectangle("fill", x0 + xDisp * scale, y0 + yDisp * scale, theW * scale, theH * scale)
xDisp = xDisp + theW
end
finalW = nW
finalH = nH
gr.setColor(0, 63, 63)
local t = finalW.." x "..finalH
local x = x0 + finalW * theW * scale / 2 - gooi.getFont():getWidth(t) / 2
local y = y0 + finalH * theH * scale / 2 - gooi.getFont():getHeight() / 2
--gr.print(t, x - gooi.getFont():getHeight() / 12, y - gooi.getFont():getHeight() / 12)
gr.print(t, x0 - gooi.getFont():getHeight() / 12, y0 - 20 - gooi.getFont():getHeight() / 12)
gr.setColor(255, 255, 255)
--gr.print(t, x, y)
gr.print(t, x0, y0 - 20)
gr.setLineWidth(win.smaller() / 300)
gr.rectangle("line", x0, y0, finalW * theW * scale, finalH * theH * scale)
end
function setOpenedAnim()
currentFrameIndex = 1
frames, imgAnalAnim, info, finalW, finalH = animManager.openAnimation(animManager.getSelectedItem().name)
loadFrames(frames, imgAnalAnim, info)
setBoundsPixel()
setBoundsCanvas()
analAnim.mode = 1
if not chbLoop.checked then
analAnim.mode = 2
end
end
function setNewAnim(n, theW, theH)
currentFrameIndex = 1
frames = animManager.createFrames(n, theW, theH)
h = #frames[1]
w = #frames[1][1]