#:use-module (system foreign)
#:use-module (irrlicht base)
#:export (get-irrlicht-proc
- null-object?))
+ null-object?
+ remember-wrapped
+ mem-wrapped))
;; We use a hash table to store foreign irrlicht methods related with their
;; classes
proc))))
(define (null-object? object)
- (eq? (irr-pointer object) %null-pointer))
+ (null-pointer? (irr-pointer object)))
+
+;; Table for storing foreign irrlicht wrapped objects by its pointer address
+;; We can recover them later, when we have an address without knowing its type, like in
+;; events case
+(define wrapped-obj-table (make-hash-table))
+
+(define (remember-wrapped object)
+ (or (hash-ref wrapped-obj-table
+ (pointer-address (irr-pointer object)))
+ object))
+
+(define (mem-wrapped object)
+ (hash-set! wrapped-obj-table
+ (pointer-address (irr-pointer object))
+ object)
+ object)
(id -1)
(text "")
(tooltiptext ""))
- (let ((addButton (get-irrlicht-proc "addButton" gui-environment parent)))
- (addButton gui-environment rectangle parent id text tooltiptext))))
+ (let* ((addButton (get-irrlicht-proc "addButton" gui-environment parent))
+ (button (addButton gui-environment rectangle parent id text tooltiptext)))
+ (mem-wrapped button))))
(define-method (add-editbox! (gui-environment <gui-environment>) text rectangle . rest)
(let-keywords rest #f
((border #t)
(parent (make <gui-element>))
(id -1))
- (let ((addEditBox (get-irrlicht-proc "addEditBox" gui-environment parent)))
- (addEditBox gui-environment text rectangle border parent id))))
+ (let* ((addEditBox (get-irrlicht-proc "addEditBox" gui-environment parent))
+ (editbox (addEditBox gui-environment text rectangle border parent id)))
+ (mem-wrapped editbox))))
(define-method (add-image! (gui-environment <gui-environment>) image pos . rest)
(let-keywords rest #f
(parent (make <gui-element>))
(id -1)
(text ""))
- (let ((addImage (get-irrlicht-proc "addImage" gui-environment parent)))
- (addImage gui-environment image pos use-alpha-channel parent id text))))
+ (let* ((addImage (get-irrlicht-proc "addImage" gui-environment parent))
+ (img (addImage gui-environment image pos use-alpha-channel parent id text)))
+ (mem-wrapped img))))
(define-method (add-listbox! (gui-environment <gui-environment>) rectangle . rest)
(let-keywords rest #f
((parent (make <gui-element>))
(id -1)
(draw-background #f))
- (let ((addListBox (get-irrlicht-proc "addListBox" gui-environment parent)))
- (addListBox gui-environment rectangle parent id draw-background))))
+ (let* ((addListBox (get-irrlicht-proc "addListBox" gui-environment parent))
+ (listbox (addListBox gui-environment rectangle parent id draw-background)))
+ (mem-wrapped listbox))))
(define-method (add-scrollbar! (gui-environment <gui-environment>) horizontal rectangle . rest)
(let-keywords rest #f
((parent (make <gui-element>))
(id -1))
- (let ((addScrollBar (get-irrlicht-proc "addScrollBar" gui-environment parent)))
- (addScrollBar gui-environment horizontal rectangle parent id))))
+ (let* ((addScrollBar (get-irrlicht-proc "addScrollBar" gui-environment parent))
+ (scrollbar (addScrollBar gui-environment horizontal rectangle parent id)))
+ (mem-wrapped scrollbar))))
(define-method (add-static-text! (gui-environment <gui-environment>) text rectangle . rest)
(let-keywords rest #f
(parent (make <gui-element>))
(id -1)
(fill-background #f))
- (let ((addStaticText (get-irrlicht-proc "addStaticText" gui-environment parent)))
- (addStaticText gui-environment text rectangle border word-wrap parent
- id fill-background))))
+ (let* ((addStaticText (get-irrlicht-proc "addStaticText" gui-environment parent))
+ (static-text (addStaticText gui-environment text rectangle border word-wrap parent
+ id fill-background)))
+ (mem-wrapped static-text))))
(define-method (draw-all (gui-environment <gui-environment>))
((get-irrlicht-proc "drawAll" gui-environment)
(define-method (get-event-gui-caller (event <event>))
(let ((SGUIEvent_Caller (get-irrlicht-proc "SGUIEvent_Caller" event)))
- (SGUIEvent_Caller event)))
+ (remember-wrapped (SGUIEvent_Caller event))))
(define-method (get-event-gui-type (event <event>))
(let ((SGUIEvent_EventType (get-irrlicht-proc "SGUIEvent_EventType" event)))
using namespace irr;
+template <typename T>
SCM
IGUIElement_getID (SCM gui_element)
{
- gui::IGUIElement* element = (gui::IGUIElement*) scm_to_irr_pointer (gui_element);
+ T element = (T) scm_to_irr_pointer (gui_element);
return scm_from_int32 (element->getID ());
}
void
init_gui_element (void)
{
- DEFINE_GSUBR ("IGUIElement_getID", 1, 0, 0, IGUIElement_getID);
+ DEFINE_GSUBR ("IGUIButton_getID", 1, 0, 0, IGUIElement_getID<gui::IGUIButton*>);
+ DEFINE_GSUBR ("IGUIEditBox_getID", 1, 0, 0, IGUIElement_getID<gui::IGUIEditBox*>);
+ DEFINE_GSUBR ("IGUIElement_getID", 1, 0, 0, IGUIElement_getID<gui::IGUIElement*>);
+ DEFINE_GSUBR ("IGUIImage_getID", 1, 0, 0, IGUIElement_getID<gui::IGUIImage*>);
+ DEFINE_GSUBR ("IGUIListBox_getID", 1, 0, 0, IGUIElement_getID<gui::IGUIListBox*>);
+ DEFINE_GSUBR ("IGUIScrollBar_getID", 1, 0, 0, IGUIElement_getID<gui::IGUIScrollBar*>);
+ DEFINE_GSUBR ("IGUIStaticText_getID", 1, 0, 0, IGUIElement_getID<gui::IGUIStaticText*>);
}