Explorar o código

Single focused entity through CoreServices singleton

Ivan Safrin %!s(int64=13) %!d(string=hai) anos
pai
achega
3f824e8dfd

+ 3 - 1
Core/Contents/Include/PolyCoreServices.h

@@ -154,13 +154,15 @@ namespace Polycode {
 					
 			~CoreServices();
 		
+			void *focusedChild;
+			
 		protected:
 		
 			CoreServices();
 					
 		private:
 		
-		
+			
 			static CoreServices* overrideInstance;
 			static std::map <long, CoreServices*> instanceMap;
 			static CoreMutex *renderMutex;

+ 0 - 1
Core/Contents/Include/PolyScreenEntity.h

@@ -207,7 +207,6 @@ class _PolyExport ScreenEntity : public Entity, public EventDispatcher {
 		Rectangle *dragLimits;
 		
 		int lastClickTicks;
-		ScreenEntity *focusedChild;
 
 };
 

+ 2 - 0
Core/Contents/Source/PolyCoreServices.cpp

@@ -133,6 +133,8 @@ CoreServices::CoreServices() : EventDispatcher() {
 	tweenManager = new TweenManager();
 	soundManager = new SoundManager();
 	fontManager = new FontManager();
+	
+	focusedChild = NULL;
 }
 
 CoreServices::~CoreServices() {

+ 19 - 11
Core/Contents/Source/PolyScreenEntity.cpp

@@ -26,6 +26,7 @@
 #include "PolyPolygon.h"
 #include "PolyVertex.h"
 #include "PolyRenderer.h"
+#include "PolyCoreServices.h"
 
 inline double round(double x) { return floor(x + 0.5); }
 
@@ -52,7 +53,6 @@ ScreenEntity::ScreenEntity() : Entity(), EventDispatcher() {
 	focusable = false;
 	hasFocus = false;
 	focusChildren = false;	
-	focusedChild = NULL;
 	blockMouseInput = false;
 	
 	snapToPixels = false;
@@ -81,15 +81,21 @@ void ScreenEntity::setDefaultScreenOptions(bool snapToPixels) {
 
 void ScreenEntity::focusNextChild() {
 	int j = 0;
-	if(focusedChild) {
+	bool hasFocusedChild = false;
+	if(CoreServices::getInstance()->focusedChild) {
 		for(int i=0; i < children.size(); i++) {
-			if(children[i] == focusedChild)
+			if(children[i] == CoreServices::getInstance()->focusedChild) {
 				j = i;
+				hasFocusedChild = true;
+			}
 		}
 	}
 	
+	if(!hasFocusedChild)
+		return;
+	
 	for(int i=0; i < children.size(); i++) {
-		if(((ScreenEntity*)children[j])->isFocusable() && children[j] != focusedChild) {
+		if(((ScreenEntity*)children[j])->isFocusable() && children[j] != CoreServices::getInstance()->focusedChild) {
 			focusChild(((ScreenEntity*)children[j]));
 			return;
 		}
@@ -105,13 +111,13 @@ Number ScreenEntity::getRotation() const {
 }
 
 void ScreenEntity::focusChild(ScreenEntity *child) {
-	if(focusedChild != NULL) {
-		focusedChild->onLoseFocus();
-		focusedChild->hasFocus = false;
+	if(CoreServices::getInstance()->focusedChild != NULL) {
+		((ScreenEntity*)CoreServices::getInstance()->focusedChild)->onLoseFocus();
+		((ScreenEntity*)CoreServices::getInstance()->focusedChild)->hasFocus = false;
 	}
-	focusedChild = child;
-	focusedChild->hasFocus = true;
-	focusedChild->onGainFocus();
+	CoreServices::getInstance()->focusedChild = child;
+	((ScreenEntity*)CoreServices::getInstance()->focusedChild)->hasFocus = true;
+	((ScreenEntity*)CoreServices::getInstance()->focusedChild)->onGainFocus();
 }
 
 bool ScreenEntity::isFocusable() const {
@@ -129,7 +135,9 @@ void ScreenEntity::stopDrag() {
 }
 
 ScreenEntity::~ScreenEntity() {
-
+	if(CoreServices::getInstance()->focusedChild == this) {
+		CoreServices::getInstance()->focusedChild = NULL;
+	}
 }
 
 void ScreenEntity::setBlendingMode(int newBlendingMode) {

+ 1 - 67
IDE/Build/Mac OS X/English.lproj/MainMenu.xib

@@ -694,6 +694,7 @@
 				<string key="NSScreenRect">{{0, 0}, {1680, 1028}}</string>
 				<string key="NSMinSize">{400, 222}</string>
 				<string key="NSMaxSize">{10000000000000, 10000000000000}</string>
+				<int key="NSWindowCollectionBehavior">128</int>
 				<bool key="NSWindowIsRestorable">YES</bool>
 			</object>
 			<object class="NSCustomObject" id="976324537">
@@ -1894,73 +1895,6 @@
 		<object class="IBClassDescriber" key="IBDocument.Classes">
 			<object class="NSMutableArray" key="referencedPartialClassDescriptions">
 				<bool key="EncodedWithXMLCoder">YES</bool>
-				<object class="IBPartialClassDescription">
-					<string key="className">NSDocument</string>
-					<object class="NSMutableDictionary" key="actions">
-						<bool key="EncodedWithXMLCoder">YES</bool>
-						<object class="NSArray" key="dict.sortedKeys">
-							<bool key="EncodedWithXMLCoder">YES</bool>
-							<string>printDocument:</string>
-							<string>revertDocumentToSaved:</string>
-							<string>runPageLayout:</string>
-							<string>saveDocument:</string>
-							<string>saveDocumentAs:</string>
-							<string>saveDocumentTo:</string>
-						</object>
-						<object class="NSArray" key="dict.values">
-							<bool key="EncodedWithXMLCoder">YES</bool>
-							<string>id</string>
-							<string>id</string>
-							<string>id</string>
-							<string>id</string>
-							<string>id</string>
-							<string>id</string>
-						</object>
-					</object>
-					<object class="NSMutableDictionary" key="actionInfosByName">
-						<bool key="EncodedWithXMLCoder">YES</bool>
-						<object class="NSArray" key="dict.sortedKeys">
-							<bool key="EncodedWithXMLCoder">YES</bool>
-							<string>printDocument:</string>
-							<string>revertDocumentToSaved:</string>
-							<string>runPageLayout:</string>
-							<string>saveDocument:</string>
-							<string>saveDocumentAs:</string>
-							<string>saveDocumentTo:</string>
-						</object>
-						<object class="NSArray" key="dict.values">
-							<bool key="EncodedWithXMLCoder">YES</bool>
-							<object class="IBActionInfo">
-								<string key="name">printDocument:</string>
-								<string key="candidateClassName">id</string>
-							</object>
-							<object class="IBActionInfo">
-								<string key="name">revertDocumentToSaved:</string>
-								<string key="candidateClassName">id</string>
-							</object>
-							<object class="IBActionInfo">
-								<string key="name">runPageLayout:</string>
-								<string key="candidateClassName">id</string>
-							</object>
-							<object class="IBActionInfo">
-								<string key="name">saveDocument:</string>
-								<string key="candidateClassName">id</string>
-							</object>
-							<object class="IBActionInfo">
-								<string key="name">saveDocumentAs:</string>
-								<string key="candidateClassName">id</string>
-							</object>
-							<object class="IBActionInfo">
-								<string key="name">saveDocumentTo:</string>
-								<string key="candidateClassName">id</string>
-							</object>
-						</object>
-					</object>
-					<object class="IBClassDescriptionSource" key="sourceIdentifier">
-						<string key="majorKey">IBProjectSource</string>
-						<string key="minorKey">./Classes/NSDocument.h</string>
-					</object>
-				</object>
 				<object class="IBPartialClassDescription">
 					<string key="className">PolycodeAppDelegate</string>
 					<string key="superclassName">NSObject</string>

+ 3 - 0
IDE/Contents/Source/PolycodeConsole.cpp

@@ -32,6 +32,8 @@ PolycodeConsole::PolycodeConsole() : UIElement() {
 	addChild(consoleTextInput);	
 	
 	consoleTextInput->addEventListener(this, Event::COMPLETE_EVENT);
+	
+	consoleTextInput->setColor(0.95, 1.0, 0.647, 1.0);
 
 	PolycodeConsole::setInstance(this);
 }
@@ -60,6 +62,7 @@ void PolycodeConsole::print(String msg) {
 
 void PolycodeConsole::_print(String msg) {
 	debugTextInput->setText(debugTextInput->getText()+msg);
+	debugTextInput->
 }
 
 void PolycodeConsole::Resize(Number width, Number height) {

+ 0 - 1
Modules/Contents/UI/Source/PolyUIScrollContainer.cpp

@@ -124,7 +124,6 @@ void UIScrollContainer::setContentSize(Number newContentWidth, Number newContent
 
 void UIScrollContainer::Update() {
 	Vector2 pos = getScreenPosition();
-	printf("POS: %f,%f\n", pos.x, pos.y);
 	scrollChild->scissorBox.setRect(pos.x,pos.y, width, height);	
 }
 

+ 4 - 0
Modules/Contents/UI/Source/PolyUIWindow.cpp

@@ -84,6 +84,8 @@ UIWindow::UIWindow(String windowName, Number width, Number height) : ScreenEntit
 	
 	focusable = true;
 	blockMouseInput = true;
+	
+	processInputEvents = true;
 }
 
 void UIWindow::setWindowSize(Number w, Number h) {
@@ -112,10 +114,12 @@ void UIWindow::onKeyDown(PolyKEY key, wchar_t charCode) {
 }
 
 void UIWindow::onLoseFocus() {
+/*
 		if(focusedChild) {
 			focusedChild->hasFocus = false;
 			focusedChild->onLoseFocus();
 		}
+*/		
 }
 
 void UIWindow::onMouseDown(Number x, Number y) {