dialog::dialog(int x, int y, int w, int h) : opened_(false), cancelled_(false), clear_bg_(196), padding_(10), add_x_(0), add_y_(0), bg_alpha_(1.0), last_draw_(-1) { set_environment(); set_loc(x,y); set_dim(w,h); forced_dimensions_ = rect(x, y, w, h); }
void widget::set_value(const std::string& key, const variant& v) { if(key == "width") { w_ = v.as_int(); } else if(key == "height") { h_ = v.as_int(); } else if(key == "rect" || key == "draw_area") { std::vector<int> r = v.as_list_int(); ASSERT_LOG(r.size() == 4, "Four values must be supplied to the rect attribute"); set_loc(r[0], r[1]); set_dim(r[2], r[3]); } else if(key == "xy" || key == "left_top") { std::vector<int> xy = v.as_list_int(); ASSERT_LOG(xy.size() == 2, "Two values must be supplied to the X, Y attribute"); set_loc(xy[0], xy[1]); } else if(key == "wh") { std::vector<int> wh = v.as_list_int(); ASSERT_LOG(wh.size() == 2, "Two values must be supplied to the W, H attribute"); set_dim(wh[0], wh[1]); } else if(key == "right_bottom") { std::vector<int> rb = v.as_list_int(); ASSERT_LOG(rb.size() == 2, "Two values must be supplied to the R, B attribute"); set_dim(rb[0] - x(), rb[1] - y()); } else if(key == "left") { x_ = v.as_int(); } else if(key == "top") { y_ = v.as_int(); } else if(key == "right") { w_ = v.as_int() - x(); } else if(key == "bottom") { h_ = v.as_int() - y(); } else if(key == "visible") { visible_ = v.as_bool(); } else if(key == "id") { id_ = v.as_string(); } else if(key == "disable") { disabled_ = v.as_bool(); } else if(key == "enable") { disabled_ = !v.as_bool(); } else if(key == "disabled_opacity") { int opa = v.as_int(); disabled_opacity_ = (opa > 255) ? 255 : (opa < 0) ? 0 : opa; } }
Thermometer_impl:: Thermometer_impl ( CCS::AssetType anum, const char * location ) : m_anum (anum) { assert (ICP_online (anum) == 0); // Mark device as on-line set_loc (location); m_ctrl->add_impl (anum, this); // Add self to controller's map }
static void gen_inst(CTX *ctx, struct ir_inst *in) { struct ir_type res_t = in->result_type; bool is_void = type_is_void(res_t); // Don't write anything not needed. Note that void values are never actually // "used" by the generated C code, and instead are replaced with VOID_VAL. if (!ir_op_writes_side_effects(in->op) && !ir_op_is_branch(in->op)) { if (is_void) return; if (in->users_count == 0) return; // If it has 1 use, it can be generated inline. if (write_inline && in->users_count == 1) { // But if it crosses side effects, it must be generated earlier. // NOTE: if there are any not yet generated instructions with read // side-effects, we must generate the code before crossing // write side-effects as well. // Consider: t1=read; t2=neg(t1); call a(); call b(t2); // Mustn't turn into: call a(); call b(neg(read)); bool crosses_sideffects = false; if (has_outstanding_sideffect_reads(in)) { struct ir_inst *user= in->users[0]; for (struct ir_inst *cur = in; cur; cur = cur->next) { if (cur == user) break; if (ir_op_writes_side_effects(cur->op)) { crosses_sideffects = true; break; } } } if (!crosses_sideffects) return; } } set_loc(ctx, in->loc); indent(ctx); if (!TEST_UNION0(IR_TYPE, any, &res_t) && !is_void && in->users_count > 0) { if (in->scratch1_i == -1) in->scratch1_i = ctx->reg++; P(ctx, "%s %s = ", type(ctx, res_t), get_temp(ctx, in->scratch1_i)); } write_inst(ctx, in, false); fprintf(ctx->f, ";\n"); talloc_free_children(ctx->tmp); }
static void write_struct(CTX *ctx, struct ir_struct_type *st, char *name) { assert(ctx->writing_types); wf(ctx, "struct %s;", name); wf(ctx, "typedef struct %s %s;", name, name); // Make sure all types are written out first. for (int n = 0; n < st->members_count; n++) { struct ir_struct_member *m = st->members[n]; def_type(ctx, m->type); } set_loc(ctx, st->loc); wf(ctx, "struct %s {", name); indent_in(ctx); for (int n = 0; n < st->members_count; n++) { struct ir_struct_member *m = st->members[n]; struct name_temp t; char *mname = member_name(m, &t); set_loc(ctx, m->loc); wf(ctx, "%s %s;", def_type(ctx, m->type), mname); } indent_out(ctx); wf(ctx, "};"); set_no_loc(ctx); }
static int hgc_init() { vdevice.sizeX = 347 * H_PIX_ASPECT; vdevice.sizeY = 347; vdevice.sizeSx = 719; vdevice.sizeSy = 347; vdevice.depth = 1; hgc_config(); hgc_gmode(); /* Also sets _buffer_segment */ _cur_color = 0; hgc_clear(); _cur_color = 1; set_loc(5); /* For the mouse */ pc_locinit(vdevice.sizeSx, vdevice.sizeSy); return (1); }
widget::widget(const variant& v, game_logic::formula_callable* e) : environ_(e), w_(0), h_(0), x_(0), y_(0), zorder_(0), true_x_(0), true_y_(0), disabled_(false), disabled_opacity_(v["disabled_opacity"].as_int(127)), tooltip_displayed_(false), id_(v["id"].as_string_default()), align_h_(HALIGN_LEFT), align_v_(VALIGN_TOP) { if(v.has_key("width")) { w_ = v["width"].as_int(); } if(v.has_key("height")) { h_ = v["height"].as_int(); } if(v.has_key("wh")) { std::vector<int> iv = v["wh"].as_list_int(); ASSERT_LOG(iv.size() == 2, "WH attribute must be 2 integer elements."); w_ = iv[0]; h_ = iv[1]; } if(v.has_key("rect")) { std::vector<int> r = v["rect"].as_list_int(); ASSERT_LOG(r.size() == 4, "Four values must be supplied to the rect attribute"); set_loc(r[0], r[1]); set_dim(r[2], r[3]); } if(v.has_key("draw_area")) { std::vector<int> r = v["draw_area"].as_list_int(); ASSERT_LOG(r.size() == 4, "Four values must be supplied to the rect attribute"); set_loc(r[0], r[1]); set_dim(r[2], r[3]); } if(v.has_key("x")) { true_x_ = x_ = v["x"].as_int(); } if(v.has_key("y")) { true_y_ = y_ = v["y"].as_int(); } if(v.has_key("xy")) { std::vector<int> iv = v["xy"].as_list_int(); ASSERT_LOG(iv.size() == 2, "XY attribute must be 2 integer elements."); true_x_ = x_ = iv[0]; true_y_ = y_ = iv[1]; } zorder_ = v["zorder"].as_int(0); if(v.has_key("on_process")) { on_process_ = boost::bind(&widget::process_delegate, this); ffl_on_process_ = get_environment()->create_formula(v["on_process"]); } if(v.has_key("tooltip")) { if(v["tooltip"].is_string()) { set_tooltip(v["tooltip"].as_string(), v["tooltip_size"].as_int(18)); } else if(v["tooltip"].is_map()) { set_tooltip(v["tooltip"]["text"].as_string(), v["tooltip"]["size"].as_int(18)); } else { ASSERT_LOG(false, "Specify the tooltip as a string, e.g. \"tooltip\":\"Text to display on mouseover\", " "or a map, e.g. \"tooltip\":{\"text\":\"Text to display.\", \"size\":14}"); } } visible_ = v["visible"].as_bool(true); if(v.has_key("align_h")) { std::string align = v["align_h"].as_string(); if(align == "left") { align_h_ = HALIGN_LEFT; } else if(align == "middle" || align == "center" || align == "centre") { align_h_ = HALIGN_CENTER; } else if(align == "right") { align_h_ = HALIGN_RIGHT; } else { ASSERT_LOG(false, "Invalid align_h attribute given: " << align); } } if(v.has_key("align_v")) { std::string align = v["align_v"].as_string(); if(align == "top") { align_v_ = VALIGN_TOP; } else if(align == "middle" || align == "center" || align == "centre") { align_v_ = VALIGN_CENTER; } else if(align == "bottom") { align_v_ = VALIGN_BOTTOM; } else { ASSERT_LOG(false, "Invalid align_v attribute given: " << align); } } disabled_ = !v["enabled"].as_bool(true); recalc_loc(); }
static void gen_fn(CTX *ctx, struct ir_function *fn, char *name, bool visible) { assert(!ctx->writing_types); if (!fn->parent) fn_complete_nested_calls(fn); for (int n = 0; n < fn->nested_functions_count; n++) { struct ir_function *nfn = fn->nested_functions[n]; ctx->writing_types = true; char *nname = def_nested_fn(ctx, nfn); ctx->writing_types = false; gen_fn(ctx, nfn, nname, false); } fn_remove_global_ssa(fn); fn_verify(fn); //dump_fn(stderr, fn); for (int b = 0; b < fn->blocks_count; b++) { for (struct ir_inst *in = fn->blocks[b]->first; in; in = in->next) in->scratch1_i = -1; } // add all C types and function declarations needed for this function ctx->writing_types = true; do_fn_types(ctx, fn->type); for (int n = 0; n < fn->vars_count; n++) def_type(ctx, fn->vars[n]->type); for (int b = 0; b < fn->blocks_count; b++) { struct ir_bb *bb = fn->blocks[b]; for (struct ir_inst *in = bb->first; in; in = in->next) { def_type(ctx, in->result_type); if (in->op == IR_OP_CALL || in->op == IR_OP_FN_PTR) { def_fn(ctx, in->fn); } } } ctx->writing_types = false; set_loc(ctx, fn->loc); if (!visible) fprintf(ctx->f, "static "); write_fn_type(ctx, fn->type, false, name); wf(ctx, " {"); indent_in(ctx); for (int n = 0; n < fn->vars_count; n++) { struct ir_var *v = fn->vars[n]; set_loc(ctx, v->loc); indent(ctx); P(ctx, "%s V%d", type(ctx, v->type), n); // void values are never assigned to (to avoid clashes with C's void); // since they have only one value, there's no need to. Initialize them // to avoid C warnings, though. if (type_is_void(v->type)) P(ctx, " = {0}"); P(ctx, ";\n"); } indent(ctx); P(ctx, "goto B%d;\n", fn->entry->index); for (int b = 0; b < fn->blocks_count; b++) { struct ir_bb *bb = fn->blocks[b]; indent(ctx); P(ctx, "B%d: {\n", b); indent_in(ctx); ctx->reg = 0; for (struct ir_inst *in = bb->first; in; in = in->next) gen_inst(ctx, in); indent_out(ctx); wf(ctx, "}"); } indent_out(ctx); wf(ctx, "}"); }
widget::widget(const variant& v, game_logic::formula_callable* e) : environ_(e), w_(0), h_(0), x_(0), y_(0), zorder_(0), true_x_(0), true_y_(0), disabled_(false), disabled_opacity_(v["disabled_opacity"].as_int(127)), tooltip_displayed_(false), id_(v["id"].as_string_default()), align_h_(HALIGN_LEFT), align_v_(VALIGN_TOP), tooltip_display_delay_(v["tooltip_delay"].as_int(500)), tooltip_ticks_(INT_MAX), resolution_(v["frame_size"].as_int(0)), display_alpha_(v["alpha"].as_int(256)), pad_w_(0), pad_h_(0), claim_mouse_events_(v["claim_mouse_events"].as_bool(true)), draw_with_object_shader_(v["draw_with_object_shader"].as_bool(true)) { set_alpha(display_alpha_ < 0 ? 0 : (display_alpha_ > 256 ? 256 : display_alpha_)); if(v.has_key("width")) { w_ = v["width"].as_int(); } if(v.has_key("height")) { h_ = v["height"].as_int(); } if(v.has_key("wh")) { std::vector<int> iv = v["wh"].as_list_int(); ASSERT_LOG(iv.size() == 2, "WH attribute must be 2 integer elements."); w_ = iv[0]; h_ = iv[1]; } if(v.has_key("rect")) { std::vector<int> r = v["rect"].as_list_int(); ASSERT_LOG(r.size() == 4, "Four values must be supplied to the rect attribute"); set_loc(r[0], r[1]); set_dim(r[2], r[3]); } if(v.has_key("draw_area")) { std::vector<int> r = v["draw_area"].as_list_int(); ASSERT_LOG(r.size() == 4, "Four values must be supplied to the rect attribute"); set_loc(r[0], r[1]); set_dim(r[2], r[3]); } if(v.has_key("x")) { true_x_ = x_ = v["x"].as_int(); } if(v.has_key("y")) { true_y_ = y_ = v["y"].as_int(); } if(v.has_key("xy")) { std::vector<int> iv = v["xy"].as_list_int(); ASSERT_LOG(iv.size() == 2, "XY attribute must be 2 integer elements."); true_x_ = x_ = iv[0]; true_y_ = y_ = iv[1]; } zorder_ = v["zorder"].as_int(0); if(v.has_key("on_process")) { on_process_ = boost::bind(&widget::process_delegate, this); ffl_on_process_ = get_environment()->create_formula(v["on_process"]); } if(v.has_key("tooltip")) { if(v["tooltip"].is_string()) { SDL_Color color = v.has_key("tooltip_color") ? graphics::color(v["tooltip_color"]).as_sdl_color() : graphics::color_yellow(); set_tooltip(v["tooltip"].as_string(), v["tooltip_size"].as_int(18), color, v["tooltip_font"].as_string_default()); } else if(v["tooltip"].is_map()) { SDL_Color color = v["tooltip"].has_key("color") ? graphics::color(v["tooltip"]["color"]).as_sdl_color() : graphics::color_yellow(); set_tooltip(v["tooltip"]["text"].as_string(), v["tooltip"]["size"].as_int(18), color, v["tooltip"]["font"].as_string_default()); } else { ASSERT_LOG(false, "Specify the tooltip as a string, e.g. \"tooltip\":\"Text to display on mouseover\", " "or a map, e.g. \"tooltip\":{\"text\":\"Text to display.\", \"size\":14}"); } } visible_ = v["visible"].as_bool(true); if(v.has_key("align_h")) { std::string align = v["align_h"].as_string(); if(align == "left") { align_h_ = HALIGN_LEFT; } else if(align == "middle" || align == "center" || align == "centre") { align_h_ = HALIGN_CENTER; } else if(align == "right") { align_h_ = HALIGN_RIGHT; } else { ASSERT_LOG(false, "Invalid align_h attribute given: " << align); } } if(v.has_key("align_v")) { std::string align = v["align_v"].as_string(); if(align == "top") { align_v_ = VALIGN_TOP; } else if(align == "middle" || align == "center" || align == "centre") { align_v_ = VALIGN_CENTER; } else if(align == "bottom") { align_v_ = VALIGN_BOTTOM; } else { ASSERT_LOG(false, "Invalid align_v attribute given: " << align); } } disabled_ = !v["enabled"].as_bool(true); if(v.has_key("frame")) { set_frame_set(v["frame"].as_string()); } if(v.has_key("frame_padding")) { ASSERT_LOG(v["frame_padding"].is_list() && v["frame_padding"].num_elements() == 2, "'pad' must be two element list"); set_padding(v["frame_padding"][0].as_int(), v["frame_padding"][1].as_int()); } if(v.has_key("frame_pad_width")) { set_padding(v["frame_pad_width"].as_int(), get_pad_height()); } if(v.has_key("frame_pad_height")) { set_padding(get_pad_width(), v["frame_pad_height"].as_int()); } recalc_loc(); }
void transform(CWtransf& xf) { set_loc(xf*_loc); notify_xform(xf); }
void offset_loc(CWvec& v) { set_loc(_loc + v); }
void Thermometer_impl::location (const char *loc) { set_loc (loc); }
bool Engine::bufferModel() { // Input loader InputManager::init(GLFWwindowPtr, WIDTH, HEIGHT, camera); // Define objects auto back = std::make_shared<Object2D>(); back->set_loc(vec3(-1, 0., -0.2)); back->set_dim(vec3(2., 1., -1.)); back->set_texture_dir("Images/sky.jpg"); back->toggle_wrap(); back->buffer("Models/sphere.obj"); om.addObject("back", std::move(back)); /* auto floor = std::make_shared<Object2D>(); floor->set_loc(vec3(-1, -1., -0.2)); floor->set_dim(vec3(2., 1., -1.)); floor->set_texture_dir("Images/floor.jpg"); floor->toggle_wrap(); floor->buffer("Models/sphere.obj"); om.addObject("floor", std::move(floor)); auto thief = std::make_shared<Player2D>(); thief->set_loc(vec3(0.0, 0.0, 0)); thief->set_dim(vec3(0.4, 0.7, 1.0)); thief->set_texture_dir("Images/thief.png"); thief->set_behavior(Player2D::CONTROLLED); thief->set_label(Player2D::PLAYER); thief->set_bound(Player2D::SQUARE); thief->set_max_force(0.7f); thief->set_max_speed(0.7f); thief->set_max_acceleration(0.3f); thief->buffer(); om.addObject("thief", std::move(thief)); auto mes = std::make_shared<Object2D>(); mes->set_dim(vec3(0.5, 0.4, 1.0)); mes->set_texture_dir("Images/ouch.png"); mes->set_invisibility(true); mes->buffer(); om.addObject("ouch", std::move(mes)); auto lord1 = std::make_shared<Object2D>(); lord1->set_loc(vec3(-0.4, -0.4, 0)); lord1->set_dim(vec3(0.4, .6, 1.)); lord1->set_texture_dir("Images/lord.png"); lord1->set_target(om.objects.at("thief")); lord1->set_behavior(Object2D::SEEK); lord1->set_label(Player2D::ENEMY); lord1->set_bound(Player2D::SQUARE); lord1->set_max_force(0.3f); lord1->set_max_speed(0.2f); lord1->buffer(); om.addObject("lord1", std::move(lord1)); auto lord2 = std::make_shared<Object2D>(); lord2->set_loc(vec3(-0.7, -0.4, 0)); lord2->set_dim(vec3(0.6, 0.7, 1.)); lord2->set_texture_dir("Images/lord2.png"); lord2->set_target(om.objects.at("thief")); lord2->set_behavior(Object2D::SEEK); lord2->set_label(Player2D::ENEMY); lord2->set_bound(Player2D::SQUARE); lord2->set_max_force(0.4f); lord2->set_max_speed(0.3f); lord2->buffer(); om.addObject("lord2", std::move(lord2)); */ // Define view camera = FreeCamera(WIDTH, HEIGHT); camera.set_camera( vec3(0.0f, 0.0f, 2.f), vec3(0.0f, 0.0f, -1.0f), vec3(0.0f, 1.0f, 0.0f) ); camera.is_ortho(false); return true; }