/* Subject: Contest submission for problem #3, file 3.cc */ /* rob@imail.EECS.Berkeley.EDU */ /* Tue Sep 9 23:41:10 PDT 2003 */ /*___CONTEST_SUBMISSION___ rob 3 */ //Assignment 2, Problem 3: GUI window //Robert Chu #include struct Window { int num; int x; //bottom-left corner int y; //bottom-left corner int width; int height; Window* next; }; int main() { Window* head = NULL; int w, h; int count = 1; cin >> w >> h; head = new Window; head->num = count; head->x = 0; head->y = 0; head->width = w; head->height = h; head->next = NULL; count++; cout << head->num << ". " << head->width << "x" << head->height; cout << " @ (" << head->x << "," << head->y << ")\n"; Window* tail = head; while(true) { int number, parent, dim; char pm; Window* temp = head; cin >> number >> parent >> dim >> pm; if(cin.peek() == EOF) { break; } while(true) { if(temp->num == parent) { break; } temp = temp->next; } Window* newWin = new Window; int newx, newy, newW, newH; int h, ytop, ybottom, w, wRight, wLeft; switch (pm) { case 'T': h = dim; ytop = (temp->y) + (temp->height); ybottom = ytop - h; temp->height = ybottom - (temp->y); newx = temp->x; newy = ybottom; newW = temp->width; newH = h; break; case 'B': h = dim; ytop = (temp->y) + h; newx = temp->x; newy = temp->y; newW = temp->width; newH = h; temp->height = (temp->y) + (temp->height) - ytop; temp->y = ytop; break; case 'L': w = dim; wRight = (temp->x) + w; newx = temp->x; newy = temp->y; newW = w; newH = temp->height; temp->width = (temp->x) + (temp->width) - wRight; temp->x = wRight; break; case 'R': w = dim; wRight = (temp->x) + (temp->width); wLeft = wRight - w; temp->width = wLeft - (temp->x); newx = wLeft; newy = temp->y; newW = w; newH = temp->height; break; } newWin->num = count; newWin->x = newx; newWin->y = newy; newWin->width = newW; newWin->height = newH; newWin->next = NULL; count++; cout << newWin->num << ". " << newWin->width << "x" << newWin->height; cout << " @ (" << newWin->x << "," << newWin->y << ")\n"; tail->next = newWin; tail = newWin; } }