mirror of
https://github.com/fltk/fltk.git
synced 2026-05-22 23:37:02 +08:00
macOS: yet simpler implementation of window resize and rescale.
This commit is contained in:
@@ -126,10 +126,6 @@ public:
|
||||
\return The captured pixels as an RGB image
|
||||
*/
|
||||
virtual Fl_RGB_Image* rectangle_capture(Fl_Widget *widget, int x, int y, int w, int h) = 0;
|
||||
/** Returns the window's GL context */
|
||||
virtual GLContext context(Fl_Widget *widget) = 0;
|
||||
/** Equivalent to widget->as_gl_window()->valid(v) */
|
||||
virtual void valid(Fl_Widget *widget, char v) = 0;
|
||||
/** Returns the OpenGL plugin */
|
||||
static Fl_Device_Plugin *opengl_plugin();
|
||||
};
|
||||
|
||||
@@ -44,14 +44,6 @@ public:
|
||||
if (!glw) return NULL;
|
||||
return Fl_OpenGL_Display_Device::capture_gl_rectangle(glw, x, y, w, h);
|
||||
}
|
||||
virtual GLContext context(Fl_Widget *widget) {
|
||||
Fl_Gl_Window *glw = widget->as_gl_window();
|
||||
return glw ? glw->context() : (GLContext)0;
|
||||
}
|
||||
virtual void valid(Fl_Widget *widget, char v) {
|
||||
Fl_Gl_Window *glw = widget->as_gl_window();
|
||||
if (glw) glw->valid(v);
|
||||
}
|
||||
};
|
||||
|
||||
static Fl_Gl_Device_Plugin Gl_Device_Plugin;
|
||||
|
||||
@@ -597,6 +597,10 @@ void Fl_Cocoa_Gl_Window_Driver::swap_buffers() {
|
||||
|
||||
char Fl_Cocoa_Gl_Window_Driver::swap_type() {return COPY;}
|
||||
|
||||
void Fl_Cocoa_Gl_Window_Driver::resize(int is_a_resize, int w, int h) {
|
||||
Fl_Cocoa_Window_Driver::GLcontext_update(pWindow->context());
|
||||
}
|
||||
|
||||
#endif // FL_CFG_GFX_QUARTZ
|
||||
|
||||
#if defined(FL_CFG_GFX_GDI)
|
||||
|
||||
@@ -110,6 +110,7 @@ class Fl_Cocoa_Gl_Window_Driver : public Fl_Gl_Window_Driver {
|
||||
virtual int mode_(int m, const int *a);
|
||||
virtual void make_current_before();
|
||||
virtual void swap_buffers();
|
||||
virtual void resize(int is_a_resize, int w, int h);
|
||||
virtual char swap_type();
|
||||
virtual Fl_Gl_Choice *find(int m, const int *alistp);
|
||||
virtual GLContext create_gl_context(Fl_Window* window, const Fl_Gl_Choice* g, int layer = 0);
|
||||
|
||||
+14
-26
@@ -1236,7 +1236,7 @@ static FLWindowDelegate *flwindowdelegate_instance = nil;
|
||||
}
|
||||
// at least since MacOS 10.9: OS sends windowDidMove to parent window and then to children
|
||||
// FLTK sets position of parent and children. setSubwindowFrame is no longer necessary.
|
||||
if (fl_mac_os_version < 100900) [nsw recursivelySendToSubwindows:@selector(setSubwindowFrame) applyToSelf:NO];
|
||||
if (fl_mac_os_version < 100900) [nsw recursivelySendToSubwindows:@selector(setSubwindowFrame) applyToSelf:NO];
|
||||
[nsw checkSubwindowFrame];
|
||||
#if MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_8
|
||||
FLView *view = (FLView*)[nsw contentView];
|
||||
@@ -1254,28 +1254,12 @@ static FLWindowDelegate *flwindowdelegate_instance = nil;
|
||||
Fl_Window *window = [nsw getFl_Window];
|
||||
int X, Y;
|
||||
CocoatoFLTK(window, X, Y);
|
||||
Fl_Cocoa_Window_Driver *d = Fl_Cocoa_Window_Driver::driver(window);
|
||||
if (window->as_gl_window() && window->shown()) {
|
||||
Fl_Device_Plugin *plugin = Fl_Device_Plugin::opengl_plugin();
|
||||
if (plugin) {
|
||||
plugin->valid(window, 0);
|
||||
[plugin->context(window) update];
|
||||
}
|
||||
}
|
||||
float s = Fl::screen_driver()->scale(window->screen_num());
|
||||
NSRect r = [view frame];
|
||||
Fl_Cocoa_Window_Driver::driver(window)->view_resized(1);
|
||||
window->resize(X, Y, lround(r.size.width/s), lround(r.size.height/s));
|
||||
Fl_Cocoa_Window_Driver::driver(window)->view_resized(0);
|
||||
update_e_xy_and_e_xy_root(nsw);
|
||||
if (d->is_a_rescale()) {
|
||||
d->x(X); d->y(Y);
|
||||
[nsw recursivelySendToSubwindows:@selector(setSubwindowFrame) applyToSelf:NO];
|
||||
}
|
||||
else {
|
||||
float s = Fl::screen_driver()->scale(d->screen_num());
|
||||
NSRect r = [view frame];
|
||||
if (d->other_xid && ( window->w() < lround(r.size.width/s) || window->h() < lround(r.size.height/s) )) {
|
||||
d->destroy_double_buffer(); // for Fl_Overlay_Window
|
||||
}
|
||||
window->Fl_Group::resize(X, Y, lround(r.size.width/s), lround(r.size.height/s));
|
||||
}
|
||||
[nsw recursivelySendToSubwindows:@selector(checkSubwindowFrame) applyToSelf:NO];
|
||||
#if MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_8
|
||||
if (views_use_CA && !window->as_gl_window()) [(FLViewLayer*)view reset_layer_data];
|
||||
#endif
|
||||
@@ -3321,7 +3305,9 @@ void Fl_Cocoa_Window_Driver::show() {
|
||||
* resize a window
|
||||
*/
|
||||
void Fl_Cocoa_Window_Driver::resize(int X, int Y, int W, int H) {
|
||||
if (visible_r()) {
|
||||
if (view_resized() || !visible_r()) {
|
||||
pWindow->Fl_Group::resize(X, Y, W, H);
|
||||
} else {
|
||||
NSPoint pt = FLTKtoCocoa(pWindow, X, Y, H);
|
||||
FLWindow *xid = fl_xid(pWindow);
|
||||
if (W != w() || H != h() || is_a_rescale()) {
|
||||
@@ -3332,13 +3318,15 @@ void Fl_Cocoa_Window_Driver::resize(int X, int Y, int W, int H) {
|
||||
r.origin = pt;
|
||||
r.size.width = round(W*s);
|
||||
r.size.height = round(H*s) + bt;
|
||||
[xid setFrame:r display:YES];
|
||||
if (NSEqualRects(r, [xid frame])) pWindow->Fl_Group::resize(X, Y, W, H);
|
||||
else [xid setFrame:r display:YES];
|
||||
pWindow->redraw();
|
||||
}
|
||||
else {
|
||||
[xid setFrameOrigin:pt]; // set cocoa coords to FLTK position
|
||||
x(X); y(Y); // useful when frame did not move
|
||||
x(X); y(Y); // useful when frame did not move but X or Y changed
|
||||
}
|
||||
} else pWindow->Fl_Group::resize(X, Y, W, H);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -82,7 +82,8 @@ private:
|
||||
void shape_bitmap_(Fl_Image* b);
|
||||
void shape_alpha_(Fl_Image* img, int offset);
|
||||
CGRect* subRect_; // makes sure subwindow remains inside its parent window
|
||||
// stores 2 binary flags: whether window is mapped to retina display; whether resolution just changed
|
||||
// stores 3 binary flags: whether window is mapped to retina display; whether resolution just changed;
|
||||
// whether window's view received the [FLView view_did_resize] message
|
||||
unsigned window_flags_;
|
||||
public:
|
||||
Fl_Cocoa_Window_Driver(Fl_Window*);
|
||||
@@ -97,6 +98,8 @@ public:
|
||||
void mapped_to_retina(bool); // sets whether window is mapped to retina display
|
||||
bool changed_resolution(); // did window just moved to display with another resolution?
|
||||
void changed_resolution(bool);// sets whether window just moved to display with another resolution
|
||||
bool view_resized(); // did window's view receive [FLView view_did_resize] message?
|
||||
void view_resized(bool b); // sets whether window's view received [FLView view_did_resize] message
|
||||
CGRect* subRect() { return subRect_; } // getter
|
||||
void subRect(CGRect *r) { subRect_ = r; } // setter
|
||||
static void destroy(FLWindow*);
|
||||
|
||||
@@ -49,6 +49,7 @@ Fl_Cocoa_Window_Driver::Fl_Cocoa_Window_Driver(Fl_Window *win)
|
||||
: Fl_Window_Driver(win)
|
||||
{
|
||||
cursor = nil;
|
||||
window_flags_ = 0;
|
||||
}
|
||||
|
||||
|
||||
@@ -274,6 +275,7 @@ int Fl_Cocoa_Window_Driver::scroll(int src_x, int src_y, int src_w, int src_h, i
|
||||
|
||||
static const unsigned mapped_mask = 1;
|
||||
static const unsigned changed_mask = 2;
|
||||
static const unsigned view_resized_mask = 4;
|
||||
|
||||
bool Fl_Cocoa_Window_Driver::mapped_to_retina() {
|
||||
return window_flags_ & mapped_mask;
|
||||
@@ -293,6 +295,16 @@ void Fl_Cocoa_Window_Driver::changed_resolution(bool b) {
|
||||
else window_flags_ &= ~changed_mask;
|
||||
}
|
||||
|
||||
bool Fl_Cocoa_Window_Driver::view_resized() {
|
||||
return window_flags_ & view_resized_mask;
|
||||
}
|
||||
|
||||
void Fl_Cocoa_Window_Driver::view_resized(bool b) {
|
||||
if (b) window_flags_ |= view_resized_mask;
|
||||
else window_flags_ &= ~view_resized_mask;
|
||||
}
|
||||
|
||||
|
||||
// clip the graphics context to rounded corners
|
||||
void Fl_Cocoa_Window_Driver::clip_to_rounded_corners(CGContextRef gc, int w, int h) {
|
||||
const CGFloat radius = 7.5;
|
||||
|
||||
Reference in New Issue
Block a user