Commits

Anonymous committed cf4e0a0

implemented scroll by wheel. rendering isn't so great

Comments (0)

Files changed (4)

 
 - (void)windowResized:(NSNotification *)notification;
 
-- (void)OnScroll:(CGFloat)deltaX deltaY:(CGFloat)deltaY;
+- (void)SetScroll:(float)hPos vPos:(float)vPos;
 
 #pragma mark c callbacks 
 void beginRendering(void* data);
 }
 
 - (void)drawRect:(NSRect)dirtyRect {
-    
     if (_tronPDFView->GetDoc()) {
         const char* bgra = _tronPDFView->GetBuffer();
         if (bgra) {
                                                                colorSpace,
                                                                kCGImageAlphaPremultipliedLast);
             
-            CFRelease(colorSpace);
-            
             CGImageRef cgImage = CGBitmapContextCreateImage(bitmapContext);
             
             __strong NSGraphicsContext * nsGraphicsContext = [NSGraphicsContext currentContext];
             __strong CGContextRef zCgContextRef = (CGContextRef) [nsGraphicsContext graphicsPort];            
             
-            NSRect imageRect;
-            imageRect.origin = NSZeroPoint;
-            imageRect.size.width = [[self superview] bounds].size.width;
-            imageRect.size.height = [[self superview] bounds].size.height;
-            CGRect	zCgRect	= NSRectToCGRect(imageRect);
+            CGRect	zCgRect	= NSRectToCGRect([[self superview] bounds]);
 
             CGContextDrawImage(zCgContextRef, zCgRect, cgImage);
             
+            CFRelease(colorSpace);            
             CFRelease(cgImage);
             CFRelease(bitmapContext);
             free(rgba);
 
 - (void)dealloc {
     if (_tronPDFView) {
-        free(_tronPDFView);
+        _tronPDFView->~PDFView();
     }
     [[NSNotificationCenter defaultCenter] removeObserver:self];
     [super dealloc];
         _tronPDFView->SetDoc(*(myDoc.tronPDFDoc));
         _tronPDFView->SetRenderBeginProc(beginRendering, self);
         _tronPDFView->SetRenderFinishProc(endRendering, self);
+        _tronPDFView->SetPageViewMode(pdftron::PDF::PDFView::e_fit_width);
+        _tronPDFView->SetPagePresentationMode(pdftron::PDF::PDFView::e_single_continuous);
         _tronPDFView->SetPageSpacing(10, 10, 20, 10);
         [self windowResized:nil];
+        double hPos = _tronPDFView->GetHScrollPos();
+        double vPos = _tronPDFView->GetVScrollPos();
+        NSLog(@"init Scroll: hPos: %0.4, vPos: %0.4f", hPos, vPos);
     }
 }
 
     NSLog(@"keyUp");
 }
 
-- (void)OnScroll:(CGFloat)deltaX deltaY:(CGFloat)deltaY {
+- (void)SetScroll:(float)hPos vPos:(float)vPos {
     if (_tronPDFView && _tronPDFView->GetDoc()) {
-        double hPos = _tronPDFView->GetHScrollPos();
-        double vPos = _tronPDFView->GetVScrollPos();
-        //_tronPDFView->OnScroll(hPos + deltaX, vPos + deltaY);
+        double final_hPos = hPos * _tronPDFView->GetCanvasWidth();
+        double final_vPos = vPos * _tronPDFView->GetCanvasHeight();
+        //_tronPDFView->OnScroll((int) final_hPos, (int) final_vPos);
+        _tronPDFView->SetHScrollPos(final_hPos);
+        _tronPDFView->SetVScrollPos(final_vPos);
+        NSLog(@"final h %0.4f final v %0.4f canvas w %0.4f h %0.4f (int)final h %d (int)final v %d", 
+              final_hPos, final_vPos, _tronPDFView->GetCanvasWidth(), _tronPDFView->GetCanvasHeight(), 
+              (int)final_hPos, (int)final_vPos);
+        NSLog(@"result h %0.4f v %0.4f", _tronPDFView->GetHScrollPos(), _tronPDFView->GetVScrollPos());
+        _tronPDFView->Update();
+        [self setNeedsDisplay:YES];
     }
 }
 

TronScrollView.mm

     CGFloat deltaY = [theEvent deltaY];
     CGFloat deltaZ = [theEvent deltaZ];
     
-    NSLog(@"deltaX: %0.4f, deltaY: %0.4f");
+    NSLog(@"deltaX: %0.4f, deltaY: %0.4f, deltaZ: %0.4f", deltaX, deltaY, deltaZ);
     
-    [pdfView OnScroll:deltaX deltaY:deltaY];
+    float vPos = [[self verticalScroller] floatValue];
+    float hPos = [[self horizontalScroller] floatValue];
+    [pdfView SetScroll:hPos vPos:vPos];
 }
 
 @end

cocoapdf.xcodeproj/quincy.mode1v3

 			<key>Content</key>
 			<dict>
 				<key>PBXProjectModuleGUID</key>
-				<string>247157EF120E1B4E00711708</string>
+				<string>24715875120E267F00711708</string>
 				<key>PBXProjectModuleLabel</key>
 				<string>TronPDFView.mm</string>
 				<key>PBXSplitModuleInNavigatorKey</key>
 					<key>Split0</key>
 					<dict>
 						<key>PBXProjectModuleGUID</key>
