Esempio n. 1
0
int main(void)
{
    // instantiate window
    GWindow window = newGWindow(320, 240);

    // instantiate slider
    addToRegion(window, newGLabel("0"), "SOUTH");
    GSlider slider = newGSlider(0, 100, 50);
    setActionCommand(slider, "slide");
    addToRegion(window, slider, "SOUTH");
    addToRegion(window, newGLabel("100"), "SOUTH");

    // listen for events
    while (true)
    {
        // wait for event
        GActionEvent event = waitForEvent(ACTION_EVENT);

        // if window was closed
        if (getEventType(event) == WINDOW_CLOSED)
        {
            break;
        }

        // if action command is "slide"
        if (strcmp(getActionCommand(event), "slide") == 0)
        {
            printf("slider was slid to %i\n", getValue(slider));
        }
    }

    // that's all folks
    closeGWindow(window);
    return 0;
}
Esempio n. 2
0
o/**
 * slider.c
 *
 * David J. Malan
 * [email protected]
 *
 * Demonstrates a slider.
 */

// standard libraries
#include <stdio.h>
#include <string.h>

// Stanford Portable Library
#include <spl/gevents.h>
#include <spl/ginteractors.h>
#include <spl/gwindow.h>

int main(void)
{
    // instantiate window
    GWindow window = newGWindow(320, 240);

    // instantiate slider
    addToRegion(window, newGLabel("0"), "SOUTH");
    GSlider slider = newGSlider(0, 100, 50);
    setActionCommand(slider, "slide");
    addToRegion(window, slider, "SOUTH");
    addToRegion(window, newGLabel("100"), "SOUTH");

    // listen for events
    while (true)
    {
        // wait for event
        GActionEvent event = waitForEvent(ACTION_EVENT);

        // if window was closed
        if (getEventType(event) == WINDOW_CLOSED)
        {
            break;
        }

        // if action command is "slide"
        if (strcmp(getActionCommand(event), "slide") == 0)
        {
            printf("slider was slid to %i\n", getValue(slider));
        }
    }

    // that's all folks
    closeGWindow(window);
    return 0;
}
Esempio n. 3
0
/**
 * Instantiates, configures, and returns label for scoreboard.
 */
GLabel initScoreboard(GWindow window)
{
    GLabel label = newGLabel("0");
    setFont(label, "SansSerif-18");
    setLocation(label, getWidth(window) / 2, getHeight(window) / 2 - 30);
    return label;
}
Esempio n. 4
0
File: label.c Progetto: kingsj/CS50
int main(void)
{
    // instantiate window
    GWindow window = newGWindow(320, 240);

    // instantiate label
    GLabel label = newGLabel("");
    setFont(label, "SansSerif-36");
    add(window, label);

    // count down from 50 to 0
    for (int i = 50; i >= 0; i--)
    {
        // to store 50 through 0 (with '\0'), we need <= 3 chars
        char s[3];

        // convert i from int to string
        sprintf(s, "%i", i);

        // update label
        setLabel(label, s);

        // center label
        double x = (getWidth(window) - getWidth(label)) / 2;
        double y = (getHeight(window) - getHeight(label)) / 2;
        setLocation(label, x, y);

        // linger for 100 milliseconds
        pause(100);
    }
 
    // that's all folks
    closeGWindow(window);
    return 0;
}
Esempio n. 5
0
/**
 * Instantiates, configures, and returns label for scoreboard.
 */
GLabel initScoreboard(GWindow window)
{
    GLabel scoreboard = newGLabel("");
    setFont(scoreboard, "SansSerif-30");
    setColor(scoreboard, "RED");
    return scoreboard;
}
Esempio n. 6
0
/**
 * Instantiates, configures, and returns label for scoreboard.
 */
GLabel initScoreboard(GWindow window)
{
    GLabel Scoreboard = newGLabel("");
    add (window, Scoreboard);
    setLocation(Scoreboard, 300, 200);
    return Scoreboard;
}
Esempio n. 7
0
/**
 * Instantiates, configures, and returns label for scoreboard.
 */
GLabel initScoreboard(GWindow window)
{
    GLabel label = newGLabel("");
    setFont(label, "SansSerif-36");
    add(window, label);
    return label;
}
Esempio n. 8
0
/**
 * Instantiates, configures, and returns label for scoreboard.
 */
