Ejemplo n.º 1
0
void BallMovement::bounce(bool collision)
{
    fix_position();

    float angle = rad(instance->direction * 11.25f);
    float found_a = -1.0f;
    for (float a = 0.0f; a < (CHOW_PI*2.0f); a += (CHOW_PI*2.0f) / 16.0f) {
        float x_move = 10.0f * cos(angle + a);
        float y_move = -10.0f * sin(angle + a);

        int x = instance->x + x_move;
        int y = instance->y + y_move;

        if (!test_position(x, y)) {
            found_a = a;
            break;
        }
    }

    if (found_a == -1.0f) {
        instance->set_direction((instance->direction + 16) % 32, false);
        return;
    }

    angle += found_a * 2.0f;
    if (angle > 2.0 * CHOW_PI)
        angle -= 2.0 * CHOW_PI;

    instance->set_direction(deg(angle) / 11.25f, false);
}
Ejemplo n.º 2
0
void DesktopIcon::drag(int x, int y, bool apply) {
	if(!micon) {
		micon = new MovableIcon(this);
#if HAVE_SHAPE
		/* 
		 * This is used to calculate correct window startup/ending
		 * position since icon is placed in the middle of the box.
		 *
		 * Opposite, window (shaped) will have small but noticeable 'jump off' and
		 * dropped icon position will not be at the exact place where was dropped.
		 */
		int ix, iy;
		ix = iy = 0;
		if(image()) {
			ix = (w()/2) - (image()->w()/2);
			iy = (h()/2) - (image()->h()/2);
		}

		micon->position(micon->x() + ix, micon->y() + iy);
#endif
		micon->show();
	} else {
		E_ASSERT(micon != NULL);
		micon->position(x, y);
	}

	if(apply) {
#if HAVE_SHAPE
		int ix, iy;
		ix = iy = 0;
		if(image()) {
			ix = (w()/2) - (image()->w()/2);
			iy = (h()/2) - (image()->h()/2);
		}
		fix_position(micon->x() - ix, micon->y() - iy);
#else
		fix_position(micon->x(), micon->y());
#endif
		delete micon;
		micon = NULL;
	}
}
Ejemplo n.º 3
0
DesktopIcon::DesktopIcon(GlobalIconSettings* gs, IconSettings* is, int bg) : 
	Fl_Widget(is->x, is->y, ICON_SIZE_MIN_W, ICON_SIZE_MIN_H) {

	E_ASSERT(gs != NULL);

	lwidth = lheight = 0;
	focus = false;
	micon = NULL;
	darker_img = NULL;

	/*
	 * GlobalIconSettings is shared from desktop so we only
	 * reference it. On other hand IconSettings is not shared
	 * and we must construct a copy from given parameter
	 */
	globals = gs;

	settings = new IconSettings;
	settings->name = is->name;
	settings->cmd  = is->cmd;
	settings->icon = is->icon;
	settings->icon2 = is->icon2;
	settings->type = is->type;
	settings->key_name= is->key_name;
	settings->full_path = is->full_path;

	// x,y are not needed since x(), y() are filled with it
	
	// setting fonts is TODO :P
#if 0	
	Fl::set_font((Fl_Font)20, "-windows-*-medium-r-*-*-14-*-*-*-*-*-*-*");
	labelfont((Fl_Font)20);
#endif

	label(settings->name.c_str());

	imenu = new Fl_Menu_Button(0, 0, 0, 0);
	if(settings->type == ICON_TRASH)
		imenu->menu(icon_trash_menu);
	else
		imenu->menu(icon_menu);

	load_icon(ICON_FACE_ONE);
	fix_position(x(), y());

	//Use desktop color as color for icon background
	color(bg);

	align(FL_ALIGN_WRAP);
	update_label_size();
}
Ejemplo n.º 4
0
DesktopIcon::DesktopIcon(GlobalIconSettings* gs, IconSettings* is, int bg) : 
	Fl_Widget(is->x, is->y, ICON_SIZE_MIN_W, ICON_SIZE_MIN_H) {

	E_ASSERT(gs != NULL);

	lwidth = lheight = 0;
	focus = false;
	micon = NULL;
	darker_img = NULL;

	gsettings = gs;
	settings = is;

	/* setting fonts is TODO :P */
#if 0	
	Fl::set_font((Fl_Font)20, "-windows-*-medium-r-*-*-14-*-*-*-*-*-*-*");
	labelfont((Fl_Font)20);
#endif

	label(settings->name.c_str());

	imenu = new MenuButton(0, 0, 0, 0);
	if(settings->type == ICON_TRASH)
		imenu->menu(icon_trash_menu);
	else {
		icon_menu[2].image(IconLoader::get("edit-delete", ICON_SIZE_TINY));
		imenu->menu(icon_menu);
	}

	load_icon(ICON_FACE_ONE);
	fix_position(x(), y());

	/* use desktop color as color for icon background */
	color(bg);

	align(FL_ALIGN_WRAP);
	update_label_size();
}
Ejemplo n.º 5
0
void EightDirections::stop(bool collision)
{
    // set_speed(0);
    if (!collision) {
        return;
    }

    // float angle = rad(instance->direction * 11.25);

    // int x, y;
    // float angle2;

    // for (float a = rad(90); a <= rad(180); a += rad(90) / 8.0f) {
    //     const float d = 8.0f;
    //     angle2 = angle + a;
    //     x = instance->x + cos(angle2) * d;
    //     y = instance->y - sin(angle2) * d;
    //     if (!test_position(x, y)) {
    //         instance->set_position(x, y);
    //         return;
    //     }
    //     angle2 = angle - a;
    //     x = instance->x + cos(angle2) * d;
    //     y = instance->y - sin(angle2) * d;
    //     if (!test_position(x, y)) {
    //         instance->set_position(x, y);
    //         return;
    //     }
    // }

    // int dir1 = instance->direction + 6;
    // int dir2 = instance->direction - 6;

    // int x, y;
    // float add_x, add_y;

    // get_dir(dir1, add_x, add_y);
    // add_x *= last_move;
    // add_y *= last_move;
    // x = old_x + add_x;
    // y = old_y + add_y;
    // if (!test_position(x, y)) {
    //     instance->set_position(x, y);
    //     return;
    // }

    // get_dir(dir2, add_x, add_y);
    // add_x *= last_move;
    // add_y *= last_move;
    // x = old_x + add_x;
    // y = old_y + add_y;
    // if (!test_position(x, y)) {
    //     instance->set_position(x, y);
    //     return;
    // }

    if (!test_position(old_x, instance->y)) {
        instance->set_position(old_x, instance->y);
        return;
    }

    if (!test_position(instance->x, old_y)) {
        instance->set_position(instance->x, old_y);
        return;
    }

    fix_position();
}
Ejemplo n.º 6
0
void BallMovement::bounce(bool collision)
{
    if (stop_speed != 0)
        return;
#ifdef CHOWDREN_IS_AVGN
    fix_position();

    int direction = instance->direction;

    float angle = rad(direction * 11.25f);

    float found_a = -1.0f;
    for (float a = 0.0f; a < (CHOW_PI*2.0f); a += (CHOW_PI*2.0f) / 16.0f) {
        float x_move = 10.0f * cos(angle + a);
        float y_move = -10.0f * sin(angle + a);

        int x = instance->x + x_move;
        int y = instance->y + y_move;

        if (!test_position(x, y)) {
            found_a = a;
            break;
        }
    }

    if (found_a == -1.0f) {
        instance->set_direction((instance->direction + 16) % 32, false);
        return;
    }

    angle += found_a * 2.0f;
    if (angle > 2.0 * CHOW_PI)
        angle -= 2.0 * CHOW_PI;

    instance->set_direction(deg(angle) / 11.25f, false);

    if (back_col)
        instance->flags &= ~REPEAT_BACK_COLLISION;
    else
        instance->collision_flags = 0;
#else
    add_x = add_y = 0;

    if (collision) {
        if (back_col)
            has_back_col = true;
        push_out();
    }

    int x = instance->x;
    int y = instance->y;
    x -= 8;
    y -= 8;
    int rebond = 0;
    if (test_position(x, y))
        rebond |= 0x01;
    x += 16;
    if (test_position(x, y))
        rebond |= 0x02;
    y += 16;
    if (test_position(x, y))
        rebond |= 0x04;
    x -= 16;
    if (test_position(x, y))
        rebond |= 0x08;
    int value = rebond_list[rebond * 32 + instance->direction];
    if (test_direction(value, 8)) {
        int angles = 4;
        int angles2 = angles;
        bool is_free = false;
        while (true) {
            value -= angles;
            value &= 31;
            if (!test_direction(value, 8)) {
                is_free = true;
                break;
            }
            value += 2 * angles;
            value &= 31;
            if (!test_direction(value, 8)) {
                is_free = true;
                break;
            }
            value -= angles;
            value &= 31;
            angles += angles2;
            if (angles <= 16)
                break;
        }
        if (!is_free)
            value = randrange(32);
    }

    int rnd = randrange(100);
    if (rnd < randomizer) {
        rnd >>= 2;
        if (rnd < 25) {
            rnd -= 12;
            rnd &= 31;
            if (!test_direction(rnd, 8))
                value = rnd;
        }
    }