예제 #1
0
/**
@method union_list( array_of_rects )
Returns a new array representing a rectangle covering all rectangles
in @array_of_rects.
*/
static VALUE rb_array_union_list(VALUE self, VALUE other_rects)
{
	int i;
	double left;
	double right;
	double top;
	double bottom;
	double l,r,t,b;
	VALUE rect;

	if(RARRAY(other_rects)->len==0){
		return Qnil;
	}

	rect=rb_ary_entry(other_rects, 0);
	left=array_get_x(rect);
	right=array_get_w(rect)+left;
	top=array_get_y(rect);
	bottom=array_get_h(rect)+top;

	for(i=1; i<RARRAY(other_rects)->len; i++){
		rect=rb_ary_entry(other_rects, i);
		l=array_get_x(rect);
		r=array_get_w(rect)+l;
		t=array_get_y(rect);
		b=array_get_h(rect)+t;
		left=RUDL_MIN(left, l);
		right=RUDL_MAX(right, r);
		top=RUDL_MIN(top, t);
		bottom=RUDL_MAX(bottom, b);
	}

	return new_rect(left, top, right-left, bottom-top);
}
예제 #2
0
파일: dummy.cpp 프로젝트: GaZ3ll3/enable
void test_disjoint_intersect(GC_TYPE &gc)
{
    kiva::rect_list_type output_rects;
    kiva::rect_list_type input_rects;
    //kiva::rect_type rect1(atof(argv[0]),atof(argv[1]),atof(argv[2]),atof(argv[3]));
    //kiva::rect_type rect2(atof(argv[4]),atof(argv[5]),atof(argv[6]),atof(argv[7]));
    input_rects.push_back(kiva::rect_type(20.5,20.5,60,50));
    //input_rects.push_back(kiva::rect_type(40.5,40.5,60,10));
    input_rects.push_back(kiva::rect_type(60.5,80.5,35,60));
//    input_rects.push_back(kiva::rect_type(40.5,60.5,60,60));
    kiva::rect_type new_rect(40.5,60.5,60,60);
    output_rects = kiva::disjoint_intersect(input_rects, new_rect);

    gc.save_state();
    gc.set_alpha(1.0);
    gc.set_stroke_color(blue);
    gc.rects(input_rects);
    gc.rect(new_rect);
    gc.stroke_path();
    gc.set_alpha(0.4);
    gc.set_fill_color(red);
    gc.rects(output_rects);
    gc.fill_path();
    gc.restore_state();
}
예제 #3
0
static duk_ret_t
js_SetClippingRectangle(duk_context* ctx)
{
	int x = duk_require_int(ctx, 0);
	int y = duk_require_int(ctx, 1);
	int width = duk_require_int(ctx, 2);
	int height = duk_require_int(ctx, 3);

	set_clip_rectangle(new_rect(x, y, x + width, y + height));
	return 0;
}
예제 #4
0
파일: room.c 프로젝트: oitofelix/mininim
void
draw_no_floor_selection (ALLEGRO_BITMAP *bitmap, struct pos *p)
{
  if (peq (p, &mouse_pos)) {
    struct rect r;
    new_rect (&r, p->room, p->place * PLACE_WIDTH + 25,
              p->floor * PLACE_HEIGHT - 13,
              PLACE_WIDTH, PLACE_HEIGHT);
    draw_filled_rect (bitmap, &r, NO_FLOOR_SELECTION_COLOR);
  }
}
void LLLayoutPanel::setTargetDim(S32 value)
{
	LLRect new_rect(getRect());
	if (mOrientation == LLLayoutStack::HORIZONTAL)
	{
		new_rect.mRight = new_rect.mLeft + value;
	}
	else
	{
		new_rect.mTop = new_rect.mBottom + value;
	}
	setShape(new_rect, true);
}
예제 #6
0
파일: guard.c 프로젝트: allisson128/mininim
void
draw_guard_lives (ALLEGRO_BITMAP *bitmap, struct anim *g, enum vm vm)
{
    if (g->dont_draw_lives) return;
    if (g->current_lives <= 0) return;

    int current_lives = (g->current_lives > 10)
                        ? 10 : g->current_lives;

    int i;
    struct coord c;
    struct rect r;
    new_rect (&r, room_view, ORIGINAL_WIDTH - 7 * current_lives,
              ORIGINAL_HEIGHT - 8, 7 * current_lives,
              ORIGINAL_HEIGHT - 1);

    ALLEGRO_COLOR bg_color;

    switch (vm) {
    case CGA:
        bg_color = C_LIVES_RECT_COLOR;
        break;
    case EGA:
        bg_color = E_LIVES_RECT_COLOR;
        break;
    case VGA:
        bg_color = V_LIVES_RECT_COLOR;
        break;
    }

    draw_filled_rect (bitmap, &r, bg_color);

    ALLEGRO_BITMAP *life = guard_life;
    palette pal = NULL;

    if ((g->type == SHADOW && g->style == 0)
            || g->type == KID) {
        pal = get_shadow_life_palette (vm);
        life = apply_palette (life, pal);
    } else if (g->type == SKELETON && g->style == 0)
        life = apply_palette (life, skeleton_life_palette);
    else if (is_guard (g)) {
        pal = get_guard_palette (g->style, vm);
        life = apply_palette (life, pal);
    }

    if (hgc) life = apply_palette (life, hgc_palette);

    for (i = 0; i < current_lives; i++)
        draw_bitmapc (life, bitmap, guard_life_coord (i, &c), 0);
}
예제 #7
0
    void dragable::
    on_mouse_move (
        unsigned long state,
        long x,
        long y
    )
    {
        if (drag && (state & base_window::LEFT) && enabled && !hidden)
        {
            // the user is trying to drag this object.  we should calculate the new
            // x and y positions for the upper left corner of this object's rectangle

            long new_x = x - this->x;
            long new_y = y - this->y;

            // make sure these points are inside the dragable area.  
            if (new_x < area.left())
                new_x = area.left();
            if (new_x + static_cast<long>(rect.width()) - 1 > area.right())
                new_x = area.right() - rect.width() + 1;

            if (new_y + static_cast<long>(rect.height()) - 1 > area.bottom())
                new_y = area.bottom() - rect.height() + 1;
            if (new_y < area.top())
                new_y = area.top();

            // now make the new rectangle for this object
            rectangle new_rect(
                new_x,
                new_y,
                new_x + rect.width() - 1,
                new_y + rect.height() - 1
            );

            // only do anything if this is a new rectangle and it is inside area
            if (new_rect != rect && area.intersect(new_rect) == new_rect)
            {
                parent.invalidate_rectangle(new_rect + rect);
                rect = new_rect;

                // call the on_drag() event handler
                on_drag();
            }
        }
        else
        {
            drag = false;
        }
    }
