Code Search for Developers
 
 
  

emview_box_component.c from EmStar at Krugle


Show emview_box_component.c syntax highlighted

/*
 *
 * Copyright (c) 2003 The Regents of the University of California.  All 
 * rights reserved.
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions
 * are met:
 *
 * - Redistributions of source code must retain the above copyright
 *   notice, this list of conditions and the following disclaimer.
 *
 * - Neither the name of the University nor the names of its
 *   contributors may be used to endorse or promote products derived
 *   from this software without specific prior written permission.
 *
 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS''
 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
 * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
 * PARTICULAR  PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR
 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 *
 */

#include "emview_i.h"

char emview_box_component_c_id[] = "$Id: emview_box_component.c,v 1.12 2004/03/26 04:39:16 girod Exp $";

/*
 *  box component creation
 */

static
component_t *emview_box_component_create()
{
  return (component_t *)g_new0(box_component_t, 1);
}

static
void emview_box_component_destroy(component_t *c)
{
  if (c) {
    component_nonexcl_clear(&(((box_component_t*)c)->above), NULL);
    free(c);
  }
}


static
component_t *emview_box_component_copy(component_t *src)
{
  component_t *copy = emview_box_component_create();
  memmove(copy, src, sizeof(box_component_t));
  return copy;
}

static
int emview_box_component_is_exclusive(int field)
{
  switch (field) {
  case EMVIEW_BOX_ABOVE:
    return 0;
  default:
    return 1;
  }
}


static
void emview_box_component_assign_aux(box_component_t *bc, int field, source_data_t *d)
{
  int flag_index;

  switch (field) {
  case EMVIEW_BOX_ABOVE:
    component_nonexcl_append(&(bc->above), d);
    break;

  case EMVIEW_BOX_INSIDE:
    bc->inside = d;
    break;

  case EMVIEW_BOX_COLOR:
    bc->color = d;
    break;

  case EMVIEW_BOX_BORDER:
    bc->border_color = d;
    break;

  default:    
    /* compute flag index */
    flag_index = field - EMVIEW_BOX_FLAG1;
    if (flag_index >= EMVIEW_BOX_MAX_FLAGS) 
      flag_index = -1;

    if (flag_index < 0)
      goto fail;
    bc->flags[flag_index] = d;
  }

  return;

fail:
  elog(LOG_WARNING, "Illegal field for box component: %d", field);
}


static
void emview_box_component_assign(component_t *c, int field, source_data_t *d)
{
  box_component_t *bc = (box_component_t *)c;

  if (field == EMVIEW_BOX_ABOVE)
    component_nonexcl_append(&(bc->above), d);

  else 
    emview_box_component_assign_aux(bc, field, d);
}


static
void emview_box_component_clear(component_t *c, int field, source_data_t *d)
{
  box_component_t *bc = (box_component_t *)c;

  if (field == EMVIEW_BOX_ALL) {
    component_nonexcl_clear(&(bc->above), NULL);
    bc->inside = NULL;
    bc->color = NULL;
    bc->border_color = NULL;
    memset(bc->flags, 0, sizeof(bc->flags));
    return;
  }

  if (field == EMVIEW_BOX_ABOVE)
    component_nonexcl_clear(&(bc->above), d);

  else 
    emview_box_component_assign_aux(bc, field, NULL);
}


/*
 *  layout and drawing
 */

void emview_box_component_checkrefs(component_t *c)
{
  /* set referenmced if any sources referenced */
  if (!c->referenced) {
    box_component_t *bc = (box_component_t *)c;
    int i;
    
    component_check_referenced(c, bc->inside);
    component_check_referenced(c, bc->color);
    component_check_referenced(c, bc->border_color);
    for (i=0; i<EMVIEW_BOX_MAX_FLAGS; i++)
      component_check_referenced(c, bc->flags[i]);
    component_nonexcl_check_referenced(c, bc->above);
  }
}


void emview_box_component_layout(component_t *c)
{
  if (c->visible && (c->active || c->referenced))
    emview_component_extend_upper_right(c, EMVIEW_BOX_WIDTH, EMVIEW_BOX_HEIGHT);
}


