diff mde/gui/WidgetManager.d @ 146:783969f4665c

Simple, inefficient context menus (displaying content description).
author Diggory Hardy <diggory.hardy@gmail.com>
date Wed, 11 Feb 2009 12:00:12 +0000
parents 66c58e5b0062
children 075705ad664a
line wrap: on
line diff
--- a/mde/gui/WidgetManager.d	Tue Feb 10 13:10:53 2009 +0000
+++ b/mde/gui/WidgetManager.d	Wed Feb 11 12:00:12 2009 +0000
@@ -329,15 +329,30 @@
     override void menuDone () {}
     
     override IChildWidget getPopupWidget (wdabs cx, wdabs cy, bool closePopup) {
-        IChildWidget ret;
+        if (popupContext) {
+            if (popupContext.onSelf (cx, cy))
+            	return popupContext;
+            if (closePopup) {
+            	menuActive = (childIPPW !is null);
+            	popupContext = null;
+                requestRedraw;
+            }
+        }
         if (childIPPW) {
-            ret = childIPPW.getPopupWidget (cx, cy, closePopup);
-            if (closePopup && ret is null) {
+            IChildWidget ret =
+                    childIPPW.getPopupWidget (cx, cy, closePopup);
+            if (ret) return ret;
+            if (closePopup) {
                 menuActive = false;
                 removeChildIPPW (childIPPW);
             }
         }
-        return ret;
+        return null;
+    }
+    
+    override void drawPopup () {
+        if (popupContext)
+            popupContext.draw();
     }
     
     debug protected override bool isChild (IPopupParentWidget ippw) {
@@ -345,7 +360,6 @@
     }
     
     override void removedIPPW () {}	// irrelevant
-    override void drawPopup () {}
     //END IPopupParentWidget methods
     
     //BEGIN IWidgetManager methods
@@ -401,17 +415,20 @@
              h = popup.height,
              x, y;
         if (flags & 1) {
-            y = parent.yPos;
-            if (y+h > this.h) y += parent.height - h;
-            x = parent.xPos + parent.width;
-            if (x+w > this.w) x = parent.xPos - w;
+            y = parent.yPos;			// height flush with top
+            if (y+h > this.h) y += parent.height - h;	// or bottom
+            x = parent.xPos + parent.width;		// on right
+            if (x+w > this.w) x = parent.xPos - w;	// or left edge
         } else {
             x = parent.xPos;				// align on left edge
             if (x+w > this.w) x += parent.width - w;	// align on right edge
             y = parent.yPos + parent.height;		// place below
-            if (y+h > this.h) y = parent.yPos - h;		// place above
+            if (y+h > this.h) y = parent.yPos - h;	// or above
         }
+        if (x < 0) x = 0;	// may be placed partially off-screen
+        if (y < 0) y = 0;
         popup.setPosition (x, y);
+        //debug logger.trace ("placed popup at {},{}; size: {},{}", x,y, w,h);
     }
 
     void requestRedraw () {
@@ -600,6 +617,9 @@
     bool mAIPPW;			// IPPW variable
     IPopupParentWidget childIPPW;	// child IPPW, if any active
     
+    // Popup(s) handled directly by AWidgetManager:
+    IChildWidget popupContext;		// context menu (active if not null)
+    
     // callbacks indexed by their frame pointers. Must support removal of elements in foreach:
     SortedMap!(void*,bool delegate(wdabs cx, wdabs cy, ubyte b, bool state)) clickCallbacks;
     SortedMap!(void*,void delegate(wdabs cx, wdabs cy)) motionCallbacks;