예제 #8
0
파일: mirror.c 프로젝트: oitofelix/mininim
void
draw_mirror (ALLEGRO_BITMAP *bitmap, struct pos *p,
                 enum em em, enum vm vm)
{
  ALLEGRO_BITMAP *mirror = NULL;

  switch (em) {
  case DUNGEON:
    switch (vm) {
    case CGA: mirror = dc_mirror; break;
    case EGA: mirror = de_mirror; break;
    case VGA: mirror = dv_mirror; break;
    }
    break;
  case PALACE:
    switch (vm) {
    case CGA: mirror = pc_mirror; break;
    case EGA: mirror = pe_mirror; break;
    case VGA: mirror = pv_mirror; break;
    }
    break;
  }

  /* make mirror black */
  struct rect r;
  new_rect (&r, p->room, PLACE_WIDTH * p->place + 2,
            PLACE_HEIGHT * p->floor + 3,
            PLACE_WIDTH - 10, PLACE_HEIGHT - 16);
  draw_filled_rect (bitmap, &r, BLACK);

  /* draw floor reflex */
  draw_floor_reflex (bitmap, p, em, vm);

  /* draw mirror properly */
  if (vm == VGA) mirror = apply_hue_palette (mirror);
  if (hgc) mirror = apply_palette (mirror, hgc_palette);
  if (peq (p, &mouse_pos))
    mirror = apply_palette (mirror, selection_palette);

