Esempio n. 1
0
BOOL BackgroundObject::shrink_to_fit()
{
	BOOL shrunk = FALSE;

/*
// Get the graphic record.
*/

	GraphicPtr graphic;
	ERRORCODE error;
	PBOX org_bound = get_bound();

	if ((graphic = (GraphicPtr)database->get_record(get_graphic_record(), &error, RECORD_TYPE_Graphic)) != NULL)
	{
		if (graphic->record.type == GRAPHIC_TYPE_CGM)
		{
			CGMHelperPtr helper = (CGMHelperPtr)graphic->my_little_helper();
			USHORT dx, dy;
			PCOORD bdx, bdy;

			CGM_POINT ext_min = helper->record.extended_min;
			CGM_POINT ext_max = helper->record.extended_max;
			CGM_POINT min = helper->record.metafile_min;
			CGM_POINT max = helper->record.metafile_max;

			dx = ext_max.x - ext_min.x;
			dy = ext_max.y - ext_min.y;

			bdx = org_bound.x1 - org_bound.x0;
			bdy = org_bound.y1 - org_bound.y0;

			if (dx != 0 && dy != 0)
			{
			/* Renormalize for extended space. */

				max.x -= (ext_min.x + min.x);
				min.x = -ext_min.x;

				max.y -= (ext_min.y + min.y);
				min.y = -ext_min.y;

			/* The extended min and max are normalized by the metafile min. */

				PBOX bound;

				bound.x1 = org_bound.x0 + scale_pcoord(max.x, bdx, dx);
				bound.x0 = org_bound.x0 + scale_pcoord(min.x, bdx, dx);
				bound.y1 = org_bound.y0 + scale_pcoord(max.y, bdy, dy);
				bound.y0 = org_bound.y0 + scale_pcoord(min.y, bdy, dy);

				set_bound(bound);
				shrunk = TRUE;
			}
		}

		graphic->release();
	}
	return shrunk;
}
Esempio n. 2
0
void initrx(void)
{
    NRF24L01_Initialize();

    reset_beken();

    // 2-bytes CRC, radio off
    uint8_t config = BV(NRF24L01_00_EN_CRC) | BV(NRF24L01_00_CRCO) | BV(NRF24L01_00_PRIM_RX);

    NRF24L01_WriteReg(NRF24L01_00_CONFIG, config);
    NRF24L01_WriteReg(NRF24L01_01_EN_AA, 0x00);      // No Auto Acknoledgement
    NRF24L01_WriteReg(NRF24L01_02_EN_RXADDR, 0x01);  // Enable data pipe 0
    NRF24L01_WriteReg(NRF24L01_03_SETUP_AW, 0x03);   // 5-byte RX/TX address
    NRF24L01_WriteReg(NRF24L01_04_SETUP_RETR, 0xFF); // 4ms retransmit t/o, 15 tries
//    NRF24L01_WriteReg(NRF24L01_05_RF_CH, 0x08);      // Channel 8 - bind
    //NRF24L01_SetBitrate(NRF24L01_BR_1M);                          // 1Mbps
    NRF24L01_SetBitrate(NRF24L01_BR_250K); //250k for longer range.
    NRF24L01_SetPower(TXPOWER_100mW);
    NRF24L01_WriteReg(NRF24L01_07_STATUS, 0x70);     // Clear data ready, data sent, and retransmit
    NRF24L01_WriteReg(NRF24L01_11_RX_PW_P0, V2X2_PAYLOAD_SIZE);  // bytes of data payload for pipe 0
    NRF24L01_WriteReg(NRF24L01_17_FIFO_STATUS, 0x00); // Just in case, no real bits to write here
    uint8_t rx_tx_addr[] = {0x66, 0x88, 0x68, 0x68, 0x68};
//    uint8_t rx_p1_addr[] = {0x88, 0x66, 0x86, 0x86, 0x86};
    NRF24L01_WriteRegisterMulti(NRF24L01_0A_RX_ADDR_P0, rx_tx_addr, 5);
//    NRF24L01_WriteRegisterMulti(NRF24L01_0B_RX_ADDR_P1, rx_p1_addr, 5);
    NRF24L01_WriteRegisterMulti(NRF24L01_10_TX_ADDR, rx_tx_addr, 5);

    initialize_beken();

    lib_timers_delaymilliseconds(50);

    NRF24L01_FlushTx();
    NRF24L01_FlushRx();

    rf_ch_num = 0;

    // Turn radio power on
    config |= BV(NRF24L01_00_PWR_UP);
    NRF24L01_WriteReg(NRF24L01_00_CONFIG, config);
    // delayMicroseconds(150);
    lib_timers_delaymilliseconds(1); // 6 times more than needed

    valid_packets = missed_packets = bad_packets = 0;

    if (usersettings.boundprotocol == PROTO_NONE) {
        bind_phase = PHASE_NOT_BOUND;
        prepare_to_bind();
    } else {
        // Prepare to listen to bound protocol, if fails
        // try to bind
        bind_phase = PHASE_JUST_BOUND;
        set_bound();
    }
    switch_channel();
}
Esempio n. 3
0
static void decode_bind_packet(uint8_t *packet)
{
    switch (tryprotocol) {
    case PROTO_V2X2:
        if ((packet[14] & V2X2_FLAG_BIND) == V2X2_FLAG_BIND) {
            // Fill out usersettings with bound protocol parameters
            v2x2_set_tx_id(&packet[7]);
            // Read usersettings into current values
            bind_phase = PHASE_BOUND;
            set_bound();
        }
        break;
    }
}
Esempio n. 4
0
	void	morph2_character_def::display(character* inst)
	{
		int i;
		float ratio = inst->m_ratio;

		// bounds
		rect	new_bound;
		new_bound.set_lerp(m_shape1->get_bound_local(), m_shape2->get_bound_local(), ratio);
		set_bound(new_bound);

		// fill styles
		for (i=0; i < m_fill_styles.size(); i++)
		{
			fill_style* fs = &m_fill_styles[i];

			const fill_style& fs1 = m_shape1->get_fill_styles()[i];
			const fill_style& fs2 = m_shape2->get_fill_styles()[i];

			fs->set_lerp(fs1, fs2, ratio);
		}

		// line styles
		for (i=0; i < m_line_styles.size(); i++)
		{
			line_style& ls = m_line_styles[i];
			const line_style& ls1 = m_shape1->get_line_styles()[i];
			const line_style& ls2 = m_shape2->get_line_styles()[i];
			ls.m_width = (Uint16)frnd(flerp(ls1.get_width(), ls2.get_width(), ratio));
			ls.m_color.set_lerp(ls1.get_color(), ls2.get_color(), ratio);
		}

		// shape
		int k = 0, n = 0;
		for (i = 0; i < m_paths.size(); i++) {
			path& p = m_paths[i];
			const path& p1 = m_shape1->get_paths()[i];

			// Swap fill styles -- for some reason, morph
			// shapes seem to be defined with their fill
			// styles backwards!
			p.m_fill0 = p1.m_fill1;
			p.m_fill1 = p1.m_fill0;

			p.m_line = p1.m_line;

			p.m_ax = flerp(p1.m_ax, m_shape2->get_paths()[n].m_ax, ratio);
			p.m_ay = flerp(p1.m_ay, m_shape2->get_paths()[n].m_ay, ratio);
      
			//  edges;
			int len = p1.m_edges.size();
			p.m_edges.resize(len);

			for (int j=0; j < p.m_edges.size(); j++) {
				p.m_edges[j].m_cx = flerp(p1.m_edges[j].m_cx, m_shape2->get_paths()[n].m_edges[k].m_cx, ratio);
				p.m_edges[j].m_cy = flerp(p1.m_edges[j].m_cy, m_shape2->get_paths()[n].m_edges[k].m_cy, ratio);
				p.m_edges[j].m_ax = flerp(p1.m_edges[j].m_ax, m_shape2->get_paths()[n].m_edges[k].m_ax, ratio);
				p.m_edges[j].m_ay = flerp(p1.m_edges[j].m_ay, m_shape2->get_paths()[n].m_edges[k].m_ay, ratio);
				k++;
				if (m_shape2->get_paths()[n].m_edges.size() <= k) {
					k = 0;
					n++;
				}
			}
		}
    
		//  display

		matrix mat = inst->get_world_matrix();
		cxform cx = inst->get_world_cxform();
		float max_error = 20.0f / mat.get_max_scale() /	inst->get_parent()->get_pixel_scale();

		if (ratio != m_last_ratio) {
			delete m_mesh;
			m_last_ratio = ratio;
			m_mesh = new mesh_set(this, max_error * 0.75f);
		}
		m_mesh->display(mat, cx, m_fill_styles, m_line_styles);
	}