Skip to content

Commit 7cd3cae

Browse files
author
Your Name
committed
20190122
1 parent 88bd154 commit 7cd3cae

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

55 files changed

+1106
-525
lines changed

Drawing02_no.nim

+4-4
Original file line numberDiff line numberDiff line change
@@ -17,14 +17,14 @@ proc DrawCB (self: ptr Fl_Double_WindowEx): long{.cdecl.} =
1717
font: FL_FONT
1818

1919
DrawPushClip(0, 0, w, h)
20-
DrawRectFillRGBColor(0, 0, w, h, ubyte(rand(255)), ubyte(rand(255)), ubyte(rand(255)))
20+
DrawRectFillRGBColor(0, 0, w, h, rand(255), rand(255), rand(255))
2121
for font in 0 .. 15:
2222
size = long(6 + rand(70))
2323
DrawSetFont(cast[FL_FONT](font), size)
2424
for i in 0 .. 1:
25-
DrawSetRGBColor(ubyte(rand(255)), ubyte(rand(255)), ubyte(rand(255)))
26-
x = long(rand(int(w)))
27-
y = long(rand(int(h)))
25+
DrawSetRGBColor(rand(255), rand(255), rand(255))
26+
x = rand(int(w))
27+
y = rand(int(h))
2828
if i == 1 :
2929
DrawStr("DrawStr()", x, y)
3030
else:

Drawing03.nim

+10-9
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import fltk_main
99