  struct coord c;
  draw_bitmapc (mirror, bitmap, mirror_coord (p, &c), 0);
}
예제 #9
0
bool GameLayer::touch_in_node(Node* target, cocos2d::Touch* touch, float scale)
{
    auto bbox = target->getBoundingBox();
    if (scale != 1)
    {
        Rect new_rect(bbox);
        new_rect.size.width = bbox.size.width*scale;
        new_rect.size.height = bbox.size.height*scale;
        new_rect.origin.x -= (bbox.size.width / 2.0)*(scale - 1.0);// - bbox.size.width );
        new_rect.origin.y -= (bbox.size.height / 2.0)*(scale - 1.0);// - bbox.size.height);
        bbox.setRect(
            new_rect.origin.x,
            new_rect.origin.y,
            new_rect.size.width,
            new_rect.size.height
        );
    }
    if (bbox.containsPoint(this->convertTouchToNodeSpace(touch))) 
    {
        return true;
    }
    return false;
};
예제 #10
0
void MandelbrotShower::mouseReleaseEvent(QMouseEvent *e){
    moving = false;
    update();

    move_now = e->pos();

    QPointF start(xmin + move_start.x()*xres, ymax - move_start.y()*yres);
    QPointF stop(xmin + move_now.x()*xres, ymax - move_now.y()*yres);
    QRectF new_rect(start, stop);

    QSize new_size;
    if (!lock_proportions){
        new_size = size;
        if (size.width() < size.height())
            new_size.setHeight(size.width()*fabs(new_rect.height()/new_rect.width()));
        else
            new_size.setWidth(size.height()*fabs(new_rect.width()/new_rect.height()));
    }

    if (!new_rect.isNull())
        emit region_selected(new_rect, new_size);
    else if (!julia)
        emit julia_point(stop);
}
예제 #11
0
// DrawSingleImage -- takes the first image in the linked list
//                    and draws it
//
//
void PictureViewer::DrawSingleImage( BView *target_view) {
   
   int32 mode = setup->ViewingMode();
   
   if (
        (mode == PEEK_IMAGE_NORMAL) ||
        (mode == PEEK_IMAGE_WINDOW_TO_IMAGE)
      ) 
   {
      float x = target_view->Bounds().Width()  / 2;
      float y = target_view->Bounds().Height() / 2;
      x = x - thePic->Bounds().Width()/2;
      y = y - thePic->Bounds().Height()/2;
      if (x < 1) x = 1;
      if (y < 1) y = 1;
      target_view->DrawBitmap( thePic , BPoint(x,y) );
   }
   
   if (
        (mode == PEEK_IMAGE_TILE)
      )
   {
      for (float i = 0; i < target_view->Bounds().Width(); i += thePic->Bounds().Width()) {
       for (float j = 0; j < target_view->Bounds().Height(); j += thePic->Bounds().Height()) {
           if (thePic != NULL) target_view->DrawBitmap( thePic, BPoint( i,j ) ); 
              else break;
        }
       if (thePic == NULL) break;
      }
   }
  
   
   if ( (mode == PEEK_IMAGE_SCALE_TO_WINDOW ) )
   {
      target_view->DrawBitmap( thePic, BRect( 1,1, Bounds().Width()-2, Bounds().Height()-2 ) );
   }

  if ( (mode == PEEK_IMAGE_SCALED_NICELY) )
  {
    float width  = target_view->Bounds().Width();
    float height = target_view->Bounds().Height();

    float  pic_width  = thePic->Bounds().Width();
    float  pic_height = thePic->Bounds().Height();
    
    float ratio = 1;
    
    if ( (width - pic_width) < (height - pic_height) )
    {
       ratio = width / pic_width;
    }
    else 
    {
       ratio = height / pic_height;
    }

    BRect new_rect(0,0,pic_width * ratio, pic_height * ratio );
    
    float x = Bounds().Width() / 2 - new_rect.Width() / 2;
    float y = Bounds().Height() / 2 - new_rect.Height() / 2;
    
    new_rect.left   += x;
    new_rect.top    += y;
    new_rect.right  += x;
    new_rect.bottom += y;
    
    target_view->DrawBitmap( thePic, new_rect );
  }

  DrawClipping();
  Sync();
}
예제 #12
0
__inline__ VALUE new_rect_from_SDL_Rect(SDL_Rect* source)
{
	return new_rect(source->x, source->y, source->w, source->h);
}
예제 #13
0
파일: test-state.c 프로젝트: nobled/clutter
G_MODULE_EXPORT gint
test_state_main (gint    argc,
                  gchar **argv)
{
  ClutterColor  black={0,0,0,0xff};
  ClutterActor *stage;
  ClutterState *layout_state;
  gint i;
  clutter_init (&argc, &argv);

  stage = clutter_stage_get_default ();
  layout_state = clutter_state_new ();
  clutter_stage_set_color (CLUTTER_STAGE (stage), &black);
  clutter_actor_set_size (stage, STAGE_WIDTH, STAGE_HEIGHT);

  g_signal_connect (stage, "button-press-event",
                    G_CALLBACK (press_event), layout_state);
  g_signal_connect (stage, "button-release-event",
                    G_CALLBACK (release_event), layout_state);

  for (i=0; i<TOTAL; i++)
    {
      ClutterActor *actor;
      ClutterState *a_state;

      int row = i/COLS;
      int col = i%COLS;

      actor = new_rect (255 * ( 1.0*col/COLS), 50,
                        255 * ( 1.0*row/ROWS), 255);
      clutter_container_add_actor (CLUTTER_CONTAINER (stage), actor);
      clutter_actor_set_position (actor, 320.0, 240.0);
      clutter_actor_set_reactive (actor, TRUE);


      clutter_state_set (layout_state, NULL, "active",
            actor, "delayed::x", CLUTTER_LINEAR,
                                         ACTOR_WIDTH * 1.0 * ((TOTAL-1-i) % COLS), 
                                        ((row*1.0/ROWS))/2, (1.0-(row*1.0/ROWS))/2,
            actor, "delayed::y", CLUTTER_LINEAR,
                                         ACTOR_HEIGHT * 1.0 * ((TOTAL-1-i) / COLS),
                                        ((row*1.0/ROWS))/2, 0.0,
            actor, "rotation-angle-x", CLUTTER_LINEAR, 0.0,
            actor, "rotation-angle-y", CLUTTER_LINEAR, 0.0,
            NULL);

      clutter_state_set (layout_state, NULL, "right",
            actor, "delayed::x", CLUTTER_LINEAR, STAGE_WIDTH * 1.0,
                                    ((row*1.0/ROWS))/2,
                                    (1.0-(row*1.0/ROWS))/2,
            actor, "delayed::y", CLUTTER_LINEAR, STAGE_HEIGHT * 1.0,
                                    ((row*1.0/ROWS))/2,
                                    0.0,
            NULL);

      clutter_state_set (layout_state, NULL, "left",
            actor, "rotation-angle-x", CLUTTER_LINEAR, 45.0,
            actor, "rotation-angle-y", CLUTTER_LINEAR, 5.0,
            actor, "x", CLUTTER_LINEAR, 0-64.0,
            actor, "y", CLUTTER_LINEAR, 0-64.0,
                         NULL);

      a_state = clutter_state_new ();
      g_object_set_data_full (G_OBJECT (actor), "hover-state-machine",
                              a_state, g_object_unref);
      g_signal_connect (actor, "enter-event",
                        G_CALLBACK (enter_event), a_state);
      g_signal_connect (actor, "leave-event",
                        G_CALLBACK (leave_event), a_state);

      clutter_state_set (a_state, NULL, "normal",
                         actor, "opacity", CLUTTER_LINEAR, 0x77,
                         actor, "rotation-angle-z", CLUTTER_LINEAR, 0.0,
                         NULL);
      clutter_state_set (a_state, NULL, "hover",
                         actor, "opacity", CLUTTER_LINEAR, 0xff,
                         actor, "rotation-angle-z", CLUTTER_LINEAR, 10.0,
                         NULL);
      clutter_actor_set_opacity (actor, 0x77);

      clutter_state_set_duration (a_state, NULL, NULL, 500);
    }

  clutter_state_set_duration (layout_state, NULL, NULL, 1000);
  clutter_state_set_duration (layout_state, "active", "left", 1400);

  g_signal_connect (layout_state, "completed", G_CALLBACK (completed), NULL);

  clutter_actor_show (stage);

  clutter_state_warp_to_state (layout_state, "left");
  clutter_state_set_state (layout_state, "active");

  clutter_main ();
  g_object_unref (layout_state);

  return EXIT_SUCCESS;
}
예제 #14
0
wxRect wxRibbonPanel::GetExpandedPosition(wxRect panel,
                                          wxSize expanded_size,
                                          wxDirection direction)
{
    // Strategy:
    // 1) Determine primary position based on requested direction
    // 2) Move the position so that it sits entirely within a display
    //    (for single monitor systems, this moves it into the display region,
    //     but for multiple monitors, it does so without splitting it over
    //     more than one display)
    // 2.1) Move in the primary axis
    // 2.2) Move in the secondary axis

    wxPoint pos;
    bool primary_x = false;
    int secondary_x = 0;
    int secondary_y = 0;
    switch(direction)
    {
    case wxNORTH:
        pos.x = panel.GetX() + (panel.GetWidth() - expanded_size.GetWidth()) / 2;
        pos.y = panel.GetY() - expanded_size.GetHeight();
        primary_x = true;
        secondary_y = 1;
        break;
    case wxEAST:
        pos.x = panel.GetRight();
        pos.y = panel.GetY() + (panel.GetHeight() - expanded_size.GetHeight()) / 2;
        secondary_x = -1;
        break;
    case wxSOUTH:
        pos.x = panel.GetX() + (panel.GetWidth() - expanded_size.GetWidth()) / 2;
        pos.y = panel.GetBottom();
        primary_x = true;
        secondary_y = -1;
        break;
    case wxWEST:
    default:
        pos.x = panel.GetX() - expanded_size.GetWidth();
        pos.y = panel.GetY() + (panel.GetHeight() - expanded_size.GetHeight()) / 2;
        secondary_x = 1;
        break;
    }
    wxRect expanded(pos, expanded_size);

    wxRect best(expanded);
    int best_distance = INT_MAX;

    const unsigned display_n = wxDisplay::GetCount();
    unsigned display_i;
#if defined(__INTEL_COMPILER) && 1 /* VDM auto patch */
#   pragma ivdep
#   pragma swp
#   pragma unroll
#   pragma prefetch
#   if 0
#       pragma simd noassert
#   endif
#endif /* VDM auto patch */
    for(display_i = 0; display_i < display_n; ++display_i)
    {
        wxRect display = wxDisplay(display_i).GetGeometry();

        if(display.Contains(expanded))
        {
            return expanded;
        }
        else if(display.Intersects(expanded))
        {
            wxRect new_rect(expanded);
            int distance = 0;

            if(primary_x)
            {
                if(expanded.GetRight() > display.GetRight())
                {
                    distance = expanded.GetRight() - display.GetRight();
                    new_rect.x -= distance;
                }
                else if(expanded.GetLeft() < display.GetLeft())
                {
                    distance = display.GetLeft() - expanded.GetLeft();
                    new_rect.x += distance;
                }
            }
            else
            {
                if(expanded.GetBottom() > display.GetBottom())
                {
                    distance = expanded.GetBottom() - display.GetBottom();
                    new_rect.y -= distance;
                }
                else if(expanded.GetTop() < display.GetTop())
                {
                    distance = display.GetTop() - expanded.GetTop();
                    new_rect.y += distance;
                }
            }
            if(!display.Contains(new_rect))
            {
                // Tried moving in primary axis, but failed.
                // Hence try moving in the secondary axis.
                int dx = secondary_x * (panel.GetWidth() + expanded_size.GetWidth());
                int dy = secondary_y * (panel.GetHeight() + expanded_size.GetHeight());
                new_rect.x += dx;
                new_rect.y += dy;

                // Squaring makes secondary moves more expensive (and also
                // prevents a negative cost)
                distance += dx * dx + dy * dy;
            }
            if(display.Contains(new_rect) && distance < best_distance)
            {
                best = new_rect;
                best_distance = distance;
            }
        }
    }

    return best;
}
예제 #15
0
G_MODULE_EXPORT gint
test_animator_main (gint    argc,
                    gchar **argv)
{
  ClutterActor *stage;
  ClutterActor *rects[COUNT];
  gint i;
  clutter_init (&argc, &argv);

  stage = clutter_stage_get_default ();

  for (i=0; i<COUNT; i++)
    {
      rects[i]=new_rect (255 *(i * 1.0/COUNT), 50, 160, 255);
      clutter_container_add_actor (CLUTTER_CONTAINER (stage), rects[i]);
      clutter_actor_set_anchor_point (rects[i], 64, 64);
      clutter_actor_set_position (rects[i], 320.0, 240.0);
      clutter_actor_set_opacity (rects[i], 0x70);
    }

  g_timeout_add (10000, nuke_one, rects[2]);

  animator = clutter_animator_new ();

  /* Note: when both animations are active for the same actor at the same
   * time there is a race, such races should be handled by avoiding
   * controlling the same properties from multiple animations. This is
   * an intentional design flaw of this test for testing the corner case.
   */

  clutter_animator_set (animator,
         rects[0], "x",       1,                    0.0,  180.0,
         rects[0], "x",       CLUTTER_LINEAR,       0.25, 450.0,
         rects[0], "x",       CLUTTER_LINEAR,       0.5,  450.0,
         rects[0], "x",       CLUTTER_LINEAR,       0.75, 180.0,
         rects[0], "x",       CLUTTER_LINEAR,       1.0,  180.0,

         rects[0], "y",       -1,                   0.0,   100.0,
         rects[0], "y",       CLUTTER_LINEAR,       0.25,  100.0,
         rects[0], "y",       CLUTTER_LINEAR,       0.5,   380.0,
         rects[0], "y",       CLUTTER_LINEAR,       0.75,  380.0,
         rects[0], "y",       CLUTTER_LINEAR,       1.0,   100.0,

         rects[3], "x",       0,                    0.0,  180.0,
         rects[3], "x",       CLUTTER_LINEAR,       0.25, 180.0,
         rects[3], "x",       CLUTTER_LINEAR,       0.5,  450.0,
         rects[3], "x",       CLUTTER_LINEAR,       0.75, 450.0,
         rects[3], "x",       CLUTTER_LINEAR,       1.0,  180.0,

         rects[3], "y",       0,                    0.0,  100.0,
         rects[3], "y",       CLUTTER_LINEAR,       0.25, 380.0,
         rects[3], "y",       CLUTTER_LINEAR,       0.5,  380.0,
         rects[3], "y",       CLUTTER_LINEAR,       0.75, 100.0,
         rects[3], "y",       CLUTTER_LINEAR,       1.0,  100.0,


         rects[2], "rotation-angle-y",       0,                    0.0,  0.0,
         rects[2], "rotation-angle-y",       CLUTTER_LINEAR,       1.0,  360.0,

         rects[1], "scale-x", 0,                    0.0,  1.0,
         rects[1], "scale-x", CLUTTER_LINEAR,       1.0,  2.0,
         rects[1], "scale-y", 0,                    0.0,  1.0,
         rects[1], "scale-y", CLUTTER_LINEAR,       1.0,  2.0,
         NULL);


  clutter_actor_set_scale (rects[0], 1.4, 1.4);
  clutter_animator_property_set_ease_in (animator, G_OBJECT (rects[0]), "x",
                                         TRUE);
  clutter_animator_property_set_ease_in (animator, G_OBJECT (rects[0]), "y",
                                         TRUE);
  clutter_animator_property_set_interpolation (animator, G_OBJECT (rects[0]),
                                               "x", CLUTTER_INTERPOLATION_CUBIC);
  clutter_animator_property_set_interpolation (animator, G_OBJECT (rects[0]),
                                               "y", CLUTTER_INTERPOLATION_CUBIC);

  clutter_stage_hide_cursor(CLUTTER_STAGE (stage));
  clutter_actor_show (stage);
  clutter_animator_set_duration (animator, 5000);

  g_signal_connect (clutter_animator_start (animator),
                    "completed", G_CALLBACK (reverse_timeline), NULL);
  clutter_main ();
  g_object_unref (animator);

  return EXIT_SUCCESS;
}
예제 #16
0
파일: DropMenu.cpp 프로젝트: axlib/OpenAX
/*
 * ax::DropMenu::DropMenu.
 */
