예제 #1
0
global
void drag_box(RECT r,
              RECT *bound,
              RECT *dist,
              RECT *last
             )
{
	G_i mb, x, y;
	RECT old = r;
	
	l_color(BLACK);

	wr_mode(MD_XOR);
	new_box(&r, nil);

	do
	{
		Syield();
		vq_mouse(C.vh, &mb, &x, &y);

		r = move_rectangle(x, y, r, dist);
		keep_inside(&r, bound);			/* Ensure we are inside the bounding rectangle */
		new_box(&r, &old);
		
	} while (mb);

	new_box(&r,nil);
	wr_mode(MD_TRANS);

	*last = r;
}
예제 #2
0
global
void rubber_box(COMPASS cp,
                RECT r,
                RECT *dist,
                int minw, int minh,
                int maxw, int maxh,
                RECT *last)
{
	G_i x, y, mb;
	RECT old = r;
	
	l_color(BLACK);

	wr_mode(MD_XOR);
	new_box(&r, nil);

	do
	{
		Syield();
		vq_mouse(C.vh, &mb, &x, &y);

		r = widen_rectangle(cp, x, y, r, dist);
		check_wh(&r, minw, minh, maxw, maxh);
		new_box(&r, &old);

	} while(mb);
	
	new_box(&r, nil);
	wr_mode(MD_TRANS);

	*last = r;
}
예제 #3
0
static void insert_inline_box(fz_context *ctx, fz_pool *pool, fz_html *box, fz_html *top)
{
    if (top->type == BOX_BLOCK)
    {
        if (top->last && top->last->type == BOX_FLOW)
        {
            insert_box(ctx, box, BOX_INLINE, top->last);
        }
        else
        {
            fz_html *flow = new_box(ctx, pool);
            flow->is_first_flow = !top->last;
            insert_box(ctx, flow, BOX_FLOW, top);
            insert_box(ctx, box, BOX_INLINE, flow);
        }
    }
    else if (top->type == BOX_FLOW)
    {
        insert_box(ctx, box, BOX_INLINE, top);
    }
    else if (top->type == BOX_INLINE)
    {
        insert_box(ctx, box, BOX_INLINE, top);
    }
}
예제 #4
0
fz_html *
fz_parse_html(fz_context *ctx, fz_html_font_set *set, fz_archive *zip, const char *base_uri, fz_buffer *buf, const char *user_css)
{
	fz_xml *xml;
	fz_css_rule *css;
	fz_css_match match;
	fz_html *box;

	xml = fz_parse_xml(ctx, buf->data, buf->len, 1);

	css = fz_parse_css(ctx, NULL, default_css, "<default>");
	if (user_css)
		css = fz_parse_css(ctx, NULL, user_css, "<user>");
	css = html_load_css(ctx, zip, base_uri, css, xml);

	// print_rules(css);

	box = new_box(ctx);

	match.up = NULL;
	match.count = 0;

	generate_boxes(ctx, set, zip, base_uri, xml, box, css, &match);

	fz_drop_css(ctx, css);
	fz_drop_xml(ctx, xml);

	return box;
}
예제 #5
0
파일: game.c 프로젝트: nnia/tetrisboxes
void timer(void)
{
	int i, j;
	static int count=0;
	count++;
	if (count >= DTICS_MAX * TICS_MIN)
	{
		count = 0;
	}
	if (gamestatus == GAME)
	{
		if (fmod(count, DTICS_BOX_FALLS) == DTICS_FMOD_MOVE)
		{
			move_all_boxes();
			//check_line();
		}
		if (fmod(count, DTICS_BOX_FALLS) == DTICS_FMOD_FALL)
		{
			//move_all_boxes();
			check_line();
		}
	
		if (fmod(count, DTICS_BOX_NEW) == DTICS_FMOD_NEW)
		{
			new_box();
			man.ay = 0;
		}
	}



	return;
}
예제 #6
0
/* add box to shelve
 *
 * return values:
 * 0: okidoki
 * 1: no luck: out of memory or MAXBOXES exceeded
 *
 */