void emview_box_component_draw(component_t *c)
{
  box_component_t *bc = (box_component_t *)c;
  static GdkGC *gc = NULL;
  int fill;
  int i,j;

  if (gc == NULL) {
    gc = gdk_gc_new(_core.gui.window->window);
    gdk_gc_copy(gc, _core.gui.window->style->black_gc);
  }

  /*
   *  box and box color
   */

  /* get the color from the data source, determine fill */
  fill = FALSE;
  if (emview_source_data_valid(bc->color)) {
    fill = emview_set_fg_color(gc, bc->color->int_value, !c->active);
    if (bc->color->int_value == EMVIEW_COLOR_WHITE)
      fill = 0;
  }
  if (!fill) 
    emview_set_fg_color(gc, EMVIEW_COLOR_WHITE, 0);
  
  /* draw the box (1 pixel larger) */
  gdk_draw_rectangle(_core.gui.fg_pixmap, gc,
		     TRUE, c->px, c->py, c->w + 1, c->h + 1);

  /* border color */
  if (emview_source_data_valid(bc->border_color)) {
    fill = emview_set_fg_color(gc, bc->border_color->int_value, !c->active);
    if (bc->border_color->int_value == EMVIEW_COLOR_WHITE)
      fill = 0;
    if (fill) {
      gdk_draw_rectangle(_core.gui.fg_pixmap, gc,
			 FALSE, c->px, c->py, c->w, c->h);
      gdk_draw_rectangle(_core.gui.fg_pixmap, gc,
			 FALSE, c->px+1, c->py+1, c->w-2, c->h-2);
    }
  }
  
  /* draw outline */
  if (!fill) {
    emview_set_fg_color(gc, EMVIEW_COLOR_BLACK, !c->active);
    gdk_draw_rectangle(_core.gui.fg_pixmap, gc,
		       FALSE, c->px, c->py, c->w, c->h);
  }

  /* 
   *  text in box
   */

  if (emview_source_data_valid(bc->inside)) {
    emview_put_label(c->px, c->py + BOX_FLAG_WIDTH + 2*BOX_FLAG_SEP, c->w, 
		     c->h - (BOX_FLAG_WIDTH + 2*BOX_FLAG_SEP), 
		     emview_source_data_string_value(bc->inside),
		     emview_source_data_bg_color(bc->inside),
		     emview_source_data_fg_color(bc->inside),
		     EMVIEW_COLOR_NONE,
		     EMVIEW_CENTER, EMVIEW_CENTER, TEXT_BG_PAD,
		     0, 0, 0, !c->active);
  }

  /* 
   *  flags
   */
  
  for (i=0; i<EMVIEW_BOX_MAX_FLAGS; i++) {
    if (emview_source_data_valid(bc->flags[i]) &&
	bc->flags[i]->int_value) {
      
      /* set color */
      emview_set_fg_color(gc, (i + EMVIEW_COLOR_RED), !c->active);
      
      /* draw flag box */
      gdk_draw_rectangle(_core.gui.fg_pixmap, gc, TRUE, 
			 c->px + BOX_FLAG_SEP + (BOX_FLAG_SEP + BOX_FLAG_WIDTH)*i, 
			 c->py + BOX_FLAG_SEP, 
			 BOX_FLAG_WIDTH+1, BOX_FLAG_WIDTH+1);
    }
  }  

  /* 
   *  over-box annotations
   */
  
  if (bc->above)
    for (i=0,j=STD_TEXT_HEIGHT+TEXT_BG_PAD*2; i<bc->above->len; i++) {
      source_data_t *data = (source_data_t*)g_ptr_array_index(bc->above, i);
      if (emview_source_data_valid(data)) {
	emview_put_label(c->px, c->py - j, 0, STD_TEXT_HEIGHT,
			 emview_source_data_string_value(data),
			 emview_source_data_bg_color(data),
			 emview_source_data_fg_color(data),
			 EMVIEW_COLOR_NONE, 
			 EMVIEW_CENTER, EMVIEW_LEFT_JUST, TEXT_BG_PAD, 0, 0, 0, !c->active);
	j += STD_TEXT_HEIGHT;
      }
    }
  
}


static
void emview_box_component_print(component_t *c, buf_t *buf)
{
  box_component_t *b = (box_component_t *)c;
  int i;

  if (b->above) 
    for (i=0; i<b->above->len; i++) 
      emview_print_source_data
	("above", ((source_data_t*)g_ptr_array_index(b->above, i)), buf);
  
  emview_print_source_data("inside", b->inside, buf);
  emview_print_source_data("color", b->color, buf);  
  emview_print_source_data("border", b->border_color, buf);
  for (i=0; i<EMVIEW_BOX_MAX_FLAGS; i++)
    emview_print_source_data("flag", b->flags[i], buf);
}

/*
 *  init function
 */

void emview_box_component_init()
{
  struct component_vtbl v = {
    name: "Box",
    create: emview_box_component_create,
    destroy: emview_box_component_destroy,
    copy: emview_box_component_copy,
    is_exclusive: emview_box_component_is_exclusive,
    assign: emview_box_component_assign,
    clear: emview_box_component_clear,
    checkrefs: emview_box_component_checkrefs,
    layout: emview_box_component_layout,
    draw: emview_box_component_draw,
    print: emview_box_component_print
  };

  _core.components.vtbl[EMVIEW_COMP_TYPE_BOX] = v;  
}




See more files for this project here

EmStar

EmStar is a software system for developing and deploying wireless sensor networks involving Linux-based platforms. As the wireless sensor network community has attempted to deploy more complex designs---large-scale, long-lived systems that need self-organization and adaptivity---a number of difficult software design issues have arisen. Advances in software design have not kept pace with the capabilities of hardware. This is because designing for an adaptive, efficient, and useful sensor network has turned out to be surprisingly complex and difficult. EmStar is a Linux-based software framework, whose goal is to dramatically reduce this complexity, enabling work to be shared and reused, and simplifying and speeding the design of new sensor network applications.

Project homepage: http://cvs.cens.ucla.edu/emstar/
Programming language(s): C,Shell Script
License: other

  emview_analysis.c
  emview_analysis.h
  emview_box_component.c
  emview_component.c
  emview_component.h
  emview_config.c
  emview_config.h
  emview_device.c
  emview_device.h
  emview_gui.c
  emview_gui.h
  emview_gui_menu.c
  emview_i.h
  emview_main.c
  emview_node.c
  emview_node.h
  emview_node_component.c
  emview_slots.c
  emview_source.c
  emview_source.h