ax::DropMenu::DropMenu(const ax::Rect& rect, const ax::DropMenu::Events& events,
	const ax::DropMenu::Info& info, const std::vector<std::string>& items,
	ax::Flag flags)
	: _events(events)
	, _flags(flags)
	, _selected_item(-1)
	, _mouse_hover_item(-1)

{
	for (int i = 0; i < items.size(); i++) {
		if (items[i].empty()) {
			_separator_index.push_back((int)_items.size());
		}
		else if (items[i] == ">") {
			// Arrow at index 0 is ignore.
			_right_arrow_index.push_back((int)_items.size() - 1);
		}
		else {
			_items.push_back(items[i]);
		}
	}

	ax::Rect new_rect(rect);

	if (_items.size()) {
		int total_height = (int)_items.size() * info.item_height;

		// Too many items for menu max height.
		if (total_height > rect.size.y) {
			int n_item = rect.size.y / info.item_height;
			_n_shown_item = n_item - 1;
			_over_flow = true;
			_over_flow_up = false;
			_over_flow_down = true;
			_top_item_index = 0;

			new_rect.size.y = n_item * info.item_height;
		}
		else {
			_over_flow = false;
			_over_flow_up = false;
			_over_flow_down = false;
			_n_shown_item = (int)_items.size();
			_top_item_index = 0;

			new_rect.size.y = (int)_items.size() * info.item_height;
		}
	}

	win = ax::Window::Create(new_rect);

	// Builtin event connection.
	win->event.OnPaint = ax::WBind<ax::GC>(this, &DropMenu::OnPaint);

	win->event.OnMouseLeftDown
		= ax::WBind<ax::Point>(this, &DropMenu::OnMouseLeftDown);
	win->event.OnMouseLeftUp
		= ax::WBind<ax::Point>(this, &DropMenu::OnMouseLeftUp);
	win->event.OnMouseEnter
		= ax::WBind<ax::Point>(this, &DropMenu::OnMouseEnter);
	win->event.OnMouseLeave
		= ax::WBind<ax::Point>(this, &DropMenu::OnMouseLeave);
	win->event.OnMouseMotion
		= ax::WBind<ax::Point>(this, &DropMenu::OnMouseMotion);

	if (_events.item_click) {
		win->AddConnection(DropMenu::Events::ITEM_CLICK, _events.item_click);
	}

//	ax::Print("new ax::DropMenu::win->component");
	win->component.Add("Widget", widget::Component::Ptr(new widget::Component(
									 win, new ax::DropMenu::Info(info))));

	if (info.font_path.empty()) {
		_font = ax::unique<ax::Font>(0);
		_font->SetFontSize(info.font_size);
	}
	else {
		_font = ax::unique<ax::Font>(info.font_path);

		if (!_font->IsFontReady()) {
			_font = ax::unique<ax::Font>(0);
		}

		_font->SetFontSize(info.font_size);
	}

	_up_img = ax::unique<ax::Image>("resources/drop_up.png");
	_down_img = ax::unique<ax::Image>("resources/drop_down.png");
	_right_img = ax::unique<ax::Image>("resources/drop_right.png");
}
예제 #17
0
void
update_cache_pos (struct pos *p, enum changed_pos_reason reason,
                  enum em em, enum vm vm)
{
  static bool recursive = false, recursive_01 = false;

