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

@@ -10,7 +10,7 @@ auto pMenuItem::destruct() -> void {
if(hbitmap) { DeleteObject(hbitmap); hbitmap = nullptr; }
}
auto pMenuItem::setImage(const Image& image) -> void {
auto pMenuItem::setIcon(const image& icon) -> void {
_createBitmap();
_synchronize();
}
@@ -26,10 +26,7 @@ auto pMenuItem::onActivate() -> void {
auto pMenuItem::_createBitmap() -> void {
if(hbitmap) { DeleteObject(hbitmap); hbitmap = nullptr; }
if(auto& image = state().image) {
nall::image icon;
icon.allocate(image.width(), image.height());
memory::copy(icon.data(), image.data(), icon.size());
if(auto icon = state().icon) {
icon.alphaBlend(GetSysColor(COLOR_MENU)); //Windows does not alpha blend menu icons properly (leaves black outline)
icon.scale(GetSystemMetrics(SM_CXMENUCHECK), GetSystemMetrics(SM_CYMENUCHECK), Interpolation::Linear);
hbitmap = CreateBitmap(icon);

View File

@@ -5,7 +5,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;
auto onActivate() -> void;

View File

@@ -19,7 +19,7 @@ auto pMenu::remove(sAction action) -> void {
_synchronize();
}
auto pMenu::setImage(const Image& image) -> void {
auto pMenu::setIcon(const image& icon) -> void {
_createBitmap();
_synchronize();
}
@@ -31,10 +31,7 @@ auto pMenu::setText(const string& text) -> void {
auto pMenu::_createBitmap() -> void {
if(hbitmap) { DeleteObject(hbitmap); hbitmap = 0; }
if(auto& image = state().image) {
nall::image icon;
icon.allocate(image.width(), image.height());
memory::copy(icon.data(), image.data(), icon.size());
if(auto icon = state().icon) {
icon.alphaBlend(GetSysColor(COLOR_MENU)); //Windows does not alpha blend menu icons properly (leaves black outline)
icon.scale(GetSystemMetrics(SM_CXMENUCHECK), GetSystemMetrics(SM_CYMENUCHECK), Interpolation::Linear);
hbitmap = CreateBitmap(icon);

View File

@@ -7,7 +7,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;
auto _createBitmap() -> void;

View File

@@ -1,11 +1,11 @@
namespace hiro {
static const unsigned Windows2000 = 0x0500;
static const unsigned WindowsXP = 0x0501;
static const unsigned WindowsVista = 0x0600;
static const unsigned Windows7 = 0x0601;
static const uint Windows2000 = 0x0500;
static const uint WindowsXP = 0x0501;
static const uint WindowsVista = 0x0600;
static const uint Windows7 = 0x0601;
static auto Button_CustomDraw(HWND, PAINTSTRUCT&, bool, bool, bool, unsigned, const Font&, const Image&, Orientation, const string&) -> void;
static auto Button_CustomDraw(HWND, PAINTSTRUCT&, bool, bool, bool, unsigned, const Font&, const image&, Orientation, const string&) -> void;
static auto OsVersion() -> unsigned {
OSVERSIONINFO versionInfo{0};
@@ -34,33 +34,6 @@ static auto CreateBitmap(image icon) -> HBITMAP {
return hbitmap;
}
static auto CreateBitmap(const Image& image) -> HBITMAP {
HDC hdc = GetDC(0);
BITMAPINFO bitmapInfo{0};
bitmapInfo.bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
bitmapInfo.bmiHeader.biWidth = image.width();
bitmapInfo.bmiHeader.biHeight = -image.height(); //bitmaps are stored upside down unless we negate height
bitmapInfo.bmiHeader.biPlanes = 1;
bitmapInfo.bmiHeader.biBitCount = 32;
bitmapInfo.bmiHeader.biCompression = BI_RGB;
bitmapInfo.bmiHeader.biSizeImage = image.width() * image.height() * sizeof(uint32_t);
void* bits = nullptr;
HBITMAP hbitmap = CreateDIBSection(hdc, &bitmapInfo, DIB_RGB_COLORS, &bits, nullptr, 0);
if(bits) {
auto source = (const uint8_t*)image.data();
auto target = (uint8_t*)bits;
for(auto n : range(image.width() * image.height())) {
target[0] = (source[0] * source[3]) / 255;
target[1] = (source[1] * source[3]) / 255;
target[2] = (source[2] * source[3]) / 255;
target[3] = (source[3]);
source += 4, target += 4;
}
}
ReleaseDC(0, hdc);
return hbitmap;
}
static auto CreateRGB(const Color& color) -> COLORREF {
return RGB(color.red(), color.green(), color.blue());
}
@@ -93,11 +66,8 @@ static auto GetWindowZOrder(HWND hwnd) -> unsigned {
return z;
}
static auto ImageList_Append(HIMAGELIST imageList, const Image& image, unsigned scale) -> void {
nall::image icon;
if(image) {
icon.allocate(image.width(), image.height());
memory::copy(icon.data(), image.data(), icon.size());
static auto ImageList_Append(HIMAGELIST imageList, image icon, unsigned scale) -> void {
if(icon) {
icon.scale(scale, scale);
} else {
icon.allocate(scale, scale);

View File

@@ -3,13 +3,13 @@
namespace hiro {
static auto Button_paintProc(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam,
bool bordered, bool checked, bool enabled, const Font& font, const Image& image, Orientation orientation, const string& text
bool bordered, bool checked, bool enabled, const Font& font, const image& icon, Orientation orientation, const string& text
) -> LRESULT {
if(msg == WM_PAINT) {
PAINTSTRUCT ps;
BeginPaint(hwnd, &ps);
auto state = Button_GetState(hwnd);
Button_CustomDraw(hwnd, ps, bordered, checked, enabled, state, font, image, orientation, text);
Button_CustomDraw(hwnd, ps, bordered, checked, enabled, state, font, icon, orientation, text);
EndPaint(hwnd, &ps);
}
return DefWindowProc(hwnd, msg, wparam, lparam);
@@ -27,7 +27,7 @@ static auto CALLBACK Button_windowProc(HWND hwnd, UINT msg, WPARAM wparam, LPARA
if(msg == WM_ERASEBKGND) return DefWindowProc(hwnd, msg, wparam, lparam);
if(msg == WM_PAINT) return Button_paintProc(hwnd, msg, wparam, lparam,
button->state.bordered, false, button->enabled(true), button->font(true),
button->state.image, button->state.orientation, button->state.text
button->state.icon, button->state.orientation, button->state.text
);
return self->windowProc(hwnd, msg, wparam, lparam);
}
@@ -53,16 +53,16 @@ auto pButton::destruct() -> void {
}
auto pButton::minimumSize() const -> Size {
Size image = state().image.size();
Size icon = {(int)state().icon.width(), (int)state().icon.height()};
Size text = state().text ? pFont::size(self().font(true), state().text) : Size{};
Size size;
if(state().orientation == Orientation::Horizontal) {
size.setWidth(image.width() + (image && text ? 5 : 0) + text.width());
size.setHeight(max(image.height(), text.height()));
size.setWidth(icon.width() + (icon && text ? 5 : 0) + text.width());
size.setHeight(max(icon.height(), text.height()));
}
if(state().orientation == Orientation::Vertical) {
size.setWidth(max(image.width(), text.width()));
size.setHeight(image.height() + (image && text ? 5 : 0) + text.height());
size.setWidth(max(icon.width(), text.width()));
size.setHeight(icon.height() + (icon && text ? 5 : 0) + text.height());
}
size.setHeight(max(size.height(), pFont::size(self().font(true), " ").height()));
return {size.width() + (state().bordered && text ? 20 : 10), size.height() + 10};
@@ -82,7 +82,7 @@ auto pButton::setFont(const Font& font) -> void {
_setState();
}
auto pButton::setImage(const Image& image) -> void {
auto pButton::setIcon(const image& icon) -> void {
_setState();
}
@@ -108,11 +108,11 @@ auto pButton::_setState() -> void {
}
//this function is designed to be used with Button, CheckButton, and RadioButton
auto Button_CustomDraw(HWND hwnd, PAINTSTRUCT& ps, bool bordered, bool checked, bool enabled, unsigned state, const Font& font, const Image& image, Orientation orientation, const string& text) -> void {
auto Button_CustomDraw(HWND hwnd, PAINTSTRUCT& ps, bool bordered, bool checked, bool enabled, unsigned state, const Font& font, const image& icon, Orientation orientation, const string& text) -> void {
RECT rc;
GetClientRect(hwnd, &rc);
Geometry geometry{rc.left, rc.top, rc.right - rc.left, rc.bottom - rc.top}, imageGeometry, textGeometry;
if(image) imageGeometry.setSize(image.size());
Geometry geometry{rc.left, rc.top, rc.right - rc.left, rc.bottom - rc.top}, iconGeometry, textGeometry;
if(icon) iconGeometry.setSize({(int)icon.width(), (int)icon.height()});
if(text) textGeometry.setSize(pFont::size(font, text));
Position position;
@@ -120,15 +120,15 @@ auto Button_CustomDraw(HWND hwnd, PAINTSTRUCT& ps, bool bordered, bool checked,
switch(orientation) {
case Orientation::Horizontal:
size = {imageGeometry.width() + (image && text ? 5 : 0) + textGeometry.width(), max(imageGeometry.height(), textGeometry.height())};
size = {iconGeometry.width() + (icon && text ? 5 : 0) + textGeometry.width(), max(iconGeometry.height(), textGeometry.height())};
position = {(geometry.width() - size.width()) / 2, (geometry.height() - size.height()) / 2};
imageGeometry.setPosition({position.x(), position.y() + (size.height() - imageGeometry.height()) / 2});
iconGeometry.setPosition({position.x(), position.y() + (size.height() - iconGeometry.height()) / 2});
textGeometry.setPosition({position.x() + size.width() - textGeometry.width(), position.y() + (size.height() - textGeometry.height()) / 2});
break;
case Orientation::Vertical:
size = {max(imageGeometry.width(), textGeometry.width()), imageGeometry.height() + (image && text ? 5 : 0) + textGeometry.height()};
size = {max(iconGeometry.width(), textGeometry.width()), iconGeometry.height() + (icon && text ? 5 : 0) + textGeometry.height()};
position = {(geometry.width() - size.width()) / 2, (geometry.height() - size.height()) / 2};
imageGeometry.setPosition({position.x() + (size.width() - imageGeometry.width()) / 2, position.y()});
iconGeometry.setPosition({position.x() + (size.width() - iconGeometry.width()) / 2, position.y()});
textGeometry.setPosition({position.x() + (size.width() - textGeometry.width()) / 2, position.y() + size.height() - textGeometry.height()});
break;
}
@@ -154,14 +154,14 @@ auto Button_CustomDraw(HWND hwnd, PAINTSTRUCT& ps, bool bordered, bool checked,
if(!(state & BST_PUSHED) && !(state & BST_HOT)) DrawFocusRect(ps.hdc, &rcFocus);
}
if(image) {
if(icon) {
HDC hdcSource = CreateCompatibleDC(ps.hdc);
auto bitmap = CreateBitmap(image);
auto bitmap = CreateBitmap(icon);
SelectBitmap(hdcSource, bitmap);
BLENDFUNCTION blend{AC_SRC_OVER, 0, (BYTE)(IsWindowEnabled(hwnd) ? 255 : 128), AC_SRC_ALPHA};
AlphaBlend(
ps.hdc, imageGeometry.x(), imageGeometry.y(), image.width(), image.height(),
hdcSource, 0, 0, image.width(), image.height(), blend
ps.hdc, iconGeometry.x(), iconGeometry.y(), icon.width(), icon.height(),
hdcSource, 0, 0, icon.width(), icon.height(), blend
);
DeleteObject(bitmap);
DeleteDC(hdcSource);

View File

@@ -9,7 +9,7 @@ struct pButton : pWidget {
auto setBordered(bool bordered) -> void;
auto setEnabled(bool enabled) -> void override;
auto setFont(const Font& font) -> 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;
auto setVisible(bool visible) -> void override;

View File

@@ -69,7 +69,7 @@ auto pCanvas::destruct() -> void {
}
auto pCanvas::minimumSize() const -> Size {
if(auto& image = state().image) return image.size();
if(auto& icon = state().icon) return {(int)icon.width(), (int)icon.height()};
return {0, 0};
}
@@ -90,7 +90,7 @@ auto pCanvas::setGradient(Gradient gradient) -> void {
update();
}
auto pCanvas::setImage(const Image& image) -> void {
auto pCanvas::setIcon(const image& icon) -> void {
update();
}
@@ -112,12 +112,12 @@ auto pCanvas::_paint() -> void {
bmi.bmiHeader.biCompression = BI_RGB;
bmi.bmiHeader.biWidth = width;
bmi.bmiHeader.biHeight = -height; //GDI stores bitmaps upside now; negative height flips bitmap
bmi.bmiHeader.biSizeImage = pixels.size() * sizeof(uint32_t);
bmi.bmiHeader.biSizeImage = pixels.size() * sizeof(uint32);
void* bits = nullptr;
HBITMAP bitmap = CreateDIBSection(hdc, &bmi, DIB_RGB_COLORS, &bits, nullptr, 0);
if(bits) {
auto source = (const uint8_t*)pixels.data();
auto target = (uint8_t*)bits;
auto source = (const uint8*)pixels.data();
auto target = (uint8*)bits;
for(auto n : range(width * height)) {
target[0] = (source[0] * source[3]) / 255;
target[1] = (source[1] * source[3]) / 255;
@@ -142,9 +142,9 @@ auto pCanvas::_paint() -> void {
}
auto pCanvas::_rasterize() -> void {
if(auto& image = state().image) {
width = image.width();
height = image.height();
if(auto& icon = state().icon) {
width = icon.width();
height = icon.height();
} else {
width = self().geometry().width();
height = self().geometry().height();
@@ -153,16 +153,16 @@ auto pCanvas::_rasterize() -> void {
pixels.reallocate(width * height);
if(auto& image = state().image) {
memory::copy(pixels.data(), image.data(), width * height * sizeof(uint32_t));
if(auto& icon = state().icon) {
memory::copy(pixels.data(), icon.data(), width * height * sizeof(uint32));
} else if(auto& gradient = state().gradient) {
auto& colors = gradient.state.colors;
nall::image fill;
image fill;
fill.allocate(width, height);
fill.gradient(colors[0].value(), colors[1].value(), colors[2].value(), colors[3].value());
memory::copy(pixels.data(), fill.data(), fill.size());
} else {
uint32_t color = state().color.value();
uint32 color = state().color.value();
for(auto& pixel : pixels) pixel = color;
}
}

View File

@@ -10,7 +10,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 _paint() -> void;

View File

@@ -9,7 +9,7 @@ static auto CALLBACK CheckButton_windowProc(HWND hwnd, UINT msg, WPARAM wparam,
if(msg == WM_ERASEBKGND) return DefWindowProc(hwnd, msg, wparam, lparam);
if(msg == WM_PAINT) return Button_paintProc(hwnd, msg, wparam, lparam,
button->state.bordered, button->state.checked, button->enabled(true), button->font(true),
button->state.image, button->state.orientation, button->state.text
button->state.icon, button->state.orientation, button->state.text
);
return self->windowProc(hwnd, msg, wparam, lparam);
}
@@ -35,16 +35,16 @@ auto pCheckButton::destruct() -> void {
}
auto pCheckButton::minimumSize() const -> Size {
Size image = state().image.size();
Size icon = {(int)state().icon.width(), (int)state().icon.height()};
Size text = state().text ? pFont::size(self().font(true), state().text) : Size{};
Size size;
if(state().orientation == Orientation::Horizontal) {
size.setWidth(image.width() + (image && text ? 5 : 0) + text.width());
size.setHeight(max(image.height(), text.height()));
size.setWidth(icon.width() + (icon && text ? 5 : 0) + text.width());
size.setHeight(max(icon.height(), text.height()));
}
if(state().orientation == Orientation::Vertical) {
size.setWidth(max(image.width(), text.width()));
size.setHeight(image.height() + (image && text ? 5 : 0) + text.height());
size.setWidth(max(icon.width(), text.width()));
size.setHeight(icon.height() + (icon && text ? 5 : 0) + text.height());
}
size.setHeight(max(size.height(), pFont::size(self().font(true), " ").height()));
return {size.width() + (state().bordered && text ? 20 : 10), size.height() + 10};
@@ -68,7 +68,7 @@ auto pCheckButton::setFont(const Font& font) -> void {
_setState();
}
auto pCheckButton::setImage(const Image& image) -> void {
auto pCheckButton::setIcon(const image& icon) -> void {
_setState();
}

View File

@@ -10,7 +10,7 @@ struct pCheckButton : pWidget {
auto setEnabled(bool enabled) -> void override;
auto setFont(const Font& font) -> void override;
auto setChecked(bool checked) -> void;
auto setImage(const Image& image) -> void;
auto setIcon(const image& icon) -> void;
auto setOrientation(Orientation orientation) -> void;
auto setText(const string& text) -> void;
auto setVisible(bool visible) -> void override;

View File

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

View File

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

View File

@@ -15,6 +15,12 @@ auto pFrame::destruct() -> void {
DestroyWindow(hwnd);
}
auto pFrame::append(sLayout layout) -> void {
}
auto pFrame::remove(sLayout layout) -> void {
}
auto pFrame::setEnabled(bool enabled) -> void {
if(auto layout = state().layout) layout->setEnabled(layout->enabled());
pWidget::setEnabled(enabled);

View File

@@ -5,6 +5,8 @@ namespace hiro {
struct pFrame : pWidget {
Declare(Frame, Widget)
auto append(sLayout layout) -> void;
auto remove(sLayout layout) -> void;
auto setEnabled(bool enabled) -> void override;
auto setGeometry(Geometry geometry) -> void override;
auto setText(const string& text) -> void;

View File

@@ -27,7 +27,7 @@ auto pListViewCell::setForegroundColor(Color color) -> void {
_repaint();
}
auto pListViewCell::setImage(const Image& icon) -> void {
auto pListViewCell::setIcon(const image& icon) -> void {
_repaint();
}

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 _parent() -> maybe<pListViewItem&>;

View File

@@ -49,7 +49,7 @@ auto pListViewColumn::setHorizontalAlignment(double alignment) -> void {
_setState();
}
auto pListViewColumn::setImage(const Image& image) -> void {
auto pListViewColumn::setIcon(const image& icon) -> void {
_setState();
}
@@ -97,7 +97,7 @@ auto pListViewColumn::_setState() -> void {
lvColumn.cx = _width;
if(state().horizontalAlignment < 0.333) lvColumn.fmt = LVCFMT_LEFT;
if(state().horizontalAlignment > 0.666) lvColumn.fmt = LVCFMT_RIGHT;
if(state().image) lvColumn.mask |= LVCF_IMAGE;
if(state().icon) lvColumn.mask |= LVCF_IMAGE;
if(!state().resizable) lvColumn.fmt |= LVCFMT_FIXED_WIDTH;
ListView_SetColumn(grandparent->hwnd, self().offset(), &lvColumn);
grandparent->unlock();

View File

@@ -12,7 +12,7 @@ struct pListViewColumn : pObject {
auto setExpandable(bool expandable) -> void;
auto setForegroundColor(Color color) -> void;
auto setHorizontalAlignment(double alignment) -> 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

@@ -218,11 +218,11 @@ auto pListView::onCustomDraw(LPARAM lparam) -> LRESULT {
rc.left += 2;
}
if(auto& image = cell->state.image) {
auto bitmap = CreateBitmap(image);
if(auto& icon = cell->state.icon) {
auto bitmap = CreateBitmap(icon);
SelectBitmap(hdcSource, bitmap);
BLENDFUNCTION blend{AC_SRC_OVER, 0, (BYTE)(selected ? 128 : 255), AC_SRC_ALPHA};
AlphaBlend(hdc, rc.left, rc.top, iconSize, iconSize, hdcSource, 0, 0, image.width(), image.height(), blend);
AlphaBlend(hdc, rc.left, rc.top, iconSize, iconSize, hdcSource, 0, 0, icon.width(), icon.height(), blend);
DeleteObject(bitmap);
rc.left += iconSize + 2;
}
@@ -322,7 +322,7 @@ auto pListView::_cellWidth(unsigned _row, unsigned _column) -> unsigned {
if(cell->state.checkable) {
width += 16 + 2;
}
if(auto& image = cell->state.image) {
if(auto& icon = cell->state.icon) {
width += 16 + 2;
}
if(auto& text = cell->state.text) {
@@ -337,7 +337,7 @@ auto pListView::_columnWidth(unsigned _column) -> unsigned {
unsigned width = 12;
if(auto header = state().header) {
if(auto column = header->column(_column)) {
if(auto& image = column->state.image) {
if(auto& icon = column->state.icon) {
width += 16 + 12; //yes; icon spacing in column headers is excessive
}
if(auto& text = column->state.text) {
@@ -384,10 +384,10 @@ auto pListView::_setIcons() -> void {
if(auto& header = state().header) {
for(auto column : range(header->columnCount())) {
nall::image icon;
if(auto& image = header->state.columns[column]->state.image) {
icon.allocate(image.width(), image.height());
memory::copy(icon.data(), image.data(), icon.size());
image icon;
if(auto& sourceIcon = header->state.columns[column]->state.icon) {
icon.allocate(sourceIcon.width(), sourceIcon.height());
memory::copy(icon.data(), sourceIcon.data(), icon.size());
icon.scale(16, 16);
} else {
icon.allocate(16, 16);
@@ -400,7 +400,7 @@ auto pListView::_setIcons() -> void {
}
//empty icon used for ListViewItems (drawn manually via onCustomDraw)
nall::image icon;
image icon;
icon.allocate(16, 16);
icon.fill(0x00ffffff);
auto bitmap = CreateBitmap(icon);

View File

@@ -9,7 +9,7 @@ static auto CALLBACK RadioButton_windowProc(HWND hwnd, UINT msg, WPARAM wparam,
if(msg == WM_ERASEBKGND) return DefWindowProc(hwnd, msg, wparam, lparam);
if(msg == WM_PAINT) return Button_paintProc(hwnd, msg, wparam, lparam,
button->state.bordered, button->state.checked, button->enabled(true), button->font(true),
button->state.image, button->state.orientation, button->state.text
button->state.icon, button->state.orientation, button->state.text
);
return self->windowProc(hwnd, msg, wparam, lparam);
}
@@ -35,16 +35,16 @@ auto pRadioButton::destruct() -> void {
}
auto pRadioButton::minimumSize() const -> Size {
Size image = state().image.size();
Size icon = {(int)state().icon.width(), (int)state().icon.height()};
Size text = state().text ? pFont::size(self().font(true), state().text) : Size{};
Size size;
if(state().orientation == Orientation::Horizontal) {
size.setWidth(image.width() + (image && text ? 5 : 0) + text.width());
size.setHeight(max(image.height(), text.height()));
size.setWidth(icon.width() + (icon && text ? 5 : 0) + text.width());
size.setHeight(max(icon.height(), text.height()));
}
if(state().orientation == Orientation::Vertical) {
size.setWidth(max(image.width(), text.width()));
size.setHeight(image.height() + (image && text ? 5 : 0) + text.height());
size.setWidth(max(icon.width(), text.width()));
size.setHeight(icon.height() + (icon && text ? 5 : 0) + text.height());
}
size.setHeight(max(size.height(), pFont::size(self().font(true), " ").height()));
return {size.width() + (state().bordered && text ? 20 : 10), size.height() + 10};
@@ -94,7 +94,7 @@ auto pRadioButton::setGroup(sGroup group) -> void {
}
}
auto pRadioButton::setImage(const Image& image) -> void {
auto pRadioButton::setIcon(const image& icon) -> void {
_setState();
}

View File

@@ -11,7 +11,7 @@ struct pRadioButton : pWidget {
auto setEnabled(bool enabled) -> void override;
auto setFont(const Font& font) -> void override;
auto setGroup(sGroup group) -> 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;
auto setVisible(bool visible) -> void override;

View File

@@ -24,7 +24,7 @@ auto pTabFrameItem::setClosable(bool closable) -> void {
//unsupported
}
auto pTabFrameItem::setImage(const Image& image) -> void {
auto pTabFrameItem::setIcon(const image& icon) -> void {
if(auto parent = _parent()) {
parent->_buildImageList();
}

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

@@ -39,7 +39,7 @@ auto pTabFrame::append(sTabFrameItem item) -> void {
TabCtrl_InsertItem(hwnd, item->offset(), &tcItem);
if(auto self = item->self()) {
self->setClosable(item->state.closable);
self->setImage(item->state.image);
self->setIcon(item->state.icon);
self->setMovable(item->state.movable);
self->setText(item->state.text);
if(item->selected()) self->setSelected();
@@ -94,13 +94,13 @@ auto pTabFrame::_buildImageList() -> void {
if(imageList) { ImageList_Destroy(imageList); imageList = nullptr; }
imageList = ImageList_Create(size, size, ILC_COLOR32, 1, 0);
for(auto& item : state().items) {
ImageList_Append(imageList, item->state.image, size);
ImageList_Append(imageList, item->state.icon, size);
}
TabCtrl_SetImageList(hwnd, imageList);
for(auto offset : range(state().items)) {
TCITEM tcItem;
tcItem.mask = TCIF_IMAGE;
tcItem.iImage = state().items[offset]->state.image ? offset : -1;
tcItem.iImage = state().items[offset]->state.icon ? offset : -1;
TabCtrl_SetItem(hwnd, offset, &tcItem);
}
}