-
Notifications
You must be signed in to change notification settings - Fork 1
/
DrawingAndSavingImage_no.nim
56 lines (46 loc) · 1.75 KB
/
DrawingAndSavingImage_no.nim
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
import random, posix, os
import fltk_main
proc DrawCB(self: ptr Fl_Widget, SaveButton: pointer){. cdecl .}=
Fl_WindowMakeCurrent(Fl_WidgetWindow(self))
var i: int
for i in 1 .. 100:
DrawSetRGBColor(rand(256), rand(256), rand(256))
DrawLine(rand(128), rand(128), rand(128), rand(128))
Fl_WidgetActivate SaveButton
proc SaveCB(self: ptr Fl_Widget, LoadButton: pointer){. cdecl .}=
Fl_WindowMakeCurrent(Fl_WidgetWindow(self))
#~ ScreenRes 128, 128, 32, , -1
#~ var p: ptr ubyte = ImageCreate(128, 128)
#~ var pixels: ptr ubyte = p+32
#~ DrawReadImage pixels, 0, 0, 128, 128, 255
#~ # BGRA->RGBA
#~ var i: int
#~ for i in 0 .. 128*128-1:
#~ var tmp: ptr ubyte = pixels[i*4+0]
#~ pixels[i*4+0]=pixels[i*4+2]
#~ pixels[i*4+2]=tmp
#~ bsave "media/temp.bmp", p
#~ ImageDestroy p
#~ Screen 0
Fl_WidgetActivate LoadButton
proc LoadCB(self: ptr Fl_Widget, RightBox: pointer){. cdecl .}=
Fl_WidgetSetImage RightBox, Fl_BMP_ImageNew("media/temp.bmp")
Fl_WidgetRedraw RightBox
#
# main
#
discard chdir getAppDir()
var MainWindow = Fl_WindowNew(128 * 3, 128, "")
var LeftBox = Fl_BoxNew( 0, 0, 128, 128)
var RightBox = Fl_BoxNew(256, 0, 128, 128)
var DrawButton = Fl_ButtonNew(128 + 32, 10 , 64, 24, "Draw")
var SaveButton = Fl_ButtonNew(128 + 32, 10 + 32, 64, 24, "Save")
var LoadButton = Fl_ButtonNew(128 + 32, 10 + 64, 64, 24, "Load")
Fl_WidgetSetImage LeftBox, Fl_BMP_ImageNew("media/renata.bmp")
Fl_WidgetSetCallbackArg(DrawButton, DrawCB, SaveButton)
Fl_WidgetSetCallbackArg(SaveButton, SaveCB, LoadButton)
Fl_WidgetSetCallbackArg(LoadButton, LoadCB, RightBox)
Fl_WidgetDeactivate SaveButton
Fl_WidgetDeactivate LoadButton
Fl_WindowShow MainWindow
Fl_Run()