  int x, y;

  struct pos p0; p0 = *p;

  struct pos pbl; prel (p, &pbl, +1, -1);
  struct pos pb; prel (p, &pb, +1, +0);
  struct pos pbr; prel (p, &pbr, +1, +1);
  struct pos pl; prel (p, &pl, +0, -1);
  struct pos pr; prel (p, &pr, +0, +1);
  struct pos par; prel (p, &par, -1, +1);

  /* if (! recursive) */
  /*   printf ("%i,%i,%i,%i\n", p->room, p->floor, p->place, reason); */

  for (y = mr.h - 1; y >= 0; y--)
    for (x = 0; x < mr.w; x++)
      if (p->room && mr.cell[x][y].room == p->room) {
        room_view = p->room;
        mr.dx = x;
        mr.dy = y;
        con_caching = true;
        struct rect r;
        struct door *d;

        switch (reason) {
        case CHPOS_NONE: break;
        case CHPOS_UNHIDE_FLOOR:
        case CHPOS_MOUSE_SELECT:
        case CHPOS_MOUSE_DESELECT:
        case CHPOS_CLOSE_LEVEL_DOOR:
        case CHPOS_CARPET_DESIGN:
        case CHPOS_WALL:
          draw_conbg (mr.cell[x][y].cache, p, em, vm, true);
          break;
        case CHPOS_SHAKE_LOOSE_FLOOR:
        case CHPOS_RELEASE_LOOSE_FLOOR:
        case CHPOS_PRESS_OPENER_FLOOR:
        case CHPOS_UNPRESS_OPENER_FLOOR:
        case CHPOS_PRESS_CLOSER_FLOOR:
        case CHPOS_UNPRESS_CLOSER_FLOOR:
          new_rect (&r, p->room,
                    PLACE_WIDTH * p->place,
                    PLACE_HEIGHT * p->floor + 49,
                    58, 17);
          clear_rect_to_color (mr.cell[x][y].cache, &r, TRANSPARENT_COLOR);

          if (con (&pbl)->fg == LEVEL_DOOR || con (&pbl)->bg == BALCONY)
            draw_conbg (mr.cell[x][y].cache, &pbl, em, vm, true);
          if (con (&pb)->fg == LEVEL_DOOR || con (&pb)->bg == BALCONY)
            draw_conbg (mr.cell[x][y].cache, &pb, em, vm, true);
          if (con (&pbr)->fg == LEVEL_DOOR || con (&pbr)->bg == BALCONY)
            draw_conbg (mr.cell[x][y].cache, &pbr, em, vm, true);

          draw_confg_top (mr.cell[x][y].cache, &pb, em, vm, true);
          draw_conbg (mr.cell[x][y].cache, &pl, em, vm, true);
          draw_conbg (mr.cell[x][y].cache, p, em, vm, true);

          break;
        case CHPOS_LOOSE_FLOOR_FALL:
        case CHPOS_CHAIN_RELEASE_LOOSE_FLOOR:
          new_rect (&r, p->room,
                    PLACE_WIDTH * p->place,
                    PLACE_HEIGHT * p->floor + 49,
                    58, 17);
          clear_rect_to_color (mr.cell[x][y].cache, &r, TRANSPARENT_COLOR);

          if (con (&pbl)->fg == LEVEL_DOOR || con (&pbl)->bg == BALCONY)
            draw_conbg (mr.cell[x][y].cache, &pbl, em, vm, true);
          if (con (&pb)->fg == LEVEL_DOOR || con (&pb)->bg == BALCONY)
            draw_conbg (mr.cell[x][y].cache, &pb, em, vm, true);
          if (con (&pbr)->fg == LEVEL_DOOR || con (&pbr)->bg == BALCONY)
            draw_conbg (mr.cell[x][y].cache, &pbr, em, vm, true);

          draw_confg_top (mr.cell[x][y].cache, &pbl, em, vm, true);
          draw_confg_top (mr.cell[x][y].cache, &pb, em, vm, true);
          draw_conbg (mr.cell[x][y].cache, &pl, em, vm, true);
          draw_conbg (mr.cell[x][y].cache, p, em, vm, true);
          draw_confg_base (mr.cell[x][y].cache, &pr, em, vm);
          draw_confg_left (mr.cell[x][y].cache, &pr, em, vm, true);
          break;
        case CHPOS_BREAK_LOOSE_FLOOR:
        case CHPOS_BREAK_OPENER_FLOOR:
        case CHPOS_BREAK_CLOSER_FLOOR:
        case CHPOS_BREAK_LEVEL_DOOR:
          new_rect (&r, p->room,
                    PLACE_WIDTH * p->place,
                    PLACE_HEIGHT * p->floor + 35,
                    57, 31);
          clear_rect_to_color (mr.cell[x][y].cache, &r, TRANSPARENT_COLOR);

          if (con (&pbl)->fg == LEVEL_DOOR || con (&pbl)->bg == BALCONY)
            draw_conbg (mr.cell[x][y].cache, &pbl, em, vm, true);
          if (con (&pb)->fg == LEVEL_DOOR || con (&pb)->bg == BALCONY)
            draw_conbg (mr.cell[x][y].cache, &pb, em, vm, true);
          if (con (&pbr)->fg == LEVEL_DOOR || con (&pbr)->bg == BALCONY)
            draw_conbg (mr.cell[x][y].cache, &pbr, em, vm, true);

          draw_confg_top (mr.cell[x][y].cache, &pb, em, vm, true);
          draw_conbg (mr.cell[x][y].cache, &pl, em, vm, true);
          draw_conbg (mr.cell[x][y].cache, p, em, vm, true);
          break;
        case CHPOS_OPEN_DOOR:
        case CHPOS_CLOSE_DOOR:
        case CHPOS_ABRUPTLY_CLOSE_DOOR:
          d = door_at_pos (p);

          int ch = 18 + d->i + 1;

          new_rect (&r, p->room,
                    PLACE_WIDTH * (p->place + 1),
                    PLACE_HEIGHT * p->floor - 6,
                    24, ch);
          clear_rect_to_color (mr.cell[x][y].cache, &r, TRANSPARENT_COLOR);

          draw_conbg (mr.cell[x][y].cache, p, em, vm, true);

          if (ch > PLACE_HEIGHT - 3)
            draw_confg_top (mr.cell[x][y].cache, &pb, em, vm, true);

          break;
        case CHPOS_OPEN_LEVEL_DOOR:
          new_rect (&r, p->room,
                    PLACE_WIDTH * p->place + 7,
                    PLACE_HEIGHT * p->floor - 1,
                    48, 51);
          clear_rect_to_color (mr.cell[x][y].cache, &r, TRANSPARENT_COLOR);

          draw_conbg (mr.cell[x][y].cache, p, em, vm, true);

          break;
        case CHPOS_SPIKES:
          new_rect (&r, p->room,
                    PLACE_WIDTH * p->place + 7,
                    PLACE_HEIGHT * p->floor + 34,
                    40, 24);
          clear_rect_to_color (mr.cell[x][y].cache, &r, TRANSPARENT_COLOR);

          draw_conbg (mr.cell[x][y].cache, &pl, em, vm, true);
          draw_conbg (mr.cell[x][y].cache, p, em, vm, true);

          break;
        case CHPOS_CHOPPER:
          new_rect (&r, p->room,
                    PLACE_WIDTH * p->place,
                    PLACE_HEIGHT * p->floor + 3,
                    27, 60);
          clear_rect_to_color (mr.cell[x][y].cache, &r, TRANSPARENT_COLOR);

          draw_conbg (mr.cell[x][y].cache, &pl, em, vm, true);
          draw_conbg (mr.cell[x][y].cache, p, em, vm, true);

          break;
        default:
          new_rect (&r, p->room,
                    PLACE_WIDTH * p->place - 1,
                    PLACE_HEIGHT * p->floor - 17,
                    2 * PLACE_WIDTH + 1, PLACE_HEIGHT + 3 + 17);
          clear_rect_to_color (mr.cell[x][y].cache, &r, TRANSPARENT_COLOR);

          for (p0.floor = p->floor + 1; p0.floor >= p->floor - 1; p0.floor--)
            for (p0.place = p->place - 2; p0.place <= p->place + 1; p0.place++)
              draw_conbg (mr.cell[x][y].cache, &p0, em, vm, true);

          break;
        }

        con_caching = false;
        goto end;
      }

