Преглед изворни кода

Numerous UI tweaks, fixed Cocoa core hanging when opening file dialogs

Ivan Safrin пре 13 година
родитељ
комит
296c0dee49

+ 6 - 3
Core/Contents/Source/PolyCocoaCore.mm

@@ -469,24 +469,27 @@ void CocoaCore::removeDiskItem(const String& itemPath) {
 }
 	
 String CocoaCore::openFolderPicker() {
-	NSOpenPanel *attachmentPanel = [NSOpenPanel openPanel];	
+	unlockMutex(eventMutex);
+	NSOpenPanel *attachmentPanel = [[NSOpenPanel openPanel] retain];
 	[attachmentPanel setCanChooseFiles:NO];
 	[attachmentPanel setCanCreateDirectories: YES];
 	[attachmentPanel setCanChooseDirectories:YES];
 	
-	if ( [attachmentPanel runModalForDirectory:nil file:nil] == NSOKButton )
+	if ( [attachmentPanel runModal] == NSOKButton )
 	{
 		// files and directories selected.
 		NSArray* files = [attachmentPanel filenames];
 		NSString* fileName = [files objectAtIndex:0];
+		[attachmentPanel release];
 		return [fileName UTF8String];
 	} else {
+		[attachmentPanel release];	
 		return [@"" UTF8String];
 	}	
 }
 
 vector<String> CocoaCore::openFilePicker(vector<CoreFileExtension> extensions, bool allowMultiple) {
-	
+	unlockMutex(eventMutex);	
 	vector<String> retVector;
 	
 	NSOpenPanel *attachmentPanel = [NSOpenPanel openPanel];	

+ 1 - 1
IDE/Contents/Include/PolycodeEditor.h

@@ -33,7 +33,7 @@ public:
 	virtual ~PolycodeEditor();
 	
 	virtual bool openFile(String filePath){ this->filePath = filePath; }
-	virtual void Resize(int x, int y) = 0;
+	virtual void Resize(int x, int y);
 	
 	virtual void saveFile(){};
 	

+ 3 - 1
IDE/Contents/Resources/UIThemes/default/theme.xml

@@ -5,7 +5,7 @@
 	<uiTextInputFontNameMultiLine>mono</uiTextInputFontNameMultiLine>
 	<uiDefaultFontSize>11</uiDefaultFontSize>
 	<uiTextInputFontSize>11</uiTextInputFontSize>
-	<uiTextInputFontSizeMultiline>12</uiTextInputFontSizeMultiline>	
+	<uiTextInputFontSizeMultiline>11</uiTextInputFontSizeMultiline>	
 	<uiTreeArrowIconImage>arrowIcon.png</uiTreeArrowIconImage>
 	<uiTreeCellHeight>20</uiTreeCellHeight>
 	<uiTreeCellPadding>4</uiTreeCellPadding>
@@ -37,6 +37,8 @@
 	<uiButtonSkin>button.png</uiButtonSkin>
 	<uiButtonFocusedSkin>buttonFocused.png</uiButtonFocusedSkin>
 	<uiButtonFontSize>11</uiButtonFontSize>	
+	<uiButtonLabelOffsetX>2</uiButtonLabelOffsetX>
+	<uiButtonLabelOffsetY>1</uiButtonLabelOffsetY>	
 	<uiButtonSkinT>4</uiButtonSkinT>
 	<uiButtonSkinR>4</uiButtonSkinR>
 	<uiButtonSkinB>4</uiButtonSkinB>

+ 4 - 4
IDE/Contents/Source/ExampleBrowserWindow.cpp

@@ -22,7 +22,7 @@
 
 #include "ExampleBrowserWindow.h"
 
-ExampleBrowserWindow::ExampleBrowserWindow() : UIWindow(L"Example Browser", 320, 300){
+ExampleBrowserWindow::ExampleBrowserWindow() : UIWindow(L"Example Browser", 320, 400){
 	
 	templateFolder = "";
 	
@@ -34,7 +34,7 @@ ExampleBrowserWindow::ExampleBrowserWindow() : UIWindow(L"Example Browser", 320,
 	int fontSize = conf->getNumericValue("Polycode", "uiDefaultFontSize");
 	
 	
-	templateContainer = new UITreeContainer("boxIcon.png", L"Examples", 300, 300-topPadding-padding-padding- 40);	
+	templateContainer = new UITreeContainer("boxIcon.png", L"Examples", 320, 410-topPadding-padding-padding-40);	
 	
 	ExampleTemplateUserData *data = new ExampleTemplateUserData();
 	data->type = 0;
@@ -67,13 +67,13 @@ ExampleBrowserWindow::ExampleBrowserWindow() : UIWindow(L"Example Browser", 320,
 	cancelButton = new UIButton(L"Cancel", 100);
 	cancelButton->addEventListener(this, UIEvent::CLICK_EVENT);
 	addChild(cancelButton);
-	cancelButton->setPosition(300-100-padding-80-10, 265);
+	cancelButton->setPosition(330-100-padding-80-10, 375);
 		
 	
 	okButton = new UIButton(L"Open Example", 100);
 	okButton->addEventListener(this, UIEvent::CLICK_EVENT);
 	addChild(okButton);
-	okButton->setPosition(300-80-padding, 265);
+	okButton->setPosition(330-80-padding, 375);
 }
 
 String ExampleBrowserWindow::getExamplePath() {

+ 2 - 1
IDE/Contents/Source/NewProjectWindow.cpp

@@ -131,7 +131,8 @@ void NewProjectWindow::handleEvent(Event *event) {
 			
 			if(event->getDispatcher() == locationSelectButton) {
 				String pathName = CoreServices::getInstance()->getCore()->openFolderPicker();
-				projectLocationInput->setText(pathName);
+				if(pathName != "")
+					projectLocationInput->setText(pathName);
 			}			
 			
 		}

+ 6 - 0
IDE/Contents/Source/PolycodeEditor.cpp

@@ -44,6 +44,12 @@ void PolycodeEditor::setFilePath(String newPath) {
 
 PolycodeEditor::PolycodeEditor(bool _isReadOnly) : ScreenEntity() {
 	this->_isReadOnly = _isReadOnly;
+	enableScissor = true;	
+}
+
+void PolycodeEditor::Resize(int x, int y) {
+	Vector2 pos = getScreenPosition();
+	scissorBox.setRect(pos.x,pos.y, x, y);	
 }
 
 PolycodeEditor::~PolycodeEditor() {

+ 1 - 0
IDE/Contents/Source/PolycodeFontEditor.cpp

@@ -89,5 +89,6 @@ bool PolycodeFontEditor::openFile(String filePath) {
 void PolycodeFontEditor::Resize(int x, int y) {
 	anchor->setPosition((x-anchor->getWidth()) /2, (y-anchor->getHeight()) /2);
 	grid->setImageCoordinates(0,0,x,y);
+	PolycodeEditor::Resize(x,y);	
 }
 

+ 1 - 0
IDE/Contents/Source/PolycodeImageEditor.cpp

@@ -51,5 +51,6 @@ bool PolycodeImageEditor::openFile(String filePath) {
 void PolycodeImageEditor::Resize(int x, int y) {
 	editorImage->setPosition((x-editorImage->getWidth()) /2, (y-editorImage->getHeight()) /2);
 	grid->setImageCoordinates(0,0,x,y);	
+	PolycodeEditor::Resize(x,y);
 }
 

+ 1 - 0
IDE/Contents/Source/PolycodeProjectEditor.cpp

@@ -245,6 +245,7 @@ bool PolycodeProjectEditor::openFile(String filePath) {
 
 void PolycodeProjectEditor::Resize(int x, int y) {
 	grid->setImageCoordinates(0,0,x,y);	
+	PolycodeEditor::Resize(x,y);	
 }
 
 void PolycodeProjectEditor::saveFile() {

+ 1 - 0
IDE/Contents/Source/PolycodeScreenEditor.cpp

@@ -189,5 +189,6 @@ void PolycodeScreenEditor::handleEvent(Event *event) {
 
 void PolycodeScreenEditor::Resize(int x, int y) {
 	grid->setImageCoordinates(0,0,x,y);	
+	PolycodeEditor::Resize(x,y);	
 }
 

+ 1 - 0
IDE/Contents/Source/PolycodeTextEditor.cpp

@@ -52,5 +52,6 @@ void PolycodeTextEditor::saveFile() {
 
 void PolycodeTextEditor::Resize(int x, int y) {
 	textInput->Resize(x,y);
+	PolycodeEditor::Resize(x,y);	
 }
 

+ 6 - 4
Modules/Contents/UI/Source/PolyUIButton.cpp

@@ -40,8 +40,10 @@ UIButton::UIButton(String text, Number width, Number height) : UIElement() {
 	Number sr = conf->getNumericValue("Polycode", "uiButtonSkinR");
 	Number sb = conf->getNumericValue("Polycode", "uiButtonSkinB");
 	Number sl = conf->getNumericValue("Polycode", "uiButtonSkinL");
-	
-	
+
+	Number labelOffsetX = conf->getNumericValue("Polycode", "uiButtonLabelOffsetX");
+	Number labelOffsetY = conf->getNumericValue("Polycode", "uiButtonLabelOffsetY");
+		
 	buttonRect = new UIBox(conf->getStringValue("Polycode", "uiButtonSkin"),
 						   st,sr,sb,sl,
 						   width, height);	
@@ -64,8 +66,8 @@ UIButton::UIButton(String text, Number width, Number height) : UIElement() {
 	
 	buttonLabel = new ScreenLabel(text, fontSize, fontName, Label::ANTIALIAS_FULL);
 	addChild(buttonLabel);
-	labelXPos = floor((width-buttonLabel->getWidth())/2.0f);
-	labelYPos = floor((height-(buttonLabel->getHeight()-5))/2.0f);
+	labelXPos = floor((width-buttonLabel->getWidth())/2.0f) + labelOffsetX;
+	labelYPos = floor((height-(buttonLabel->getHeight()))/2.0f) + labelOffsetY;
 	buttonLabel->setPosition(labelXPos,labelYPos);
 	
 	this->width = width;

+ 2 - 0
Modules/Contents/UI/Source/PolyUIHSizer.cpp

@@ -57,6 +57,7 @@ UIHSizer::UIHSizer(Number width, Number height, Number mainWidth, bool leftSizer
 	separatorHitShape->addEventListener(this, InputEvent::EVENT_MOUSEUP_OUTSIDE);
 	separatorHitShape->addEventListener(this, InputEvent::EVENT_MOUSEOVER);	
 	separatorHitShape->addEventListener(this, InputEvent::EVENT_MOUSEOUT);		
+	separatorHitShape->addEventListener(this, InputEvent::EVENT_MOUSEMOVE);			
 	separatorHitShape->visible = false;
 	
 	coreInput = CoreServices::getInstance()->getCore()->getInput();
@@ -88,6 +89,7 @@ void UIHSizer::handleEvent(Event *event) {
 				resizing = false;			
 			}
 			break;
+			case InputEvent::EVENT_MOUSEMOVE:			
 			case InputEvent::EVENT_MOUSEOVER:
 				CoreServices::getInstance()->getCore()->setCursor(CURSOR_RESIZE_LEFT_RIGHT);
 			break;

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

@@ -113,6 +113,7 @@ void UIScrollContainer::setContentSize(Number newContentWidth, Number newContent
 	if(hasVScroll) {
 		if((height / newContentHeight) >= 1) {
 			vScrollBar->enabled = false;
+			vScrollBar->scrollTo(0);
 		} else {
 			vScrollBar->enabled = true;		
 		}
@@ -121,6 +122,7 @@ void UIScrollContainer::setContentSize(Number newContentWidth, Number newContent
 	if(hasHScroll) {
 		if((width / newContentWidth) >= 1) {
 			hScrollBar->enabled = false;
+			hScrollBar->scrollTo(0);			
 		} else {
 			hScrollBar->enabled = true;		
 		}

+ 2 - 0
Modules/Contents/UI/Source/PolyUITreeContainer.cpp

@@ -59,6 +59,8 @@ UITreeContainer::UITreeContainer(String icon, String text, Number treeWidth, Num
 	width = treeWidth;
 	height = treeHeight;
 	setHitbox(width, height);
+	
+	Resize(width, height);
 }
 
 void UITreeContainer::Resize(Number width, Number height) {

+ 2 - 0
Modules/Contents/UI/Source/PolyUIVSizer.cpp

@@ -57,6 +57,7 @@ UIVSizer::UIVSizer(Number width, Number height, Number mainHeight, bool topSizer
 	separatorHitShape->addEventListener(this, InputEvent::EVENT_MOUSEUP_OUTSIDE);
 	separatorHitShape->addEventListener(this, InputEvent::EVENT_MOUSEOVER);	
 	separatorHitShape->addEventListener(this, InputEvent::EVENT_MOUSEOUT);		
+	separatorHitShape->addEventListener(this, InputEvent::EVENT_MOUSEMOVE);			
 	separatorHitShape->visible = false;
 	
 	coreInput = CoreServices::getInstance()->getCore()->getInput();
@@ -88,6 +89,7 @@ void UIVSizer::handleEvent(Event *event) {
 				resizing = false;			
 			}
 			break;
+			case InputEvent::EVENT_MOUSEMOVE:			
 			case InputEvent::EVENT_MOUSEOVER:
 				CoreServices::getInstance()->getCore()->setCursor(CURSOR_RESIZE_UP_DOWN);
 			break;