static int add_box(int nnodes){

  // is there room for another box?
  if ( shelve.nboxes >= MAXBOXES ) return 1;

  Box *b = new_box(nnodes, shelve.q, shelve.nstr);
  if ( b != NULL ){
    shelve.box[shelve.nboxes] = b;
    shelve.nboxes++;
    return 1L;
  } else {
    return 0L;
  }
  
}
예제 #7
0
/**
 * Updates the screen configuration, as well as the screen property of every
 * client window.
 */
void ClientModel::update_screens(std::vector<Box> &bounds)
{
    m_crt_manager.rebuild_graph(bounds);

    // Now, translate the location of every client back into its updated screen
    for (std::map<Window, Dimension2D>::iterator client_location = m_location.begin();
         client_location != m_location.end();
         client_location++)
    {
        Window client = client_location->first;
        Dimension2D &location = client_location->second;

        // Although this technically *should* occur, the way that this is handled would
        // cause the client to be moved outside of our control, and we don't want that
        if (is_packed_client(client))
            continue;

        // Keep the old screen - if the new screen is the same, we don't want
        // to send out a change notification
        const Box &old_box = m_screen[client];
        Box new_box(-1, -1, 0, 0);

        Crt *new_screen = m_crt_manager.screen_of_coord(
            DIM2D_X(location), DIM2D_Y(location));

        if (new_screen)
            new_box = m_crt_manager.box_of_screen(new_screen);

        if (new_box != old_box)
        {
            m_screen.erase(client);
            m_screen.insert(std::pair<Window, const Box>(client, new_box));

            // Why do the ref like this? Well, if it is done as a reference
            // to new_box directly, then new_box will go out of scope and
            // our data will be thoroughly shat over. Thankfully the unit
            // tests caught this one.
            m_changes.push(new ChangeScreen(client, m_screen[client]));
        }
    }

    // Since the location of the primary screen's corners may have changed, we
    // have to repack everything
    repack_corner(PACK_NORTHEAST);
    repack_corner(PACK_NORTHWEST);
    repack_corner(PACK_SOUTHEAST);
    repack_corner(PACK_SOUTHWEST);
}
예제 #8
0
파일: qgram.c 프로젝트: cran/stringdist
/* add box to shelf
 *
 * return values:
 * 0: okidoki
 * 1: no luck: out of memory or MAXBOXES exceeded
 *
 */