-						<string>247157FD120E1CCB00711708</string>
+						<string>24715879120E26B400711708</string>
 						<key>PBXProjectModuleLabel</key>
 						<string>TronPDFView.mm</string>
 						<key>_historyCapacity</key>
 						<integer>0</integer>
 						<key>bookmark</key>
-						<string>24715811120E1DBD00711708</string>
+						<string>24715955120E52EA00711708</string>
 						<key>history</key>
 						<array>
-							<string>247157FE120E1CCB00711708</string>
-							<string>247157FF120E1CCB00711708</string>
-							<string>24715801120E1CCB00711708</string>
+							<string>24715881120E276800711708</string>
+							<string>247158A9120E419600711708</string>
+							<string>247158F1120E48B300711708</string>
+							<string>24715944120E511900711708</string>
+							<string>24715954120E52EA00711708</string>
+							<string>24715950120E529300711708</string>
 						</array>
 					</dict>
 					<key>SplitCount</key>
 				<key>PBXModuleWindowStatusBarHidden2</key>
 				<false/>
 				<key>RubberWindowFrame</key>
-				<string>227 121 1003 642 0 0 1280 778 </string>
+				<string>158 101 1003 642 0 0 1280 778 </string>
 			</dict>
 		</dict>
 	</array>
 							<key>PBXSmartGroupTreeModuleOutlineStateSelectionKey</key>
 							<array>
 								<array>
-									<integer>12</integer>
+									<integer>4</integer>
 									<integer>2</integer>
 									<integer>0</integer>
 								</array>
 										<key>_historyCapacity</key>
 										<integer>0</integer>
 										<key>bookmark</key>
-										<string>24715810120E1DBD00711708</string>
+										<string>24715953120E52EA00711708</string>
 										<key>history</key>
 										<array>
 											<string>241D2A8211FBCBED0067260B</string>
 											<string>24E4BEA71207A02F00CA10EA</string>
 											<string>24E4BECC1207A25400CA10EA</string>
 											<string>247157F8120E1CCB00711708</string>
-											<string>247157F9120E1CCB00711708</string>
+											<string>24715853120E23FA00711708</string>
 										</array>
 									</dict>
 									<key>SplitCount</key>
 	<key>PerspectivesBarVisible</key>
 	<false/>
 	<key>PinnedNavigatorIdentifier</key>
-	<string>247157EF120E1B4E00711708</string>
+	<string>24715875120E267F00711708</string>
 	<key>ShelfIsVisible</key>
 	<false/>
 	<key>SourceDescription</key>
 	<integer>5</integer>
 	<key>WindowOrderList</key>
 	<array>
-		<string>24715813120E1DBD00711708</string>
 		<string>24715814120E1DBD00711708</string>
 		<string>24715815120E1DBD00711708</string>
-		<string>1C78EAAD065D492600B07095</string>
 		<string>1CD10A99069EF8BA00B06720</string>
 		<string>/Users/quincy/Repositories/CocoaPDF/cocoapdf.xcodeproj</string>
+		<string>1C78EAAD065D492600B07095</string>
 		<string>2492503F11CB2A5D0076F523</string>
-		<string>247157EF120E1B4E00711708</string>
+		<string>24715875120E267F00711708</string>
 	</array>
 	<key>WindowString</key>
 	<string>190 177 788 504 0 0 1280 778 </string>
 			<key>WindowToolGUID</key>
 			<string>1CD10A99069EF8BA00B06720</string>
 			<key>WindowToolIsVisible</key>
-			<true/>
+			<false/>
 		</dict>
 		<dict>
 			<key>Identifier</key>
 					<key>Dock</key>
 					<array>
 						<dict>
+							<key>BecomeActive</key>
+							<true/>
 							<key>ContentConfiguration</key>
 							<dict>
 								<key>PBXProjectModuleGUID</key>
 							<key>GeometryConfiguration</key>
 							<dict>
 								<key>Frame</key>
-								<string>{{0, 0}, {641, 397}}</string>
+								<string>{{0, 0}, {953, 428}}</string>
 								<key>RubberWindowFrame</key>
-								<string>630 271 641 438 0 0 1280 778 </string>
+								<string>235 233 953 469 0 0 1280 778 </string>
 							</dict>
 							<key>Module</key>
 							<string>PBXDebugCLIModule</string>
 							<key>Proportion</key>
-							<string>397pt</string>
+							<string>428pt</string>
 						</dict>
 					</array>
 					<key>Proportion</key>
-					<string>397pt</string>
+					<string>428pt</string>
 				</dict>
 			</array>
 			<key>Name</key>
 			<key>ToolbarConfiguration</key>
 			<string>xcode.toolbar.config.consoleV3</string>
 			<key>WindowString</key>
-			<string>630 271 641 438 0 0 1280 778 </string>
+			<string>235 233 953 469 0 0 1280 778 </string>
 			<key>WindowToolGUID</key>
 			<string>1C78EAAD065D492600B07095</string>
 			<key>WindowToolIsVisible</key>
-			<false/>
+			<true/>
 		</dict>
 		<dict>
 			<key>Identifier</key>