Exemple #1
0
static int
init_conf(void)
{
  Gra2cairoConf = g_malloc(sizeof(*Gra2cairoConf));
  if (Gra2cairoConf == NULL)
    return 1;

  Gra2cairoConf->fontmap = nhash_new();
  if (Gra2cairoConf->fontmap == NULL) {
    g_free(Gra2cairoConf);
    Gra2cairoConf = NULL;
    return 1;
  }

  Gra2cairoConf->fontmap_list_root = NULL;
  Gra2cairoConf->font_num = 0;

  if (loadconfig()) {
    free_fonts(Gra2cairoConf);
    nhash_free(Gra2cairoConf->fontmap);
    g_free(Gra2cairoConf);
    Gra2cairoConf = NULL;
    return 1;
  }

  return 0;
}
Exemple #2
0
static void
free_conf(void)
{
  if (Gra2cairoConf == NULL)
    return;

  free_fonts(Gra2cairoConf);
  nhash_free(Gra2cairoConf->fontmap);

  g_free(Gra2cairoConf);
  Gra2cairoConf = NULL;
}
Exemple #3
0
void
release_molecule(ModeInfo * mi)
{
  if (mcs != NULL) {
	int         screen;

	for (screen = 0; screen < MI_NUM_SCREENS(mi); screen++) {
	  molecule_configuration *mc = &mcs[screen];

#if 0
	int         i;

	  for (i = 0; i < mc->nmolecules; i++) {
	    molecule *m = &mc->molecules[i];

	    if (m->atoms) {
		free(m->atoms);
		m->atoms = (molecule_atom *) NULL;
	    }
	    if (m->bonds) {
		free(m->bonds);
		m->bonds = (molecule_bond *) NULL;
	    }
	    if (m->label) {
		free(m->label);
		m->label = (char *) NULL;
	    }
	  }
	  if (mc->molecules) {
		free(mc->molecules);
		mc->molecules = (molecule *) NULL;
	  }
#endif

	  if (mc->glx_context) {
		/* Display lists MUST be freed while their glXContext is current. */
#ifdef WIN32
		wglMakeCurrent(hdc, mc->glx_context);
#else
		glXMakeCurrent(MI_DISPLAY(mi), MI_WINDOW(mi), *(mc->glx_context));
#endif
		/* Free font stuff */
		free_fonts (mi);
	  }
	}
	free(mcs);
	mcs = (molecule_configuration *) NULL;
  }
  FreeAllGL(mi);
}
Exemple #4
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;
}