 end:;

  /* if (is_room_visible (p->room)) printf ("%i,%i,%i\n", p->room, p->floor, p->place); */

  bool depedv =
    ((em == DUNGEON && vm == VGA)
     || (em == DUNGEON && vm == EGA)
     || (em == PALACE && vm == EGA));

  if (! recursive_01 && depedv && con (&pl)->fg == WALL) {
    recursive_01 = true;
    update_cache_pos (&pl, CHPOS_WALL, em, vm);
    recursive_01 = false;
  }

  if (! recursive && p->place == -1) {
    p0.room = roomd (&global_level, p->room, LEFT);
    p0.floor = p->floor;
    p0.place = PLACES - 1;
    recursive = true;
    update_cache_pos (&p0, reason, em, vm);
    recursive = false;
  }

  if (! recursive && p->floor == -1) {
    p0.room = roomd (&global_level, p->room, ABOVE);
    p0.floor = FLOORS - 1;
    p0.place = p->place;
    recursive = true;
    update_cache_pos (&p0, reason, em, vm);
    recursive = false;
  }

  if (! recursive && p->floor == 0) {
    p0.room = roomd (&global_level, p->room, ABOVE);
    p0.floor = FLOORS;
    p0.place = p->place;
    recursive = true;
    update_cache_pos (&p0, reason, em, vm);
    recursive = false;
  }

