예제 #1
0
// Load up the main window
static void main_window_load(Window *window) {
  load_fonts();
  create_time_layer();
  create_background_layer();
  create_weather_layer();
  create_date_layer();
  create_battery_layer();

  // Add each layer as a child layer to the Window's root layer
  layer_add_child(window_get_root_layer(window), bitmap_layer_get_layer(s_background_layer));
  layer_add_child(window_get_root_layer(window), text_layer_get_layer(s_hour_layer0));
  layer_add_child(window_get_root_layer(window), text_layer_get_layer(s_hour_layer1));
  layer_add_child(window_get_root_layer(window), text_layer_get_layer(s_min_layer0));
  layer_add_child(window_get_root_layer(window), text_layer_get_layer(s_min_layer1));
  layer_add_child(window_get_root_layer(window), text_layer_get_layer(s_colon_layer));
  layer_add_child(window_get_root_layer(window), text_layer_get_layer(s_temperature_layer));
  layer_add_child(window_get_root_layer(window), text_layer_get_layer(s_battery_layer));
  layer_add_child(window_get_root_layer(window), text_layer_get_layer(s_date_layer));
  layer_add_child(window_get_root_layer(window), text_layer_get_layer(s_battery_layer));
}
예제 #2
0
파일: EnFonted.cpp 프로젝트: berkus/graf
// ──────────────────────────────────────────────────────────────────────────
int main()
{
   try {
      load_fonts();
      if(!graf_init_lfb()) return -1;

      EventManager ev;
      Event e;

      boxframe(0,0,799,599, true);
      buttonframe(515,3,796,514,false);

      AddHandler(new OpenFileHandler);
      AddHandler(new SaveFileHandler);
      AddHandler(new SaveFileAsHandler);
      AddHandler(new ExitHandler);
      AddHandler(new PaintImageHandler);

      e.what = ev_null; // init handlers
      CallHandlers(e);

      while(going)
      {
         ev.get_event(e);
         if(e.what != ev_null) CallHandlers(e);
      }

      graf_close();
   }
   catch(Exception& e)
   {
      graf_close();
      printf("Exception! %s\n", e.reason());
   }
   return 0;
}
예제 #3
0
int main()
{
    //shell vars
    bool render = false;

    //allegro vars
    ALLEGRO_DISPLAY *display = NULL;
    ALLEGRO_EVENT_QUEUE *event_queue = NULL;
    ALLEGRO_TIMER *timer = NULL;

    //allegro init functions
    printf ("Initializing allegro\n");
    if (!al_init())
    {
        al_show_native_message_box(NULL, NULL, NULL, "failed", NULL, 0);
        return -1;
    }

    printf("Creating display\n");
    display = al_create_display(WIDTH, HEIGHT);
    if (!display)
    {
        al_show_native_message_box(NULL, NULL, NULL, "failed", NULL, 0);
        return -1;
    }

    printf("Installing addons\n");
    al_init_font_addon();
    al_init_ttf_addon();
    al_init_primitives_addon();
    al_init_image_addon();
    al_install_keyboard();
    al_install_mouse();
    al_install_audio();
    al_init_acodec_addon();
    al_reserve_samples(10);

    //project inits
    srand(time(NULL));

    printf("Initializing timer\n");
    event_queue = al_create_event_queue();
    timer = al_create_timer(1.0 / FPS);

    printf("Registering event sources\n");
    al_register_event_source(event_queue, al_get_display_event_source(display));
    al_register_event_source(event_queue, al_get_keyboard_event_source());
    al_register_event_source(event_queue, al_get_timer_event_source(timer));
    al_start_timer(timer);

    printf("Init mouse and keyboard\n");
    init_keyboard();
    init_mouse();

    printf("Loading assets\n");
    load_bitmaps();
    load_fonts();
    load_samples();

    printf ("Creating manager\n");
    push_state(new TitleMenu());
    
    printf("Beginning game\n");
    while (!is_game_over())
    {
        //declare an event
        ALLEGRO_EVENT event;

        //monitor event sources
        al_wait_for_event(event_queue, &event);
        if (event.type == ALLEGRO_EVENT_DISPLAY_CLOSE)
        {
            end_game();
        }
        else if (event.type == ALLEGRO_EVENT_TIMER)
        {
            render = true;

            update_mouse();
            update_keyboard();

            handle_key();
            update_game();
        }

        // Render screen
        if (render && al_event_queue_is_empty(event_queue))
        {
            render = false;
            render_game();
            al_flip_display();
        }
    }

    unload_assets();
    al_destroy_event_queue(event_queue);
    al_destroy_display(display);
    al_destroy_timer(timer);

    return 0;
}
예제 #4
0
ENTRYPOINT void 
init_molecule (ModeInfo *mi)
{
  molecule_configuration *mc;
  int wire;

  if (!mcs) {
    mcs = (molecule_configuration *)
      calloc (MI_NUM_SCREENS(mi), sizeof (molecule_configuration));
    if (!mcs) {
      fprintf(stderr, "%s: out of memory\n", progname);
      exit(1);
    }
  }

  mc = &mcs[MI_SCREEN(mi)];

  if ((mc->glx_context = init_GL(mi)) != NULL) {
    gl_init(mi);
    reshape_molecule (mi, MI_WIDTH(mi), MI_HEIGHT(mi));
  }

  load_fonts (mi);
  startup_blurb (mi);

  wire = MI_IS_WIREFRAME(mi);

  {
    Bool spinx=False, spiny=False, spinz=False;
    double spin_speed   = 0.5;
    double spin_accel   = 0.3;
    double wander_speed = 0.01;

    char *s = do_spin;
    while (*s)
      {
        if      (*s == 'x' || *s == 'X') spinx = True;
        else if (*s == 'y' || *s == 'Y') spiny = True;
        else if (*s == 'z' || *s == 'Z') spinz = True;
        else if (*s == '0') ;
        else
          {
            fprintf (stderr,
         "%s: spin must contain only the characters X, Y, or Z (not \"%s\")\n",
                     progname, do_spin);
            exit (1);
          }
        s++;
      }

    mc->rot = make_rotator (spinx ? spin_speed : 0,
                            spiny ? spin_speed : 0,
                            spinz ? spin_speed : 0,
                            spin_accel,
                            do_wander ? wander_speed : 0,
                            (spinx && spiny && spinz));
    mc->trackball = gltrackball_init ();
  }

  orig_do_labels = do_labels;
  orig_do_atoms  = do_atoms;
  orig_do_bonds  = do_bonds;
  orig_do_shells = do_shells;
  orig_wire = MI_IS_WIREFRAME(mi);

  mc->molecule_dlist = glGenLists(1);
  if (do_shells)
    mc->shell_dlist = glGenLists(1);

  load_molecules (mi);
  mc->which = random() % mc->nmolecules;

  mc->no_label_threshold = get_float_resource (mi->dpy, "noLabelThreshold",
                                               "NoLabelThreshold");
  mc->wireframe_threshold = get_float_resource (mi->dpy, "wireframeThreshold",
                                                "WireframeThreshold");
  mc->mode = 0;

  if (wire)
    do_bonds = 1;
}
예제 #5
0
/**
 * \brief Redraws the text surface.
 *
 * This function is called when there is a change.
 */
