Index: main/panel.lisp
===================================================================
--- main/panel.lisp	(revision main,16)
+++ main/panel.lisp	(revision main,16)
@@ -0,0 +1,82 @@
+(defpackage #:panel
+  (:documentation
+   "Panels should be considered the fundamental division of a screen.
+Doing so allows for overlapping regions to be painted correctly.")
+  (:use #:cl #:cffi)
+  (:export #:create-panel #:update-panels #:do-update #:redraw-panels
+           #:client-window #:destroy-panel #:with-panel))
+
+(in-package #:panel)
+
+
+
+(define-foreign-library panel
+  (:unix "libpanel.so"))
+
+(use-foreign-library panel)
+
+
+
+(defcfun "new_panel" :pointer
+  (window :pointer))
+
+(defcfun "update_panels" :void)
+
+(defcfun ("doupdate" do-update) :int)
+
+(defcfun "touchwin" :int
+  (window :pointer))
+
+(defcfun "del_panel" :int
+  (panel :pointer))
+
+(defcfun "panel_above" :pointer
+  (panel :pointer))
+
+(defcfun "panel_window" :pointer
+  (panel :pointer))
+
+
+
+(defclass panel ()
+  ((panel-ptr :initarg :panel-ptr)))
+
+
+
+(defun create-panel (height width y x)
+  "Creates a new panel.  Associates a client window with it, covering
+the entire panel."
+  (let* ((window (cdk::c-new-window height width y x))
+         (panel-ptr (new-panel window)))
+    (make-instance 'panel :panel-ptr panel-ptr)))
+
+(defmethod client-window ((panel panel))
+  "Returns the client window associated with the panel."
+  (with-slots (panel-ptr) panel
+    (panel-window panel-ptr)))
+
+(defun redraw-panels ()
+  "Forces all panels to be completely redrawn to the screen.  This is
+necessary when a panel is removed, or maybe when the order of panels
+is changed."
+  (do ((panel-ptr (panel-above (null-pointer)) (panel-above panel-ptr)))
+      ((null-pointer-p panel-ptr))
+    (touchwin (panel-window panel-ptr)))
+  (update-panels)
+  (do-update))
+
+(defun destroy-panel (panel)
+  "Destroys a panel and insures that the screen is correct."
+  (let ((window (client-window panel)))
+    (with-slots (panel-ptr) panel
+      (del-panel panel-ptr))
+    (cdk::c-delete-window window))
+  (redraw-panels))
+
+
+
+(defmacro with-panel ((var height width y x) &body body)
+  `(let ((,var (create-panel ,height ,width ,y ,x)))
+     (unwind-protect
+          (progn ,@body)
+       (destroy-panel ,var))))
Index: main/tui.asd
===================================================================
--- main/tui.asd	(revision main,14)
+++ main/tui.asd	(revision main,16)
@@ -5,4 +5,5 @@
   :components (#|(:file "curses")|#
                (:file "cdk")
+               (:file "panel")
                (:file "input")
                (:file "flat-menu"))
