@@ -400,34 +400,20 @@ static CGFloat _get_device_scale(CGContextRef cr)
400400FigureCanvas_set_rubberband (FigureCanvas* self, PyObject *args)
401401{
402402 View* view = self->view ;
403- int x0, y0, x1, y1;
404- NSRect rubberband;
405403 if (!view) {
406404 PyErr_SetString (PyExc_RuntimeError, " NSView* is NULL" );
407405 return NULL ;
408406 }
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+ }
411411 x0 /= view->device_scale ;
412412 x1 /= view->device_scale ;
413413 y0 /= view->device_scale ;
414414 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));
431417 [view setRubberband: rubberband];
432418 Py_RETURN_NONE;
433419}
@@ -586,35 +572,26 @@ static CGFloat _get_device_scale(CGContextRef cr)
586572static int
587573FigureManager_init (FigureManager *self, PyObject *args, PyObject *kwds)
588574{
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+ }
598579
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 */
602582 PyErr_SetString (PyExc_RuntimeError, " NSView* is NULL" );
603583 return -1 ;
604584 }
605585
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 (canvas , " get_width_height" , " " );
587+ int width, height;
588+ if (!size || ! PyArg_ParseTuple (size, " ii" , &width, &height)) {
589+ Py_XDECREF (size);
610590 return -1 ;
611591 }
612592 Py_DECREF (size);
613593
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);
618595
619596 self->window = [self ->window initWithContentRect: rect
620597 styleMask: NSWindowStyleMaskTitled
@@ -624,7 +601,7 @@ static CGFloat _get_device_scale(CGContextRef cr)
624601 backing: NSBackingStoreBuffered
625602 defer: YES
626603 withManager: (PyObject*)self ];
627- window = self->window ;
604+ Window* window = self->window ;
628605 [window setDelegate: view];
629606 [window makeFirstResponder: view];
630607 [[window contentView ] addSubview: view];
0 commit comments