From aa3fc46df54bf3f6591c8b127b93001a80c03118 Mon Sep 17 00:00:00 2001 From: Sven Weidauer Date: Fri, 28 Jan 2011 08:54:55 +0000 Subject: Implemented resolution independence fot the TreeView and HistoryView and moved the coordinate transform function to their own header. svn path=/trunk/netsurf/; revision=11513 --- cocoa/FormSelectMenu.m | 9 +-- cocoa/HistoryView.m | 11 ++- cocoa/NetSurf.xcodeproj/project.pbxproj | 2 + cocoa/TreeView.m | 29 +++++--- cocoa/coordinates.h | 114 ++++++++++++++++++++++++++++++++ cocoa/plotter.h | 70 +------------------- cocoa/plotter.m | 4 ++ 7 files changed, 150 insertions(+), 89 deletions(-) create mode 100644 cocoa/coordinates.h diff --git a/cocoa/FormSelectMenu.m b/cocoa/FormSelectMenu.m index dba919e23..822655839 100644 --- a/cocoa/FormSelectMenu.m +++ b/cocoa/FormSelectMenu.m @@ -19,7 +19,7 @@ #import "FormSelectMenu.h" #import "render/form.h" -#import "render/box.h" +#import "cocoa/coordinates.h" @interface FormSelectMenu () @@ -78,12 +78,7 @@ cell = [[NSPopUpButtonCell alloc] initTextCell: @"" pullsDown: YES]; [cell setMenu: menu]; - struct rect r; - box_bounds( control->box, &r ); - - - const NSRect rect = NSMakeRect( browser->scale * r.x0, browser->scale * r.y0, - browser->scale * (r.x1 - r.x0), browser->scale * (r.y1 - r.y0) ); + const NSRect rect = cocoa_rect_for_box( browser, control->box ); [cell attachPopUpWithFrame: rect inView: view]; [cell performClickWithFrame: rect inView: view]; diff --git a/cocoa/HistoryView.m b/cocoa/HistoryView.m index bbaec6c6e..9dc8da71c 100644 --- a/cocoa/HistoryView.m +++ b/cocoa/HistoryView.m @@ -22,12 +22,14 @@ #import "desktop/history_core.h" #import "desktop/plotters.h" #import "cocoa/font.h" +#import "cocoa/coordinates.h" +#import "cocoa/plotter.h" static NSRect cocoa_history_rect( struct browser_window *bw ) { int width, height; history_size( bw->history, &width, &height ); - return NSMakeRect( 0, 0, width + 10, height + 10 ); + return cocoa_rect( 0, 0, width + 10, height + 10 ); } @implementation HistoryView @@ -98,7 +100,8 @@ static NSRect cocoa_history_rect( struct browser_window *bw ) [path stroke]; cocoa_set_font_scale_factor( 1.0 ); - plot.clip( NSMinX( rect ), NSMinY( rect ), NSMaxX( rect ), NSMaxY( rect ) ); + cocoa_set_clip( rect ); + history_redraw( browser->history ); } @@ -106,7 +109,9 @@ static NSRect cocoa_history_rect( struct browser_window *bw ) { const NSPoint location = [self convertPoint: [theEvent locationInWindow] fromView: nil]; const bool newWindow = [theEvent modifierFlags] & NSCommandKeyMask; - history_click( browser, browser->history, location.x, location.y, newWindow ); + history_click( browser, browser->history, + cocoa_pt_to_px( location.x ), cocoa_pt_to_px( location.y ), + newWindow ); } - (BOOL) isFlipped; diff --git a/cocoa/NetSurf.xcodeproj/project.pbxproj b/cocoa/NetSurf.xcodeproj/project.pbxproj index 22188e5a9..07e7efeaf 100644 --- a/cocoa/NetSurf.xcodeproj/project.pbxproj +++ b/cocoa/NetSurf.xcodeproj/project.pbxproj @@ -322,6 +322,7 @@ 262711BE12DDDD1500B2FA62 /* release.xcconfig */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.xcconfig; path = release.xcconfig; sourceTree = ""; }; 262711C212DDDDC300B2FA62 /* NetSurf.xcconfig */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.xcconfig; path = NetSurf.xcconfig; sourceTree = ""; }; 262711D412DDDEEE00B2FA62 /* common.xcconfig */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.xcconfig; path = common.xcconfig; sourceTree = ""; }; + 2639E20512F2ADEE00699678 /* coordinates.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = coordinates.h; sourceTree = ""; }; 264C344112F0987E00D11246 /* gui.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = gui.h; sourceTree = ""; }; 265F30A712D6637E0048B600 /* NetSurf-Info.plist */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.plist.xml; path = "NetSurf-Info.plist"; sourceTree = ""; }; 265F30AB12D6637E0048B600 /* Prefix.pch */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = Prefix.pch; sourceTree = ""; }; @@ -863,6 +864,7 @@ 261223B712D77F9C00E10F91 /* font.h */, 265F321E12D66D510048B600 /* font.m */, 26AFED0312E09916005AD082 /* selection.m */, + 2639E20512F2ADEE00699678 /* coordinates.h */, ); name = "Platform Interface"; sourceTree = ""; diff --git a/cocoa/TreeView.m b/cocoa/TreeView.m index e67e89db4..4f5f9b7be 100644 --- a/cocoa/TreeView.m +++ b/cocoa/TreeView.m @@ -21,7 +21,7 @@ #import "desktop/tree.h" #import "desktop/plotters.h" #import "desktop/history_global_core.h" - +#import "cocoa/coordinates.h" @implementation TreeView @@ -60,7 +60,9 @@ static const struct treeview_table cocoa_tree_callbacks = { - (void)drawRect:(NSRect)dirtyRect { tree_set_redraw( treeHandle, true ); - tree_draw( treeHandle, 0, 0, NSMinX( dirtyRect ), NSMinY( dirtyRect ), NSWidth( dirtyRect ), NSHeight( dirtyRect ) ); + tree_draw( treeHandle, 0, 0, + cocoa_pt_to_px( NSMinX( dirtyRect ) ), cocoa_pt_to_px( NSMinY( dirtyRect ) ), + cocoa_pt_to_px( NSWidth( dirtyRect ) ), cocoa_pt_to_px( NSHeight( dirtyRect ) ) ); } - (BOOL) isFlipped; @@ -73,17 +75,21 @@ static const struct treeview_table cocoa_tree_callbacks = { NSPoint point = [self convertPoint: [theEvent locationInWindow] fromView: nil]; dragStart = point; - tree_mouse_action( treeHandle, BROWSER_MOUSE_PRESS_1, point.x, point.y ); + tree_mouse_action( treeHandle, BROWSER_MOUSE_PRESS_1, + cocoa_pt_to_px( point.x ), cocoa_pt_to_px( point.y ) ); } - (void) mouseUp: (NSEvent *)theEvent; { NSPoint point = [self convertPoint: [theEvent locationInWindow] fromView: nil]; if (isDragging) { - tree_drag_end( treeHandle, BROWSER_MOUSE_DRAG_1, dragStart.x, dragStart.y, point.x, point.y ); + tree_drag_end( treeHandle, BROWSER_MOUSE_DRAG_1, + cocoa_pt_to_px( dragStart.x ), cocoa_pt_to_px( dragStart.y ), + cocoa_pt_to_px( point.x ), cocoa_pt_to_px( point.y ) ); isDragging = NO; } else { - tree_mouse_action( treeHandle, BROWSER_MOUSE_CLICK_1, point.x, point.y ); + tree_mouse_action( treeHandle, BROWSER_MOUSE_CLICK_1, + cocoa_pt_to_px( point.x ), cocoa_pt_to_px( point.y ) ); } } @@ -101,30 +107,31 @@ static const struct treeview_table cocoa_tree_callbacks = { } if (isDragging) { - tree_mouse_action( treeHandle, BROWSER_MOUSE_DRAG_1, point.x, point.y ); + tree_mouse_action( treeHandle, BROWSER_MOUSE_DRAG_1, + cocoa_pt_to_px( point.x ), cocoa_pt_to_px( point.y ) ); } } static void tree_redraw_request( int x, int y, int w, int h, void *data ) { - [(TreeView *)data setNeedsDisplayInRect: NSMakeRect( x, y, w, h )]; + [(TreeView *)data setNeedsDisplayInRect: cocoa_rect_wh( x, y, w, h )]; } static void tree_resized( struct tree *tree, int w, int h, void *data ) { - [(TreeView *)data setMinimumSize: NSMakeSize( w, h )]; + [(TreeView *)data setMinimumSize: cocoa_size( w, h )]; } static void tree_scroll_visible( int y, int height, void *data ) { - [(TreeView *)data scrollPoint: NSMakePoint( 0, y )]; + [(TreeView *)data scrollPoint: cocoa_point( 0, y )]; } static void tree_get_window_dimensions( int *width, int *height, void *data ) { NSSize size = [(TreeView *)data frame].size; - *width = size.width; - *height = size.height; + *width = cocoa_pt_to_px( size.width ); + *height = cocoa_pt_to_px( size.height ); } @end diff --git a/cocoa/coordinates.h b/cocoa/coordinates.h new file mode 100644 index 000000000..5d044b04b --- /dev/null +++ b/cocoa/coordinates.h @@ -0,0 +1,114 @@ +/* + * Copyright 2011 Sven Weidauer + * + * This file is part of NetSurf, http://www.netsurf-browser.org/ + * + * NetSurf is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; version 2 of the License. + * + * NetSurf is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +#ifndef COCOA_COORDINATES_H +#define COCOA_COORDINATES_H + +#import "desktop/browser.h" +#import "render/box.h" + +extern CGFloat cocoa_scale_factor; + +static inline CGFloat cocoa_px_to_pt( int location ) __attribute__((always_inline,pure)); +static inline CGFloat cocoa_px_to_pt_f( CGFloat location ) __attribute__((always_inline,pure)); + +static inline int cocoa_pt_to_px( CGFloat location ) __attribute__((always_inline,pure)); + +static inline NSPoint cocoa_point( int x, int y ) __attribute__((always_inline,pure)); +static inline NSPoint cocoa_scaled_point( CGFloat scale, int x, int y ) __attribute__((always_inline,pure)); + +static inline NSSize cocoa_size( int w, int h ) __attribute__((always_inline,pure)); +static inline NSSize cocoa_scaled_size( CGFloat scale, int w, int h ) __attribute__((always_inline,pure)); + +static inline NSRect cocoa_rect( int x0, int y0, int x1, int y1 ) __attribute__((always_inline,pure)); +static inline NSRect cocoa_rect_wh( int x, int y, int w, int h ) __attribute__((always_inline,pure)); + +static inline NSRect cocoa_scaled_rect( CGFloat scale, int x0, int y0, int x1, int y1 ) __attribute__((always_inline,pure)); +static inline NSRect cocoa_scaled_rect_wh( CGFloat scale, int x, int y, int w, int h ) __attribute__((always_inline,pure)); + +static inline CGFloat cocoa_px_to_pt( int location ) +{ + return (CGFloat)location * cocoa_scale_factor; +} + +static inline CGFloat cocoa_px_to_pt_f( CGFloat location ) +{ + return floor( location ) * cocoa_scale_factor; +} + +static inline int cocoa_pt_to_px( CGFloat location ) +{ + return location / cocoa_scale_factor; +} + +static inline NSPoint cocoa_point( int x, int y ) +{ + return NSMakePoint( cocoa_px_to_pt( x ), cocoa_px_to_pt( y ) ); +} + +static inline NSPoint cocoa_scaled_point( CGFloat scale, int x, int y ) +{ + return NSMakePoint( cocoa_px_to_pt_f( scale * x ), cocoa_px_to_pt_f( scale * y ) ); +} + +static inline NSSize cocoa_size( int w, int h ) +{ + return NSMakeSize( cocoa_px_to_pt( w ), cocoa_px_to_pt( h ) ); +} + +static inline NSSize cocoa_scaled_size( CGFloat scale, int w, int h ) +{ + return NSMakeSize( cocoa_px_to_pt_f( scale * w ), cocoa_px_to_pt_f( scale * h ) ); +} + +static inline NSRect cocoa_rect( int x0, int y0, int x1, int y1 ) +{ + return cocoa_rect_wh( x0, y0, x1 - x0, y1 - y0 ); +} + +static inline NSRect cocoa_rect_wh( int x, int y, int w, int h ) +{ + const NSRect result = { + .origin = cocoa_point( x, y ), + .size = cocoa_size( w, h ) + }; + return result; +} + +static inline NSRect cocoa_scaled_rect_wh( CGFloat scale, int x, int y, int w, int h ) +{ + const NSRect result = { + .origin = cocoa_scaled_point( scale, x, y ), + .size = cocoa_scaled_size( scale, w, h ) + }; + return result; +} + +static inline NSRect cocoa_scaled_rect( CGFloat scale, int x0, int y0, int x1, int y1 ) +{ + return cocoa_scaled_rect_wh( scale, x0, y0, x1 - x0, y1 - y0 ); +} + +static inline NSRect cocoa_rect_for_box( struct browser_window *bw, struct box *box ) +{ + struct rect r; + box_bounds( box, &r ); + return cocoa_scaled_rect( bw->scale, r.x0, r.y0, r.x1, r.y1 ); +} + +#endif diff --git a/cocoa/plotter.h b/cocoa/plotter.h index e756a26f6..fbcbc4615 100644 --- a/cocoa/plotter.h +++ b/cocoa/plotter.h @@ -21,78 +21,12 @@ #import #import "desktop/plot_style.h" +#import "cocoa/coordinates.h" NSColor *cocoa_convert_colour( colour clr ); void cocoa_update_scale_factor( void ); -extern CGFloat cocoa_scale_factor; - -static inline CGFloat cocoa_px_to_pt( int location ) __attribute__((always_inline,pure)); -static inline CGFloat cocoa_px_to_pt_f( CGFloat location ) __attribute__((always_inline,pure)); -static inline int cocoa_pt_to_px( CGFloat location ) __attribute__((always_inline,pure)); -static inline NSPoint cocoa_point( int x, int y ) __attribute__((always_inline,pure)); -static inline NSSize cocoa_size( int w, int h ) __attribute__((always_inline,pure)); -static inline NSSize cocoa_scaled_size( float scale, int w, int h ) __attribute__((always_inline,pure)); -static inline NSRect cocoa_rect( int x0, int y0, int x1, int y1 ) __attribute__((always_inline,pure)); -static inline NSRect cocoa_rect_wh( int x, int y, int w, int h ) __attribute__((always_inline,pure)); -static inline NSRect cocoa_scaled_rect_wh( float scale, int x, int y, int w, int h ) __attribute__((always_inline,pure)); - -static inline CGFloat cocoa_px_to_pt( int location ) -{ - return ((CGFloat)location) * cocoa_scale_factor; -} - -static inline CGFloat cocoa_px_to_pt_f( CGFloat location ) -{ - return floor( location ) * cocoa_scale_factor; -} - -static inline int cocoa_pt_to_px( CGFloat location ) -{ - return location / cocoa_scale_factor; -} - -static inline NSPoint cocoa_point( int x, int y ) -{ - return NSMakePoint( cocoa_px_to_pt( x ), cocoa_px_to_pt( y ) ); -} - -static inline NSSize cocoa_size( int w, int h ) -{ - return NSMakeSize( cocoa_px_to_pt( w ), cocoa_px_to_pt( h ) ); -} - -static inline NSSize cocoa_scaled_size( float scale, int w, int h ) -{ - return NSMakeSize( cocoa_px_to_pt_f( scale * w ), cocoa_px_to_pt_f( scale * h ) ); -} - -static inline NSRect cocoa_rect( int x0, int y0, int x1, int y1 ) -{ - const NSRect result = { - .origin = cocoa_point( x0, y0 ), - .size = cocoa_size( x1 - x0, y1 - y0 ) - }; - return result; -} - -static inline NSRect cocoa_rect_wh( int x, int y, int w, int h ) -{ - const NSRect result = { - .origin = cocoa_point( x, y ), - .size = cocoa_size( w, h ) - }; - return result; -} - -static inline NSRect cocoa_scaled_rect_wh( float scale, int x, int y, int w, int h ) -{ - const NSRect result = { - .origin = NSMakePoint( cocoa_px_to_pt_f( scale * x ), cocoa_px_to_pt_f( scale * y ) ), - .size = cocoa_scaled_size( scale, w, h ) - }; - return result; -} +void cocoa_set_clip( NSRect rect ); #endif diff --git a/cocoa/plotter.m b/cocoa/plotter.m index c37a017c9..bff1ac02a 100644 --- a/cocoa/plotter.m +++ b/cocoa/plotter.m @@ -119,6 +119,10 @@ static bool plot_text(int x, int y, const char *text, size_t length, return true; } +void cocoa_set_clip( NSRect rect ) +{ + cocoa_plot_clip_rect = rect; +} static bool plot_clip(int x0, int y0, int x1, int y1) { -- cgit v1.2.3