/** Create a new Pango font. * \param fontname Pango fontname (e.g. [FAMILY-LIST] [STYLE-OPTIONS] [SIZE]). * \return A new font. */ font_t * draw_font_new(const char *fontname) { cairo_surface_t *surface; xcb_screen_t *s = xutil_screen_get(globalconf.connection, globalconf.default_screen); cairo_t *cr; PangoLayout *layout; font_t *font = p_new(font_t, 1); /* Create a dummy cairo surface, cairo context and pango layout in * order to get font informations */ surface = cairo_xcb_surface_create(globalconf.connection, globalconf.default_screen, globalconf.screens.tab[0].visual, s->width_in_pixels, s->height_in_pixels); cr = cairo_create(surface); layout = pango_cairo_create_layout(cr); /* Get the font description used to set text on a PangoLayout */ font->desc = pango_font_description_from_string(fontname); pango_layout_set_font_description(layout, font->desc); /* Get height */ pango_layout_get_pixel_size(layout, NULL, &font->height); g_object_unref(layout); cairo_destroy(cr); cairo_surface_destroy(surface); return font; }
/** Define a global key binding. This key binding will always be available. * \param L The Lua VM state. * * \luastack * \lparam A table with modifier keys. * \lparam A key name. * \lparam A function to execute. * \lreturn The keybinding. */ static int luaA_keybinding_new(lua_State *L) { size_t i, len; keybinding_t *k; const char *key; /* arg 2 is key mod table */ luaA_checktable(L, 2); /* arg 3 is key */ key = luaL_checklstring(L, 3, &len); /* arg 4 is cmd to run */ luaA_checkfunction(L, 4); /* get the last arg as function */ k = p_new(keybinding_t, 1); luaA_keystore(k, key, len); luaA_registerfct(L, 4, &k->fct); len = lua_objlen(L, 2); for(i = 1; i <= len; i++) { size_t blen; lua_rawgeti(L, 2, i); key = luaL_checklstring(L, -1, &blen); k->mod |= xutil_key_mask_fromstr(key, blen); } return luaA_keybinding_userdata_new(L, k); }
static void get_metadata_cache_fields(struct mailbox *box, struct mailbox_metadata *metadata_r) { const struct mail_cache_field *fields; enum mail_cache_decision_type dec; ARRAY_TYPE(mailbox_cache_field) *cache_fields; struct mailbox_cache_field *cf; unsigned int i, count; if (box->metadata_pool == NULL) { box->metadata_pool = pool_alloconly_create("mailbox metadata", 1024*3); } fields = mail_cache_register_get_list(box->cache, box->metadata_pool, &count); cache_fields = p_new(box->metadata_pool, ARRAY_TYPE(mailbox_cache_field), 1); p_array_init(cache_fields, box->metadata_pool, count); for (i = 0; i < count; i++) { dec = fields[i].decision & ~MAIL_CACHE_DECISION_FORCED; if (dec != MAIL_CACHE_DECISION_NO) { cf = array_append_space(cache_fields); cf->name = fields[i].name; cf->decision = fields[i].decision; cf->last_used = fields[i].last_used; } } metadata_r->cache_fields = cache_fields; }
static void* substr_create(int argc, char** argv) { substr_struct *obj = p_new(substr_class); if (argc > 1) { if (argc > 2) { obj->to = atoi(argv[2]); } else { obj->to = -1; } obj->from = atoi(argv[1]); } else { obj->from = 0; obj->to = -1; } obj->part = strdup(""); t_inlet *str_in = add_inlet(obj, "string", NULL); t_inlet *from_in = add_inlet(obj, "from", NULL); t_inlet *to_in = add_inlet(obj, "to", NULL); p_inlet_add_string_fn(str_in, substr_perform); p_inlet_add_trigger_fn(str_in, substr_send_part); p_inlet_add_int_fn(from_in, substr_set_from); p_inlet_add_int_fn(to_in, substr_set_to); obj->out = add_outlet(obj, "substring"); return obj; }
local void scan_formals(int level, Expr *formals) { if (formals != NULL && formals->e_class == E_APPLY) { scan_formals(level+1, formals->e_func); gen_matches(level, p_new(), formals->e_arg); } }
static void* itoa_create(int argc, char **argv) { itoa_obj *obj = p_new(itoa_class); obj->result = strdup(""); t_inlet *int_in = add_inlet(obj, "int", NULL); p_inlet_add_int_fn(int_in, itoa_perform); obj->out = add_outlet(obj, "string"); return obj; }
static void* strlen_create(int argc, char **argv) { strlen_struct *op = p_new(strlen_class); op->len= 0; op->out = add_outlet(op, "length"); t_inlet *string = add_inlet(op, "string", NULL); p_inlet_add_string_fn(string, strlen_perform); return op; }
static void dispatch(const char *file_name, int print_only) { char *source = read_whole_file(file_name); program_t *prog = p_new(source, 1024); if (print_only) { bc_dump(stdout, prog->bytecode); } else { p_exec(prog, 30000); } p_destroy(prog); }
string_t *str_new_const(pool_t pool, const char *str, size_t len) { string_t *ret; i_assert(str[len] == '\0'); ret = p_new(pool, buffer_t, 1); buffer_create_from_const_data(ret, str, len + 1); str_truncate(ret, len); return ret; }
/** Initialize a systray widget. * \param w The widget to initialize. * \return The same widget. */ widget_t * widget_systray(widget_t *w) { w->draw = systray_draw; w->extents = systray_extents; w->destructor = systray_destructor; systray_data_t *d = w->data = p_new(systray_data_t, 1); d->height = 0; return w; }
/** Create a new textbox widget. * \param w The widget to initialize. * \return A brand new widget. */ widget_t * widget_textbox(widget_t *w) { w->draw = textbox_draw; w->index = luaA_textbox_index; w->newindex = luaA_textbox_newindex; w->destructor = textbox_destructor; w->extents = textbox_extents; textbox_data_t *d = w->data = p_new(textbox_data_t, 1); d->ellip = PANGO_ELLIPSIZE_END; d->valign = AlignCenter; return w; }
static void* char_at_create(int argc, char**argv) { char_at_struct *obj = p_new(char_at_class); if (argc>1) { obj->pos = atoi(argv[1]); } else { obj->pos = 0; } t_inlet * str_in = add_inlet(obj, "string", NULL); p_inlet_add_string_fn(str_in, char_at_perform); t_inlet * pos_in = add_inlet(obj, "position", NULL); p_inlet_add_int_fn(pos_in, char_at_set_pos); obj->out = add_outlet(obj, "character"); return obj; }
static ARRAY_TYPE(imap_arg_list) * test_parse_imap_args_dup(pool_t pool, const struct imap_arg *args) { ARRAY_TYPE(imap_arg_list) *list; struct imap_arg *dub; unsigned int i, count = 0; while (args[count++].type != IMAP_ARG_EOL) ; list = p_new(pool, ARRAY_TYPE(imap_arg_list), 1); p_array_init(list, pool, count); for (i = 0; i < count; i++) { dub = array_append_space(list); test_parse_imap_arg_dup(pool, &args[i], dub); } return list; }
static void* strcat_create(int argc, char **argv) { strcat_struct *op = p_new(strcat_class); op->result = strdup(""); if (argc > 1) { op->to_concat = strdup((const char*)argv[1]); } else { op->to_concat = strdup(""); } t_inlet *str_i = add_inlet(op, "string", NULL); if (strcmp("strcat", (const char *)argv[0])==0) { p_inlet_add_string_fn(str_i, strcat_perform); } else { p_inlet_add_string_fn(str_i, strcat_perform); } t_inlet *to_concat = add_inlet(op, "string", NULL); p_inlet_add_string_fn(to_concat, strcat_set_to_concat); op->out = add_outlet(op, "concatenated"); return op; }
Real DisplacementAboutAxis::computeQpValue() { Point p(*_current_node); Real angle(_func.value(_t, *_current_node)); if (_angle_units == "degrees") angle = angle*libMesh::pi/180.0; ColumnMajorMatrix p_old(4,1); p_old(0,0) = p(0); p_old(1,0) = p(1); p_old(2,0) = p(2); p_old(3,0) = 1; ColumnMajorMatrix p_new = rotateAroundAxis(p_old, angle); return p_new(_component,0)-p_old(_component,0); }
void WorldModel::setRelation(Idx parent, Idx child, const RelationConstPtr& r) { const EntityConstPtr& p = entities_[parent]; const EntityConstPtr& c = entities_[child]; if (!p || !c) { std::cout << "[ED] ERROR: Invalid relation addition: parent or child does not exit." << std::endl; return; } Idx r_idx = p->relationTo(child); if (r_idx == INVALID_IDX) { r_idx = addRelation(r); EntityPtr p_new(new Entity(*entities_[parent])); EntityPtr c_new(new Entity(*entities_[child])); p_new->setRelationTo(child, r_idx); c_new->setRelationFrom(parent, r_idx); entities_[parent] = p_new; entities_[child] = c_new; } else { relations_[r_idx] = r; } // Update entity revisions for(std::size_t i = entity_revisions_.size(); i < std::max(parent, child) + 1; ++i) entity_revisions_.push_back(0); entity_revisions_[parent] = revision_; entity_revisions_[child] = revision_; }
/** Create a new tag. Parameters values are checked. * \param name Tag name. * \param len Tag name length. * \param layout Layout to use. * \param mwfact Master width factor. * \param nmaster Number of master windows. * \param ncol Number of columns for slaves windows. * \return A new tag with all these parameters. */ tag_t * tag_new(const char *name, ssize_t len, layout_t *layout, double mwfact, int nmaster, int ncol) { tag_t *tag; tag = p_new(tag_t, 1); a_iso2utf8(&tag->name, name, len); tag->layout = layout; /* to avoid error */ tag->screen = SCREEN_UNDEF; tag->mwfact = mwfact; if(tag->mwfact <= 0 || tag->mwfact >= 1) tag->mwfact = 0.5; if((tag->nmaster = nmaster) < 0) tag->nmaster = 1; if((tag->ncol = ncol) < 1) tag->ncol = 1; return tag; }
/** Create a brand new graph. * \param w The widget to initialize. * \return The same widget. */ widget_t * widget_graph(widget_t *w) { luaA_deprecate(globalconf.L, "awful.widget.graph"); w->draw = graph_draw; w->index = luaA_graph_index; w->newindex = luaA_graph_newindex; w->destructor = graph_destructor; w->extents = graph_extents; graph_data_t *d = w->data = p_new(graph_data_t, 1); d->width = 80; d->height = 0.80; d->size = d->width - 2; d->grow = Left; d->draw_from = p_new(int, d->size); d->draw_to = p_new(int, d->size); xcolor_to_color(&globalconf.colors.bg, &d->bg); xcolor_to_color(&globalconf.colors.fg, &d->border_color); return w; }
int can_go(Pair* p){ Pair *b = bts; Pair s, t, md, mv, mh, next, buf1, buf2, buf3; int v, h, ver, hor; /* coordinate steps */ double val; int vis; while(b != bts+2){ ln_init(b,p_get(Z,b)+0.5,p,p_get(Z,p)+0.5); /* go from the bottom up */ if(p_get(Z,p) < p_get(Z,b)){ s = *p; t = *b; }else{ s = *b; t = *p; } hor = (s.c > t.c) ? -1 : 1; ver = (s.r > t.r) ? -1 : 1; #ifdef DEBUG printf("v: %d, h: %d\n",ver,hor); #endif h = (hor>0) ? 0 : 1; v = (ver>0) ? 0 : 1; vis = 1; while(!p_eq(&s,&t)){ md = p_new(ver,hor); md = p_sum(&s,&md); buf1 = p_new(md.r+v,md.c+h); if(ln_rc_val(&buf1)==0){ val = ln_z_by_r(buf1.r); next = md; }else{ mv = p_new(ver,0); mv = p_sum(&s,&mv); buf2 = p_new(mv.r+v,mv.c+h); if(!ln_rc_on_same_side(&buf1,&buf2)){ val = ln_z_by_r(buf2.r); next = mv; }else{ mh = p_new(0,hor); mh = p_sum(&s,&mh); buf3 = p_new(mh.r+v,mh.c+h); val = ln_z_by_c(buf3.c); next = mh; } } #ifdef DEBUG printf("next %d,%d\n",next.r,next.c); #endif if(p_get(Z,&next) > val){ #ifdef DEBUG printf("bad p: %d,%d val: %f\n",next.r,next.c,val); #endif vis = 0; break; } s = next; } if(vis) break; ++b; /* take next bts */ } return vis; }