Esempio n. 1
0
char *attr_to_string( int code )
{
  static char result[136];
  unsigned int i;
  int pair = ( code & 65280 ) >> 8;
  int bold = 0;
  if ( bold )
    code &= -2097153;
  result[0] = 0;
  i = 0;
  for ( ; i <= 6; i++ )
  {
    if ( Mono_Attrs[ i ].code & code )
    {
      if ( result[0] )
      {
        memcpy( &result[ strlen( result ) ] );
      }
      strcat( result, Mono_Attrs[ i ].name );
    }
    // i++;
  }
  if ( pair && pair_content( pair, &f, &b ) != -1 )
  {
    char *fg = lookup_color( f );
    char *bg = lookup_color( b );
    if ( result[0] )
      strcat( result, "+" );
    sprintf( &result[ strlen( result ) ], "%s/%s", fg, bg );
  }
  return result;
}
Esempio n. 2
0
result_t create_hsi_window(handle_t parent, memid_t key, handle_t *hwnd)
  {
  result_t result;

  // create our window
  if (failed(result = create_child_widget(parent, key, widget_wndproc, hwnd)))
    return result;

  // create the window data.
  hsi_window_t *wnd = (hsi_window_t *)neutron_malloc(sizeof(hsi_window_t));
  memset(wnd, 0, sizeof(hsi_window_t));

  wnd->version = sizeof(hsi_window_t);

  if (failed(lookup_color(key, "background-color", &wnd->background_color)))
    wnd->background_color = color_black;

  reg_get_bool(key, "draw-border", &wnd->draw_border);

  if (failed(lookup_font(key, "font", &wnd->font)))
    {
    // we always have the neo font.
    if (failed(result = open_font("neo", 9, &wnd->font)))
      return result;
    }

  // store the parameters for the window
  set_wnddata(*hwnd, wnd);

  rect_t rect;
  get_window_rect(*hwnd, &rect);
  invalidate_rect(*hwnd, &rect);

  return s_ok;
  }
