Add tasks for all the new languages
This commit is contained in:
parent
9dc3c2bb62
commit
bba7bfd280
13208 changed files with 134745 additions and 0 deletions
52
Task/Window-creation/Nim/window-creation-1.nim
Normal file
52
Task/Window-creation/Nim/window-creation-1.nim
Normal file
|
|
@ -0,0 +1,52 @@
|
|||
import
|
||||
gdk2, glib2, gtk2
|
||||
|
||||
proc thisDestroy(widget: pWidget, data: pgpointer){.cdecl.} =
|
||||
main_quit()
|
||||
|
||||
const
|
||||
Inside: cstring = "Mouse is over label"
|
||||
OutSide: cstring = "Mouse is not over label"
|
||||
|
||||
var
|
||||
OverButton: bool
|
||||
|
||||
nim_init()
|
||||
var window = window_new(gtk2.WINDOW_TOPLEVEL)
|
||||
var stackbox = vbox_new(TRUE, 10)
|
||||
var button1 = button_new("Move mouse over button")
|
||||
var buttonstyle = copy(get_style(Button1))
|
||||
ButtonStyle.bg[STATE_PRELIGHT].pixel = 0
|
||||
ButtonStyle.bg[STATE_PRELIGHT].red = -1'i16
|
||||
ButtonStyle.bg[STATE_PRELIGHT].blue = 0'i16
|
||||
ButtonStyle.bg[STATE_PRELIGHT].green = 0'i16
|
||||
set_style(button1, buttonstyle)
|
||||
var button2 = button_new()
|
||||
var ALabel = label_new(Outside)
|
||||
var button3 = button_new("Quit")
|
||||
|
||||
|
||||
proc ChangeLabel(P: PWidget, Event: gdk2.PEventCrossing,
|
||||
Data: var bool){.cdecl.} =
|
||||
if Not Data: set_text(ALabel, Inside)
|
||||
else: set_text(ALabel, Outside)
|
||||
Data = Not Data
|
||||
|
||||
|
||||
add(button2, ALAbel)
|
||||
pack_start(stackbox, button1, TRUE, TRUE, 0)
|
||||
pack_start(stackbox, button2, TRUE, TRUE, 0)
|
||||
pack_start(stackbox, button3, TRUE, TRUE, 0)
|
||||
set_border_width(Window, 5)
|
||||
add(window, stackbox)
|
||||
discard signal_connect(window, "destroy",
|
||||
SIGNAL_FUNC(thisDestroy), nil)
|
||||
overbutton = False
|
||||
discard signal_connect(button1, "enter_notify_event",
|
||||
SIGNAL_FUNC(ChangeLabel), addr(OverButton))
|
||||
discard signal_connect(button1, "leave_notify_event",
|
||||
SIGNAL_FUNC(ChangeLabel), addr(OverButton))
|
||||
discard signal_connect(button3, "clicked",
|
||||
SIGNAL_FUNC(thisDestroy), nil)
|
||||
show_all(window)
|
||||
main()
|
||||
48
Task/Window-creation/Nim/window-creation-2.nim
Normal file
48
Task/Window-creation/Nim/window-creation-2.nim
Normal file
|
|
@ -0,0 +1,48 @@
|
|||
import
|
||||
sdl, sdl_image, colors
|
||||
|
||||
var
|
||||
screen, greeting: PSurface
|
||||
r: TRect
|
||||
event: TEvent
|
||||
bgColor = colChocolate.int32
|
||||
|
||||
if init(INIT_VIDEO) != 0:
|
||||
quit "SDL failed to initialize!"
|
||||
|
||||
screen = SetVideoMode(640, 480, 16, SWSURFACE or ANYFORMAT)
|
||||
if screen.isNil:
|
||||
quit($sdl.getError())
|
||||
|
||||
greeting = IMG_load("tux.png")
|
||||
if greeting.isNil:
|
||||
echo "Failed to load tux.png"
|
||||
else:
|
||||
## convert the image to alpha and free the old one
|
||||
var s = greeting.displayFormatAlpha()
|
||||
swap(greeting, s)
|
||||
s.freeSurface()
|
||||
|
||||
r.x = 0
|
||||
r.y = 0
|
||||
|
||||
block game_loop:
|
||||
while true:
|
||||
|
||||
while pollEvent(addr event) > 0:
|
||||
case event.kind
|
||||
of QUITEV:
|
||||
break game_loop
|
||||
of KEYDOWN:
|
||||
if EvKeyboard(addr event).keysym.sym == K_ESCAPE:
|
||||
break game_loop
|
||||
else:
|
||||
discard
|
||||
|
||||
discard fillRect(screen, nil, bgColor)
|
||||
discard blitSurface(greeting, nil, screen, addr r)
|
||||
discard flip(screen)
|
||||
|
||||
greeting.freeSurface()
|
||||
screen.freeSurface()
|
||||
sdl.Quit()
|
||||
73
Task/Window-creation/Nim/window-creation-3.nim
Normal file
73
Task/Window-creation/Nim/window-creation-3.nim
Normal file
|
|
@ -0,0 +1,73 @@
|
|||
import xlib, xutil, x, keysym
|
||||
|
||||
const
|
||||
WINDOW_WIDTH = 400
|
||||
WINDOW_HEIGHT = 300
|
||||
|
||||
var
|
||||
width, height: cuint
|
||||
display: PDisplay
|
||||
screen: cint
|
||||
depth: int
|
||||
win: TWindow
|
||||
sizeHints: TXSizeHints
|
||||
|
||||
proc create_window =
|
||||
width = WINDOW_WIDTH
|
||||
height = WINDOW_HEIGHT
|
||||
|
||||
display = XOpenDisplay(nil)
|
||||
if display == nil:
|
||||
echo("Verbindung zum X-Server fehlgeschlagen")
|
||||
quit(1)
|
||||
|
||||
screen = XDefaultScreen(display)
|
||||
depth = XDefaultDepth(display, screen)
|
||||
var rootwin = XRootWindow(display, screen)
|
||||
win = XCreateSimpleWindow(display, rootwin, 100, 10,
|
||||
width, height, 5,
|
||||
XBlackPixel(display, screen),
|
||||
XWhitePixel(display, screen))
|
||||
size_hints.flags = PSize or PMinSize or PMaxSize
|
||||
size_hints.min_width = width.cint
|
||||
size_hints.max_width = width.cint
|
||||
size_hints.min_height = height.cint
|
||||
size_hints.max_height = height.cint
|
||||
discard XSetStandardProperties(display, win, "Simple Window", "window",
|
||||
0, nil, 0, addr(size_hints))
|
||||
discard XSelectInput(display, win, ButtonPressMask or KeyPressMask or
|
||||
PointerMotionMask)
|
||||
discard XMapWindow(display, win)
|
||||
|
||||
proc close_window =
|
||||
discard XDestroyWindow(display, win)
|
||||
discard XCloseDisplay(display)
|
||||
|
||||
var
|
||||
xev: TXEvent
|
||||
|
||||
proc process_event =
|
||||
var key: TKeySym
|
||||
case int(xev.theType)
|
||||
of KeyPress:
|
||||
key = XLookupKeysym(cast[ptr TXKeyEvent](addr(xev)), 0)
|
||||
if key.int != 0:
|
||||
echo("keyboard event",$key.int)
|
||||
if key.int == 65307: # <Esc>
|
||||
quit(1)
|
||||
of ButtonPressMask, PointerMotionMask:
|
||||
Echo("Mouse event")
|
||||
else: nil
|
||||
|
||||
proc eventloop =
|
||||
discard XFlush(display)
|
||||
var num_events = int(XPending(display))
|
||||
while num_events != 0:
|
||||
dec(num_events)
|
||||
discard XNextEvent(display, addr(xev))
|
||||
process_event()
|
||||
|
||||
create_window()
|
||||
while true:
|
||||
eventloop()
|
||||
close_window()
|
||||
13
Task/Window-creation/Nim/window-creation-4.nim
Normal file
13
Task/Window-creation/Nim/window-creation-4.nim
Normal file
|
|
@ -0,0 +1,13 @@
|
|||
import glut
|
||||
|
||||
var win: int = 0
|
||||
|
||||
proc myOnKeyPress(c: int8, v1, v2: cint) {.cdecl.} =
|
||||
echo(c)
|
||||
if c == 27:
|
||||
glutDestroyWindow(win)
|
||||
|
||||
glutInit()
|
||||
win = glutCreateWindow("Goodbye, World!")
|
||||
glutKeyboardFunc(TGlut1Char2IntCallback(myOnKeyPress))
|
||||
glutMainLoop()
|
||||
9
Task/Window-creation/Nim/window-creation-5.nim
Normal file
9
Task/Window-creation/Nim/window-creation-5.nim
Normal file
|
|
@ -0,0 +1,9 @@
|
|||
# test a Windows GUI application
|
||||
|
||||
import
|
||||
windows, shellapi, nb30, mmsystem, shfolder
|
||||
|
||||
#proc MessageBox(hWnd: int, lpText, lpCaption: CString, uType: uint): int
|
||||
# {stdcall, import: "MessageBox", header: "<windows.h>"}
|
||||
|
||||
discard MessageBox(0, "Hello World!", "Nim GUI Application", 0)
|
||||
24
Task/Window-creation/Nim/window-creation-6.nim
Normal file
24
Task/Window-creation/Nim/window-creation-6.nim
Normal file
|
|
@ -0,0 +1,24 @@
|
|||
import iup
|
||||
|
||||
# assumes you have the iup .dll or .so installed
|
||||
|
||||
discard iup.open(nil,nil)
|
||||
|
||||
|
||||
# now use a Dialog box to show a message
|
||||
var lbl = label("Hello World")
|
||||
setAttribute(lbl,"PADDING","10x10")
|
||||
|
||||
var contents = hbox(lbl, nil)
|
||||
#SetAttribute(contents, "MARGIN", "5x5")
|
||||
|
||||
var dlg = dialog(contents)
|
||||
#SetAttribute(dlg, "SIZE", "100x50")
|
||||
|
||||
discard dlg.show()
|
||||
|
||||
# a window via a quick message box, sitting on top of the main dialog window
|
||||
discard Alarm("MyTitle","Hello World","Ok", "Not Ok", nil)
|
||||
|
||||
discard mainloop()
|
||||
iup.close()
|
||||
Loading…
Add table
Add a link
Reference in a new issue