;================================================================================= ; Xlib shapes drawing. ; ; The LSCR Project. ;================================================================================= format ELF include '../../macros.inc' include '../../../include/symbols.inc' include '../../../include/structs.inc' include '../../../include/x.inc' include '../../../include/x_structs.inc' public _start section '.text' executable _start: ccall XOpenDisplay, 0 ; connect to the X server test eax, eax je error mov [dpy], eax ccall XDefaultScreen, [dpy] ; obtain BLACK color value ccall XBlackPixel, [dpy], eax mov [color_black], eax ccall XDefaultScreen, [dpy] ; obtain WHITE color value ccall XWhitePixel, [dpy], eax mov [color_white], eax ccall XDefaultRootWindow, [dpy] ; create the window ccall XCreateSimpleWindow, [dpy], eax, 0, 0, 300, 300, 0, [color_black], [color_black] mov [win], eax ; register events. ccall XSelectInput, [dpy], [win], StructureNotifyMask or ButtonPressMask ccall XMapWindow, [dpy], [win] ; display the main window ccall XCreateGC, [dpy], [win], 0, 0 ; create a Graphics Context mov [gc], eax ccall XSetForeground, [dpy], [gc], [color_white] ; set foreground to WHITE color @@: ccall XNextEvent, [dpy], event ; we should wait for mapping to finish cmp [event], MapNotify ; prior to proceeding any further jne @b mov [text_items.chars], label_s ; draw a text string mov [text_items.nchars], label_s_sz ccall XDrawText, [dpy], [win], [gc], 5, 10, text_items, 1 ccall XDrawRectangle, [dpy], [win], [gc], 50, 50, 60, 80 ; draw rectangle ccall XDrawLine, [dpy], [win], [gc], 120, 100, 250, 230 ; draw line ccall XDrawArc, [dpy], [win], [gc], 100, 60, 220, 220, 180*64, 90*64 ; draw filled arc ccall XFillArc, [dpy], [win], [gc], 100, 60, 220, 220, 180*64, 90*64 @@: ccall XNextEvent, [dpy], event ; wait for a button click cmp [event], ButtonPress jne @b ccall XCloseDisplay, [dpy] ; close the display connection & destroy all windows exit: mov eax, SYS_EXIT xor ebx, ebx int 0x80 error: mov eax, SYS_WRITE mov ebx, STDOUT mov ecx, error_s mov edx, error_s_sz int 0x80 jmp exit section '.data' writeable dpy rd 1 event rd sizeof.XButtonEvent ; this actually should be an XEvent union color_black rd 1 color_white rd 1 win rd 1 gc rd 1 text_items XTextItem label_s db "To exit, click somewhere inside this window." label_s_sz = $-label_s error_s db "Failed to open a connection to the X server.",0xa error_s_sz = $-error_s