mirror of
https://github.com/cocos/cocos4.git
synced 2026-12-04 10:32:39 +08:00
@@ -846,7 +846,7 @@ void GraphicsNode::flattenPaths()
|
||||
{
|
||||
if (_curPath && _curPath->points.size() <= 1) {
|
||||
_nPath --;
|
||||
_curPath = _paths[_nPath - 1];
|
||||
_curPath = _nPath > 0 ? _paths[_nPath - 1] : nullptr;
|
||||
}
|
||||
|
||||
for (int i = _pathOffset; i < _nPath; i++) {
|
||||
|
||||
@@ -26,7 +26,7 @@
|
||||
#import <AppKit/AppKit.h>
|
||||
#include "ui/UIEditBox/Mac/CCUITextInput.h"
|
||||
|
||||
@interface CCUIPasswordTextField : NSSecureTextField<CCUITextInput>
|
||||
@interface CCUIPasswordTextField : NSTextField<CCUITextInput>
|
||||
{
|
||||
NSMutableDictionary* _placeholderAttributes;
|
||||
}
|
||||
|
||||
@@ -1,19 +1,19 @@
|
||||
/****************************************************************************
|
||||
Copyright (c) 2010-2012 cocos2d-x.org
|
||||
Copyright (c) 2013-2016 zilongshanren
|
||||
|
||||
|
||||
http://www.cocos2d-x.org
|
||||
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
|
||||
The above copyright notice and this permission notice shall be included in
|
||||
all copies or substantial portions of the Software.
|
||||
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
@@ -26,6 +26,78 @@
|
||||
#import "ui/UIEditBox/Mac/CCUIPasswordTextField.h"
|
||||
#include "ui/UIEditBox/Mac/CCUITextFieldFormatter.h"
|
||||
|
||||
@interface RSVerticallyCenteredSecureTextFieldCell : NSSecureTextFieldCell
|
||||
{
|
||||
BOOL mIsEditingOrSelecting;
|
||||
}
|
||||
|
||||
@end
|
||||
|
||||
@implementation RSVerticallyCenteredSecureTextFieldCell
|
||||
|
||||
- (NSRect)drawingRectForBounds:(NSRect)theRect
|
||||
{
|
||||
// Get the parent's idea of where we should draw
|
||||
NSRect newRect = [super drawingRectForBounds:theRect];
|
||||
|
||||
// When the text field is being
|
||||
// edited or selected, we have to turn off the magic because it screws up
|
||||
// the configuration of the field editor. We sneak around this by
|
||||
// intercepting selectWithFrame and editWithFrame and sneaking a
|
||||
// reduced, centered rect in at the last minute.
|
||||
if (mIsEditingOrSelecting == NO)
|
||||
{
|
||||
// Get our ideal size for current text
|
||||
NSSize textSize = [self cellSizeForBounds:theRect];
|
||||
|
||||
// Center that in the proposed rect
|
||||
float heightDelta = newRect.size.height - textSize.height;
|
||||
if (heightDelta > 0)
|
||||
{
|
||||
newRect.size.height -= heightDelta;
|
||||
newRect.origin.y += (heightDelta / 2);
|
||||
}
|
||||
}
|
||||
|
||||
return newRect;
|
||||
}
|
||||
|
||||
- (void)selectWithFrame:(NSRect)aRect
|
||||
inView:(NSView *)controlView
|
||||
editor:(NSText *)textObj
|
||||
delegate:(id)anObject
|
||||
start:(long)selStart
|
||||
length:(long)selLength
|
||||
{
|
||||
aRect = [self drawingRectForBounds:aRect];
|
||||
mIsEditingOrSelecting = YES;
|
||||
[super selectWithFrame:aRect
|
||||
inView:controlView
|
||||
editor:textObj
|
||||
delegate:anObject
|
||||
start:selStart
|
||||
length:selLength];
|
||||
mIsEditingOrSelecting = NO;
|
||||
}
|
||||
|
||||
- (void)editWithFrame:(NSRect)aRect
|
||||
inView:(NSView *)controlView
|
||||
editor:(NSText *)textObj
|
||||
delegate:(id)anObject
|
||||
event:(NSEvent *)theEvent
|
||||
{
|
||||
aRect = [self drawingRectForBounds:aRect];
|
||||
mIsEditingOrSelecting = YES;
|
||||
[super editWithFrame:aRect
|
||||
inView:controlView
|
||||
editor:textObj
|
||||
delegate:anObject
|
||||
event:theEvent];
|
||||
mIsEditingOrSelecting = NO;
|
||||
}
|
||||
|
||||
@end
|
||||
|
||||
@interface CCUIPasswordTextField()
|
||||
@property (nonatomic, retain) NSMutableDictionary *placeholderAttributes;
|
||||
|
||||
@@ -45,15 +117,22 @@
|
||||
font, NSFontAttributeName,
|
||||
[NSColor grayColor], NSForegroundColorAttributeName,
|
||||
nil];
|
||||
[self setLineBreakMode:NSLineBreakByTruncatingTail];
|
||||
|
||||
}
|
||||
|
||||
|
||||
return self;
|
||||
}
|
||||
|
||||
+(void)load
|
||||
{
|
||||
[self setCellClass:[RSVerticallyCenteredSecureTextFieldCell class]];
|
||||
}
|
||||
|
||||
- (void)dealloc
|
||||
{
|
||||
self.placeholderAttributes = nil;
|
||||
|
||||
|
||||
[super dealloc];
|
||||
}
|
||||
|
||||
@@ -81,9 +160,9 @@
|
||||
{
|
||||
NSAttributedString *as = [[NSAttributedString alloc] initWithString:text
|
||||
attributes:self.placeholderAttributes];
|
||||
|
||||
|
||||
[[self cell] setPlaceholderAttributedString:as];
|
||||
|
||||
|
||||
[as release];
|
||||
}
|
||||
|
||||
|
||||
@@ -32,5 +32,10 @@
|
||||
<string>MainMenu</string>
|
||||
<key>NSPrincipalClass</key>
|
||||
<string>NSApplication</string>
|
||||
<key>NSAppTransportSecurity</key>
|
||||
<dict>
|
||||
<key>NSAllowsArbitraryLoads</key>
|
||||
<true/>
|
||||
</dict>
|
||||
</dict>
|
||||
</plist>
|
||||
|
||||
@@ -32,5 +32,10 @@
|
||||
<string>MainMenu</string>
|
||||
<key>NSPrincipalClass</key>
|
||||
<string>NSApplication</string>
|
||||
<key>NSAppTransportSecurity</key>
|
||||
<dict>
|
||||
<key>NSAllowsArbitraryLoads</key>
|
||||
<true/>
|
||||
</dict>
|
||||
</dict>
|
||||
</plist>
|
||||
|
||||
Reference in New Issue
Block a user