Update to 20160106 OS X Preview for Developers release.

byuu says:

New update. Most of the work today went into eliminating hiro::Image
from all objects in all ports, replacing with nall::image. That took an
eternity.

Changelog:
- fixed crashing bug when loading games [thanks endrift!!]
- toggling "show status bar" option adjusts window geometry (not
  supposed to recenter the window, though)
- button sizes improved; icon-only button icons no longer being cut off
This commit is contained in:
Tim Allen
2016-01-07 19:14:33 +11:00
parent 4d193d7d94
commit 0b923489dd
308 changed files with 699 additions and 1326 deletions

View File

@@ -24,7 +24,7 @@ auto pMenuItem::construct() -> void {
cocoaAction = cocoaMenuItem = [[CocoaMenuItem alloc] initWith:self()];
pAction::construct();
setImage(state().image);
setIcon(state().icon);
setText(state().text);
}
}
@@ -35,10 +35,10 @@ auto pMenuItem::destruct() -> void {
}
}
auto pMenuItem::setImage(const Image& image) -> void {
auto pMenuItem::setIcon(const image& icon) -> void {
@autoreleasepool {
uint size = 15; //there is no API to retrieve the optimal size
[cocoaAction setImage:NSMakeImage(image, size, size)];
[cocoaAction setImage:NSMakeImage(icon, size, size)];
}
}

View File

@@ -13,7 +13,7 @@ namespace hiro {
struct pMenuItem : pAction {
Declare(MenuItem, Action)
auto setImage(const Image& image) -> void;
auto setIcon(const image& icon) -> void;
auto setText(const string& text) -> void;
CocoaMenuItem* cocoaMenuItem = nullptr;

View File

@@ -25,7 +25,7 @@ auto pMenu::construct() -> void {
cocoaAction = cocoaMenu = [[CocoaMenu alloc] initWith:self()];
pAction::construct();
setImage(state().image);
setIcon(state().icon);
setText(state().text);
}
}
@@ -53,10 +53,10 @@ auto pMenu::remove(sAction action) -> void {
}
}
auto pMenu::setImage(const Image& image) -> void {
auto pMenu::setIcon(const image& icon) -> void {
@autoreleasepool {
uint size = 15; //there is no API to retrieve the optimal size
[cocoaAction setImage:NSMakeImage(image, size, size)];
[cocoaAction setImage:NSMakeImage(icon, size, size)];
}
}

View File

@@ -16,7 +16,7 @@ struct pMenu : pAction {
auto append(sAction action) -> void;
auto remove(sAction action) -> void;
auto setImage(const Image& image) -> void;
auto setIcon(const image& icon) -> void;
auto setText(const string& text) -> void;
CocoaMenu* cocoaMenu = nullptr;

View File

@@ -36,6 +36,7 @@ auto pStatusBar::setVisible(bool visible) -> void {
@autoreleasepool {
if(auto parent = _parent()) {
[[parent->cocoaWindow statusBar] setHidden:!visible];
parent->setGeometry(parent->state().geometry);
}
}
}

View File

@@ -2,40 +2,25 @@ auto NSMakeColor(const hiro::Color& color) -> NSColor* {
return [NSColor colorWithRed:(color.red() / 255.0) green:(color.green() / 255.0) blue:(color.blue() / 255.0) alpha:(color.alpha() / 255.0)];
}
auto NSMakeImage(hiro::Image image, uint scaleWidth = 0, uint scaleHeight = 0) -> NSImage* {
if(!image.state.data) return nil;
auto NSMakeImage(image icon, uint scaleWidth = 0, uint scaleHeight = 0) -> NSImage* {
if(!icon) return nil;
//convert ARGB8888 to ABGR8888
auto p = image.data();
for(auto n : range(image.width() * image.height())) {
uint32 color = *p;
color = (color & 0xff00ff00) | ((color & 0xff0000) >> 16) | ((color & 0x0000ff) << 16);
*p++ = color;
}
if(scaleWidth && scaleHeight) icon.scale(scaleWidth, scaleHeight);
icon.transform(0, 32, 255u << 24, 255u << 0, 255u << 8, 255u << 16); //Cocoa stores images in ABGR format
//create NSImage from memory
NSImage* cocoaImage = [[[NSImage alloc] initWithSize:NSMakeSize(image.width(), image.height())] autorelease];
NSImage* cocoaImage = [[[NSImage alloc] initWithSize:NSMakeSize(icon.width(), icon.height())] autorelease];
NSBitmapImageRep* bitmap = [[[NSBitmapImageRep alloc]
initWithBitmapDataPlanes:nil
pixelsWide:image.width() pixelsHigh:image.height()
pixelsWide:icon.width() pixelsHigh:icon.height()
bitsPerSample:8 samplesPerPixel:4 hasAlpha:YES
isPlanar:NO colorSpaceName:NSCalibratedRGBColorSpace
bitmapFormat:NSAlphaNonpremultipliedBitmapFormat
bytesPerRow:4*image.width() bitsPerPixel:32
bytesPerRow:(4 * icon.width()) bitsPerPixel:32
] autorelease];
memory::copy([bitmap bitmapData], image.data(), 4 * image.width() * image.height());
memory::copy([bitmap bitmapData], icon.data(), 4 * icon.width() * icon.height());
[cocoaImage addRepresentation:bitmap];
if(!scaleWidth || !scaleHeight) return cocoaImage;
//scale image
[cocoaImage setScalesWhenResized:YES];
NSImage* scaleImage = [[[NSImage alloc] initWithSize:NSMakeSize(scaleWidth, scaleHeight)] autorelease];
[scaleImage lockFocus];
[cocoaImage setSize:NSMakeSize(scaleWidth, scaleHeight)];
[[NSGraphicsContext currentContext] setImageInterpolation:NSImageInterpolationHigh];
[cocoaImage drawAtPoint:NSZeroPoint fromRect:CGRectMake(0, 0, scaleWidth, scaleHeight) operation:NSCompositeCopy fraction:1.0];
[scaleImage unlockFocus];
return scaleImage;
return cocoaImage;
}
auto DropPathsOperation(id<NSDraggingInfo> sender) -> NSDragOperation {

View File

@@ -27,7 +27,7 @@ auto pButton::construct() -> void {
pWidget::construct();
setBordered(state().bordered);
setImage(state().image);
setIcon(state().icon);
setOrientation(state().orientation);
setText(state().text);
}
@@ -35,6 +35,7 @@ auto pButton::construct() -> void {
auto pButton::destruct() -> void {
@autoreleasepool {
[cocoaView removeFromSuperview];
[cocoaView release];
}
}
@@ -43,16 +44,16 @@ auto pButton::minimumSize() const -> Size {
Size size = pFont::size(self().font(true), state().text);
if(state().orientation == Orientation::Horizontal) {
size.setWidth(size.width() + state().image.width());
size.setHeight(max(size.height(), state().image.height()));
size.setWidth(size.width() + state().icon.width());
size.setHeight(max(size.height(), state().icon.height()));
}
if(state().orientation == Orientation::Vertical) {
size.setWidth(max(size.width(), state().image.width()));
size.setHeight(size.height() + state().image.height());
size.setWidth(max(size.width(), state().icon.width()));
size.setHeight(size.height() + state().icon.height());
}
return {size.width() + (state().text ? 20 : 4), size.height() + 4};
return {size.width() + (state().text ? 20 : 8), size.height() + 8};
}
auto pButton::setBordered(bool bordered) -> void {
@@ -65,14 +66,9 @@ auto pButton::setGeometry(Geometry geometry) -> void {
});
}
auto pButton::setImage(const Image& image) -> void {
auto pButton::setIcon(const image& icon) -> void {
@autoreleasepool {
if(!image) {
[cocoaView setImage:nil];
return;
}
[cocoaView setImage:NSMakeImage(image)];
[cocoaView setImage:NSMakeImage(icon)];
}
}

View File

@@ -16,7 +16,7 @@ struct pButton : pWidget {
auto minimumSize() const -> Size override;
auto setBordered(bool bordered) -> void;
auto setGeometry(Geometry geometry) -> void override;
auto setImage(const Image& image) -> void;
auto setIcon(const image& icon) -> void;
auto setOrientation(Orientation orientation) -> void;
auto setText(const string& text) -> void;

View File

@@ -99,6 +99,7 @@ auto pCanvas::construct() -> void {
auto pCanvas::destruct() -> void {
@autoreleasepool {
[cocoaView removeFromSuperview];
[cocoaView release];
}
}
@@ -146,7 +147,7 @@ auto pCanvas::setGeometry(Geometry geometry) -> void {
auto pCanvas::setGradient(Gradient gradient) -> void {
}
auto pCanvas::setImage(const Image& image) -> void {
auto pCanvas::setIcon(const image& icon) -> void {
}
auto pCanvas::update() -> void {

View File

@@ -31,7 +31,7 @@ struct pCanvas : pWidget {
auto setDroppable(bool droppable) -> void;
auto setGeometry(Geometry geometry) -> void override;
auto setGradient(Gradient gradient) -> void;
auto setImage(const Image& image) -> void;
auto setIcon(const image& icon) -> void;
auto update() -> void;
auto _rasterize() -> void;

View File

@@ -30,7 +30,7 @@ auto pCheckButton::construct() -> void {
setBordered(state().bordered);
setChecked(state().checked);
setImage(state().image);
setIcon(state().icon);
setOrientation(state().orientation);
setText(state().text);
}
@@ -38,6 +38,7 @@ auto pCheckButton::construct() -> void {
auto pCheckButton::destruct() -> void {
@autoreleasepool {
[cocoaView removeFromSuperview];
[cocoaView release];
}
}
@@ -46,16 +47,16 @@ auto pCheckButton::minimumSize() const -> Size {
Size size = pFont::size(self().font(true), state().text);
if(state().orientation == Orientation::Horizontal) {
size.setWidth(size.width() + state().image.width());
size.setHeight(max(size.height(), state().image.height()));
size.setWidth(size.width() + state().icon.width());
size.setHeight(max(size.height(), state().icon.height()));
}
if(state().orientation == Orientation::Vertical) {
size.setWidth(max(size.width(), state().image.width()));
size.setHeight(size.height() + state().image.height());
size.setWidth(max(size.width(), state().icon.width()));
size.setHeight(size.height() + state().icon.height());
}
return {size.width() + 20, size.height() + 4};
return {size.width() + (state().text ? 20 : 8), size.height() + 8};
}
auto pCheckButton::setBordered(bool bordered) -> void {
@@ -74,14 +75,9 @@ auto pCheckButton::setGeometry(Geometry geometry) -> void {
});
}
auto pCheckButton::setImage(const Image& image) -> void {
auto pCheckButton::setIcon(const image& icon) -> void {
@autoreleasepool {
if(!image) {
[cocoaView setImage:nil];
return;
}
[cocoaView setImage:NSMakeImage(image)];
[cocoaView setImage:NSMakeImage(icon)];
}
}

View File

@@ -17,7 +17,7 @@ struct pCheckButton : pWidget {
auto setBordered(bool bordered) -> void;
auto setChecked(bool checked) -> void;
auto setGeometry(Geometry geometry) -> void override;
auto setImage(const Image& image) -> void;
auto setIcon(const image& icon) -> void;
auto setOrientation(Orientation orientation) -> void;
auto setText(const string& text) -> void;

View File

@@ -34,6 +34,7 @@ auto pCheckLabel::construct() -> void {
auto pCheckLabel::destruct() -> void {
@autoreleasepool {
[cocoaView removeFromSuperview];
[cocoaView release];
}
}

View File

@@ -8,7 +8,7 @@ auto pComboButtonItem::construct() -> void {
auto pComboButtonItem::destruct() -> void {
}
auto pComboButtonItem::setImage(const Image& icon) -> void {
auto pComboButtonItem::setIcon(const image& icon) -> void {
}
auto pComboButtonItem::setSelected() -> void {

View File

@@ -5,7 +5,7 @@ namespace hiro {
struct pComboButtonItem : pObject {
Declare(ComboButtonItem, Object)
auto setImage(const Image& icon) -> void;
auto setIcon(const image& icon) -> void;
auto setSelected() -> void;
auto setText(const string& text) -> void;

View File

@@ -30,6 +30,7 @@ auto pComboButton::construct() -> void {
auto pComboButton::destruct() -> void {
@autoreleasepool {
[cocoaView removeFromSuperview];
[cocoaView release];
}
}

View File

@@ -36,6 +36,7 @@ void pConsole::constructor() {
void pConsole::destructor() {
@autoreleasepool {
[cocoaView removeFromSuperview];
[cocoaView release];
}
}

View File

@@ -26,6 +26,7 @@ auto pFrame::construct() -> void {
auto pFrame::destruct() -> void {
@autoreleasepool {
[cocoaView removeFromSuperview];
[cocoaView release];
}
}

View File

@@ -42,6 +42,7 @@ void pHexEdit::constructor() {
void pHexEdit::destructor() {
@autoreleasepool {
[cocoaView removeFromSuperview];
[cocoaView release];
}
}

View File

@@ -66,6 +66,7 @@ auto pHorizontalScrollBar::construct() -> void {
auto pHorizontalScrollBar::destruct() -> void {
@autoreleasepool {
[cocoaView removeFromSuperview];
[cocoaView release];
}
}

View File

@@ -34,6 +34,7 @@ auto pHorizontalSlider::construct() -> void {
auto pHorizontalSlider::destruct() -> void {
@autoreleasepool {
[cocoaView removeFromSuperview];
[cocoaView release];
}
}

View File

@@ -29,6 +29,7 @@ auto pLabel::construct() -> void {
auto pLabel::destruct() -> void {
@autoreleasepool {
[cocoaView removeFromSuperview];
[cocoaView release];
}
}

View File

@@ -42,6 +42,7 @@ auto pLineEdit::construct() -> void {
auto pLineEdit::destruct() -> void {
@autoreleasepool {
[cocoaView removeFromSuperview];
[cocoaView release];
}
}

View File

@@ -23,7 +23,7 @@ auto pListViewCell::setChecked(bool checked) -> void {
auto pListViewCell::setForegroundColor(Color color) -> void {
}
auto pListViewCell::setImage(const Image& image) -> void {
auto pListViewCell::setIcon(const image& icon) -> void {
}
auto pListViewCell::setText(const string& text) -> void {

View File

@@ -10,7 +10,7 @@ struct pListViewCell : pObject {
auto setCheckable(bool checkable) -> void;
auto setChecked(bool checked) -> void;
auto setForegroundColor(Color color) -> void;
auto setImage(const Image& image) -> void;
auto setIcon(const image& icon) -> void;
auto setText(const string& text) -> void;
auto _grandparent() -> maybe<pListView&>;

View File

@@ -42,7 +42,7 @@ auto pListViewColumn::setForegroundColor(Color color) -> void {
auto pListViewColumn::setHorizontalAlignment(double alignment) -> void {
}
auto pListViewColumn::setImage(const Image& image) -> void {
auto pListViewColumn::setIcon(const image& icon) -> void {
}
auto pListViewColumn::setResizable(bool resizable) -> void {

View File

@@ -13,7 +13,7 @@ struct pListViewColumn : pObject {
auto setFont(const Font& font) -> void override;
auto setForegroundColor(Color color) -> void;
auto setHorizontalAlignment(double) -> void;
auto setImage(const Image& image) -> void;
auto setIcon(const image& icon) -> void;
auto setResizable(bool resizable) -> void;
auto setSortable(bool sortable) -> void;
auto setText(const string& text) -> void;

View File

@@ -177,8 +177,8 @@
frame.size.width -= frame.size.height + 2;
}
if(listViewCell->state.image) {
NSImage* image = NSMakeImage(listViewCell->state.image, frame.size.height, frame.size.height);
if(listViewCell->state.icon) {
NSImage* image = NSMakeImage(listViewCell->state.icon, frame.size.height, frame.size.height);
[[NSGraphicsContext currentContext] saveGraphicsState];
NSRect targetRect = NSMakeRect(frame.origin.x, frame.origin.y, frame.size.height, frame.size.height);
NSRect sourceRect = NSMakeRect(0, 0, [image size].width, [image size].height);
@@ -269,6 +269,7 @@ auto pListView::construct() -> void {
auto pListView::destruct() -> void {
@autoreleasepool {
[cocoaView removeFromSuperview];
[cocoaView release];
}
}
@@ -361,8 +362,8 @@ auto pListView::_cellWidth(uint row, uint column) -> uint {
if(pListViewCell->state.checkable) {
width += 24;
}
if(auto& image = pListViewCell->state.image) {
width += image.width() + 2;
if(auto& icon = pListViewCell->state.icon) {
width += icon.width() + 2;
}
if(auto& text = pListViewCell->state.text) {
width += pFont::size(pListViewCell->font(true), text).width();
@@ -376,8 +377,8 @@ auto pListView::_columnWidth(uint column) -> uint {
uint width = 8;
if(auto& header = state().header) {
if(auto pListViewColumn = header->column(column)) {
if(auto& image = pListViewColumn->state.image) {
width += image.width() + 2;
if(auto& icon = pListViewColumn->state.icon) {
width += icon.width() + 2;
}
if(auto& text = pListViewColumn->state.text) {
width += pFont::size(pListViewColumn->font(true), text).width();

View File

@@ -28,6 +28,7 @@ auto pProgressBar::construct() -> void {
auto pProgressBar::destruct() -> void {
@autoreleasepool {
[cocoaView removeFromSuperview];
[cocoaView release];
}
}

View File

@@ -31,7 +31,7 @@ auto pRadioButton::construct() -> void {
setBordered(state().bordered);
if(state().checked) setChecked();
setImage(state().image);
setIcon(state().icon);
setOrientation(state().orientation);
setText(state().text);
}
@@ -39,6 +39,7 @@ auto pRadioButton::construct() -> void {
auto pRadioButton::destruct() -> void {
@autoreleasepool {
[cocoaView removeFromSuperview];
[cocoaView release];
}
}
@@ -47,16 +48,16 @@ auto pRadioButton::minimumSize() const -> Size {
Size size = pFont::size(self().font(true), state().text);
if(state().orientation == Orientation::Horizontal) {
size.setWidth(size.width() + state().image.width());
size.setHeight(max(size.height(), state().image.height()));
size.setWidth(size.width() + state().icon.width());
size.setHeight(max(size.height(), state().icon.height()));
}
if(state().orientation == Orientation::Vertical) {
size.setWidth(max(size.width(), state().image.width()));
size.setHeight(size.height() + state().image.height());
size.setWidth(max(size.width(), state().icon.width()));
size.setHeight(size.height() + state().icon.height());
}
return {size.width() + 20, size.height() + 4};
return {size.width() + (state().text ? 20 : 8), size.height() + 8};
}
auto pRadioButton::setBordered(bool bordered) -> void {
@@ -89,14 +90,9 @@ auto pRadioButton::setGeometry(Geometry geometry) -> void {
auto pRadioButton::setGroup(sGroup group) -> void {
}
auto pRadioButton::setImage(const Image& image) -> void {
auto pRadioButton::setIcon(const image& icon) -> void {
@autoreleasepool {
if(!image) {
[cocoaView setImage:nil];
return;
}
[cocoaView setImage:NSMakeImage(image)];
[cocoaView setImage:NSMakeImage(icon)];
}
}

View File

@@ -18,7 +18,7 @@ struct pRadioButton : pWidget {
auto setChecked() -> void;
auto setGeometry(Geometry geometry) -> void override;
auto setGroup(sGroup group) -> void;
auto setImage(const Image& image) -> void;
auto setIcon(const image& icon) -> void;
auto setOrientation(Orientation orientation) -> void;
auto setText(const string& text) -> void;

View File

@@ -34,6 +34,7 @@ auto pRadioLabel::construct() -> void {
auto pRadioLabel::destruct() -> void {
@autoreleasepool {
[cocoaView removeFromSuperview];
[cocoaView release];
}
}

View File

@@ -17,7 +17,7 @@ auto pTabFrameItem::remove(sLayout layout) -> void {
auto pTabFrameItem::setClosable(bool closable) -> void {
}
auto pTabFrameItem::setImage(const Image& image) -> void {
auto pTabFrameItem::setIcon(const image& icon) -> void {
}
auto pTabFrameItem::setMovable(bool movable) -> void {

View File

@@ -8,7 +8,7 @@ struct pTabFrameItem : pObject {
auto append(sLayout layout) -> void;
auto remove(sLayout layout) -> void;
auto setClosable(bool closable) -> void;
auto setImage(const Image& image) -> void;
auto setIcon(const image& icon) -> void;
auto setMovable(bool movable) -> void;
auto setSelected() -> void;
auto setText(const string& text) -> void;

View File

@@ -33,7 +33,7 @@
int selection = [cocoaTabFrame indexOfTabViewItem:self];
if(selection >= 0) {
if(auto item = tabFrame->item(selection)) {
if(item->state.image) {
if(item->state.icon) {
uint iconSize = hiro::pFont::size(tabFrame->font(true), " ").height();
sizeOfLabel.width += iconSize + 2;
}
@@ -46,9 +46,9 @@
int selection = [cocoaTabFrame indexOfTabViewItem:self];
if(selection >= 0) {
if(auto item = tabFrame->item(selection)) {
if(item->state.image) {
if(item->state.icon) {
uint iconSize = hiro::pFont::size(tabFrame->font(true), " ").height();
NSImage* image = NSMakeImage(item->state.image);
NSImage* image = NSMakeImage(item->state.icon);
[[NSGraphicsContext currentContext] saveGraphicsState];
NSRect targetRect = NSMakeRect(tabRect.origin.x, tabRect.origin.y + 2, iconSize, iconSize);
@@ -78,6 +78,7 @@ auto pTabFrame::construct() -> void {
auto pTabFrame::destruct() -> void {
@autoreleasepool {
[cocoaView removeFromSuperview];
[cocoaView release];
}
}

View File

@@ -59,6 +59,7 @@ auto pTextEdit::construct() -> void {
auto pTextEdit::destruct() -> void {
@autoreleasepool {
[cocoaView removeFromSuperview];
[cocoaView release];
}
}

View File

@@ -66,6 +66,7 @@ auto pVerticalScrollBar::construct() -> void {
auto pVerticalScrollBar::destruct() -> void {
@autoreleasepool {
[cocoaView removeFromSuperview];
[cocoaView release];
}
}

View File

@@ -34,6 +34,7 @@ auto pVerticalSlider::construct() -> void {
auto pVerticalSlider::destruct() -> void {
@autoreleasepool {
[cocoaView removeFromSuperview];
[cocoaView release];
}
}

View File

@@ -48,6 +48,7 @@ auto pViewport::construct() -> void {
auto pViewport::destruct() -> void {
@autoreleasepool {
[cocoaView removeFromSuperview];
[cocoaView release];
}
}

View File

@@ -21,18 +21,11 @@ auto pWidget::construct() -> void {
auto pWidget::destruct() -> void {
@autoreleasepool {
[cocoaView removeFromSuperview];
[cocoaView release];
}
}
/*
bool pWidget::enabled() {
@autoreleasepool {
return [cocoaView respondsToSelector:@selector(enabled)] && [cocoaView enabled];
}
}
*/
auto pWidget::focused() const -> bool {
@autoreleasepool {
return cocoaView == [[cocoaView window] firstResponder];
@@ -80,6 +73,14 @@ auto pWidget::setVisible(bool visible) -> void {
}
}
/*
bool pWidget::enabled() {
@autoreleasepool {
return [cocoaView respondsToSelector:@selector(enabled)] && [cocoaView enabled];
}
}
*/
}
#endif

View File

@@ -337,7 +337,9 @@ auto pWindow::sizeEvent() -> void {
auto pWindow::statusBarHeight() -> uint {
if(auto& statusBar = state().statusBar) {
return pFont::size(statusBar->font(true), " ").height() + 6;
if(statusBar->visible()) {
return pFont::size(statusBar->font(true), " ").height() + 6;
}
}
return 0;
}