void TextSurface::rebuild() {

    if (!fonts_loaded) {
        // First time: lazy load of the fonts.
        load_fonts();
        if (font_id.empty()) {
            font_id = default_font_id;
        }
    }

    if (surface != NULL) {
        // another text was previously set: delete it
        if (!surface->owns_internal_surface) {
            SDL_FreeSurface(surface->get_internal_surface());
        }
        delete surface;
        surface = NULL;
    }

    if (is_empty()) {
        // Empty string or only whitespaces: no surface to create.
        // Some fonts make TTF_Font fail if the string contains only whitespaces.
        return;
    }

    Debug::check_assertion(has_font(font_id), StringConcat() <<
                           "No such font: '" << font_id << "'");

    if (fonts[font_id].bitmap) {
        rebuild_bitmap();
    }
    else {
        rebuild_ttf();
    }

    // calculate the coordinates of the top-left corner
    int x_left = 0, y_top = 0;

    switch (horizontal_alignment) {

    case ALIGN_LEFT:
        x_left = x;
        break;

    case ALIGN_CENTER:
        x_left = x - surface->get_width() / 2;
        break;

    case ALIGN_RIGHT:
        x_left = x - surface->get_width();
        break;
    }

    switch (vertical_alignment) {

    case ALIGN_TOP:
        y_top = y;
        break;

    case ALIGN_MIDDLE:
        y_top = y - surface->get_height() / 2;
        break;

    case ALIGN_BOTTOM:
        y_top = y - surface->get_height();
        break;
    }

    text_position.set_xy(x_left, y_top);
}
예제 #6
0
파일: start.c 프로젝트: wsj-zz/FamesOS
void demo_init_gui(void)
{
    InitBMPINFO(&icon);
    LoadBmp(&icon, "icon.bmp");
    load_fonts();

    gui_desktop_enable();
    gui_desktop_set_color(CLRSCR_COLOR2);
    
    form = gui_create_widget(GUI_WIDGET_FORM, 180, 120, 632, 500, 0, 0, 0, FORM_STYLE_XP_BORDER|FORM_STYLE_TITLE);
    if(!form)
        goto err;
    gui_form_init_private(form, 128);
    gui_form_set_caption(form, "控件演示");
    gui_form_set_icon(form, &icon);

    edit = gui_create_widget(GUI_WIDGET_EDIT, 80, 270, 460, 48, color, bkcolor, 0, style);
    if(!edit)
        goto err;
    gui_edit_init_private(edit, 128);
    gui_edit_set_text(edit, "这是一个文本框");

    button = gui_create_widget(GUI_WIDGET_BUTTON, 235+156, 142+100, 236, 32, COLOR_YELLOW, 64, font16, 0); /*BUTTON_STYLE_CLIENT_BDR*/
    if(!edit)
        goto err;
    gui_button_init_private(button, 128);
    gui_button_set_caption(button, "将那个Label盖住");

    test = gui_create_widget(GUI_WIDGET_EDIT, 80, 330, 460, 32, 0, 0, 0, 0);
    if(!test)
        goto err;
    gui_edit_init_private(test, 128);
    gui_edit_set_text(test, "");

    label = gui_create_widget(GUI_WIDGET_LABEL, 80, 380, 460, 64, COLOR_WHITE, 66, font48, LABEL_STYLE_SUBSIDE);
    if(!edit)
        goto err;
    gui_label_init_private(label, 128);
    gui_label_set_text(label, "Startting...");

    view = gui_create_widget(GUI_WIDGET_VIEW, 80, 48, 460, 200, 0, 0, 0, VIEW_STYLE_NONE_FIRST|VIEW_STYLE_FIELDS_TITLE|VIEW_STYLE_STATISTIC_BAR);
    if(!view)
        goto err;
    init_view(view);

    progress1 = gui_create_widget(GUI_WIDGET_PROGRESS, 80, 251, 460, 14, 0, 0, 0, PROGRESS_STYLE_BORDER);
    if(!progress1)
        goto err;
    gui_progress_init_private(progress1, 100);

    dialog = input_dialog_initialize(&abcde);
    if(!dialog)
        goto err;

    gui_widget_link(NULL, form);
    gui_widget_link(form, view);
    gui_widget_link(form, edit);
    gui_widget_link(form, label);
    gui_widget_link(form, progress1);
    gui_widget_link(form, test);

    gui_widget_link(NULL, dialog);

    gui_widget_link(NULL, button);

    window1 = gui_create_window(form);
    gui_show_window(window1);

    window2 = gui_create_window(dialog);
    gui_show_window(window2);

    window3 = gui_create_window(button);
    gui_show_window(window3);

    gui_form_set_caption(form, os_get_description());

    StartGUI();
    
err:
    return;
}
예제 #7
0
void
init_molecule (ModeInfo *mi)
{
  molecule_configuration *mc;
  int wire;

#ifndef STANDALONE
  timeout = MI_CYCLES(mi);
#endif
  if (!mcs) {
    mcs = (molecule_configuration *)
      calloc (MI_NUM_SCREENS(mi), sizeof (molecule_configuration));
    if (!mcs) {
       return;
    }
  }

  mc = &mcs[MI_SCREEN(mi)];
  if (mc->glx_context) {
	/* Free font stuff */
	free_fonts (mi);
  }

  if ((mc->glx_context = init_GL(mi)) != NULL) {
    glDrawBuffer(GL_BACK);
    gl_init();
    last = 0;
    reshape_molecule (mi, MI_WIDTH(mi), MI_HEIGHT(mi));
  }

  if (!load_fonts (mi)) {
	release_molecule(mi);
	return;
  }
  if (firstcall)
  startup_blurb (mi);
  cur_wire = MI_IS_WIREFRAME(mi);
  wire = cur_wire;

  mc->rotx = FLOATRAND(1.0) * RANDSIGN();
  mc->roty = FLOATRAND(1.0) * RANDSIGN();
  mc->rotz = FLOATRAND(1.0) * RANDSIGN();

  /* bell curve from 0-6 degrees, avg 3 */
  mc->dx = (FLOATRAND(0.1) + FLOATRAND(0.1) + FLOATRAND(0.1)) / (360/2);
  mc->dy = (FLOATRAND(0.1) + FLOATRAND(0.1) + FLOATRAND(0.1)) / (360/2);
  mc->dz = (FLOATRAND(0.1) + FLOATRAND(0.1) + FLOATRAND(0.1)) / (360/2);

  mc->d_max = mc->dx * 8;

  mc->ddx = 0.00006 + FLOATRAND(0.00003);
  mc->ddy = 0.00006 + FLOATRAND(0.00003);
  mc->ddz = 0.00006 + FLOATRAND(0.00003);

  {
    char *s = do_spin;
    while (*s)
      {
        if      (*s == 'x' || *s == 'X') mc->spin_x = 1;
        else if (*s == 'y' || *s == 'Y') mc->spin_y = 1;
        else if (*s == 'z' || *s == 'Z') mc->spin_z = 1;
        else
          {
            (void) fprintf (stderr,
         "molecule: spin must contain only the characters X, Y, or Z (not \"%s\")\n",
                     do_spin);
            /* exit (1); */
          }
        s++;
      }
  }

  mc->molecule_dlist = glGenLists(1);

  load_molecules (mi);
  mc->which =  NRAND(mc->nmolecules);

#ifdef STANDALONE
  mc->no_label_threshold = get_float_resource ("noLabelThreshold",
                                               "NoLabelThreshold");
  mc->wireframe_threshold = get_float_resource ("wireframeThreshold",
                                                "WireframeThreshold");
#else
  mc->no_label_threshold = 30;
  mc->wireframe_threshold = 150;
#endif

  if (wire)
    do_bonds = 1;
}
예제 #8
0
파일: nunifont.c 프로젝트: new299/wflow
void nunifont_init() {
  load_fonts("unifont.hex",&fontmap,&widthmap);
  nunifont_initcache();
  initialised = true;
}