bsnes/hiro/cocoa/widget/tab-frame.cpp
Tim Allen 47d4bd4d81 Update to v096r01 release.
byuu says:

Changelog:

- restructured the project and removed a whole bunch of old/dead
  directives from higan/GNUmakefile
- huge amounts of work on hiro/cocoa (compiles but ~70% of the
  functionality is commented out)
- fixed a masking error in my ARM CPU disassembler [Lioncash]
- SFC: decided to change board cic=(411,413) back to board
  region=(ntsc,pal) ... the former was too obtuse

If you rename Boolean (it's a problem with an include from ruby, not
from hiro) and disable all the ruby drivers, you can compile an
OS X binary, but obviously it's not going to do anything.

It's a boring WIP, I just wanted to push out the project structure
change now at the start of this WIP cycle.
2015-12-30 17:54:59 +11:00

169 lines
4.4 KiB
C++

#if defined(Hiro_TabFrame)
@implementation CocoaTabFrame : NSTabView
-(id) initWith:(hiro::mTabFrame&)tabFrameReference {
if(self = [super initWithFrame:NSMakeRect(0, 0, 0, 0)]) {
tabFrame = &tabFrameReference;
[self setDelegate:self];
}
return self;
}
-(void) tabView:(NSTabView*)tabView didSelectTabViewItem:(NSTabViewItem*)tabViewItem {
tabFrame->self()->_updateSelected([tabView indexOfTabViewItem:tabViewItem]);
tabFrame->self()->_synchronizeLayout();
tabFrame->doChange();
}
@end
@implementation CocoaTabFrameItem : NSTabViewItem
-(id) initWith:(hiro::mTabFrame&)tabFrameReference {
if(self = [super initWithIdentifier:nil]) {
tabFrame = &tabFrameReference;
cocoaTabFrame = tabFrame->self()->cocoaTabFrame;
}
return self;
}
-(NSSize) sizeOfLabel:(BOOL)shouldTruncateLabel {
NSSize sizeOfLabel = [super sizeOfLabel:shouldTruncateLabel];
int selection = [cocoaTabFrame indexOfTabViewItem:self];
if(selection < 0) return sizeOfLabel; //should never happen
// if(!tabFrame->state.image[selection].empty()) {
// uint iconSize = hiro::pFont::size(tabFrame->font(true), " ").height();
// sizeOfLabel.width += iconSize + 2;
// }
return sizeOfLabel;
}
-(void) drawLabel:(BOOL)shouldTruncateLabel inRect:(NSRect)tabRect {
int selection = [cocoaTabFrame indexOfTabViewItem:self];
/*if(selection >= 0 && !tabFrame->state.image[selection].empty()) {
uint iconSize = phoenix::Font::size(tabFrame->font(), " ").height;
NSImage* image = NSMakeImage(tabFrame->state.image[selection]);
[[NSGraphicsContext currentContext] saveGraphicsState];
NSRect targetRect = NSMakeRect(tabRect.origin.x, tabRect.origin.y + 2, iconSize, iconSize);
[image drawInRect:targetRect fromRect:NSZeroRect operation:NSCompositeSourceOver fraction:1.0 respectFlipped:YES hints:nil];
[[NSGraphicsContext currentContext] restoreGraphicsState];
tabRect.origin.x += iconSize + 2;
tabRect.size.width -= iconSize + 2;
}*/
[super drawLabel:shouldTruncateLabel inRect:tabRect];
}
@end
namespace hiro {
auto pTabFrame::construct() -> void {
@autoreleasepool {
cocoaView = cocoaTabFrame = [[CocoaTabFrame alloc] initWith:self()];
pWidget::construct();
setNavigation(state().navigation);
}
}
auto pTabFrame::destruct() -> void {
@autoreleasepool {
[cocoaView release];
}
}
auto pTabFrame::append(sTabFrameItem item) -> void {
}
auto pTabFrame::remove(sTabFrameItem item) -> void {
}
/*
auto pTabFrame::append(string text, const image& image) -> void {
@autoreleasepool {
CocoaTabFrameItem* item = [[CocoaTabFrameItem alloc] initWith:tabFrame];
[item setLabel:[NSString stringWithUTF8String:text]];
[cocoaView addTabViewItem:item];
tabs.append(item);
}
}
auto pTabFrame::remove(unsigned selection) -> void {
@autoreleasepool {
CocoaTabFrameItem* item = tabs[selection];
[cocoaView removeTabViewItem:item];
tabs.remove(selection);
}
}
auto pTabFrame::setEnabled(bool enabled) -> void {
for(auto& layout : tabFrame.state.layout) {
if(layout) layout->setEnabled(layout->enabled());
}
pWidget::setEnabled(enabled);
}
*/
auto pTabFrame::setGeometry(Geometry geometry) -> void {
/*
pWidget::setGeometry({
geometry.x - 7, geometry.y - 5,
geometry.width + 14, geometry.height + 6
});
geometry.x += 1, geometry.width -= 2;
geometry.y += 22, geometry.height -= 32;
for(auto& layout : tabFrame.state.layout) {
if(layout == nullptr) continue;
layout->setGeometry(geometry);
}
synchronizeLayout();
*/
}
auto pTabFrame::setNavigation(Navigation navigation) -> void {
}
/*
auto pTabFrame::setSelection(unsigned selection) -> void {
@autoreleasepool {
CocoaTabFrameItem* item = tabs[selection];
[cocoaView selectTabViewItem:item];
}
synchronizeLayout();
}
auto pTabFrame::setText(unsigned selection, string text) -> void {
@autoreleasepool {
CocoaTabFrameItem* item = tabs[selection];
[item setLabel:[NSString stringWithUTF8String:text]];
}
}
auto pTabFrame::setVisible(bool visible) -> void {
for(auto& layout : tabFrame.state.layout) {
if(layout) layout->setVisible(layout->visible());
}
pWidget::setVisible(visible);
}
*/
auto pTabFrame::_synchronizeLayout() -> void {
/*
uint selection = 0;
for(auto& layout : tabFrame.state.layout) {
if(layout) layout->setVisible(selection == tabFrame.state.selection);
selection++;
}
*/
}
auto pTabFrame::_updateSelected(int selected) -> void {
}
}
#endif