  if (! recursive && p->place == PLACES - 1) {
    p0.room = roomd (&global_level, p->room, RIGHT);
    p0.floor = p->floor;
    p0.place = -1;
    recursive = true;
    update_cache_pos (&p0, reason, em, vm);
    recursive = false;
  }

  if (! recursive && p->floor == FLOORS - 1) {
    p0.room = roomd (&global_level, p->room, BELOW);
    p0.floor = -1;
    p0.place = p->place;
    recursive = true;
    update_cache_pos (&p0, reason, em, vm);
    recursive = false;
  }

  if (! recursive && p->floor == -1 && p->place == -1) {
    p0.room = roomd (&global_level, p->room, ABOVE);
    p0.room = roomd (&global_level, p0.room, LEFT);
    p0.floor = FLOORS - 1;
    p0.place = PLACES - 1;
    recursive = true;
    update_cache_pos (&p0, reason, em, vm);
    recursive = false;
  }

  if (! recursive && p->floor == 0 && p->place == PLACES - 1) {
    p0.room = roomd (&global_level, p->room, ABOVE);
    p0.room = roomd (&global_level, p0.room, RIGHT);
    p0.floor = FLOORS;
    p0.place = -1;
    recursive = true;
    update_cache_pos (&p0, reason, em, vm);
    recursive = false;
  }

  if (! recursive && p->floor == -1 && p->place == PLACES - 1) {
    p0.room = roomd (&global_level, p->room, ABOVE);
    p0.room = roomd (&global_level, p0.room, RIGHT);
    p0.floor = FLOORS - 1;
    p0.place = -1;
    recursive = true;
    update_cache_pos (&p0, reason, em, vm);
    recursive = false;
  }

  if (! recursive && p->floor == FLOORS - 1 && p->place == -1) {
    p0.room = roomd (&global_level, p->room, LEFT);
    p0.room = roomd (&global_level, p0.room, BELOW);
    p0.floor = -1;
    p0.place = PLACES - 1;
    recursive = true;
    update_cache_pos (&p0, reason, em, vm);
    recursive = false;
  }

  if (! recursive && p->floor == FLOORS - 1 && p->place == PLACES - 1) {
    p0.room = roomd (&global_level, p->room, BELOW);
    p0.room = roomd (&global_level, p0.room, RIGHT);
    p0.floor = -1;
    p0.place = -1;
    recursive = true;
    update_cache_pos (&p0, reason, em, vm);
    recursive = false;
  }

  /* if (is_room_visible (p->room) && ! recursive) printf ("----------------------------\n"); */
}
예제 #18
0
파일: mirror.c 프로젝트: oitofelix/mininim
void
draw_mirror_fg (ALLEGRO_BITMAP *bitmap, struct pos *p, struct frame *f,
                enum em em, enum vm vm)
{
  ALLEGRO_BITMAP *mirror = NULL;

  switch (em) {
  case DUNGEON:
    switch (vm) {
    case CGA: mirror = dc_mirror; break;
    case EGA: mirror = de_mirror; break;
    case VGA: mirror = dv_mirror; break;
    }
    break;
  case PALACE:
    switch (vm) {
    case CGA: mirror = pc_mirror; break;
    case EGA: mirror = pe_mirror; break;
    case VGA: mirror = pv_mirror; break;
    }
    break;
  }

  /* make mirror black */
  struct rect r;
  new_rect (&r, p->room, PLACE_WIDTH * p->place + 2,
            PLACE_HEIGHT * p->floor + 3,
            13, PLACE_HEIGHT - 16);
  draw_filled_rect (bitmap, &r, BLACK);

  /* draw floor reflex */
  draw_floor_reflex (bitmap, p, em, vm);

