Newest update

This commit is contained in:
Morten Delenk 2016-09-03 17:58:22 +02:00
parent 8cc9b803da
commit 98013a8337
No known key found for this signature in database
GPG key ID: 3F818D0F65DCB490
5 changed files with 37 additions and 7 deletions

View file

@ -1,4 +1,5 @@
#include <nall/platform.hpp>
#include <nall/chrono.hpp>
#include <nall/directory.hpp>
#include <nall/function.hpp>
#include <nall/image.hpp>
@ -203,6 +204,8 @@ struct Position {
Position();
Position(signed x, signed y);
template<typename X, typename Y>
Position(X x, Y y) : Position((signed)x, (signed)y) {}
explicit operator bool() const;
auto operator==(const Position& source) const -> bool;
@ -230,6 +233,8 @@ struct Size {
Size();
Size(signed width, signed height);
template<typename W, typename H>
Size(W width, H height) : Size((signed)width, (signed)height) {}
explicit operator bool() const;
auto operator==(const Size& source) const -> bool;
@ -261,6 +266,8 @@ struct Geometry {
Geometry();
Geometry(Position position, Size size);
Geometry(signed x, signed y, signed width, signed height);
template<typename X, typename Y, typename W, typename H>
Geometry(X x, Y y, W width, H height) : Geometry((signed)x, (signed)y, (signed)width, (signed)height) {}
explicit operator bool() const;
auto operator==(const Geometry& source) const -> bool;

View file

@ -41,7 +41,23 @@ auto pWidget::setFont(const Font& font) -> void {
auto pWidget::setGeometry(Geometry geometry) -> void {
if(!gtkWidget) return;
if(gtkParent) gtk_fixed_move(GTK_FIXED(gtkParent), gtkWidget, geometry.x(), geometry.y());
gtk_widget_set_size_request(gtkWidget, max(1, geometry.width()), max(1, geometry.height()));
if(geometry.width() < 1) geometry.setWidth (1);
if(geometry.height() < 1) geometry.setHeight(1);
gtk_widget_set_size_request(gtkWidget, geometry.width(), geometry.height());
if(gtk_widget_get_realized(gtkWidget)) {
static bool locked = false;
if(!locked) {
locked = true;
auto time = chrono::millisecond();
while(chrono::millisecond() - time < 20) {
gtk_main_iteration_do(false);
if(gtkWidget->allocation.width != geometry.width ()) continue;
if(gtkWidget->allocation.height != geometry.height()) continue;
break;
}
locked = false;
}
}
self().doSize();
}

View file

@ -266,6 +266,8 @@ auto pWindow::setFullScreen(bool fullScreen) -> void {
gtk_window_unfullscreen(GTK_WINDOW(widget));
state().geometry = windowedGeometry;
}
auto time = chrono::millisecond();
while(chrono::millisecond() - time < 20) gtk_main_iteration_do(false);
}
auto pWindow::setGeometry(Geometry geometry) -> void {
@ -278,7 +280,12 @@ auto pWindow::setGeometry(Geometry geometry) -> void {
gtk_window_set_geometry_hints(GTK_WINDOW(widget), GTK_WIDGET(widget), &geom, GDK_HINT_MIN_SIZE);
gtk_widget_set_size_request(formContainer, geometry.width(), geometry.height());
auto time1 = chrono::millisecond();
while(chrono::millisecond() - time1 < 20) gtk_main_iteration_do(false);
gtk_window_resize(GTK_WINDOW(widget), geometry.width(), geometry.height() + _menuHeight() + _statusHeight());
auto time2 = chrono::millisecond();
while(chrono::millisecond() - time2 < 20) gtk_main_iteration_do(false);
}
auto pWindow::setModal(bool modal) -> void {

View file

@ -44,8 +44,8 @@ struct pWindow : pObject {
GtkWidget* gtkMenu = nullptr;
GtkWidget* gtkStatus = nullptr;
GtkAllocation lastAllocation = {0};
bool onSizePending = false;
Geometry windowedGeometry{128, 128, 256, 256};
bool onSizePending = false;
};
}

View file

@ -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);
bmi.bmiHeader.biSizeImage = pixels.size() * sizeof(uint32_t);
void* bits = nullptr;
HBITMAP bitmap = CreateDIBSection(hdc, &bmi, DIB_RGB_COLORS, &bits, nullptr, 0);
if(bits) {
auto source = (const uint8*)pixels.data();
auto target = (uint8*)bits;
auto source = (const uint8_t*)pixels.data();
auto target = (uint8_t*)bits;
for(auto n : range(width * height)) {
target[0] = (source[0] * source[3]) / 255;
target[1] = (source[1] * source[3]) / 255;
@ -155,7 +155,7 @@ auto pCanvas::_rasterize() -> void {
pixels.resize(width * height);
if(auto& icon = state().icon) {
memory::copy(pixels.data(), icon.data(), width * height * sizeof(uint32));
memory::copy(pixels.data(), icon.data(), width * height * sizeof(uint32_t));
} else if(auto& gradient = state().gradient) {
auto& colors = gradient.state.colors;
image fill;
@ -163,7 +163,7 @@ auto pCanvas::_rasterize() -> void {
fill.gradient(colors[0].value(), colors[1].value(), colors[2].value(), colors[3].value());
memory::copy(pixels.data(), fill.data(), fill.size());
} else {
uint32 color = state().color.value();
uint32_t color = state().color.value();
for(auto& pixel : pixels) pixel = color;
}
}