Esempio n. 1
0
gint
main (gint argc, char *argv[])
{
   gtk_init (&argc, &argv);

   create_colors ();
   gtk_main ();

   return 0;
}
Esempio n. 2
0
/**
 * Initializes the graphics sub-system, making it ready to draw.
 * Also determines the number of pixels on the screen and uses
 * that to set the SCALE global variable.
 */
void Gi::InitializeGraphics()
{
  XSetWindowAttributes xswa;
  XGCValues gcv;
 
  if (dpy == NULL)
  {
    /* Open access to local display */
    if ((dpy = XOpenDisplay (NULL)) == NULL)
    {
      printf ("XOpenDisplay returned NULL\n"); 
      exit (1); 
    }
  
    // Get some colors
    create_colors();
  
    /* Get size of root window. (Will be used to limit size of RARS window) */
    {
      Window w;
      int x,y;
      unsigned b,d;
    
      XGetGeometry(dpy,DefaultRootWindow(dpy),&w,&x,&y,&maxx,&maxy,&b,&d);
    }
    /* Make RARS window smaller than root window (need space for borders etc.) */
    maxx-=64;
    maxy-=48;
    // Don't make the RARS window larger than 960x720. We don't know the size of
    // the area visible on the monitor. It might be smaller than the root window.
    if (maxx>960)
        maxx=960;
    if (maxy>700)
        maxy=700;
    /* Aspect ratio of RARS window should be 4/3 */
    if (maxx>maxy*4/3)
        maxx=maxy*4/3;
    if (maxy>maxx*3/4)
        maxy=maxx*3/4;
    // uncomment this if you prefer to hardcode the size of the RARS window:
    // maxx=960;
    // maxy=720;
    fprintf( stderr, "XWindow size: maxx %d, maxy %d\n", maxx, maxy );
  
    /* These three used in XCreateWindow */
    /* Set the events you want */
    xswa.event_mask = VisibilityChangeMask|ExposureMask|KeyPressMask|ButtonPressMask;
    /* Set the background colors */
    xswa.background_pixel = tran_table[FIELD_COLOR];
    /* Set to store when overlapped? */
    xswa.backing_store = Always;
    /* Make window */
    win = XCreateWindow (dpy, DefaultRootWindow (dpy), 
                         0, 10, maxx, maxy, 2, 0, 
                         InputOutput, CopyFromParent, 
                         CWEventMask | CWBackPixel | CWBackingStore, 
                         & xswa);
    /* Set name of window */
    XStoreName (dpy, win, "RARS");
  
    /* Make a graphics context */
    gcv.function = GXcopy;
    gcv.plane_mask = AllPlanes;
    /* Set foreground color */
    gcv.foreground = BlackPixel(dpy,DefaultScreen(dpy));
    /* Set background color */
    gcv.background = WhitePixel(dpy,DefaultScreen(dpy));
    /* Set width of lines */
    gcv.line_width = 0;
    /* The edge of the track needs CapButt, but it's faster with CapNotLast. */
    gcv.cap_style = CapButt;
    /* Set fill and line style to solid */
    gcv.fill_style = FillSolid;
    gcv.line_style = LineSolid;
    /* Create the GC for solid lines */
    gc = XCreateGC (dpy, win, 
                    GCFunction | GCPlaneMask | GCForeground | GCBackground | 
                    GCLineWidth | GCFillStyle | GCLineStyle | GCCapStyle, 
                    & gcv);
    fill_gc = XCreateGC (dpy, win, 
                    GCFunction | GCPlaneMask | GCForeground | GCBackground | 
                    GCLineWidth | GCFillStyle | GCLineStyle | GCCapStyle, 
                    & gcv);
    /* Ready the window for drawing */
    XMapWindow (dpy, win);
    /* Tell X to display the window */
    XFlush(dpy);
    init_fonts();
    maxx = get_width();
    maxy = get_height();

    /*
     * Create pixmap.
     *  The pixmap is created after the display of the windows due that some
     *  window manager decides to change the size of the window 
     */
    pixmap = XCreatePixmap(dpy, win, maxx, maxy, DefaultDepth(dpy, XDefaultScreen(dpy)));
    drawable = pixmap;
  }
  // End of system dependent code.
  // The rest of this function is portable:
  // determine the distance in feet that each pixel will represent:
  SCALE = currentTrack->m_fXMax / (double)maxx;          // Either m_fXMax or m_fYMax will
  if(currentTrack->m_fYMax / (double)maxy > SCALE)       // determine the SCALE; The
  {
    SCALE = currentTrack->m_fYMax / (double)maxy;       // SCALE will be the smallest that
    currentTrack->m_fXMax = maxx * SCALE;               // will show both m_fXMax & m_fYMax.
  }
  else
  {
    currentTrack->m_fYMax = maxy * SCALE;
  }
  CHR_HGT = CHR_HGT_PIX * SCALE;      // compute character height in feet
  CHR_WID = CHR_WID_PIX * SCALE;      // compute character width in feet
}
Esempio n. 3
0
/* erstellt die Bedienungsoberfläche */
GtkWidget *gui_create(void)
{
    gint i, scr_width, scr_height;
    GdkScreen *screen;
    GtkWidget *window, *box[N_BOXES];

    /* ruft die Abmessungen des Bildschirms (screen) ab */
    screen = gdk_screen_get_default();
    scr_width = gdk_screen_get_width(screen);
    scr_height = gdk_screen_get_height(screen);

    /* erstellt das Hauptfenster, und setzt Größe,
       Namen und Randabstand */
    window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
    gtk_window_set_default_size(GTK_WINDOW(window),
                                scr_width * 0.85, scr_height * 0.85);
    gtk_window_set_title(GTK_WINDOW(window),
                         _("Simulation of radioactive decay"));
    gtk_container_set_border_width(GTK_CONTAINER(window), 5);

    /* verknüpft das Hauptfenster mit Callback-Funktionen */
    g_signal_connect(G_OBJECT(window),
                     "delete_event",
                     G_CALLBACK(gui_delete),
                     NULL);

    g_signal_connect(G_OBJECT(window),
                     "destroy",
                     G_CALLBACK(gui_destroy),
                     NULL);

    /* erstellt Layout

       Skizze der Kästen (box)
       |-0---------------------------------------------------|
       | |-1-----------------------------------------------| |
       | |                               |-2-------------| | |
       | |                               |               | | |
       | |                               |               | | |
       | |                               |               | | |
       | |                               |               | | |
       | |                               | |-3---------| | | |
       | |                               | |           | | | |
       | |                               | |-----------| | | |
       | |                               |---------------| | |
       | |-------------------------------------------------| |
       |                                                     |
       | |-4-----------------------------------------------| |
       | | |-5---| |-6------------------------| |-7------| | |
       | | |     | |                          | |        | | |
       | | |-----| |--------------------------| |--------| | |
       | |-------------------------------------------------| |
       |-----------------------------------------------------|
    */

    box[0] = gtk_vbox_new(FALSE, 0);
    gtk_container_add(GTK_CONTAINER(window), box[0]);

    box[1] = gtk_hbox_new(FALSE, 0);
    gtk_box_pack_start(GTK_BOX(box[0]), box[1], TRUE, TRUE, 0);

    box[2] = gtk_vbox_new(FALSE, 0);

    /* erstellt die beiden Zeichenbereiche */
    create_dareas(window, box[1], box[2]);

    box[3] = gtk_vbox_new(FALSE, 0);
    gtk_box_pack_start(GTK_BOX(box[2]), box[3], FALSE, FALSE, 0);

    /* erstellt die Status-Anzeigen */
    create_status(window, box[3]);

    box[4] = gtk_hbox_new(FALSE, 20);
    gtk_box_pack_start(GTK_BOX(box[0]), box[4], FALSE, FALSE, 0);

    box[5] = gtk_vbox_new(FALSE, 0);
    gtk_box_pack_start(GTK_BOX(box[4]), box[5], FALSE, FALSE, 0);

    /* erstellt die Eingabefelder */
    create_sim_input(window, box[5]);

    box[6] = gtk_vbox_new(FALSE, 0);
    gtk_box_pack_start(GTK_BOX(box[4]), box[6], FALSE, FALSE, 0);

    /* erstellt die Graphen-Auswahl */
    create_graph_input(window, box[6]);

    box[7] = gtk_vbox_new(FALSE, 0);
    gtk_box_pack_start(GTK_BOX(box[4]), box[7], TRUE, TRUE, 0);

    toggle_states(g_object_get_data(G_OBJECT(window), "spin_states"),
                  window);

    /* erstellt die Buttons */
    create_buttons(window, box[7]);

    /* gibt die Widgets zum Zeichnen auf dem Bildschirm frei */
    for (i = 0; i < N_BOXES; i++)
        gtk_widget_show(box[i]);
    gtk_widget_show(window);

    /* erstellt eine Liste mit ein paar Farben, die dann
       später im Programm benutzt werden (das _muss_ nach
       dem Zeichnen auf den Bildschirm passieren) */
    create_colors(window);

    /* setzt die Farben der Checkboxen der Graphen */
    color_graph_input(window);
    
    return window;
}