GLabel initScoreboard(GWindow window)
{
  GLabel scoreboard = newGLabel("%i", points);
  setFont(scoreboard, "SansSerif-18");
  add(window, scoreboard);
  return NULL;
}
Esempio n. 9
0
/**
 * Instantiates, configures, and returns label for scoreboard.
 */
GLabel initScoreboard(GWindow window)
{
    GLabel scoreboard = newGLabel("0");
    setFont(scoreboard, "SansSerif-48");
    setColor(scoreboard, "0xC0C0C0");
    add(window, scoreboard);
    return scoreboard;
}
Esempio n. 10
0
/**
 * Instantiates, configures, and returns label for scoreboard.
 */
GLabel initScoreboard(GWindow window)
{    
    GLabel label = newGLabel("");
    setFont(label, "SansSerif-24");
    setLocation(label, 8, HEIGHT - 10);
    add(window, label);
    return label;
}
Esempio n. 11
0
/**
 * Instantiates, configures, and returns label for scoreboard.
 */
GLabel initScoreboard(GWindow window)
{
    GLabel label = newGLabel("");
    setFont(label, "SansSerif-72");
    setColor(label, "GRAY");
    add(window, label);
    sendToBack(label);
    return label;
}
/**
 * Instantiates, configures, and returns label for scoreboard.
 */
GLabel initScoreboard(GWindow window)
{
    // TODO
    GLabel label = newGLabel("0");
    setFont(label, "SansSerif-36");
    add(window, label);
    setLocation(label, (getWidth(window) - getWidth(label)) / 2, (getHeight(window) - getHeight(label)) / 2);
    return label;
}
Esempio n. 13
0
/**
 * Instantiates, configures, and returns label for scoreboard.
 */
GLabel initScoreboard(GWindow window)
{
    GLabel label = newGLabel(" ");
    setFont(label, "SansSerif-50");
    setColor(label, "C0C0C0");
    add(window, label);
    setLocation(label, 185, 300);
    return label;
}
Esempio n. 14
0
/**
 * Instantiates, configures, and returns label for scoreboard.
 */
GLabel initScoreboard(GWindow window)
{
    // Initializing Score Board
    GLabel scoreboard = newGLabel("");
    setFont(scoreboard, "Ubuntu-50");
    add(window, scoreboard);
    
    return scoreboard;
}
Esempio n. 15
0
/**
 * Instantiates, configures, and returns label for scoreboard.
 */
GLabel initScoreboard(GWindow window)
{
    // instantiate label
    GLabel label = newGLabel("");
    setFont(label, "SansSerif-36");
    setLocation(label, 200, 300);
    add(window, label);
    return label;
}
Esempio n. 16
0
/**
 * Instantiates, configures, and returns label for scoreboard.
 */
GLabel initScoreboard(GWindow window)
{
    GLabel label = newGLabel("Score: 0");
    setColor(label, "BLACK");
    setLocation(label, WIDTH / 2 - getWidth(label) / 2, HEIGHT * .33);
    add(window, label);
    
    return label;
}
Esempio n. 17
0
/**
 * Instantiates, configures, and returns label for scoreboard.
 */
GLabel initScoreboard(GWindow window)
{
    GLabel score = newGLabel("0");
    setFont(score, "SansSerif-36");
    add(window, score);
    double x_score = (getWidth(window) - getWidth(score)) / 2;
    double y_score = (getHeight(window) - getHeight(score)) / 2;
    setLocation(score, x_score, y_score);
    return score;
}
Esempio n. 18
0
/**
 * Instantiates, configures, and returns label for scoreboard.
 */
GLabel initScoreboard(GWindow window)
{
    GLabel label = newGLabel("0");
    setColor(label, "BLACK");
    setFont(label, "SansSerif-20");

    updateScoreboard(window, label, 0);
    add(window, label);
    return label;
}
Esempio n. 19
0
/**
 * Instantiates, configures, and returns label for scoreboard.
 */
GLabel initScoreboard(GWindow window)
{
    GLabel label = newGLabel ("");
    setFont(label,"Courier-25");
    setColor(label,"DF7401");
    setFilled(label, true);
    add(window,label);
    setLocation(label,150,150);
    return label;
}
Esempio n. 20
0
GLabel initEnd(GWindow window)
{
    GLabel label = newGLabel("Click to Close Window");
    setFont(label, "SansSerif-24");
    add(window, label);
    double x = (getWidth(window) - getWidth(label)) / 2;
    double y = (getHeight(window) - getHeight(label)) / 2;
    setLocation(label, x, y);
    return label;
}
Esempio n. 21
0
/**
 * Instantiates, configures, and returns label for scoreboard.
 */