Esempio n. 3
0
char *LYgetTableString( int code )
{
  int eax;
  int mask = decode_mono_code( code );
  int second = encode_color_attr( mask );
  int pair = ( second & 65280 ) >> 8;
  int mono = 0;
  int fg = lynx_color_pairs[ pair ].fg;
  int bg = lynx_color_pairs[ pair ].bg;
  unsigned int n;
  char *result = 0;
  if ( WWW_TraceFlag )
  {
    fprintf( TraceFP( ), "LYgetTableString(%d)\n", code );
  }
  if ( fg == 0 && bg == 0 )
    fg = 7;
  if ( WWW_TraceFlag )
  {
    fprintf( TraceFP( ), "%#x -&gt; %#x (mono %#x pair %d) fg=%d, bg=%d\n", mask, second, mono, pair, fg, bg );
  }
  n = 0;
  for ( ; n <= 6; n++ )
  {
    if ( Mono_Attrs[ n ].code & mono )
    {
      if ( result )
        HTSACat( &result, "+" );
      HTSACat( &result, Mono_Attrs[ n ].name );
    }
    // n++;
  }
  if ( result == 0 )
    HTSACopy( &result, "normal" );
  HTSACat( &result, ":" );
  HTSACat( &result, lookup_color( fg ) );
  if ( bg >= 0 )
  {
    HTSACat( &result, ":" );
    HTSACat( &result, lookup_color( bg ) );
  }
  if ( WWW_TraceFlag )
  {
    fprintf( TraceFP( ), "-&gt;%s\n", result );
  }
  return result;
}
Esempio n. 4
0
static int write_byte(state *s, unsigned char c)
{
  RGBQUAD r;

  if (0 == c)
    r.rgbBlue = r.rgbRed = r.rgbGreen = 0;
  else if (0xff == c)
    // RBF - What happens if 0xff characters are just dark red? 
    r.rgbBlue = r.rgbRed = r.rgbGreen = 0xff;
  else
    {
      r.rgbBlue  = lookup_color( (int16_t)c+128);
      r.rgbGreen = lookup_color( (int16_t)c );
      r.rgbRed   = lookup_color( (int16_t)c-128);
    }
  
  fwrite(&r,sizeof(RGBQUAD),1,s->out_handle);
  
  return FALSE;
}
Esempio n. 5
0
//plot points
//params coordinate pair, index into color palette
extern int plot(coords * p, float * c, int t){
  int x;
  int y;
  int i;
  color * ccolor;
  
#if defined(DEBUG)
  printf("plot: received p:(%LG,%LG)\n", p->x, p->y);
  printf("      minX: %LG, rangeX: %LG\n", minX, rangeX);
  printf("      minY: %LG, rangeY: %LG\n", minY, rangeY);
#endif

  x = (int)((p->x - minX)/rangeX * winW + 0.5);
  y = (int)((p->y - minY)/rangeY * winH + 0.5);
  
  //don't try to plot if out of range
  if(x < 0 || x >= winW || y < 0 || y >= winH){
    //printf("plot: coordinates (%d,%d) out of range.  not plotting.\n",x,y);
    return 0;
  }

#if defined(DEBUG)
  printf("plot: about to increment framecounts[t][%d]. (x,y):(%d,%d)\n",
         i, x, y);
#endif

  i = y*winW + x;

  //increment count where point is in grid
  framecounts[t][i]++;
  
  //look up color in palette using index
  ccolor = lookup_color(*c);

  //accumulate color values
  frames[t][3*i] += ccolor->r;
  frames[t][3*i+1] += ccolor->g;
  frames[t][3*i+2] += ccolor->b;
  
  return 1;
}
Esempio n. 6
0
gboolean
hitori_draw_cb (GtkWidget *drawing_area, cairo_t *cr, Hitori *hitori)
{
	gint area_width, area_height;
	HitoriVector iter;
	guint board_width, board_height;
	gfloat cell_size;
	gdouble x_pos, y_pos;
	GtkStyleContext *style_context;

	area_width = gdk_window_get_width (gtk_widget_get_window (hitori->drawing_area));
	area_height = gdk_window_get_height (gtk_widget_get_window (hitori->drawing_area));
	style_context = gtk_widget_get_style_context (hitori->drawing_area);

	/* Clamp the width/height to the minimum */
	if (area_height < area_width) {
		board_width = area_height;
		board_height = area_height;
	} else {
		board_width = area_width;
		board_height = area_width;
	}

	/* Work out the cell size and scale all text accordingly */
	cell_size = board_width / hitori->board_size;
	pango_font_description_set_absolute_size (hitori->normal_font_desc, cell_size * NORMAL_FONT_SCALE * 0.8 * PANGO_SCALE);
	pango_font_description_set_absolute_size (hitori->painted_font_desc, cell_size * PAINTED_FONT_SCALE * 0.8 * PANGO_SCALE);

	/* Centre the board */
	hitori->drawing_area_x_offset = (area_width - board_width) / 2;
	hitori->drawing_area_y_offset = (area_height - board_height) / 2;
	cairo_translate (cr, hitori->drawing_area_x_offset, hitori->drawing_area_y_offset);

	/* Draw the unpainted cells first. */
	for (iter.x = 0, x_pos = 0; iter.x < hitori->board_size; iter.x++, x_pos += cell_size) { /* columns (X) */
		for (iter.y = 0, y_pos = 0; iter.y < hitori->board_size; iter.y++, y_pos += cell_size) { /* rows (Y) */
			if (!(hitori->board[iter.x][iter.y].status & CELL_PAINTED)) {
				draw_cell (hitori, style_context, cr, cell_size, x_pos, y_pos, iter);
			}
		}
	}

	/* Next draw the painted cells (so that their borders are painted over those of the unpainted cells).. */
	for (iter.x = 0, x_pos = 0; iter.x < hitori->board_size; iter.x++, x_pos += cell_size) { /* columns (X) */
		for (iter.y = 0, y_pos = 0; iter.y < hitori->board_size; iter.y++, y_pos += cell_size) { /* rows (Y) */
			if (hitori->board[iter.x][iter.y].status & CELL_PAINTED) {
				draw_cell (hitori, style_context, cr, cell_size, x_pos, y_pos, iter);
			}
		}
	}

	/* Draw a hint if applicable */
	if (hitori->hint_status % 2 == 1) {
		gfloat line_width = BORDER_LEFT * 2.5;
		GdkRGBA colour;
		lookup_color (style_context, "hint-border-color", &colour);
		gdk_cairo_set_source_rgba (cr, &colour);
		cairo_set_line_width (cr, line_width);
		cairo_rectangle (cr,
				 hitori->hint_position.x * cell_size + line_width / 2,
				 hitori->hint_position.y * cell_size + line_width / 2,
				 cell_size - line_width,
				 cell_size - line_width);
		cairo_stroke (cr);
	}

	return FALSE;
}
Esempio n. 7
0
static void
draw_cell (Hitori *hitori, GtkStyleContext *style_context, cairo_t *cr, gfloat cell_size, gdouble x_pos, gdouble y_pos,
           HitoriVector iter)
{
	gchar *text;
	PangoLayout *layout;
	gint text_width, text_height;
	GtkStateFlags state;
	gboolean painted = FALSE;
	PangoFontDescription *font_desc;
	GtkBorder border;
	GdkRGBA colour = {0.0, 0.0, 0.0, 0.0};

	state = gtk_style_context_get_state (style_context);

	if (hitori->board[iter.x][iter.y].status & CELL_PAINTED) {
		painted = TRUE;
		state = GTK_STATE_FLAG_INSENSITIVE;
		gtk_style_context_set_state (style_context, state);
	}

	/* Set up the border */
	gtk_style_context_get_border (style_context, state, &border);
	border.left = BORDER_LEFT; /* Hack! */

	/* Draw the fill */
	if (hitori->debug == TRUE) {
		g_debug ("State: %u", state);
	}

	if (painted) {
		lookup_color (style_context, "painted-bg-color", &colour);
	} else {
		lookup_color (style_context, "unpainted-bg-color", &colour);
	}

	gdk_cairo_set_source_rgba (cr, &colour);
	cairo_rectangle (cr, x_pos, y_pos, cell_size, cell_size);
	cairo_fill (cr);

	/* If the cell is tagged, draw the tag dots */
	if (hitori->board[iter.x][iter.y].status & CELL_TAG1) {
		if (painted) {
			lookup_color (style_context, "tag1-painted-color", &colour);
		} else {
			lookup_color (style_context, "tag1-unpainted-color", &colour);
		}
		gdk_cairo_set_source_rgba (cr, &colour);

		cairo_move_to (cr, x_pos, y_pos + TAG_OFFSET);
		cairo_line_to (cr, x_pos, y_pos);
		cairo_line_to (cr, x_pos + TAG_OFFSET, y_pos);
		cairo_arc (cr, x_pos + TAG_OFFSET, y_pos + TAG_OFFSET, TAG_RADIUS * cell_size, 0.0, 0.5 * M_PI);
		cairo_fill (cr);
	}

	if (hitori->board[iter.x][iter.y].status & CELL_TAG2) {
		if (painted) {
			lookup_color (style_context, "tag2-painted-color", &colour);
		} else {
			lookup_color (style_context, "tag2-unpainted-color", &colour);
		}
		gdk_cairo_set_source_rgba (cr, &colour);

		cairo_move_to (cr, x_pos + cell_size - TAG_OFFSET, y_pos);
		cairo_line_to (cr, x_pos + cell_size, y_pos);
		cairo_line_to (cr, x_pos + cell_size, y_pos + TAG_OFFSET);
		cairo_arc (cr, x_pos + cell_size - TAG_OFFSET, y_pos + TAG_OFFSET, TAG_RADIUS * cell_size, 0.5 * M_PI, 1.0 * M_PI);
		cairo_fill (cr);
	}

	/* Draw the border */
	if (painted) {
		lookup_color (style_context, "painted-border-color", &colour);
	} else {
		lookup_color (style_context, "unpainted-border-color", &colour);
	}
	gdk_cairo_set_source_rgba (cr, &colour);
	cairo_set_line_width (cr, border.left);
	cairo_rectangle (cr, x_pos, y_pos, cell_size, cell_size);
	cairo_stroke (cr);

	/* Draw the text */
	text = g_strdup_printf ("%u", hitori->board[iter.x][iter.y].num);
	layout = pango_cairo_create_layout (cr);

	pango_layout_set_text (layout, text, -1);

	font_desc = (painted == TRUE) ? hitori->painted_font_desc : hitori->normal_font_desc;

	if (hitori->board[iter.x][iter.y].status & CELL_ERROR) {
		lookup_color (style_context, "mistaken-number-color", &colour);
		gdk_cairo_set_source_rgba (cr, &colour);
		pango_font_description_set_weight (font_desc, PANGO_WEIGHT_BOLD);
	} else if (painted) {
		lookup_color (style_context, "painted-number-color", &colour);
		gdk_cairo_set_source_rgba (cr, &colour);
		pango_font_description_set_weight (font_desc, PANGO_WEIGHT_NORMAL);
	} else {
		g_assert (!painted);
		lookup_color (style_context, "unpainted-number-color", &colour);
		gdk_cairo_set_source_rgba (cr, &colour);
		pango_font_description_set_weight (font_desc, PANGO_WEIGHT_NORMAL);
	}

	pango_layout_set_font_description (layout, font_desc);

	pango_layout_get_pixel_size (layout, &text_width, &text_height);
	cairo_move_to (cr,
	               x_pos + (cell_size - text_width) / 2,
	               y_pos + (cell_size - text_height) / 2);

	pango_cairo_show_layout (cr, layout);

	g_free (text);
	g_object_unref (layout);
}
Esempio n. 8
0
/*+++++++++++++++++++++++++++ draw_mon_bar() ++++++++++++++++++++++++++++*/
void
draw_mon_bar(int         pos,
             signed char delta,
             char        bar_no,
             int         x,
             int         y)
{
   int x_offset,
       y_offset;

   x_offset = x + x_offset_bars;

   if (connect_data[pos].bar_length[(int)bar_no] > 0)
   {
      if (bar_no == MON_TR_BAR_NO)  /* TRANSFER RATE */
      {
         y_offset = y + SPACE_ABOVE_LINE;
         XFillRectangle(display, line_window, tr_bar_gc, x_offset, y_offset,
                        connect_data[pos].bar_length[(int)bar_no],
                        bar_thickness_3);
         XFillRectangle(display, line_pixmap, tr_bar_gc, x_offset, y_offset,
                        connect_data[pos].bar_length[(int)bar_no],
                        bar_thickness_3);
      }
      else if (bar_no == HOST_ERROR_BAR_NO) /* ERROR HOSTS */
           {
              XGCValues gc_values;

              y_offset = y + SPACE_ABOVE_LINE + bar_thickness_3 + bar_thickness_3;
              gc_values.foreground = color_pool[ERROR_ID];
              XChangeGC(display, color_gc, GCForeground, &gc_values);
              XFillRectangle(display, line_window, color_gc,
                             x_offset, y_offset,
                             connect_data[pos].bar_length[(int)bar_no],
                             bar_thickness_3);
              XFillRectangle(display, line_pixmap, color_gc,
                             x_offset, y_offset,
                             connect_data[pos].bar_length[(int)bar_no],
                             bar_thickness_3);
           }
           else
           {
              XColor    color;
              XGCValues gc_values;

              y_offset = y + SPACE_ABOVE_LINE + bar_thickness_3;
              color.red = 0;
              color.green = connect_data[pos].green_color_offset;
              color.blue = connect_data[pos].blue_color_offset;
              lookup_color(&color);
              gc_values.foreground = color.pixel;
              XChangeGC(display, color_gc, GCForeground, &gc_values);
              XFillRectangle(display, line_window, color_gc,
                             x_offset, y_offset,
                             connect_data[pos].bar_length[(int)bar_no],
                             bar_thickness_3);
              XFillRectangle(display, line_pixmap, color_gc,
                             x_offset, y_offset,
                             connect_data[pos].bar_length[(int)bar_no],
                             bar_thickness_3);
           }
   }
   else
   {
      if (bar_no == MON_TR_BAR_NO)  /* TRANSFER RATE */
      {
         y_offset = y + SPACE_ABOVE_LINE;
      }
      else if (bar_no == HOST_ERROR_BAR_NO) /* ERROR HOSTS */
           {
              y_offset = y + SPACE_ABOVE_LINE + bar_thickness_3 + bar_thickness_3;
           }
           else
           {
              y_offset = y + SPACE_ABOVE_LINE + bar_thickness_3;
           }
   }

   /* Remove color behind shrunken bar. */
   if (delta < 0)
   {
      GC tmp_gc;

      if (connect_data[pos].inverse == OFF)
      {
         tmp_gc = default_bg_gc;
      }
      else
      {
         if (connect_data[pos].inverse == ON)
         {
            tmp_gc = normal_bg_gc;
         }
         else
         {
            tmp_gc = locked_bg_gc;
         }
      }
      XFillRectangle(display, line_window, tmp_gc,
                     x_offset + connect_data[pos].bar_length[(int)bar_no],
                     y_offset,
                     (int)max_bar_length - connect_data[pos].bar_length[(int)bar_no],
                     bar_thickness_3);
      XFillRectangle(display, line_pixmap, tmp_gc,
                     x_offset + connect_data[pos].bar_length[(int)bar_no],
                     y_offset,
                     (int)max_bar_length - connect_data[pos].bar_length[(int)bar_no],
                     bar_thickness_3);
   }

   return;
}
Esempio n. 9
0
File: draw.c Progetto: zanton/dagviz
static void draw_dvdag_node_1(cairo_t *cr, dv_dag_node_t *node) {
  // Count node drawn
  S->nd++;
  // Node color
  double x = node->vl->c;
  double y = node->c;
  double c[4];
  int v = 0;
  switch (S->nc) {
  case 0:
    v = node->pi->info.worker; break;
  case 1:
    v = node->pi->info.cpu; break;
  case 2:
    v = node->pi->info.kind; break;
  default:
    v = node->pi->info.worker;
  }
  lookup_color(v, c, c+1, c+2, c+3);
  // Alpha
  double alpha = 1.0;
  // Draw path
  cairo_save(cr);
  cairo_new_path(cr);
  if (dv_is_union(node)) {

    double xx, yy, w, h;
    if (dv_is_expanding(node) || dv_is_shrinking(node)) {

      double margin = 1.0;
      if (dv_is_expanding(node)) {
        // Fading out
        alpha = get_alpha_fading_out();
        margin = get_alpha_fading_in();
      } else {
        // Fading in
        alpha = get_alpha_fading_in();
        margin = get_alpha_fading_out();
      }
      // Large-sized box
      margin *= DV_UNION_NODE_MARGIN;
      xx = x - node->lc * DV_HDIS - DV_RADIUS - margin;
      yy = y - DV_RADIUS - margin;
      dv_dag_node_t * hd = (dv_dag_node_t *) node->heads->top->item;
      h = hd->dc * DV_VDIS + 2 * (DV_RADIUS + margin);
      w = (node->lc + node->rc) * DV_HDIS + 2 * (DV_RADIUS + margin);
      
    } else {
      
      // Normal-sized box
      xx = x - DV_RADIUS;
      yy = y - DV_RADIUS;
      w = 2 * DV_RADIUS;
      h = 2 * DV_RADIUS;
      if (node->lv > S->a->new_sel) {
        // Fading out
        alpha = get_alpha_fading_out();
      } else if (node->lv > S->sel) {
        // Fading in
        alpha = get_alpha_fading_in();
      }
      
    }

    // Box
    cairo_move_to(cr, xx, yy);
    cairo_line_to(cr, xx + w, yy);
    cairo_line_to(cr, xx + w, yy + h);
    cairo_line_to(cr, xx, yy + h);
    cairo_close_path(cr);
    
  } else {
    
    // Normal-sized circle
    cairo_arc(cr, x, y, DV_RADIUS, 0.0, 2*M_PI);
    if (node->lv > S->a->new_sel) {
      // Fading out
      alpha = get_alpha_fading_out();
    } else if (node->lv > S->sel) {
      // Fading in
      alpha = get_alpha_fading_in();
    }
    
  }
  
  // Draw node
  cairo_set_source_rgba(cr, c[0], c[1], c[2], c[3] * alpha);
  cairo_fill_preserve(cr);
  cairo_set_source_rgba(cr, 0.0, 0.0, 0.0, alpha);
  cairo_stroke(cr);
  cairo_restore(cr);
}