static int add_box(int nnodes){

  Shelf *shelf = &wall[get_shelf_num()];
  // is there room for another box?
  if ( shelf->nboxes >= MAXBOXES ) return 1;

  Box *b = new_box(nnodes, shelf->q, shelf->nstr);
  if ( b != NULL ){
    shelf->box[shelf->nboxes] = b;
    shelf->nboxes++;
    return 1L;
  } else {
    return 0L;
  }
  
}
예제 #9
0
파일: wdbtool.c 프로젝트: DimondTheCat/xray
Activate( long version, GlobalFunc *global, LWMeshEditTool *local,
   void *serverData )
{
   BoxData *box;

   if ( version != LWMESHEDITTOOL_VERSION )
      return AFUNC_BADVERSION;

   if ( !get_xpanf( global )) return AFUNC_BADGLOBAL;
   box = new_box();
   if ( !box ) return AFUNC_OK;

   local->instance     = box;

   local->tool->done   = Done;
   local->tool->help   = Help;
   local->tool->count  = Count;
   local->tool->handle = Handle;
   local->tool->adjust = Adjust;
   local->tool->start  = Start;
   local->tool->draw   = Draw;
   local->tool->dirty  = Dirty;
   local->tool->event  = Event;
   local->tool->panel  = Panel;

   local->build        = Build;
   local->test         = Test;
   local->end          = End;

   /* the debug trace file and a mouse hook */

   fp = fopen( TR_FILENAME, "w" );
   SetWindowsHookEx( WH_MOUSE, mouse_hook, hinst, 0 );

   return AFUNC_OK;
}
예제 #10
0
static void generate_boxes(fz_context *ctx, fz_pool *pool,
                           fz_html_font_set *set, fz_archive *zip, const char *base_uri,
                           fz_xml *node, fz_html *top, fz_css_rule *rule, fz_css_match *up_match, int list_counter)
{
    fz_css_match match;
    fz_html *box;
    const char *tag;
    int display;

    while (node)
    {
        match.up = up_match;
        match.count = 0;

        tag = fz_xml_tag(node);
        if (tag)
        {
            fz_match_css(ctx, &match, rule, node);

            display = fz_get_css_match_display(&match);

            if (!strcmp(tag, "br"))
            {
                if (top->type == BOX_INLINE)
                {
                    fz_html *flow = top;
                    while (flow->type != BOX_FLOW)
                        flow = flow->up;
                    add_flow_break(ctx, pool, flow, &top->style);
                }
                else
                {
                    box = new_box(ctx, pool);
                    fz_apply_css_style(ctx, set, &box->style, &match);
                    top = insert_break_box(ctx, box, top);
                }
            }

            else if (!strcmp(tag, "img"))
            {
                const char *src = fz_xml_att(node, "src");
                if (src)
                {
                    box = new_box(ctx, pool);
                    fz_apply_css_style(ctx, set, &box->style, &match);
                    insert_inline_box(ctx, pool, box, top);
                    generate_image(ctx, pool, zip, base_uri, box, src);
                }
            }

            else if (display != DIS_NONE)
            {
                box = new_box(ctx, pool);
                fz_apply_css_style(ctx, set, &box->style, &match);

                if (display == DIS_BLOCK || display == DIS_INLINE_BLOCK)
                {
                    top = insert_block_box(ctx, box, top);
                }
                else if (display == DIS_LIST_ITEM)
                {
                    top = insert_block_box(ctx, box, top);
                    box->list_item = ++list_counter;
                }
                else if (display == DIS_INLINE)
                {
                    insert_inline_box(ctx, pool, box, top);
                }
                else
                {
                    fz_warn(ctx, "unknown box display type");
                    insert_box(ctx, box, BOX_BLOCK, top);
                }

                if (fz_xml_down(node))
                {
                    int child_counter = list_counter;
                    if (!strcmp(tag, "ul") || !strcmp(tag, "ol"))
                        child_counter = 0;
                    generate_boxes(ctx, pool, set, zip, base_uri, fz_xml_down(node), box, rule, &match, child_counter);
                }

                // TODO: remove empty flow boxes
            }
        }
        else
        {
            if (top->type != BOX_INLINE)
            {
                /* Create anonymous inline box, with the same style as the top block box. */
                box = new_box(ctx, pool);
                insert_inline_box(ctx, pool, box, top);
                box->style = top->style;
                /* Make sure not to recursively multiply font sizes. */
                box->style.font_size.value = 1;
                box->style.font_size.unit = N_SCALE;
                generate_text(ctx, pool, box, fz_xml_text(node));
            }
            else
            {
                generate_text(ctx, pool, top, fz_xml_text(node));
            }
        }

        node = fz_xml_next(node);
    }
}
예제 #11
0
FlattenedHierarchy::FlattenedHierarchy(
   const PatchHierarchy& hierarchy,
   int coarsest_level,
   int finest_level)