GLabel initScoreboard(GWindow window)
{
    // TODO
    GLabel label = newGLabel("");
    setFont(label, "SansSerif-36");
    add(window, label);
    // count down from 50 to 0
    
    return label;
}
Esempio n. 22
0
/**
 * Instantiates, configures, and returns label for scoreboard.
 */
GLabel initScoreboard(GWindow window)
{
    // TODO
    int points;
    GLabel label = newGLabel(" ");
    setFont(label, "ComicSans-18");
    add(window, label);
    setLocation(label, 192, 332);
    return label;
}
Esempio n. 23
0
/**
 * Instantiates, configures, and returns label for scoreboard.
 */
GLabel initScoreboard(GWindow window)
{
    GLabel label = newGLabel("0");
    setFont(label, "SansSerif-24");
    double x = (getWidth(window) - getWidth(label)) / 2;
    double y = (getHeight(window) + getFontAscent(label)) / 2;
    setLocation(label, x, y);
    add(window, label);
    return label;
}
Esempio n. 24
0
GLabel initlives(GWindow window)
{
    GLabel label = newGLabel("");
    setFont(label, "SansSerif-24");
    add(window, label);
    double x = 10;
    double y = 590;
    setLocation(label, x, y);
    return label;
}
Esempio n. 25
0
GLabel initWin(GWindow window)
{
    GLabel label = newGLabel("You Win!!!");
    setFont(label, "SansSerif-24");
    add(window, label);
    double x = (getWidth(window) - getWidth(label)) / 2;
    double y = (getHeight(window) - getHeight(label)) / 2;
    setLocation(label, x, y);
    return label;
}
Esempio n. 26
0
/**
 * Instantiates, configures, and returns label for scoreboard.
 */
GLabel initScoreboard(GWindow window)
{
    // TODO
    GLabel label = newGLabel("");
    setFont(label, "SansSerif-72");
    setColor(label, "GRAY");
    add(window, label);
    setLabel(label, "0");
    setLocation(label, 175, 200);
    return label;    
}
Esempio n. 27
0
/**
 * Instantiates, configures, and returns label for scoreboard.
 */
GLabel initScoreboard(GWindow window)
{
    GLabel label = newGLabel("0");
    setFont(label,"DejaVuSansMono-40");
    double x = (getWidth(window) - getWidth(label)) / 2;
    double y = (getHeight(window) - getHeight(label)) / 2;
    setLocation(label, x, y);
    setColor(label, "GRAY");
    add(window, label);
    return label;
}
Esempio n. 28
0
/**
 * Instantiates, configures, and returns label for scoreboard.
 */
GLabel initScoreboard(GWindow window)
{
    int posX = (WIDTH / 2) - 19;
    int posY = (HEIGHT / 2) - 19;
    GLabel label = newGLabel("0");
    setFont(label, "Ubuntu-bold-30");
    setColor(label, "LIGHT_GRAY");
    setLocation(label, posX, posY);
    add(window, label);
    return label;
}
/**
 * Instantiates, configures, and returns label for scoreboard.
 */
GLabel initScoreboard(GWindow window)
{
  GLabel label = newGLabel("CLICK");
  double x = (WIDTH - getWidth(label)) / 2;
  double y = (HEIGHT + getFontAscent(label)) / 2;
  setFont(label, "Courier 10 Pitch-bold-50");
  setColor(label, "#cccccc");
  setLocation(label, x, y);
  sendToBack(label);
  return label;
}
Esempio n. 30
0
/**
 * Instantiates, configures, and returns label for scoreboard.
 */
GLabel initScoreboard(GWindow window)
{
    // TODO
    GLabel scoreboard = newGLabel("0");
    setFont(scoreboard, "SansSerif-22");
    double x = (getWidth(window) - getWidth(scoreboard)) / 2;
    double y = (getHeight(window) - getHeight(scoreboard)) / 2;
    setLocation(scoreboard, x, y);
    setColor(scoreboard, "#7700AA");
    add(window, scoreboard);
    return scoreboard;
}