  ignore_clipping_rectangle_intersection = true;
  /* draw anim */
  if (f) {
    push_clipping_rectangle (bitmap, PLACE_WIDTH * p->place + 2,
                             PLACE_HEIGHT * p->floor + 3,
                             16, PLACE_HEIGHT - 9);
    struct anim *a = get_anim_by_id (f->parent_id);
    struct anim a0 = *a;
    invert_frame_dir (&a0.f, &a0.f);
    a0.f.c.x = (2 * PLACE_WIDTH * p->place + 36)
      - (a->f.c.x + al_get_bitmap_width (a->f.b));
    draw_anim_frame (bitmap, &a0, vm);
    pop_clipping_rectangle ();
  }

  /* draw mirror properly */
  if (vm == VGA) mirror = apply_hue_palette (mirror);
  if (hgc) mirror = apply_palette (mirror, hgc_palette);
  if (peq (p, &mouse_pos))
    mirror = apply_palette (mirror, selection_palette);

  struct coord c;
  int h = al_get_bitmap_height (mirror);
  push_reset_clipping_rectangle (bitmap);
  draw_bitmap_regionc (mirror, bitmap, 0, 0, 22, h, mirror_coord (p, &c), 0);
  pop_clipping_rectangle ();

  ignore_clipping_rectangle_intersection = false;
}
예제 #19
0
void TextureRegionEditor::_edit_region() {
	Ref<Texture> texture = NULL;
	if (node_sprite)
		texture = node_sprite->get_texture();
	else if (node_patch9)
		texture = node_patch9->get_texture();
	else if (obj_styleBox.is_valid())
		texture = obj_styleBox->get_texture();
	else if (atlas_tex.is_valid())
		texture = atlas_tex->get_atlas();

	if (texture.is_null()) {
		return;
	}

	autoslice_cache.clear();
	Ref<Image> i;
	i.instance();
	if (i->load(texture->get_path()) == OK) {
		BitMap bm;
		bm.create_from_image_alpha(i);
		for (int y = 0; y < i->get_height(); y++) {
			for (int x = 0; x < i->get_width(); x++) {
				if (bm.get_bit(Point2(x, y))) {
					bool found = false;
					for (List<Rect2>::Element *E = autoslice_cache.front(); E; E = E->next()) {
						Rect2 grown = E->get().grow(1.5);
						if (grown.has_point(Point2(x, y))) {
							E->get().expand_to(Point2(x, y));
							E->get().expand_to(Point2(x + 1, y + 1));
							x = E->get().position.x + E->get().size.x - 1;
							bool merged = true;
							while (merged) {
								merged = false;
								bool queue_erase = false;
								for (List<Rect2>::Element *F = autoslice_cache.front(); F; F = F->next()) {
									if (queue_erase) {
										autoslice_cache.erase(F->prev());
										queue_erase = false;
									}
									if (F == E)
										continue;
									if (E->get().grow(1).intersects(F->get())) {
										E->get().expand_to(F->get().position);
										E->get().expand_to(F->get().position + F->get().size);
										if (F->prev()) {
											F = F->prev();
											autoslice_cache.erase(F->next());
										} else {
											queue_erase = true;
											//Can't delete the first rect in the list.
										}
										merged = true;
									}
								}
							}
							found = true;
							break;
						}
					}
					if (!found) {
						Rect2 new_rect(x, y, 1, 1);
						autoslice_cache.push_back(new_rect);
					}
				}
			}
		}
	}

	if (node_sprite)
		rect = node_sprite->get_region_rect();
	else if (node_patch9)
		rect = node_patch9->get_region_rect();
	else if (obj_styleBox.is_valid())
		rect = obj_styleBox->get_region_rect();
	else if (atlas_tex.is_valid())
		rect = atlas_tex->get_region();

	edit_draw->update();
}
예제 #20
0
// Refresh --  Should anything change within the View, this is the method
//             to call. it does everything you need to.
//             It also handles the refreshing of only the refresh-needing parts
//             so it does smooth scrolling, etc
void PictureViewer::Refresh() {

  Window()->Lock();
  int32 mode = setup->ViewingMode();

  if (  thePic != NULL && 
        ( 
          mode == PEEK_IMAGE_NORMAL ||
          mode == PEEK_IMAGE_WINDOW_TO_IMAGE
        )
      ) 
  {
   float pointx = Bounds().Width()/2 - thePic->Bounds().Width()/2 ;
   float pointy = Bounds().Height()/2 - thePic->Bounds().Height()/2 ;
   if (pointy < 1) pointy = 1;
   if (pointx < 1) pointx = 1;

   BRegion viewRegion( Bounds() );
   viewRegion.Exclude(  BRect(pointx+1,pointy+1, pointx + thePic->Bounds().Width(), pointy + thePic->Bounds().Height()) );
   Invalidate(&viewRegion);
  }
  
  if ( (thePic != NULL) && (mode == PEEK_IMAGE_SCALED_NICELY) )
  {
    float width  = Bounds().Width();
    float height = Bounds().Height();

    float  pic_width  = thePic->Bounds().Width();
    float  pic_height = thePic->Bounds().Height();
    
    float ratio = 1;
    
    if ( (width - pic_width) < (height - pic_height) )
    {
       ratio = width / pic_width;
    }
    else 
    {
       ratio = height / pic_height;
    }

    BRect new_rect(0,0,pic_width * ratio, pic_height * ratio );
    
    float x = Bounds().Width() / 2 - new_rect.Width() / 2;
    float y = Bounds().Height() / 2 - new_rect.Height() / 2;
    
    new_rect.left   += x;
    new_rect.top    += y;
    new_rect.right  += x;
    new_rect.bottom += y;
    
    BRegion viewRegion( Bounds() );
    viewRegion.Exclude(  new_rect );
    Invalidate(&viewRegion);
  }
  
  
 
 if ( thePic != NULL  )   
 {
       DrawSingleImage(this);
 }
 else 
 {
  Invalidate();
 }

 AdjustScrollBars();
 Window()->Unlock();
}