Data commit
This commit is contained in:
parent
7387c8f97b
commit
cb5bb5e222
199093 changed files with 3378972 additions and 0 deletions
12
Task/Window-creation/Nim/window-creation-1.nim
Normal file
12
Task/Window-creation/Nim/window-creation-1.nim
Normal file
|
|
@ -0,0 +1,12 @@
|
|||
import gintro/[glib, gobject, gtk, gio]
|
||||
|
||||
proc activate(app: Application) =
|
||||
## Activate the application.
|
||||
let window = newApplicationWindow(app)
|
||||
window.setTitle("Window for Rosetta")
|
||||
window.setSizeRequest(640, 480)
|
||||
window.showAll()
|
||||
|
||||
let app = newApplication(Application, "Rosetta.Window")
|
||||
discard app.connect("activate", activate)
|
||||
discard app.run()
|
||||
47
Task/Window-creation/Nim/window-creation-2.nim
Normal file
47
Task/Window-creation/Nim/window-creation-2.nim
Normal file
|
|
@ -0,0 +1,47 @@
|
|||
import gdk2, glib2, gtk2
|
||||
|
||||
const
|
||||
Inside = "Mouse is over label"
|
||||
OutSide = "Mouse is not over label"
|
||||
|
||||
# Context transmitted to callback.
|
||||
type Context = object
|
||||
label: PLabel
|
||||
overButton: bool
|
||||
|
||||
|
||||
proc changeLabel(p: PWidget; event: gdk2.PEventCrossing; context: var Context) {.cdecl.} =
|
||||
context.label.set_text(if context.overButton: OutSide else: Inside)
|
||||
context.overButton = not context.overButton
|
||||
|
||||
proc thisDestroy(widget: PWidget, data: Pgpointer) {.cdecl.} =
|
||||
main_quit()
|
||||
|
||||
|
||||
var context: Context
|
||||
nim_init()
|
||||
|
||||
let window = window_new(gtk2.WINDOW_TOPLEVEL)
|
||||
let stackbox = vbox_new(true, 10)
|
||||
let button1 = button_new("Move mouse over button")
|
||||
let buttonstyle = copy(button1.get_style())
|
||||
buttonstyle.bg[STATE_PRELIGHT] = TColor(pixel: 0, red: 255, green: 0, blue: 0)
|
||||
button1.set_style(buttonstyle)
|
||||
let button2 = button_new()
|
||||
context = Context(label: label_new(Outside), overButton: false)
|
||||
let button3 = button_new("Quit")
|
||||
|
||||
button2.add(context.label)
|
||||
stackbox.pack_start(button1, true, true, 0)
|
||||
stackbox.pack_start(button2, true, true, 0)
|
||||
stackbox.pack_start(button3, true, true, 0)
|
||||
window.set_border_width(5)
|
||||
window.add(stackbox)
|
||||
|
||||
discard window.signal_connect("destroy", SIGNAL_FUNC(thisDestroy), nil)
|
||||
discard button1.signal_connect("enter_notify_event", SIGNAL_FUNC(changeLabel), addr(context))
|
||||
discard button1.signal_connect("leave_notify_event", SIGNAL_FUNC(changeLabel), addr(context))
|
||||
discard button3.signal_connect("clicked", SIGNAL_FUNC(thisDestroy), nil)
|
||||
|
||||
window.show_all()
|
||||
main()
|
||||
48
Task/Window-creation/Nim/window-creation-3.nim
Normal file
48
Task/Window-creation/Nim/window-creation-3.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()
|
||||
64
Task/Window-creation/Nim/window-creation-4.nim
Normal file
64
Task/Window-creation/Nim/window-creation-4.nim
Normal file
|
|
@ -0,0 +1,64 @@
|
|||
import x11/[xlib, xutil, x]
|
||||
|
||||
const
|
||||
WINDOW_WIDTH = 400
|
||||
WINDOW_HEIGHT = 300
|
||||
|
||||
type WindowData = tuple[display: PDisplay; window: Window]
|
||||
|
||||
proc createWindow: WindowData =
|
||||
let width: cuint = WINDOW_WIDTH
|
||||
let height: cuint = WINDOW_HEIGHT
|
||||
var sizeHints: XSizeHints
|
||||
|
||||
let display = XOpenDisplay(nil)
|
||||
if display == nil:
|
||||
echo "Connection to X server failed."
|
||||
quit QuitFailure
|
||||
|
||||
let screen = XDefaultScreen(display)
|
||||
var rootwin = XRootWindow(display, screen)
|
||||
let win = XCreateSimpleWindow(display, rootwin, 100, 10, width, height, 5,
|
||||
XBlackPixel(display, screen), XWhitePixel(display, screen))
|
||||
sizeHints.flags = PSize or PMinSize or PMaxSize
|
||||
sizeHints.min_width = width.cint
|
||||
sizeHints.max_width = width.cint
|
||||
sizeHints.min_height = height.cint
|
||||
sizeHints.max_height = height.cint
|
||||
discard XSetStandardProperties(
|
||||
display, win, "Simple Window", "window", 0, nil, 0, addr(sizeHints))
|
||||
discard XSelectInput(display, win, ButtonPressMask or KeyPressMask or PointerMotionMask)
|
||||
discard XMapWindow(display, win)
|
||||
result = (display, win)
|
||||
|
||||
proc closeWindow(data: WindowData) =
|
||||
discard XDestroyWindow(data.display, data.window)
|
||||
discard XCloseDisplay(data.display)
|
||||
|
||||
proc processEvent(xev: var XEvent) =
|
||||
var key: KeySym
|
||||
case xev.theType.int
|
||||
of KeyPress:
|
||||
key = XLookupKeysym(cast[ptr XKeyEvent](addr(xev)), 0)
|
||||
if key.int != 0:
|
||||
echo "keyboard event ", key.int
|
||||
if key.int == 65307: # <Esc>
|
||||
quit QuitSuccess
|
||||
of ButtonPressMask, PointerMotionMask:
|
||||
echo "Mouse event"
|
||||
else:
|
||||
discard
|
||||
|
||||
proc eventloop(data: WindowData) =
|
||||
var xev: XEvent
|
||||
discard XFlush(data.display)
|
||||
var numEvents = XPending(data.display).int
|
||||
while numEvents != 0:
|
||||
dec numEvents
|
||||
discard XNextEvent(data.display, addr(xev))
|
||||
processEvent(xev)
|
||||
|
||||
let windata = createWindow()
|
||||
while true:
|
||||
eventloop(windata)
|
||||
windata.closeWindow()
|
||||
13
Task/Window-creation/Nim/window-creation-5.nim
Normal file
13
Task/Window-creation/Nim/window-creation-5.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-6.nim
Normal file
9
Task/Window-creation/Nim/window-creation-6.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-7.nim
Normal file
24
Task/Window-creation/Nim/window-creation-7.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()
|
||||
18
Task/Window-creation/Nim/window-creation-8.nim
Normal file
18
Task/Window-creation/Nim/window-creation-8.nim
Normal file
|
|
@ -0,0 +1,18 @@
|
|||
import wx
|
||||
|
||||
{.experimental.}
|
||||
|
||||
const
|
||||
TITLE = "Rosetta Code - Window Creation Nim"
|
||||
WIDTH = 300
|
||||
HEIGHT = 300
|
||||
|
||||
let
|
||||
POSITION = construct_wxPoint(100,100)
|
||||
SIZE = construct_wxSize(WIDTH,HEIGHT)
|
||||
|
||||
let window = cnew construct_wxFrame(nil, wxID_ANY, TITLE, POSITION, SIZE)
|
||||
|
||||
window.show(true)
|
||||
|
||||
run_main_loop()
|
||||
Loading…
Add table
Add a link
Reference in a new issue