float.cpp (1811B)
1 // Copyright (c) 2003 - 2009 Anselm R Garbe <anselm@garbe.us> 2 // See LICENSE for license details. 3 4 #include "float.h" 5 6 #include "rectangle.h" 7 8 // applied patch by Dr. J. Pfefferl 9 void Float::resize(Rectangle *rect, Direction dir, int stepW, int stepH) 10 { 11 int newW, newH; 12 13 switch (dir) { 14 case NORTH_WEST: 15 case SOUTH_WEST: 16 case LEFT: 17 newW = rect->width() - stepW; 18 if (0 < newW) { 19 rect->setX(rect->x() + stepW); 20 rect->setWidth(newW); 21 } 22 break; 23 case NORTH_EAST: 24 case SOUTH_EAST: 25 case RIGHT: 26 newW = rect->width() + stepW; 27 if (0 < newW) { 28 rect->setWidth(newW); 29 } 30 break; 31 default: 32 break; 33 } 34 35 switch (dir) { 36 case NORTH_WEST: 37 case NORTH_EAST: 38 case UP: 39 newH = rect->height() - stepH; 40 if (0 < newH) { 41 rect->setY(rect->y() + stepH); 42 rect->setHeight(newH); 43 } 44 break; 45 case SOUTH_WEST: 46 case SOUTH_EAST: 47 case DOWN: 48 newH = rect->height() + stepH; 49 if (0 < newH) { 50 rect->setHeight(newH); 51 } 52 break; 53 default: 54 break; 55 } 56 } 57 58 void Float::move(Rectangle *rect, int stepW, int stepH) { 59 rect->setX(rect->x() + stepW); 60 rect->setY(rect->y() + stepH); 61 } 62 63 void Float::center(Rectangle *rect, Rectangle *parentRect) { 64 65 unsigned int clientCenterX = (rect->x() + rect->width()) / 2; 66 unsigned int clientCenterY = (rect->y() + rect->height()) / 2; 67 unsigned int parentCenterX = (parentRect->x() + parentRect->width()) / 2; 68 unsigned int parentCenterY = (parentRect->y() + parentRect->height()) / 2; 69 int dx = parentCenterX - clientCenterX; 70 int dy = parentCenterY - clientCenterY; 71 rect->setX(rect->x() + dx); 72 rect->setY(rect->y() + dy); 73 }