summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSven Weidauer <sven.weidauer@gmail.com>2011-01-28 08:54:55 +0000
committerSven Weidauer <sven.weidauer@gmail.com>2011-01-28 08:54:55 +0000
commitaa3fc46df54bf3f6591c8b127b93001a80c03118 (patch)
treea7578241121b5d79bacb4c5943987bea7545a34c
parenta1f1138479a276b78be2866bd6a29ee6eb019fb6 (diff)
downloadnetsurf-aa3fc46df54bf3f6591c8b127b93001a80c03118.tar.gz
netsurf-aa3fc46df54bf3f6591c8b127b93001a80c03118.tar.bz2
Implemented resolution independence fot the TreeView and HistoryView and moved the coordinate transform function to their own header.
svn path=/trunk/netsurf/; revision=11513
-rw-r--r--cocoa/FormSelectMenu.m9
-rw-r--r--cocoa/HistoryView.m11
-rw-r--r--cocoa/NetSurf.xcodeproj/project.pbxproj2
-rw-r--r--cocoa/TreeView.m29
-rw-r--r--cocoa/coordinates.h114
-rw-r--r--cocoa/plotter.h70
-rw-r--r--cocoa/plotter.m4
7 files changed, 150 insertions, 89 deletions
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 = "<group>"; };
262711C212DDDDC300B2FA62 /* NetSurf.xcconfig */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.xcconfig; path = NetSurf.xcconfig; sourceTree = "<group>"; };
262711D412DDDEEE00B2FA62 /* common.xcconfig */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.xcconfig; path = common.xcconfig; sourceTree = "<group>"; };
+ 2639E20512F2ADEE00699678 /* coordinates.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = coordinates.h; sourceTree = "<group>"; };
264C344112F0987E00D11246 /* gui.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = gui.h; sourceTree = "<group>"; };
265F30A712D6637E0048B600 /* NetSurf-Info.plist */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.plist.xml; path = "NetSurf-Info.plist"; sourceTree = "<group>"; };
265F30AB12D6637E0048B600 /* Prefix.pch */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = Prefix.pch; sourceTree = "<group>"; };
@@ -863,6 +864,7 @@
261223B712D77F9C00E10F91 /* font.h */,
265F321E12D66D510048B600 /* font.m */,
26AFED0312E09916005AD082 /* selection.m */,
+ 2639E20512F2ADEE00699678 /* coordinates.h */,
);
name = "Platform Interface";
sourceTree = "<group>";
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 <sven.weidauer@gmail.com>
+ *
+ * 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 <http://www.gnu.org/licenses/>.
+ */
+
+#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 <Cocoa/Cocoa.h>
#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)
{