: d_coarsest_level(coarsest_level),
  d_finest_level(finest_level),
  d_patch_hierarchy(&hierarchy)
{
   int num_levels = hierarchy.getNumberOfLevels();
   TBOX_ASSERT(coarsest_level >= 0);
   TBOX_ASSERT(coarsest_level <= finest_level);
   TBOX_ASSERT(finest_level < num_levels);

   d_visible_boxes.resize(num_levels);

   LocalId local_id(0);

   for (int ln = finest_level; ln >= coarsest_level; --ln) {
      const std::shared_ptr<PatchLevel>& current_level =
         hierarchy.getPatchLevel(ln);

      if (ln != finest_level) {

         const Connector& coarse_to_fine =
            current_level->findConnector(
               *(hierarchy.getPatchLevel(ln+1)),
               IntVector::getOne(hierarchy.getDim()),
               CONNECTOR_IMPLICIT_CREATION_RULE,
               true);

         const IntVector& connector_ratio = coarse_to_fine.getRatio();

         for (PatchLevel::iterator ip(current_level->begin());
              ip != current_level->end(); ++ip) {

            const std::shared_ptr<Patch>& patch = *ip;
            const Box& box = patch->getBox();
            const BlockId& block_id = box.getBlockId();
            const BoxId& box_id = box.getBoxId();
            BoxContainer& visible_boxes = d_visible_boxes[ln][box_id];

            BoxContainer coarse_boxes(box);

            BoxContainer fine_nbr_boxes;
            if (coarse_to_fine.hasNeighborSet(box_id)) {
               coarse_to_fine.getNeighborBoxes(box_id, fine_nbr_boxes);
            }
            if (!fine_nbr_boxes.empty()) {
               BoxContainer fine_boxes;
               for (SAMRAI::hier::RealBoxConstIterator
                    nbr_itr = fine_nbr_boxes.realBegin();
                    nbr_itr != fine_nbr_boxes.realEnd(); ++nbr_itr) {
                  if (nbr_itr->getBlockId() == block_id) {
                     fine_boxes.pushBack(*nbr_itr);
                  }
               }

               fine_boxes.coarsen(connector_ratio);

               coarse_boxes.removeIntersections(fine_boxes);
               coarse_boxes.coalesce();
            }

            for (BoxContainer::iterator itr =
                 coarse_boxes.begin(); itr != coarse_boxes.end(); ++itr) {

               Box new_box(*itr, local_id, box_id.getOwnerRank());
               ++local_id;
               visible_boxes.insert(visible_boxes.end(), new_box);
            }
         }
      } else {
         for (PatchLevel::iterator ip(current_level->begin());
              ip != current_level->end(); ++ip) {
            const std::shared_ptr<Patch>& patch = *ip;
            const Box& box = patch->getBox();
            const BoxId& box_id = box.getBoxId();
            BoxContainer& visible_boxes = d_visible_boxes[ln][box_id];

            Box new_box(box, local_id, box.getOwnerRank());
            ++local_id;
            visible_boxes.insert(visible_boxes.end(), new_box);
         }
      }
   }
}
예제 #12
0
unsigned extract_text(
    rdp_ppocr::OcrDatasConstant const & ocr_constant,
    rdp_ppocr::OcrContext & ocr_context,
    const ImageView & input, unsigned tid,
    mln::box2d const & box, unsigned button_col)
{
    (void)button_col;

    bool const is_win2012 = (tid == ::ocr::titlebar_color_id::WINDOWS_2012);
    bool const is_win2012_vnc = (tid == ::ocr::titlebar_color_id::WINDOWS_2012_VNC);

    /*chrono*///using resolution_clock = std::chrono::high_resolution_clock;
    /*chrono*///auto t1 = resolution_clock::now();

    size_t x = box.min_col();
    size_t y = box.min_row();
    size_t w = static_cast<unsigned>(box.max_col()+1);
    size_t h = static_cast<unsigned>(box.max_row()+1);
    if (is_win2012) {
        detail_::shrink_box(input, ::ocr::titlebar_color_windows2012_standard(), x, y, w, h);
    }
    else if (is_win2012_vnc) {
        detail_::shrink_box(input, ::ocr::titlebar_color_windows2012_vnc_standard(), x, y, w, h);
    }
    else {
        detail_::shrink_box(input, ::ocr::titlebar_colors[tid], x, y, w, h);
    }
    auto const bounds = ppocr::Bounds{w, h};

    ocr_context.ambiguous.clear();

    std::vector<ppocr::Box> & boxes = ocr_context.boxes;
    std::vector<unsigned> & spaces = ocr_context.spaces;
    boxes.clear();
    spaces.clear();

    size_t const whitespace = (is_win2012 || is_win2012_vnc) ? /*4*/5 : 3;

    unsigned i_space = 0;
    while (auto const cbox = is_win2012
        ? detail_::box_character(input, ::ocr::titlebar_color_windows2012_standard(), {x, y}, bounds)
        : is_win2012_vnc
        ? detail_::box_character(input, ::ocr::titlebar_color_windows2012_vnc_standard(), {x, y}, bounds)
        : detail_::box_character(input, ::ocr::titlebar_colors[tid], {x, y}, bounds)
    ) {
        //min_y = std::min(cbox.y(), min_y);
        //bounds_y = std::max(cbox.y() + cbox.h(), bounds_y);
        //bounds_x = cbox.x() + cbox.w();
        //std::cerr << "\nbox(" << cbox << ")\n";

        mln::box2d new_box(mln::point2d(cbox.y(), cbox.x()), mln::point2d(cbox.bottom(), cbox.right()));
        auto & img_word = is_win2012
            ? detail_::to_img(ocr_context.img_ctx, input, ::ocr::titlebar_color_windows2012_standard(), new_box)
            : is_win2012_vnc
            ? detail_::to_img(ocr_context.img_ctx, input, ::ocr::titlebar_color_windows2012_vnc_standard(), new_box)
            : detail_::to_img(ocr_context.img_ctx, input, ::ocr::titlebar_colors[tid], new_box);
        //std::cout << img_word << std::endl;

        if (x + whitespace <= cbox.x()) {
            spaces.push_back(i_space);
        }
        ++i_space;

        auto it = ocr_context.images_cache.find(img_word);
        if (it != ocr_context.images_cache.end()) {
            ocr_context.ambiguous.emplace_back(it->second);
        }
        else {
            auto it = ocr_context.images_cache.emplace(
                img_word.clone(),
                ppocr::ocr2::compute_image(
                    ppocr::PpOcrSimpleDatas{},
                    ppocr::PpOcrComplexDatas{},
                    ppocr::PpOcrExclusiveDatas{},
                    ocr_context.probabilities,
                    ocr_context.tmp_probabilities,
                    ocr_constant.datas,
                    ocr_constant.first_strategy_ortered,
                    ocr_constant.data_indexes_by_words,
                    ocr_constant.glyphs,
                    ocr_constant.id_views,
                    img_word,
                    ocr_context.img_ctx.img90()
                )
            ).first;
            ocr_context.ambiguous.emplace_back(it->second);
        }

        boxes.push_back(cbox);

        x = cbox.x() + cbox.w();
    }

    ppocr::ocr2::filter_by_lines(
        /*ocr_context.filter_by_lines_context,*/
        ocr_context.ambiguous,
        ocr_constant.words_infos,
        ocr_context.boxes
    );

    ppocr::ocr2::filter_by_font(
        /*ocr_context.filter_by_font_context,*/
        ocr_context.ambiguous
    );

    /*chrono*///auto t2 = resolution_clock::now();
    /*chrono*///std::cerr << "t2: " << std::chrono::duration<double>(t2-t1).count() << "s\n";

    std::string & result = ocr_context.result;
    ocr_context.spaces.push_back(ocr_context.ambiguous.size());
    unsigned unrecognized_count = ppocr::ocr2::disambiguous_with_dict(
        ocr_context.ambiguous,
        ocr_constant.glyphs,
        ocr_constant.dict,
        ocr_context.spaces.cbegin(),
        result
    );

    /*chrono*///auto t3 = resolution_clock::now();
    /*chrono*///std::cerr << "t3: " << std::chrono::duration<double>(t3-t1).count() << "s\n";

    ppocr::ocr2::replace_words(
        ocr_context.result,
        ocr_constant.replacements
    );
    // TODO recall dict ?

    //std::cout << " ## result3: " << (result3) << "\n";

    /*chrono*///auto t4 = resolution_clock::now();
    /*chrono*///std::cerr << "t4: " << std::chrono::duration<double>(t4-t1).count() << "s\n";

    return unrecognized_count;
}
예제 #13
0
static void generate_boxes(fz_context *ctx, fz_html_font_set *set, fz_archive *zip, const char *base_uri,
	fz_xml *node, fz_html *top, fz_css_rule *rule, fz_css_match *up_match)
{
	fz_css_match match;
	fz_html *box;
	const char *tag;
	int display;

	while (node)
	{
		match.up = up_match;
		match.count = 0;

		tag = fz_xml_tag(node);
		if (tag)
		{
			fz_match_css(ctx, &match, rule, node);

			display = fz_get_css_match_display(&match);

			if (!strcmp(tag, "br"))
			{
				box = new_box(ctx);
				fz_apply_css_style(ctx, set, &box->style, &match);
				top = insert_break_box(ctx, box, top);
			}

			else if (!strcmp(tag, "img"))
			{
				const char *src = fz_xml_att(node, "src");
				if (src)
				{
					box = new_box(ctx);
					fz_apply_css_style(ctx, set, &box->style, &match);
					insert_inline_box(ctx, box, top);
					generate_image(ctx, zip, base_uri, box, src);
				}
			}

			else if (display != DIS_NONE)
			{
				box = new_box(ctx);
				fz_apply_css_style(ctx, set, &box->style, &match);

				if (display == DIS_BLOCK)
				{
					top = insert_block_box(ctx, box, top);
				}
				else if (display == DIS_LIST_ITEM)
				{
					top = insert_block_box(ctx, box, top);
				}
				else if (display == DIS_INLINE)
				{
					insert_inline_box(ctx, box, top);
				}
				else
				{
					fz_warn(ctx, "unknown box display type");
					insert_box(ctx, box, BOX_BLOCK, top);
				}

				if (fz_xml_down(node))
					generate_boxes(ctx, set, zip, base_uri, fz_xml_down(node), box, rule, &match);

				// TODO: remove empty flow boxes
			}
		}
		else
		{
			if (top->type != BOX_INLINE)
			{
				box = new_box(ctx);
				insert_inline_box(ctx, box, top);
				box->style = top->style;
				generate_text(ctx, box, fz_xml_text(node));
			}
			else
			{
				generate_text(ctx, top, fz_xml_text(node));
			}
		}

		node = fz_xml_next(node);
	}
}
예제 #14
0
파일: game.c 프로젝트: nnia/tetrisboxes
void game()
{
	static int count = 0;
	static unsigned char first_time = 1;

	/***********/
	char buff[64];
	int i, j;
	/***********/

	if (first_time==1)
	{

		glEnable(GL_LIGHTING);
		glEnable(GL_LIGHT0);		
//		glEnable(GL_LIGHT1);
		glEnable(GL_DEPTH_TEST);
		glEnable(GL_COLOR_MATERIAL);
		LoadPic1();




		for (i=0; i<BOX_MAX; i++)
		{
			box[i].x = BOX_X_INIT;
			box[i].y = BOX_Y_INIT;
			box[i].status = BOX_OFF;
		}
		/*
		for (j=0; j<N_ROW; j++)
		{
			for (i=0; i<N_COL; i++)
			{
				pole[i][j] = 0;
			}
		}
		*/
		srand(time);
		new_box();
		
		man.x = fmod(rand(), N_COL);
		man.y = 0;
		man.flag_up = MAN_FLAG_UP_0;
		man.ay = 0;

		first_time = 0;
	}


	glPushMatrix(); // all
//	glScalef(0.1, 0.1, 1);

	// pole
	glColor3f(0.0, 0.0, 0.5);


	rectangletex(	START_X + 0*SX, START_Y + 0*SY, 
				START_X + (N_COL)*SX, START_Y + (N_ROW)*SY);
	glColor3f(0, 1.0, 0.5);



	// box to pole
	// box_to_pole();

	// draw
/*

	for (j=0; j<N_ROW; j++)
	{
		for (i=0; i<N_COL; i++)
		{
			if (pole[i][j] != BOX_OFF)
			{
		/ *		rectangle(	START_X + i*SX, START_Y + j*SY, 
							START_X + (i+0.9)*SX, START_Y + (j+0.9)*SY);* /
				drawbox()
				/ *textout(	START_X + i*SX, START_Y + j*SY, 1, &num[pole[i][j]] );* /
			}
		}
	}
*/

	if (gamestatus == GAMEMENU)
	{
		draw_menu_new();
	}
	if (gamestatus == GAME)
	{
		for (i=0; i<BOX_MAX; i++)
		{
			if (box[i].status != BOX_OFF)
			{
				drawbox(box[i]);
			}
		}
		draw_man(man);
	}
	
	// lines
	if (lines > 0)
	{
		sprintf(buff, "Линий: %d", lines);
		textout(RES_LINES_X, RES_LINES_Y, strlen(buff), buff);
	}
	if (pobashke > 0)
	{
		sprintf(buff, "По башке: %d", pobashke);
		textout(RES_POBASHKE_X, RES_POBASHKE_Y, strlen(buff), buff);
	}

	if (gamestatus == GAMEOVER)
	{
		glColor3f(1.0, 1.0, 1.0);
		textout(	START_X + N_COL*HSX, START_Y + N_ROW*HSY, 9, "GAME OVER" );
	}

	if (gamestatus == GAMEPAUSE)
	{
		glColor3f(1.0, 1.0, 1.0);
		textout(	START_X + N_COL*HSX, START_Y + N_ROW*HSY, 5, "PAUSE" );
	}


	glPopMatrix(); // all
}