File: expr2bmp.c | Size: 2,081 bytes | Download file | Back to directory listing | BWPOW's homepage
/*
    expC - Expressions analyzator and viewer
    Copyright (C) 2004 Samuel Kupka
 
    This program is free software; you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation; either version 2 of the License, or
    (at your option) any later version.
 
    This program is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.
 
    You should have received a copy of the GNU General Public License
    along with this program; if not, write to the Free Software
    Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
 
#include <stdio.h>
#include <string.h>
#include <allegro.h>
 
#include "expC.h"
 
/* Globalne premenne */
extern EXPR_NODE *expr_tree;
extern int tree_size;
extern int tree_used;
extern int num_leaves;
extern int expr_max_x;
extern int expr_max_y;
 
extern EXPR_ATOM atom[MAX_ATOM];
extern int num_atom;
 
/* Program */
 
int expr2bmp(void)
{
  int i,x,y,xx,yy,n,w;
 
  if(exp_bmp!=NULL) destroy_bitmap(exp_bmp);
 
  x=expr_max_x+100;
  if(x<675) x=675;
  y=expr_max_y+100;
  if(y<600) y=600;
  exp_bmp=create_bitmap(x,y);
  if(exp_bmp==0) return -3;
  clear_to_color(exp_bmp,makecol(255,255,255));
 
  hline(exp_bmp,0,30,exp_bmp->w,0);
 
  expr_show_text(exp_bmp,10,5);
 
  for(i=0;i<tree_used;i++){
    x=expr_tree[i].x+20;
    y=expr_tree[i].y+50;
    rect(exp_bmp,x,y,x+59,y+29,0);
    n=expr_tree[i].next[0];
    if(n>i){
      xx=expr_tree[n].x+20;
      yy=expr_tree[n].y+50;
      line(exp_bmp,x+30,y+30,xx+30,yy,0);
    }
    n=expr_tree[i].next[1];
    if(n>i){
      xx=expr_tree[n].x+20;
      yy=expr_tree[n].y+50;
      line(exp_bmp,x+30,y+30,xx+30,yy,0);
    }
 
    w=expr_draw_node(exp_bmp,0,0,i,0,-1,0);
    xx=x+30-w/2;
    expr_draw_node(exp_bmp,xx,y+6,i,0,-1,1);
  }
 
  return 0;
}