void test_front_back() {
    string colors[3] = {"blue", "red", "green"};
    const int objWidth = 100;
    const int objHeight = 100;
    const int x0 = 100;
    const int y0 = 100;
    const int dx = 40;
    const int dy = 0;
    GButton *forward = new GButton("Cycle Forward");
    GButton *backward = new GButton("Cycle Backward");
    GButton *stepUp = new GButton("Backmost +1");
    GButton *stepDown = new GButton("Frontmost -1");
    Vector<GObject *> objects;
    gw->addToRegion(forward, "south");
    gw->addToRegion(backward, "south");
    gw->addToRegion(stepUp, "south");
    gw->addToRegion(stepDown, "south");
    GCompound *compound = new GCompound();
    for (int i = 0; i < 3; i++) {
        GOval *oval = new GOval(x0 + i*dx, y0 + i*dy, objWidth, objHeight);
        if (i == 1)
            oval->setLocation(oval->getLocation().getX(), oval->getLocation().getY() + 50);
        oval->setFilled(true);
        oval->setFillColor(colors[i]);
        objects.add(oval);
        compound->add(oval);
    }
    gw->add(new GLabel("Click in window to end test", 10, 30));
    gw->add(compound);
    while(true) {
        GEvent e = waitForEvent(ACTION_EVENT | CLICK_EVENT);
        if (e.getEventType() == MOUSE_CLICKED)
            break;
        else if (e.getEventType() == ACTION_PERFORMED) {
            string cmd = ((GActionEvent) e).getActionCommand();
            if (cmd == "Cycle Forward")
                cycleObjects(objects);
            if (cmd == "Cycle Backward")
                cycleObjects(objects, false);
            if (cmd == "Backmost +1")
                moveBottomUp(objects);
            if (cmd == "Frontmost -1")
                moveTopDown(objects);
        }
    }

}
Exemplo n.º 2
0
/*
 * Function: drawSun
 * Usage: if(sun->isSelected()) drawSun(gw,MAX_SUN_RADIUS,(dusk?DUSK_SUN_COLOR:DAY_SUN_COLOR));
 * --------------------------
 * Uses a recursive function to draw the sun/moon as series of concentric circles.
 * Totally unnecessary to do this recursively, but it's the recursive contest. #YOLO
 */
int drawSun(GWindow gw, int radius, int color){
    if(radius<=0){
        return 0;
    }
    GOval *oval;
    if(dusk){
        oval = new GOval(width/4-radius,height*.45-radius,radius*2,radius*2);
    }
    else{
        radius/=2;
        oval = new GOval(2.0*width/3.0-radius,height/3.0-radius,radius*2,radius*2);
        radius*=2;
    }
    oval->setColor(color);
    oval->setFilled(true);
    oval->setColor(color);
    gw.add(oval);
    radius--;
    color -=2;
    return drawSun(gw, radius, color);
}