Example #1
0
int main(int argc, char *argv[])
{
    GtkWidget *window;
    GtkWidget *darea;

    gtk_init(&argc, &argv);

    window = gtk_window_new(GTK_WINDOW_TOPLEVEL);

    darea = gtk_drawing_area_new();
    gtk_container_add(GTK_CONTAINER(window), darea);

    g_signal_connect(darea, "expose-event",
        G_CALLBACK(on_expose_event), NULL);
    g_signal_connect(window, "destroy", G_CALLBACK(gtk_main_quit), NULL);

    gtk_window_set_position(GTK_WINDOW(window), GTK_WIN_POS_CENTER);
    gtk_window_set_default_size(GTK_WINDOW(window), 170, 100);

    gtk_window_set_title(GTK_WINDOW(window), "timer");
    g_timeout_add(1000, (GSourceFunc) time_handler, (gpointer)window);
    gtk_widget_show_all(window);
    time_handler(window);

    gtk_main();

    return 0;
}
Example #2
0
void* mazeDrawer() 
{
    // The window and background information.
    GtkWidget *window;
    GdkRGBA color = {0, 0, 0, 0};

    // Calculate the window size based on the size of the maze.
    int window_width = graphics_width*MAZESQUARE + (graphics_width + 2)*WALLDIM;
    int window_height = graphics_height*MAZESQUARE + (graphics_height + 2)*WALLDIM;

    gtk_init (0, NULL);
    window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
    gtk_window_set_position(GTK_WINDOW(window), GTK_WIN_POS_CENTER);
    gtk_window_set_default_size(GTK_WINDOW(window), window_width, window_height);
    gtk_widget_override_background_color(window, GTK_STATE_NORMAL, &color);

    gtk_widget_set_app_paintable(window, TRUE);

 
    g_signal_connect(window, "draw", G_CALLBACK (on_draw_event), NULL);
    g_signal_connect(window, "destroy", G_CALLBACK (gtk_main_quit), NULL);

    g_timeout_add(50, (GSourceFunc) time_handler, (gpointer) window);

    gtk_widget_show_all(window);

    time_handler(window);

    gtk_main ();

    return 0;
}
Example #3
0
int main (int argc, char *argv[]) {
  // initialize gtk application
  gtk_init (&argc, &argv);

  // glade builder
  builder = gtk_builder_new ();
  gtk_builder_add_from_file (builder, "trayweather.glade", NULL);
  gtk_builder_add_from_file (builder, "/share/jwmtools/trayweather.glade", NULL);

  // main window
  window1 = GTK_WIDGET (gtk_builder_get_object (builder, "winWeatherTray1"));
  window2 = GTK_WIDGET (gtk_builder_get_object (builder, "winMain1"));
  gtk_builder_connect_signals (builder, NULL);          
  
  // tray components
  imgTray1 = (GtkImage*)gtk_builder_get_object(builder, "imgTray1");
  labTray1 = (GtkLabel*)gtk_builder_get_object(builder, "labTray1");
  
  // get components
  labTitle1 = (GtkLabel*)gtk_builder_get_object(builder, "labTitle1");
  labDateTime1 = (GtkLabel*)gtk_builder_get_object(builder, "labDateTime1");
  labPressureVisibility1 = (GtkLabel*)gtk_builder_get_object(builder, "labPressureVisibility1");
  labTemp1 = (GtkLabel*)gtk_builder_get_object(builder, "labTemp1");
  labWind1 = (GtkLabel*)gtk_builder_get_object(builder, "labWind1");
  imgClouds1 = (GtkImage*)gtk_builder_get_object(builder, "imgClouds1");
  imgWind1 = (GtkImage*)gtk_builder_get_object(builder, "imgWind1");
  
  // set component values
  gtk_label_set_markup(labTitle1,"<b>??????, ????? ( ?????? ??? )</b>");
  gtk_label_set_markup(labDateTime1,"??. ??????? 20??, ??:??");
  gtk_label_set_markup(labPressureVisibility1,"Tlak ???? kPa, viditeľnosť ?? km");
  gtk_label_set_markup(labTemp1,"<b>? °C</b>");
  gtk_label_set_markup(labWind1,"<b>? m/s</b>");
  gtk_image_set_from_icon_name(imgClouds1,"gtk-dialog-error",GTK_ICON_SIZE_LARGE_TOOLBAR);
  gtk_image_set_from_icon_name(imgWind1,"gtk-dialog-error",GTK_ICON_SIZE_LARGE_TOOLBAR);

  // timer + its first run (time is in ms, 600'000 is 10 minutes)
  g_timeout_add(600000, (GSourceFunc) time_handler, (gpointer) window1);
  time_handler(window1);

  // main loop
  //g_object_unref (G_OBJECT (builder));
  gtk_widget_show (window1);       
  gtk_main ();
  
  return 0;
}
Example #4
0
//The taskswitcher is basically the program that runs all the time.
//It is  responsible for switching ro various processes and terminating them.
void taskswitcher()
{
    char temp[255];
    DWORD cputime=0;
    PCB386 *readyprocess;
    do
    {
        stopints();
        //fetch a ready process from the ready queue

        do {
            if (!sigwait)
                {
                //if the wait register is not set, switch to
                //another process, the wait is used to prevent
                //other processes from taking control during
                //a critical section, sigwait should be
                //returned to its original state after the critical
                //section is over

                //obtain next job from the scheduler
                //readyprocess=extension_current->ps_scheduler->scheduler(&kernelPCB);
                devmgr_scheduler_extension *cursched = (devmgr_scheduler_extension*)extension_table[CURRENT_SCHEDULER].iface;
                readyprocess = (PCB386*)bridges_link((devmgr_generic*)cursched,&cursched->scheduler,
                current_process,0,0,0,0,0);
                };
                //readyprocess=bridges_ps_scheduler(current_process);
            
            current_process=readyprocess;

            //tell the cpu to give control to <readyprocess>
            ps_switchto(readyprocess);

            /*Make sure the taskwitcher was really called by the timer, since
              another way of calling the taskswithcer is through taskswitch().
              In that case we must not call time_handler in order to make
              the time as accurate as possible*/
            
            
            if (!ps_notimeincrement)
            {
                //Increment system time... etc.
                time_handler();
            }
                else
            ps_notimeincrement = 0;
            
            //record the number of milleseconds the process used
            readyprocess->totalcputime++;
            
            //A process wants to get immediate control, usually set by
            //device drivers that are hooked to IRQs
            if (sigpriority)
            {
                PCB386 *priorityprocess = ps_findprocess(sigpriority);
                if (priorityprocess!=-1)
                {
                    //give the process to the CPU       
                    ps_switchto(priorityprocess);       
                };
                sigpriority = 0;
            };

        } 
        while (sigwait);

        //check the registers, and act if necessary

        if (pfoccured)
        {
            setattb(PF_TSS,0x89);
            memcpy(&pfPCB.regs,&pfPCB_copy.regs,sizeof(pfPCB.regs));
            pfoccured=0;
        };

        if (sigterm&&!flushing)
        {
            flushok=0;
            kill_process(sigterm);
            flushok=1;
            sigterm=0;
            ;
        };

        if (sched_sysmes[0])
        {
            sendmessage(sched_sysmes[0],sched_sysmes[1],sched_sysmes[2]);
            sched_sysmes[0]=0;
            ;
        };

        if (sigshutdown)
        {
            broadcastmessage(1,SIG_KILL,0);
            ;
        };

    } 
    while (1);

    ;
};
Example #5
0
int main( int argc, char *argv[])
{
  GtkWidget *window;
  GtkWidget *kickU3;
  GtkWidget *takeAway;
  GtkWidget *normal;
  GtkWidget *pause;
  GtkWidget *beamON;
  GtkWidget *beamOFF;
  GtkWidget *liteON;
  GtkWidget *mtcON;
  GtkWidget *vbox;
  time_t time0,curtime;
  int ii = 0;
  
  gtk_init(&argc, &argv);

  if (ii == 0){
    ii=1;
    time0=time(NULL);
  }
 
  window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
  gtk_window_set_position(GTK_WINDOW(window), GTK_WIN_POS_CENTER);
  gtk_window_set_title(GTK_WINDOW(window), "Testing");
  gtk_window_set_default_size(GTK_WINDOW(window), 350, 400);

  kickU3 = gtk_label_new("Kick-u3 status");
  takeAway = gtk_label_new("TakeAway Mode");
  normal = gtk_label_new("Normal Mode");
  pause = gtk_label_new("Pause On");
  beamON = gtk_label_new("Beam On");
  beamOFF = gtk_label_new("Beam Off");
  liteON = gtk_label_new("Laser On");
  mtcON = gtk_label_new("MTC On");

  //  gtk_label_set_justify(GTK_LABEL(label), GTK_JUSTIFY_CENTER);
  //  gtk_container_add(GTK_CONTAINER(window), label);
  //  gtk_container_add(GTK_CONTAINER(window), takeAway);
  curtime=time(NULL);
  vbox = gtk_box_new(TRUE, 1);
  gtk_container_add(GTK_CONTAINER(window), vbox);
  gtk_box_pack_start(GTK_BOX(vbox), kickU3, TRUE, TRUE, 0);
  if ((curtime - time0) > 10) gtk_box_pack_start(GTK_BOX(vbox), takeAway, TRUE, TRUE, 0);
  gtk_box_pack_start(GTK_BOX(vbox), normal, TRUE, TRUE, 0);
  gtk_box_pack_start(GTK_BOX(vbox), pause, TRUE, TRUE, 0);
  gtk_box_pack_start(GTK_BOX(vbox), beamON, TRUE, TRUE, 0);
  gtk_box_pack_start(GTK_BOX(vbox), beamOFF, TRUE, TRUE, 0);
  gtk_box_pack_start(GTK_BOX(vbox), liteON, TRUE, TRUE, 0);
  gtk_box_pack_start(GTK_BOX(vbox), mtcON, TRUE, TRUE, 0);

  
  //  g_signal_connect(G_OBJECT(button), "clicked", 
  //     G_CALLBACK(gtk_main_quit), G_OBJECT(window));
   g_signal_connect_swapped(window, "destroy",
      G_CALLBACK (gtk_main_quit), NULL);
  g_timeout_add(1000, (GSourceFunc) time_handler, (gpointer) window);
  gtk_widget_show_all(window);
  time_handler(window);
  gtk_main();

  return 0;
}
Example #6
0
int main(int argc, char **argv){
  //  GtkWidget *cyc_lab1, *cyc_lab2, *cyc_lab3, *cyc_lab4;
  int mapped=0;
/*
  Shared memory creation and attachment
  the segment number is stored in lnptr->pid
*/
  mapped = mmapSetup();
  if (mapped == -1) {
    printf(" Error on setting up memory map ... exiting \n");
    return 0;
  }
  time0 = time(NULL);
  
  gtk_init (&argc, &argv);                                                    // mandatory for gtk applications
  window = gtk_window_new (GTK_WINDOW_TOPLEVEL);                              // creates new window
  gtk_window_set_title (GTK_WINDOW (window),"CONTROLS STATUS");               // sets title of window
  gtk_container_set_border_width (GTK_CONTAINER(window),1);                   // sets border width

  fixed = gtk_fixed_new();                                                // create a container to hold future widgets
  gtk_container_add(GTK_CONTAINER(window), fixed);                        // I must determine position of all widgets

  g_signal_connect (window, "delete-event",G_CALLBACK (delete_event), NULL);        // handler to exit gtk
/*
  draw and expose-event redraws on any event including mouse movement.  They are usually needed in programs.
   But in this program I am renewing the widgets on a timer based on eitehr 50 or 100 ms
*/
  g_signal_connect (window, "draw", G_CALLBACK (on_expose_event), NULL);    // gtk3 - 
  //g_signal_connect (window, "expose-event", G_CALLBACK (on_expose_event), NULL); // gtk2 from cairo example  window -> frame1
  g_signal_connect (window, "destroy", G_CALLBACK (gtk_main_quit), NULL);           // from cairo example  window -> frame1

  gtk_window_set_default_size(GTK_WINDOW(window), 300, 500);                    // from cairo example  window -> frame1

/* track the number of cycles 
   - create the text
   - create the widget containing the text
   - define the location of the widget in the widget fixed
*/
  tapeMode();
  /* 
  sprintf(txt6,"Total cycles: %li",numCycles);
  cyc_labtotal = gtk_label_new(txt6);
  gtk_fixed_put(GTK_FIXED(fixed),cyc_labtotal,20,20);

  sprintf(txt7,"Data cycles: %li",numData);
  cyc_labdata = gtk_label_new(txt7);
  gtk_fixed_put(GTK_FIXED(fixed),cyc_labdata,20,40);


  sprintf(txt8,"Bkg cycles: %li",numBkg);
  cyc_labbkg = gtk_label_new(txt8);
  gtk_fixed_put(GTK_FIXED(fixed),cyc_labbkg,20,60);

  if (bkgCycle == bkg) sprintf(txt9,"Current cycle: BKG");
  else sprintf(txt9,"Current cycle: DATA %i", bkgCycle);
  cyc_labnow = gtk_label_new(txt9);
  gtk_fixed_put(GTK_FIXED(fixed),cyc_labnow,20,80);


  gtk_widget_show(cyc_lab1);
  gtk_widget_show(cyc_lab2);
  gtk_widget_show(cyc_lab3);
  gtk_widget_show(cyc_lab4);
*/

/*
 Show all in window
*/
  g_timeout_add(REFRESH, (GSourceFunc) time_handler, (gpointer) fixed);             // timer to refresh widget "fixed"
  gtk_widget_show_all (window);    // show windows before stating timer loop
  time_handler(fixed);
  gtk_main ();

 /*
  Ending the program so release the memory map and close file
*/

  if (munmap(mtcptr, sizeof (struct mtc*)) == -1) {
    perror("Error un-mapping the file");
  }
  close(mapped);
  printf(" File closed and file unmapped \n");

  return 0;
}
Example #7
0
int main(int argc, char *argv[])
{
    char c;
    int status = 0;
    
    printf("Hello World, I'm game!\n");
    
    status = init_display();
    if (status != 0)
    {
        printf("Error: Failed to init display\n");
        return status;
    }
    
    status = init_driver();
    if (status != 0)
    {
        printf("Error: Failed to init driver\n");
        destroy_display();
        return status;
    }
    
    status = setup_handler();
    if (status != 0)
    {
        printf("Error: Failed to init signal handler\n");
        destroy_display();
        close(file_gamepad_driver);
        return status;
    }
    time_handler();
    
    /* Intializes random number generator */
    srand((unsigned) time(&t));
    
    sigset_t myset;
    (void) sigemptyset(&myset);

    while(1)
    {
        clear_LCD();       
        draw_game();
        draw_score(p1_score, p2_score);
        redraw();
        
        waitForButton();      
        printf("start game\n");
        
        while((p1_score < 5) && (p2_score < 5))
        {
            random_timer = (rand() % 3) + 2;
            startTimer(random_timer);
            waitForTimer();
            
            random_button = (rand() % 4);
            
            draw_button(random_button, true, RED);
            redraw();
            
            gettimeofday(&time_button_appears, NULL);

            // start timer
            startTimer(3);
            buf = 0;
            while((playerButtonPressed(random_button) == 0) && (timer_expired == false))
            {
                waitForButton(); 
            }
            
            stopTimer();
            if (timer_expired == false)
            {
                time_elapsed = getGameTime();
                draw_time(time_elapsed, BLUE);
                redraw();
            }
      
            if (playerButtonPressed(random_button) == P1)
            {
                p1_score++;
                p1_time += time_elapsed;
                
            }
            else if (playerButtonPressed(random_button) == P2)
            {
                p2_score++;    
                p2_time += time_elapsed;
            }
                
            draw_score(p1_score, p2_score);    
            reset_button(random_button);
            redraw();
            
        }
        // draw winner
        button_pressed = 0;
        if (p1_score == 5)
        {
            winner = P1;
            winner_time = p1_time;
        }
        else if (p2_score == 5)
        {
            winner = P2;
            winner_time = p2_time;
        }
        
        while(button_pressed == 0)
        {
            startTimer(1);
            winner_blink(winner, winner_time);
            waitForTimer();
        }
               
        // print waiting
        waitForButton();
        p1_score = 0;
        p1_time = 0;
        p2_score = 0;
        p2_time = 0;
    }

}