2013-03-15 13:11:33 +00:00
|
|
|
@implementation CocoaButton : NSButton
|
|
|
|
|
2013-03-21 12:59:01 +00:00
|
|
|
-(id) initWith:(phoenix::Button&)buttonReference {
|
2013-03-15 13:11:33 +00:00
|
|
|
if(self = [super initWithFrame:NSMakeRect(0, 0, 0, 0)]) {
|
|
|
|
button = &buttonReference;
|
|
|
|
[self setTarget:self];
|
|
|
|
[self setAction:@selector(activate:)];
|
|
|
|
//NSRoundedBezelStyle has a fixed height; which breaks both icons and larger/smaller text
|
|
|
|
[self setBezelStyle:NSRegularSquareBezelStyle];
|
|
|
|
}
|
|
|
|
return self;
|
|
|
|
}
|
|
|
|
|
2013-03-21 12:59:01 +00:00
|
|
|
-(IBAction) activate:(id)sender {
|
2013-03-15 13:11:33 +00:00
|
|
|
if(button->onActivate) button->onActivate();
|
|
|
|
}
|
|
|
|
|
|
|
|
@end
|
|
|
|
|
|
|
|
namespace phoenix {
|
|
|
|
|
|
|
|
Size pButton::minimumSize() {
|
|
|
|
Size size = Font::size(button.font(), button.state.text);
|
|
|
|
|
|
|
|
if(button.state.orientation == Orientation::Horizontal) {
|
|
|
|
size.width += button.state.image.width;
|
|
|
|
size.height = max(button.state.image.height, size.height);
|
|
|
|
}
|
|
|
|
|
|
|
|
if(button.state.orientation == Orientation::Vertical) {
|
|
|
|
size.width = max(button.state.image.width, size.width);
|
|
|
|
size.height += button.state.image.height;
|
|
|
|
}
|
|
|
|
|
2013-04-09 13:31:46 +00:00
|
|
|
return {size.width + 20, size.height + 4};
|
|
|
|
}
|
|
|
|
|
2013-05-02 11:25:45 +00:00
|
|
|
void pButton::setGeometry(const Geometry& geometry) {
|
2013-04-09 13:31:46 +00:00
|
|
|
pWidget::setGeometry({
|
|
|
|
geometry.x - 2, geometry.y - 2,
|
|
|
|
geometry.width + 4, geometry.height + 4
|
|
|
|
});
|
2013-03-15 13:11:33 +00:00
|
|
|
}
|
|
|
|
|
2013-05-02 11:25:45 +00:00
|
|
|
void pButton::setImage(const image& image, Orientation orientation) {
|
2013-03-15 13:11:33 +00:00
|
|
|
@autoreleasepool {
|
|
|
|
if(image.empty()) {
|
|
|
|
[cocoaView setImage:nil];
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
[cocoaView setImage:NSMakeImage(image)];
|
|
|
|
|
|
|
|
if(orientation == Orientation::Horizontal) [cocoaView setImagePosition:NSImageLeft];
|
|
|
|
if(orientation == Orientation::Vertical ) [cocoaView setImagePosition:NSImageAbove];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-05-02 11:25:45 +00:00
|
|
|
void pButton::setText(const string& text) {
|
2013-03-15 13:11:33 +00:00
|
|
|
@autoreleasepool {
|
|
|
|
[cocoaView setTitle:[NSString stringWithUTF8String:text]];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void pButton::constructor() {
|
|
|
|
@autoreleasepool {
|
|
|
|
cocoaView = cocoaButton = [[CocoaButton alloc] initWith:button];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void pButton::destructor() {
|
|
|
|
@autoreleasepool {
|
|
|
|
[cocoaView release];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|