@@ -400,34 +400,20 @@ static CGFloat _get_device_scale(CGContextRef cr)
400
400
FigureCanvas_set_rubberband (FigureCanvas* self, PyObject *args)
401
401
{
402
402
View* view = self->view ;
403
- int x0, y0 , x1, y1 ;
404
- NSRect rubberband;
405
403
if (!view) {
406
404
PyErr_SetString (PyExc_RuntimeError, " NSView* is NULL" );
407
405
return NULL ;
408
406
}
409
- if (!PyArg_ParseTuple (args, " iiii" , &x0, &y0 , &x1, &y1 )) { return NULL ; }
410
-
407
+ int x0, y0 , x1, y1 ;
408
+ if (!PyArg_ParseTuple (args, " iiii" , &x0, &y0 , &x1, &y1 )) {
409
+ return NULL ;
410
+ }
411
411
x0 /= view->device_scale ;
412
412
x1 /= view->device_scale ;
413
413
y0 /= view->device_scale ;
414
414
y1 /= view->device_scale ;
415
-
416
- if (x1 > x0) {
417
- rubberband.origin .x = x0;
418
- rubberband.size .width = x1 - x0;
419
- } else {
420
- rubberband.origin .x = x1;
421
- rubberband.size .width = x0 - x1;
422
- }
423
- if (y1 > y0 ) {
424
- rubberband.origin .y = y0 ;
425
- rubberband.size .height = y1 - y0 ;
426
- } else {
427
- rubberband.origin .y = y1 ;
428
- rubberband.size .height = y0 - y1 ;
429
- }
430
-
415
+ NSRect rubberband = NSMakeRect (x0 < x1 ? x0 : x1, y0 < y1 ? y0 : y1 ,
416
+ abs (x1 - x0), abs (y1 - y0 ));
431
417
[view setRubberband: rubberband];
432
418
Py_RETURN_NONE;
433
419
}
@@ -586,35 +572,26 @@ static CGFloat _get_device_scale(CGContextRef cr)
586
572
static int
587
573
FigureManager_init (FigureManager *self, PyObject *args, PyObject *kwds)
588
574
{
589
- NSRect rect;
590
- Window* window;
591
- View* view;
592
- PyObject* size;
593
- int width, height;
594
- PyObject* obj;
595
- FigureCanvas* canvas;
596
-
597
- if (!PyArg_ParseTuple (args, " O" , &obj)) { return -1 ; }
575
+ PyObject* canvas;
576
+ if (!PyArg_ParseTuple (args, " O" , &canvas)) {
577
+ return -1 ;
578
+ }
598
579
599
- canvas = (FigureCanvas*)obj;
600
- view = canvas->view ;
601
- if (!view) { /* Something really weird going on */
580
+ View* view = (FigureCanvas*)canvas->view ;
581
+ if (!view) { /* Something really weird going on */
602
582
PyErr_SetString (PyExc_RuntimeError, " NSView* is NULL" );
603
583
return -1 ;
604
584
}
605
585
606
- size = PyObject_CallMethod (obj, " get_width_height" , " " );
607
- if (!size) { return - 1 ; }
608
- if (!PyArg_ParseTuple (size, " ii" , &width, &height)) {
609
- Py_DECREF (size);
586
+ PyObject* size = PyObject_CallMethod (obj, " get_width_height" , " " );
587
+ int width, height;
588
+ if (!size || ! PyArg_ParseTuple (size, " ii" , &width, &height)) {
589
+ Py_XDECREF (size);
610
590
return -1 ;
611
591
}
612
592
Py_DECREF (size);
613
593
614
- rect.origin .x = 100 ;
615
- rect.origin .y = 350 ;
616
- rect.size .height = height;
617
- rect.size .width = width;
594
+ NSRect rect = NSMakeRect ( /* x */ 100 , /* y */ 350 , height, width);
618
595
619
596
self->window = [self ->window initWithContentRect: rect
620
597
styleMask: NSWindowStyleMaskTitled
@@ -624,7 +601,7 @@ static CGFloat _get_device_scale(CGContextRef cr)
624
601
backing: NSBackingStoreBuffered
625
602
defer: YES
626
603
withManager: (PyObject*)self ];
627
- window = self->window ;
604
+ Window* window = self->window ;
628
605
[window setDelegate: view];
629
606
[window makeFirstResponder: view];
630
607
[[window contentView ] addSubview: view];
0 commit comments