int node_data(struct node *p) { if (p == NULL) return 0; node_data(p->left); printf("%d\n", p->data); node_data(p->right); return 0; }
static void hash_object(object_t* object, uint32_t* hash) { switch (object->type) { case type_nil: *hash = hash_nil(*hash); return; case type_bool: *hash = hash_bool(*hash, object->b); return; case type_double: *hash = hash_double(*hash, object->d); return; case type_int: *hash = hash_i64(*hash, object->i); return; case type_uint: *hash = hash_u64(*hash, object->u); return; case type_str: *hash = hash_str(*hash, object->str, object->l); return; // unused types in this benchmark #if 0 case type_float: write_float(hash, node_float(node)); return; case type_bin: *hash = hash_str(*hash, node_data(node), node_data_len(node)); return; case type_ext: *hash = hash_u8(*hash, node_exttype(node)); *hash = hash_str(*hash, node_data(node), node_data_len(node)); return; #endif case type_array: { uint32_t count = object->l; for (uint32_t i = 0; i < count; ++i) hash_object(object->children + i, hash); *hash = hash_u32(*hash, count); return; } case type_map: { uint32_t count = object->l; for (uint32_t i = 0; i < count; ++i) { // we expect keys to be short strings object_t* key = object->children + (i * 2); *hash = hash_str(*hash, key->str, key->l); hash_object(object->children + (i * 2) + 1, hash); } *hash = hash_u32(*hash, count); return; } default: break; } abort(); }
static _hit_t hit_node(designer_node_t *n, _point_t m) { // designer_node_type_t *nt = n->type; // node_type_data_t *ntd = node_type_data(nt); node_data_t *nd = node_data(n); _point_t pos = nd->origin; _point_t mr = _point(m.x - pos.x, m.y - pos.y); if (!_inrect(mr, nd->nr)) return HIT_NOTHING; /* check for head rect */ if (_inrect(mr, nd->tr)) { if (_inrect(mr, nd->xr)) return HIT_CLOSE; if (_inrect(mr, nd->lr)) return HIT_LABEL; return HIT_TITLE; } else { if (_inrect(mr, nd->ir)) return HIT_INPUT; if (_inrect(mr, nd->or)) return HIT_OUTPUT; return HIT_BODY; } }
void BTree<Key, Value>::Node::insertValue(Key key, Value val) { auto kv = node_data(key, val); if (vals_size == 0) { vals_size++; vals[0] = kv; return; } else { if (vals.data()->first > key) { vals_size++; insert_to_array(vals.data(), vals_size, 0, kv); return; } } auto lb_iter = std::lower_bound( this->vals.data(), this->vals.data() + vals_size, kv, [](const std::pair<Key, Value> &l, const std::pair<Key, Value> &r) { return l.first < r.first; }); if (lb_iter != this->vals.data() + vals_size) { auto d = std::distance(vals.data(), lb_iter); vals_size++; insert_to_array(vals.data(), vals_size, d, kv); return; } this->vals[vals_size] = (kv); vals_size++; }
static _rect_t recalc_area(cairo_t *cr, widget_data_t *data) { _rect_t area; int count = 0; /* no valid data */ if (!data || !data->design || !data->design->nodes) return _zeror; /* check the nodes */ for (GSList *list = data->design->nodes; list != NULL; list = list->next) { designer_node_t *node = list->data; if (cr) { calc_node_type(cr, node->type); calc_node(cr, node); } node_data_t *nd = node_data(node); _rect_t nr = _offset(nd->nr, _ptos(nd->origin)); area = (count++) ? _union(area, nr) : nr; } return _inset(area, _size(-40, -20)); }
void CL_DiskBTreeNodeSpace::NodeModified (CL_GenericBTreeNode* node) { if (!node) return; CL_ByteString node_data (DEFAULT_SIZE); CL_ByteStream s (node_data); ((CL_DiskBTreeNode*) node)->WriteTo (s); _store.Modify (node->Handle(), node_data); }
bool BTree<Key, Value>::iner_find(Key key, typename Node::Ptr cur_node, typename Node::Ptr&out_ptr, Value &out_res)const { if (cur_node->is_leaf) { auto find_res = std::lower_bound( cur_node->vals.data(), cur_node->vals.data() + cur_node->vals_size, std::make_pair(key, Value()), [key](const std::pair<Key, Value> &v, const std::pair<Key, Value> &v2) { return (v.first < v2.first); }); out_ptr = cur_node; if (find_res != cur_node->vals.data() + cur_node->vals_size) { out_res = find_res->second; return true; } else { return false; } } //case k < k_0 if (key < cur_node->vals[0].first) { return iner_find(key, this->getNode(cur_node->childs[0]), out_ptr, out_res); } //case k_d ≤ k if ((cur_node->childs_size != 0) && (cur_node->vals_size != 0)) { if (key >= cur_node->vals[cur_node->vals_size - 1].first) { auto last = cur_node->childs[cur_node->childs_size - 1]; return iner_find(key, this->getNode(last), out_ptr, out_res); } } // case k_i ≤ k < k_{i+1} auto kv = node_data(key, Value()); auto low_bound = std::lower_bound(cur_node->vals.data(), cur_node->vals.data() + cur_node->vals_size, kv, [key](const node_data& v, const node_data&v2) { return (v.first < v2.first); }); auto nxt_it = low_bound + 1; if (low_bound->first != kv.first) { low_bound--; nxt_it--; } if (key < nxt_it->first) { auto d = std::distance(cur_node->vals.data(), low_bound); return iner_find(key, getNode(cur_node->childs[d + 1]), out_ptr, out_res); } return false; }
static int hit_output_slot(designer_node_t *n, _point_t m) { designer_node_type_t *nt = n->type; node_type_data_t *ntd = node_type_data(nt); node_data_t *nd = node_data(n); _size_t d = _delta(_move(nd->or.o, _ptos(nd->origin)), m); return d.h / ntd->sr.s.h; }
static _point_t output_slot_origin(designer_node_t *n, int i) { designer_node_type_t *nt = n->type; node_type_data_t *ntd = node_type_data(nt); node_data_t *nd = node_data(n); return _move(_move(nd->or.o, _size(nd->or.s.w - 3, 5 + ntd->sr.s.h * i)), _ptos(nd->origin)); }
void designer_widget_move_node (GtkWidget *widget, designer_node_t *node, double x, double y) { widget_data_t *data = get_widget_data(widget); #ifdef DEBUG_OUTPUT g_print("widget %p moves node %s to %gx%g\n", data, node->name, x, y); #endif node_data_t *nd = node_data(node); nd->origin = _point(x,y); update_area_conditional(data, FALSE); }
CL_GenericBTreeNode* CL_DiskBTreeNodeSpace::BorrowNode (CL_BTreeNodeHandle h) const { CL_ByteString node_data (DEFAULT_SIZE); if (!_store.Retrieve (h, node_data)) return NULL; CL_ByteStream s (node_data); CL_DiskBTreeNode* n = new CL_DiskBTreeNode (_order, _tree, _cmp); if (n) { n->ReadFrom (s); _SetHandle (*n, h); } return n; }
void designer_widget_get_node_position (GtkWidget *widget, designer_node_t *node, double *x, double *y) { widget_data_t *data = get_widget_data(widget); #ifdef DEBUG_OUTPUT g_print("widget %p retrieves position of node %s\n", data, node->name); #endif node_data_t *nd = node_data(node); *x = nd->origin.x; *y = nd->origin.y; }
void designer_widget_add_node (GtkWidget *widget, designer_node_t *node, double x, double y) { widget_data_t *data = get_widget_data(widget); #ifdef DEBUG_OUTPUT g_print("widget %p adds node %s at %gx%g\n", data, node->name, x, y); #endif node_data_t *nd = node_data(node); nd->origin = place_new_node(data); designer_node_push_back(node); set_root_focus (data, node); update_area_conditional(data, TRUE); gtk_widget_queue_draw(widget); }
void input_byte(command_queue_t *q, uint8_t data) { int status = 0; if (empty_queue(q)) { put_queue(q, new_node()); status = set_node_command(last_node(q), data); } else if (!command_recieved(node_data(last_node(q)))) { status = set_node_command(last_node(q), data); } else { put_queue(q, new_node()); status = set_node_command(last_node(q), data); } }
static void draw_highlight(cairo_t *cr, designer_node_t *n, _point_t m, _hit_t hit, int check) { node_data_t *nd = node_data(n); _point_t pos = nd->origin; // _point_t mr = _point(m.x - pos.x, m.y - pos.y); cairo_save(cr); switch (hit) { case HIT_LABEL: case HIT_TITLE: case HIT_CLOSE: case HIT_BODY: cairo_translate(cr, pos.x, pos.y); cairo_set_line_width(cr, 4.0); cairo_set_source_rgba(cr, RGBA_HIGHLIGHT); round_path(cr, _inset(nd->nr, _size(-1, -1)), round_s); cairo_stroke(cr); break; break; case HIT_INPUT: { /* FIME: replace by target */ int si = hit_input_slot(n, m); _point_t sl = input_slot_origin(n, si); draw_slot_highlight(cr, sl, check); break; } case HIT_OUTPUT: { /* FIME: replace by target */ int si = hit_output_slot(n, m); _point_t sl = output_slot_origin(n, si); draw_slot_highlight(cr, sl, check); break; } default: break; } cairo_restore(cr); }
static void calc_node(cairo_t *cr, designer_node_t *n) { node_data_t *nd = node_data(n); node_type_data_t *ntd = node_type_data(n->type); _rect_t nr, lr, tr, ir, or, br, xr; set_title_font(cr); lr = text_rect(cr, n->name); tr = _inset(lr, _size(-5, -5)); tr.s.w += 20; /* button space */ br = ntd->br; /* move into place */ br.o.y = tr.o.y + tr.s.h; nr = _union(tr, br); /* break down areas once again */ br = nr; tr = _splitv(&br, tr.s.h); /* split off close button */ xr = tr; _splith(&xr, tr.s.w - 16); xr = _splitv(&xr, 16); xr = _inset(xr, _size(4, 4)); ir = ntd->ir; /* align inputs to the left */ ir.o = _move(br.o, _size(5, 5)); or = ntd->or; /* align outputs to the right */ or.o = _move(br.o, _size(br.s.w - or.s.w - 5, 5)); nd->nr = nr; nd->lr = lr; nd->tr = tr; nd->br = br; nd->ir = ir; nd->or = or; nd->xr = xr; }
static gboolean motion_notify_event (GtkWidget *widget, GdkEventMotion *event) { widget_data_t *data = get_widget_data(widget); int x, y; GdkModifierType state; if (event->is_hint) gdk_window_get_pointer (event->window, &x, &y, &state); else { x = event->x; y = event->y; state = event->state; } data->mouse = map_location(data, _point(x, y)); switch(data->state) { case STATE_MOVING: if (data->active_node) { node_data(data->active_node)->origin = _move(data->origin, _delta(data->mouse_down, data->mouse)); } break; case STATE_CONIN: break; case STATE_CONOUT: break; default: break; } gtk_widget_queue_draw(widget); return TRUE; }
int main() { int arr[10] = {19, 23, 10, 11, 3, 392, 2, 43, 42, 4}; int i, search_num; for (i = 0; i < 10; i++) { root = insert_node(arr[i], root); } printf("<帰りがけ順に表示>\n"); node_data(root); printf("合計 : %d\n", sum_node(root)); while(1) { printf("検索したい数値を入力して下さい。(-1を入力することで検索を終了)\n"); printf(" ⇒ "); scanf("%d", &search_num); if (search_num == -1) break; else if (search_node(search_num, root) == 0) printf("検索結果 : 入力された数値は存在しません。\n"); else printf("検索結果 : 入力された数値は存在します。\n"); } }
void cCellMesh::calc_dist(){ std::cout << "<MESH> calculating node distance to surface..." << std::endl; Eigen::Matrix<tCoord,1,3> v1, v2; for(tElement n = 0; n < nodes_count; n++){ if(surface_node(n)){ node_data(n, dist_surface) = 0.0; continue; } v1 = coordinates.block<1,3>(n, 0); node_data(n, dist_surface) = std::numeric_limits<tCalcs>::max(); for(tElement s = 1; s < nodes_count; s++){ if(!surface_node(s)) continue; v2 = coordinates.block<1,3>(s, 0); tCalcs d = (v1 - v2).squaredNorm(); if(d < node_data(n, dist_surface)) node_data(n, dist_surface) = d; } node_data(n, dist_surface) = std::sqrt(tCalcs(node_data(n, dist_surface))); } }
unsigned int IMPInitializer::initializeDataOnPatchLevel(const int lag_node_index_idx, const unsigned int global_index_offset, const unsigned int local_index_offset, Pointer<LData> X_data, Pointer<LData> U_data, const Pointer<PatchHierarchy<NDIM> > hierarchy, const int level_number, const double /*init_data_time*/, const bool can_be_refined, const bool /*initial_time*/, LDataManager* const /*l_data_manager*/) { // Determine the extents of the physical domain. Pointer<CartesianGridGeometry<NDIM> > grid_geom = hierarchy->getGridGeometry(); const double* const grid_x_lower = grid_geom->getXLower(); const double* const grid_x_upper = grid_geom->getXUpper(); // Loop over all patches in the specified level of the patch level and // initialize the local vertices. boost::multi_array_ref<double, 2>& X_array = *X_data->getLocalFormVecArray(); boost::multi_array_ref<double, 2>& U_array = *U_data->getLocalFormVecArray(); int local_idx = -1; int local_node_count = 0; Pointer<PatchLevel<NDIM> > level = hierarchy->getPatchLevel(level_number); const IntVector<NDIM>& ratio = level->getRatio(); for (PatchLevel<NDIM>::Iterator p(level); p; p++) { Pointer<Patch<NDIM> > patch = level->getPatch(p()); const Pointer<CartesianPatchGeometry<NDIM> > patch_geom = patch->getPatchGeometry(); Pointer<LNodeSetData> index_data = patch->getPatchData(lag_node_index_idx); // Initialize the vertices whose initial locations will be within the // given patch. std::vector<std::pair<int, int> > patch_vertices; getPatchVertices(patch_vertices, patch, level_number, can_be_refined); local_node_count += patch_vertices.size(); for (std::vector<std::pair<int, int> >::const_iterator it = patch_vertices.begin(); it != patch_vertices.end(); ++it) { const std::pair<int, int>& point_idx = (*it); const int lagrangian_idx = getCanonicalLagrangianIndex(point_idx, level_number) + global_index_offset; const int local_petsc_idx = ++local_idx + local_index_offset; const int global_petsc_idx = local_petsc_idx + global_index_offset; // Get the coordinates of the present vertex. const libMesh::Point& X = getVertexPosn(point_idx, level_number); const CellIndex<NDIM> idx = IndexUtilities::getCellIndex(&X(0), grid_geom, ratio); for (int d = 0; d < NDIM; ++d) { X_array[local_petsc_idx][d] = X(d); if (X(d) <= grid_x_lower[d]) { TBOX_ERROR(d_object_name << "::initializeDataOnPatchLevel():\n" << " encountered node below lower physical boundary\n" << " please ensure that all nodes are within the " "computational domain." << std::endl); } if (X(d) >= grid_x_upper[d]) { TBOX_ERROR(d_object_name << "::initializeDataOnPatchLevel():\n" << " encountered node above upper physical boundary\n" << " please ensure that all nodes are within the " "computational domain." << std::endl); } } // Create or retrieve a pointer to the LNodeSet associated with the // current Cartesian grid cell. if (!index_data->isElement(idx)) { index_data->appendItemPointer(idx, new LNodeSet()); } LNodeSet* const node_set = index_data->getItem(idx); static const IntVector<NDIM> periodic_offset(0); static const IBTK::Point periodic_displacement(IBTK::Point::Zero()); Pointer<MaterialPointSpec> point_spec = new MaterialPointSpec(lagrangian_idx, d_vertex_wgt[level_number][point_idx.first][point_idx.second], d_vertex_subdomain_id[level_number][point_idx.first][point_idx.second]); std::vector<Pointer<Streamable> > node_data(1, point_spec); node_set->push_back(new LNode(lagrangian_idx, global_petsc_idx, local_petsc_idx, /*initial*/ periodic_offset, /*current*/ periodic_offset, /*initial*/ periodic_displacement, /*current*/ periodic_displacement, node_data)); // Initialize the velocity of the present vertex. std::fill(&U_array[local_petsc_idx][0], &U_array[local_petsc_idx][0] + NDIM, 0.0); } } X_data->restoreArrays(); U_data->restoreArrays(); d_level_is_initialized[level_number] = true; // If a Lagrangian Silo data writer is registered with the initializer, // setup the visualization data corresponding to the present level of the // locally refined grid. if (d_silo_writer) initializeLSiloDataWriter(level_number); return local_node_count; } // initializeDataOnPatchLevel
static gboolean expose_event (GtkWidget *widget, GdkEventExpose *event) { widget_data_t *data = get_widget_data(widget); designer_node_t *hn = NULL; _hit_t hit; int hs = -1; cairo_t *cr = gdk_cairo_create( GTK_WIDGET (data->drawing_area)->window); cairo_set_source_rgb(cr, 0.9, 0.9, 0.9); cairo_paint(cr); _size_t delta = _ptos(data->visible_area.o); cairo_translate(cr, 0.5 - delta.w, 0.5 - delta.h); #if 0 cairo_set_line_width(cr, 3.0); cairo_set_source_rgba(cr, 0.3, 0.3, 0.3, 0.5); round_path(cr, data->used_area, round_s); cairo_stroke(cr); cairo_set_source_rgba(cr, 0.8, 0.6, 0.3, 0.5); round_path(cr, data->visible_area, round_s); cairo_stroke(cr); { char buf[32]; _point_t o = data->mouse; show_axis(cr, o, 0,0,0, 20, 20); set_title_font(cr); cairo_set_source_rgba(cr, 1.0, 0.0, 0.0, 0.8); cairo_move_to(cr, o.x + 5, o.y - 5); sprintf(buf, "(%.0f,%.0f)", o.x, o.y); cairo_show_text(cr, buf); cairo_stroke(cr); cairo_move_to(cr, o.x + 5, o.y + 13); sprintf(buf, "[%.0f,%.0f,%.0fx%.0f]", data->used_area.o.x, data->used_area.o.y, data->used_area.s.w, data->used_area.s.h); cairo_show_text(cr, buf); cairo_stroke(cr); cairo_move_to(cr, o.x + 5, o.y + 28); sprintf(buf, "[%.0f,%.0f,%.0fx%.0f]", data->visible_area.o.x, data->visible_area.o.y, data->visible_area.s.w, data->visible_area.s.h); cairo_show_text(cr, buf); cairo_stroke(cr); show_axis(cr, _zerop, 1,0,0, 10, 10); } #endif /* draw the slot conenctions */ for (GSList *list = data->design->nodes; list != NULL; list = list->next) { designer_node_t *dst = list->data; node_data_t *ndd = node_data(dst); calc_node_type(cr, dst->type); calc_node(cr, dst); for (GSList *slot_list = dst->input_slots; slot_list != NULL; slot_list = slot_list->next) { designer_slot_t *slot = slot_list->data; designer_node_t *src = slot->source; node_data_t *nsd = node_data(src); designer_slot_spec_t *src_spec = slot->output_slot_spec; designer_slot_spec_t *dst_spec = slot->input_slot_spec; slot_spec_data_t *ssd = slot_spec_data(src_spec); slot_spec_data_t *dsd = slot_spec_data(dst_spec); _point_t sp = _move(_move(nsd->or.o, _ptos(nsd->origin)), ssd->offset); _point_t dp = _move(_move(ndd->ir.o, _ptos(ndd->origin)), dsd->offset); draw_connect(cr, sp, dp, 0); } /* check for 'highest' node hit */ _hit_t nht = hit_node(dst, data->mouse); if (nht) { hn = dst; hit = nht; } } /* update target info */ switch (hit) { case HIT_INPUT: hs = hit_input_slot(hn, data->mouse); data->target = input_slot_origin(hn, hs); if (data->state == STATE_IDLE) /* show 'break' if already connected */ data->target_check = input_slot_check(hn, hs); else if (data->state == STATE_CONIN) data->target_check = DESIGNER_CONNECTION_UNCONNECTABLE; else if (data->state == STATE_CONOUT && ((hn != data->target_node) || (hs != data->target_slot_id))) data->target_check = connect_check( data->active_node, data->active_slot_id, hn, hs); break; case HIT_OUTPUT: hs = hit_output_slot(hn, data->mouse); data->target = output_slot_origin(hn, hs); if (data->state == STATE_IDLE) data->target_check = DESIGNER_CONNECTION_FREE; else if (data->state == STATE_CONOUT) data->target_check = DESIGNER_CONNECTION_UNCONNECTABLE; else if (data->state == STATE_CONIN && ((hn != data->target_node) || (hs != data->target_slot_id))) data->target_check = connect_check( hn, hs, data->active_node, data->active_slot_id); break; default: data->target_check = DESIGNER_CONNECTION_UNCONNECTABLE; hs = -1; break; } data->target_node = hn; data->target_slot_id = hs; /* draw the nodes */ for (GSList *list = data->design->nodes; list != NULL; list = list->next) { designer_node_t *node = list->data; int flags = (node == data->design->root) ? 0x1 : 0; draw_node(cr, node, flags); if (node == hn) { draw_highlight(cr, node, data->mouse, hit, data->target_check); } } if (data->state == STATE_CONIN) { draw_connect(cr, data->mouse, data->origin, 0); } if (data->state == STATE_CONOUT) { draw_connect(cr, data->origin, data->mouse, 0); } cairo_destroy(cr); return FALSE; }
void cCellMesh::get_mesh(std::string file_name){ // local variables std::ifstream cell_file(file_name.c_str()); // open the mesh file std::string line; // file line buffer std::vector <std::string> tokens; // tokenized line // get the mesh nodes std::cout << "<MESH> getting the mesh nodes..." << std::endl; while(getline(cell_file, line)){ if(line != "$Nodes") continue; getline(cell_file, line); nodes_count = std::atof(line.c_str()); coordinates.resize(nodes_count, Eigen::NoChange); for(tElement n = 0; n < nodes_count; n++){ getline(cell_file, line); boost::split(tokens, line, boost::is_any_of(", "), boost::token_compress_on); for(int m = 0; m < 3; m++) coordinates(n, m) = atof(tokens[m + 1].c_str()); } break; } surface_node.resize(nodes_count, Eigen::NoChange); surface_node.setZero(); // get the mesh elements std::cout << "<MESH> getting the mesh elements..." << std::endl; while(getline(cell_file, line)){ if(line != "$Elements") continue; getline(cell_file, line); total_elements_count = std::atof(line.c_str()); surface_elements.resize(total_elements_count, Eigen::NoChange); // overkill for now volume_elements.resize(total_elements_count, Eigen::NoChange); // for(tElement n = 0; n < total_elements_count; n++){ getline(cell_file, line); boost::split(tokens, line, boost::is_any_of(", "), boost::token_compress_on); int element_type = atoi(tokens[1].c_str()); if(element_type == 2){ // surface triangles for(int m = 0; m < 3; m++){ // index from zero tElement i = atol(tokens[m + 5].c_str()) - 1; surface_elements(surface_elements_count, m) = i; surface_node(i) = true; } surface_elements_count++; } if(element_type == 4){ // volume tetrahedrons for(int m = 0; m < 4; m++) // index from zero volume_elements(volume_elements_count, m) = atol(tokens[m + 5].c_str()) - 1; volume_elements_count++; } } surface_elements.conservativeResize(surface_elements_count, Eigen::NoChange); // correct the size volume_elements.conservativeResize(volume_elements_count, Eigen::NoChange); // break; } // get the node data std::cout << "<MESH> getting the mesh node data..." << std::endl; while(getline(cell_file, line)){ if(line != "\"distance to nearest lumen\"") continue; else for(int i = 0; i < 6; i++) getline(cell_file, line); // skip six lines node_data.resize(nodes_count, Eigen::NoChange); for(tElement n = 0; n < nodes_count; n++){ getline(cell_file, line); boost::split(tokens, line, boost::is_any_of(", "), boost::token_compress_on); node_data(n, dist_lumen) = atof(tokens[1].c_str()); } break; } cell_file.close(); }
static gboolean button_press_event (GtkWidget *widget, GdkEventButton *event) { widget_data_t *data = get_widget_data(widget); data->mouse_down = map_location(data, _point(event->x, event->y)); designer_node_t *hn = NULL; _hit_t ht = HIT_NOTHING; int hs = -1; /* check for best node hit */ for (GSList *list = data->design->nodes; list != NULL; list = list->next) { designer_node_t *node = list->data; _hit_t nht = hit_node(node, data->mouse_down); if (nht) { hn = node; ht = nht; } } if (event->type == GDK_2BUTTON_PRESS) return double_click_event(widget, event, hn, ht); switch(ht) { case HIT_LABEL: case HIT_TITLE: case HIT_BODY: data->active_node = hn; data->state = STATE_MOVING; data->origin = node_data(hn)->origin; designer_node_push_back(hn); break; case HIT_CLOSE: designer_disconnect_and_delete_node(hn); promote_focus(data); signal_design_change(data); update_area_conditional(data, FALSE); break; case HIT_INPUT: hs = hit_input_slot(hn, data->mouse_down); /* loosen connection if connected */ if (data->target_check == DESIGNER_CONNECTION_CONNECTABLE) { loosen_connection(data, hn, hs); data->state = STATE_CONOUT; break; } data->active_node = hn; data->active_slot_id = hs; data->origin = input_slot_origin(hn, hs); // g_print("hit %lf,%lf -> %d\n", event->x, event->y, data->active_slot_id); data->state = STATE_CONIN; break; case HIT_OUTPUT: hs = hit_output_slot(hn, data->mouse_down); data->active_node = hn; data->active_slot_id = hs; data->origin = output_slot_origin(hn, data->active_slot_id); // g_print("hit %lf,%lf -> %d\n", event->x, event->y, data->active_slot_Id); data->state = STATE_CONOUT; break; default: data->state = STATE_IDLE; break; } data->dragging = TRUE; gtk_widget_queue_draw(widget); return TRUE; }
static void draw_node(cairo_t *cr, designer_node_t *n, int flags) { designer_node_type_t *nt = n->type; node_type_data_t *ntd = node_type_data(nt); node_data_t *nd = node_data(n); _point_t pos = nd->origin; cairo_save(cr); cairo_translate(cr, pos.x, pos.y); /* drop shadow */ cairo_set_source_rgba(cr, RGBA_DROP_SHADOW); round_path(cr, _offset(nd->nr, _size(3, 3)), round_s); cairo_fill(cr); /* title area color */ cairo_set_source_rgba(cr, RGBA_TITLE_AREA); round_path(cr, nd->tr, upper_s); cairo_fill(cr); /* title text */ set_title_font(cr); cairo_set_source_rgba(cr, RGBA_TITLE_TEXT); cairo_move_to(cr, nd->lr.o.x - 1, nd->lr.o.y + nd->lr.s.h - 1); cairo_show_text(cr, n->name); /* close button */ cairo_set_line_width(cr, 1.0); rect_path(cr, nd->xr); cairo_set_source_rgba(cr, 1.0, 1.0, 1.0, 0.8); cairo_fill_preserve(cr); cairo_set_source_rgba(cr, 0.0, 0.0, 0.0, 0.5); cairo_stroke(cr); cross_path(cr, nd->xr, 2); cairo_stroke(cr); /* body area color */ cairo_set_source_rgba(cr, RGBA_BODY_AREA); round_path(cr, nd->br, lower_s); cairo_fill(cr); #if 0 /* slot border */ cairo_set_source_rgba(cr, 0.0, 0.0, 0.0, 0.3); cairo_set_line_width(cr, 1.0); rect_path(cr, nd->ir); cairo_stroke(cr); rect_path(cr, nd->or); cairo_stroke(cr); #endif /* prepare for slots */ cairo_set_source_rgba(cr, 0.0, 0.0, 0.0, 0.6); cairo_set_line_width(cr, 1.0); set_slot_font(cr); /* input slots */ for (int i=0; i<ntd->is; i++) { designer_slot_spec_t *slot = g_slist_nth_data(nt->input_slot_specs, i); slot_spec_data_t *ssd = slot_spec_data(slot); _point_t sl = _move(nd->ir.o, ssd->offset); cairo_move_to(cr, sl.x + 6, sl.y + 3); cairo_show_text(cr, slot->name); cairo_stroke(cr); circle_path(cr, sl, 3.0); cairo_stroke(cr); } for (int i=0; i<ntd->os; i++) { designer_slot_spec_t *slot = g_slist_nth_data(nt->output_slot_specs, i); slot_spec_data_t *ssd = slot_spec_data(slot); _rect_t sr = text_rect(cr, slot->name); _point_t sl = _move(nd->or.o, ssd->offset); cairo_move_to(cr, sl.x - sr.s.w - 8, sl.y + 3); cairo_show_text(cr, slot->name); cairo_stroke(cr); circle_path(cr, sl, 3.0); cairo_stroke(cr); } /* filter border */ cairo_set_line_width(cr, 1.0); cairo_set_source_rgba(cr, 0.0, 0.0, 0.0, 0.8); round_path(cr, nd->nr, round_s); cairo_stroke(cr); cairo_move_to(cr, nd->br.o.x, nd->br.o.y); cairo_line_to(cr, nd->br.o.x + nd->br.s.w, nd->br.o.y); cairo_stroke(cr); /* root node? */ if (flags & 0x1) { cairo_set_line_width(cr, 2.0); cairo_set_source_rgba(cr, RGBA_ROOT_NODE); // cairo_set_line_cap(cr, CAIRO_LINE_CAP_BUTT); // cairo_set_dash(cr, round_d, 2, 0); round_path(cr, _inset(nd->nr, _size(-3,-3)), rnd13_s); cairo_stroke(cr); } /* rect_path(cr, nd->ir); cairo_stroke(cr); rect_path(cr, nd->or); cairo_stroke(cr); */ cairo_restore(cr); }