1010
proc `\` (x: long; y: long): long = long(x.float / y.float)
1111

12+
1213
proc DrawMe(win: ptr Fl_Window) =
1314
var gfxPrimitive{.global.}: long = 0
1415
# select the window as curent drawing target
@@ -31,24 +32,24 @@ proc DrawMe(win: ptr Fl_Window) =
3132
i: int
3233

3334
for i in 1 .. 10:
34-
DrawSetRGBColor ubyte(rand(255)), ubyte(rand(255)), ubyte(rand(255))
35+
DrawSetRGBColor rand(255), rand(255), rand(255)
3536
case gfxPrimitive:
3637
of 0 :
37-
DrawPoint long(rand(w)), long(rand(h))
38+
DrawPoint rand(w), rand(h)
3839
of 1 :
39-
DrawLine long(rand(w)), long(rand(h)), long(rand(w)), long(rand(h))
40+
DrawLine rand(w), rand(h), rand(w), rand(h)
4041
of 2 :
41-
DrawRect long(rand(w)), long(rand(h)), long(rand(w)), long(rand(h))
42+
DrawRect rand(w), rand(h), rand(w), rand(h)
4243
of 3 :
43-
r = long(rand(h))\2
44-
DrawArc long(rand(w)), long(rand(h)), r, r, 0, 360 # circle
44+
r = rand(h)\2
45+
DrawArc rand(w), rand(h), r, r, 0, 360 # circle
4546
of 4 :
46-
DrawRectFill long(rand(w)), long(rand(h)), long(rand(w)), long(rand(h))
47+
DrawRectFill rand(w), rand(h), rand(w), rand(h)
4748
of 5 :
4849
var bt = FL_BOXTYPE(1 + rand(15))
49-
DrawBox bt, long(rand(w)), long(rand(h)), long(rand(w)), long(rand(h)), Fl_RGB_Color(ubyte(rand(255)), ubyte(rand(255)), ubyte(rand(255)))
50+
DrawBox bt, rand(w), rand(h), rand(w), rand(h), Fl_RGB_Color(rand(255), rand(255), rand(255))
5051
of 6 :
51-
DrawArc long(rand(w)), long(rand(h)), long(rand(w)), long(rand(h)), 0, 360 # oval
52+
DrawArc rand(w), rand(h), rand(w), rand(h), 0, 360 # oval
5253
else:
5354
discard
5455

Drawing04_no.nim

+4-4
Original file line numberDiff line numberDiff line change
@@ -72,11 +72,11 @@ proc SliderCB (self: ptr Fl_Widget, sld: ptr Fl_Hor_Value_Slider){.cdecl.}=
7272
# main
7373
#
7474
var win = Fl_Double_WindowNew(640, 480, "Drawing04.nim")
75-
#~ var box = Fl_BoxExNew(0, 0, 640, 430)
76-
var box = Fl_BoxNew(0, 0, 640, 430)
75+
var box = Fl_BoxExNew(0, 0, 640, 430)
76+
#~ var box = Fl_BoxNew(0, 0, 640, 430)
7777
var sld = Fl_Hor_Value_SliderNew(10, 430, 620, 30, "zoom")
78-
#~ Fl_BoxExSetDrawCB box, DrawCB
79-
Fl_BoxSetDrawCB box, DrawCB
78+
Fl_BoxExSetDrawCB box, DrawCB
79+
#~ Fl_BoxSetDrawCB box, DrawCB
8080
Fl_WidgetSetUserData box, sld
8181
Fl_WidgetSetCallbackArg sld, SliderCB, sld
8282
Fl_ValuatorBounds sld, 0.01, 3.0

Drawing05_no.nim

+2-2
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import fltk_main
22

33
#~ ' test of 8 bit palette drawing
44

5-
proc DrawCB (self: ptr any): long {.cdecl.} =
5+
proc DrawCB (self: pointer): long {.cdecl.} =
66
echo "DrawCB"
77
var x, y, z: long
88

@@ -19,7 +19,7 @@ proc DrawCB (self: ptr any): long {.cdecl.} =
1919
#~ '
2020
var win = Fl_WindowExNew(8*80,5*16,"Drawing05.nim")
2121
#~ var win = Fl_WindowNew(8*80,5*16,"Drawing05.nim")
22-
#~ Fl_WindowExSetDrawCB win, DrawCB
22+
Fl_WindowExSetDrawCB win, DrawCB
2323
#~ Fl_WindowSetDrawCB win, DrawCB
2424
Fl_WindowShow win
2525
Fl_Run()

DrawingAndSavingImage_no.nim

+2-2
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@ proc DrawCB(self: ptr Fl_Widget, SaveButton: ptr Fl_Button){. cdecl .}=
55
Fl_WindowMakeCurrent(Fl_WidgetWindow(self))
66
var i: int
77
for i in 1 .. 100:
8-
DrawSetRGBColor(ubyte(rand(256)), ubyte(rand(256)), ubyte(rand(256)))
9-
DrawLine((rand(128)), (rand(128)), (rand(128)), (rand(128)))
8+
DrawSetRGBColor(rand(256), rand(256), rand(256))
9+
DrawLine(rand(128), rand(128), rand(128), rand(128))
1010

1111
Fl_WidgetActivate SaveButton
1212

Fl_Align_Image_no.nim

+11-9
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,19 @@
1+
import fltk_main
2+
13
#include "fltk-c.bi"
24
#include "media/gradient_xpm.bi"
35

4-
' test of:
5-
' Fl_PixmapNew
6-
' FL_ALIGN_IMAGE_BACKDROP
6+
# test of:
7+
# Fl_PixmapNew
8+
# FL_ALIGN_IMAGE_BACKDROP
79

8-
var win = Fl_WindowNew(320,45,"FL_ALIGN_IMAGE_BACKDROP")
9-
var but1 = Fl_ButtonNew( 10, 10,140,25,"Button 1")
10-
var but2 = Fl_ButtonNew(160, 10,140,25,"Button 2")
11-
Fl_WidgetSetImage but1,Fl_PixmapNew(@gradient_xpm(0))
12-
Fl_WidgetSetAlign but1,FL_ALIGN_IMAGE_BACKDROP
10+
var win = Fl_WindowNew(320, 45, "FL_ALIGN_IMAGE_BACKDROP")
11+
var but1 = Fl_ButtonNew( 10, 10, 140, 25, "Button 1")
12+
var but2 = Fl_ButtonNew(160, 10, 140, 25, "Button 2")
13+
#~ Fl_WidgetSetImage but1, Fl_PixmapNew(@gradient_xpm(0))
14+
Fl_WidgetSetAlign but1, FL_ALIGN_IMAGE_BACKDROP
1315

1416
Fl_WindowShow win
15-
Fl_Run
17+
Fl_Run()
1618

1719

Fl_Boxtype01.nim

+1-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ const BOX_HEIGHT = 50
1111

1212
var i, row, col: int
1313

14-
var win = Fl_Double_WindowNew(long(6*10+5*BOX_WIDTH), long(12*10+11*BOX_HEIGHT), "Fl_Boxtype01.nim")
14+
var win = Fl_Double_WindowNew(6*10+5*BOX_WIDTH, 12*10+11*BOX_HEIGHT, "Fl_Boxtype01.nim")
1515
Fl_WidgetSetColor win,12
1616
for i in 0 .. 55:
1717
row = int(i / 5)

Fl_Clock02.nim

+3-3
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,11 @@ import fltk_c
66
proc `/`(x:long; y: long): long = long(x.float / y.float)
77

88
#~ ' centered window
9-
var win = Fl_Double_WindowNew2(Fl_GetW()/2-300,Fl_GetH()/2-150,600,300,"FL_CLOCK")
9+
var win = Fl_Double_WindowNew2(Fl_GetW()/2-300, Fl_GetH()/2-150, 600, 300,"FL_CLOCK")
1010
var w = Fl_WidgetGetW(win)/2
1111
var h = Fl_WidgetGetH(win)
12-
Fl_WidgetSetType Fl_ClockNew(0,0,w,h),FL_CLOCK_SQUARE
13-
Fl_WidgetSetType Fl_ClockNew(w,0,w,h),FL_CLOCK_ROUND
12+
Fl_WidgetSetType Fl_ClockNew(0, 0, w, h), FL_CLOCK_SQUARE
13+
Fl_WidgetSetType Fl_ClockNew(w, 0, w, h), FL_CLOCK_ROUND
1414

1515
Fl_WindowShow win
1616
Fl_Run()

Fl_CommonDialogs_no.nim

+2-2
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,9 @@ var
1212
file: string
1313
path:string
1414

15-
proc FileOrFolderCB (path: string){.cdecl.} =
15+
proc FileOrFolderCB (path: cstring){.cdecl.} =
1616
if len(path) != 0 :
17-
echo """FileChFileOrFolderCB("""" & path & """")"""
17+
echo """FileChFileOrFolderCB("""" & $path & """")"""
1818

1919

2020

Fl_File_Browser02_no.nim

+2-1
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,9 @@ else:
1717
const PATH = "$HOME"
1818

1919

20-
var UserPath: string
20+
var UserPath: cstring
2121
#~ UserPath = callocate(FL_MAX_PATH)
22+
#~ var UserPath: array[FL_MAX_PATH, char]
2223
flFilenameExpand(UserPath, FL_MAX_PATH, PATH)
2324

2425
proc BrowserCB (self: ptr FL_WIDGET, filebrowser: ptr Fl_File_Browser){.cdecl.}=

Fl_File_Icon03_modify.nim

+95
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,95 @@
1+
from winim import HIWORD, LOWORD
2+
import fltk_main
3+
4+
# test of:
5+
# icon = Fl_File_IconNew(patter, type, size, data)
6+
7+
# The Fl_File_Icon class is a container for vector graphics.
8+
# You can create and use your own vector images.
9+
10+
# bottom, left is the vertex position 0, 0
11+
# the center is the vertex position 5000, 5000
12+
# right , top is the vertex position 10000, 10000
13+
14+
#~ {. emit: """
15+
#~ #define DOP_COLOR(col) HIWORD(col), LOWORD(col)
16+
#~ """ .}
17+
18+
template DOP_COLOR(col: untyped):untyped=
19+
(HIWORD(col), LOWORD(col))
20+
21+
#~ template DOP_COLOR*(col: untyped): untyped =
22+
#~ HIWORD(col)
23+
#~ LOWORD(col)
24+
25+
var opcodes: array[0, short] = [
26+
FL_DOP_COLOR , HIWORD(FL_RED), LOWORD(FL_RED),
27+
FL_DOP_LINE ,
28+
FL_DOP_VERTEX, 0, 0,
29+
FL_DOP_VERTEX, 10000, 10000,
30+
FL_DOP_END ,
31+
FL_DOP_COLOR , FL_DATAOPCODE(HIWORD(FL_GREEN)), FL_DATAOPCODE(LOWORD(FL_GREEN)),
32+
FL_DOP_LINE ,
33+
FL_DOP_VERTEX, 0, 10000,
34+
FL_DOP_VERTEX, 10000, 0,
35+
FL_DOP_END ,
36+
FL_DOP_COLOR , FL_DATAOPCODE(HIWORD(FL_BLUE)), FL_DATAOPCODE(LOWORD(FL_BLUE)),
37+
FL_DOP_LINE ,
38+
FL_DOP_VERTEX, 0, 5000,
39+
FL_DOP_VERTEX, 10000, 5000,
40+
FL_DOP_END ,
41+
FL_DOP_COLOR , FL_DATAOPCODE(HIWORD(Fl_DARK_YELLOW)), FL_DATAOPCODE(LOWORD(Fl_DARK_YELLOW)),
42+
FL_DOP_POLYGON ,
43+
FL_DOP_VERTEX, 1000, 1000,
44+
FL_DOP_VERTEX, 1000, 9000,
45+
FL_DOP_VERTEX, 9000, 9000,
46+
FL_DOP_VERTEX, 9000, 1000,
47+
FL_DOP_VERTEX, 1000, 1000,
48+
# opposite direction = hole
49+
FL_DOP_VERTEX, 1500, 1500,
50+
FL_DOP_VERTEX, 8500, 1500,
51+
FL_DOP_VERTEX, 8500, 8500,
52+
FL_DOP_VERTEX, 1500, 8500,
53+
FL_DOP_VERTEX, 1500, 1500,
54+
FL_DOP_END
55+
] #]
56+
57+
proc ButtonCB (self: ptr Fl_Widget, btn: ptr any) {.cdecl.} =
58+
flMessageTitle "ButtonCB"
59+
flMessage "you pressed the button."
60+
61+
proc SliderCB cdecl (self: ptr Fl_Widget, sld: ptr any)
62+
var win = Fl_WidgetWindow(self)
63+
var btn = Fl_WidgetGetUserdata(win)
64+
var size = Fl_ValuatorGetValue(sld)
65+
Fl_WidgetResize btn, 256-size*0.5, 256-size*0.5, size, size
66+
Fl_WidgetRedraw win
67+
68+
#
69+
# main
70+
#
71+
Fl_SetScheme "plastic"
72+
Fl_SetScheme "gleam"
73+
# create icon by array of vector opcodes
74+
var icn = Fl_File_IconNew("", FL_FILEICON_ANY, high(opcodes), opcodes)
75+
var win = Fl_Double_WindowNew(512, 512+50, "Fl_File_Icon03.nim")
76+
Fl_WidgetSetColor win, Fl_RGB_Color(128, 128, 128)
77+
var btn = Fl_ButtonNew(0, 0, 512, 512)
78+
Fl_WidgetSetColor btn, Fl_RGB_Color(128, 128, 128)
79+
Fl_WidgetSetCallbackArg btn, ButtonCB, btn
80+
Fl_File_IconLabel icn, btn
81+
82+
Fl_WidgetSetUserdata win, btn
83+
84+
var sld = Fl_Hor_Value_SliderNew(10, 512, 492, 30, "scale")
85+
Fl_WidgetSetColor sld, Fl_RGB_Color(128, 128, 128)
86+
Fl_WidgetSetSelectionColor sld, Fl_RGB_Color(128, 128, 128)
87+
88+
Fl_WidgetSetCallbackArg sld, SliderCB, sld
89+
Fl_ValuatorBounds sld, 8, 512
90+
Fl_ValuatorSetValue sld, 256
91+
SliderCB sld, sld
92+
93+
94+
Fl_WindowShow win
95+
Fl_Run()

Fl_File_Icon03_no.nim

+4-2
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,12 @@ import fltk_main
1111
# the center is the vertex position 5000, 5000
1212
# right , top is the vertex position 10000, 10000
1313

14-
#define DOP_COLOR(col) HIWORD(col), LOWORD(col)
14+
#~ {. emit: """
15+
#~ #define DOP_COLOR(col) HIWORD(col), LOWORD(col)
16+
#~ """ .}
1517

1618
template DOP_COLOR(col: untyped):untyped=
17-
HIWORD(col), LOWORD(col)
19+
(HIWORD(col), LOWORD(col))
1820

1921
#~ template DOP_COLOR*(col: untyped): untyped =
2022
#~ HIWORD(col)

Fl_GetFirstWindow.nim

+1-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ proc rand(x: int64): long = rand(int(x))
1010

1111
proc CloseCB (self: ptr FL_WIDGET) {.cdecl.} =
1212
var win = Fl_GetFirstWindow()
13-
while cast[long](win) > 0 :
13+
while not win.isNil :
1414
Fl_WindowHide win
1515
win = Fl_GetFirstWindow()
1616
sleep 500

Fl_Group01_no.nim

+27
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
import fltk_main
2+
3+
proc InputCB(self: ptr Fl_Widget, me: ptr Fl_Input) {.cdecl.} =
4+
echo "InputCB: " & $Fl_Input_GetValue(me)
5+
6+
proc Fl_InputGridNew(parent : ptr Fl_Group,
7+
nCols : integer,
8+
nRows : integer,
9+
CellWidth : integer=64,
10+
CellHeight: integer=24) {.cdecl.} =
11+
var
12+
r, c: integer
13+
Fl_GroupBegin parent
14+
for r in 0 .. nRows-1:
15+
for c in 0 .. nCols-1:
16+
var ip = Fl_InputNew(c*CellWidth, r*CellHeight, CellWidth, CellHeight)
17+
Fl_Input_SetValue ip, "r: " & $r & " c:" & $c
18+
Fl_WidgetSetCallbackArg ip, InputCB, ip
19+
Fl_GroupAdd parent, ip
20+
Fl_GroupEnd parent
21+
22+
23+
var win = Fl_WindowNew(320,240,"A grid of Fl_Input wigets.")
24+
Fl_InputGridNew win,10, 12
25+
Fl_GroupSetResizable win,win
26+
Fl_WindowShow win
27+
Fl_Run()

0 commit comments

Comments
 (0)