Example #1
0
/**
 * Inicialize the button_width and button_height values.
 *
 * button_width is computed as width of the whole keyboard / 10
 * button_height is computed as height of the whole keyboard / 5
 *
 */
void
KeyboardControl::set_buttons_size()
{
  button_width = get_width() / 10;
  button_height = get_height() / 5;
}
Example #2
0
 void stretch(SDL_Surface *src) {
   stretch(0, 0, get_width(), get_height(),
           src, 0, 0, src->w, src->h);
 }
Example #3
0
void LCD_GetCharDimensions(u32 c, u16 *width, u16 *height) {
    *height = HEIGHT(cur_str.font);
    *width = get_width(c);
}
Example #4
0
/**
 * \brief Returns the size of the surface containing the text.
 * \return the size of the surface
 */
const Rectangle TextSurface::get_size() const {
    return Rectangle(0, 0, get_width(), get_height());
}
Example #5
0
 void clear(const Color color) {
   fill_rectangle(0, 0, get_width(), get_height(), color);
 }
Example #6
0
void
TexturePatch::adjust_colors(std::vector<math::Vec3f> const & adjust_values) {
    assert(blending_mask != NULL);

    validity_mask->fill(0);

    mve::FloatImage::Ptr iadjust_values = mve::FloatImage::create(get_width(), get_height(), 3);
    for (std::size_t i = 0; i < texcoords.size(); i += 3) {
        math::Vec2f v1 = texcoords[i];
        math::Vec2f v2 = texcoords[i + 1];
        math::Vec2f v3 = texcoords[i + 2];

        Tri tri(v1, v2, v3);

        float area = tri.get_area();
        if (area < std::numeric_limits<float>::epsilon()) continue;

        Rect<float> aabb = tri.get_aabb();
        int const min_x = static_cast<int>(std::floor(aabb.min_x)) - texture_patch_border;
        int const min_y = static_cast<int>(std::floor(aabb.min_y)) - texture_patch_border;
        int const max_x = static_cast<int>(std::ceil(aabb.max_x)) + texture_patch_border;
        int const max_y = static_cast<int>(std::ceil(aabb.max_y)) + texture_patch_border;
        assert(0 <= min_x && max_x <= get_width());
        assert(0 <= min_y && max_y <= get_height());

        for (int y = min_y; y < max_y; ++y) {
            for (int x = min_x; x < max_x; ++x) {

                math::Vec3f bcoords = tri.get_barycentric_coords(x, y);
                bool inside = bcoords.minimum() >= 0.0f;
                if (inside) {
                    assert(x != 0 && y != 0);
                    for (int c = 0; c < 3; ++c) {
                        iadjust_values->at(x, y, c) = math::interpolate(
                            adjust_values[i][c], adjust_values[i + 1][c], adjust_values[i + 2][c],
                            bcoords[0], bcoords[1], bcoords[2]);
                    }
                    validity_mask->at(x, y, 0) = 255;
                    blending_mask->at(x, y, 0) = 255;
                } else {

                    if (validity_mask->at(x, y, 0) == 255)
                        continue;

                    /* Check whether the pixels distance from the triangle is more than one pixel. */
                    float ha = 2.0f * -bcoords[0] * area / (v2 - v3).norm();
                    float hb = 2.0f * -bcoords[1] * area / (v1 - v3).norm();
                    float hc = 2.0f * -bcoords[2] * area / (v1 - v2).norm();

                    if (ha > sqrt_2 || hb > sqrt_2 || hc > sqrt_2)
                        continue;

                    for (int c = 0; c < 3; ++c) {
                        iadjust_values->at(x, y, c) = math::interpolate(
                            adjust_values[i][c], adjust_values[i + 1][c], adjust_values[i + 2][c],
                            bcoords[0], bcoords[1], bcoords[2]);
                    }
                    validity_mask->at(x, y, 0) = 255;
                    blending_mask->at(x, y, 0) = 64;
                }
            }
        }
    }

    for (int i = 0; i < image->get_pixel_amount(); ++i) {
        if (validity_mask->at(i, 0) != 0){
            for (int c = 0; c < 3; ++c) {
                image->at(i, c) += iadjust_values->at(i, c);
            }
        } else {
            math::Vec3f color(0.0f, 0.0f, 0.0f);
            //DEBUG math::Vec3f color(1.0f, 0.0f, 1.0f);
            std::copy(color.begin(), color.end(), &image->at(i, 0));
        }
    }
}
Example #7
0
static char *process_args(CHARSET_INFO *cs, char *to, char *end,
                          const char* fmt, size_t arg_index, va_list ap)
{
  ARGS_INFO args_arr[MAX_ARGS];
  PRINT_INFO print_arr[MAX_PRINT_INFO];
  uint idx= 0, arg_count= arg_index;

start:
  /* Here we are at the beginning of positional argument, right after $ */
  arg_index--;
  print_arr[idx].flags= 0;
  if (*fmt == '`')
  {
    print_arr[idx].flags|= ESCAPED_ARG;
    fmt++;
  }
  if (*fmt == '-')
    fmt++;
  print_arr[idx].length= print_arr[idx].width= 0;
  /* Get print length */
  if (*fmt == '*')
  {
    fmt++;
    fmt= get_length(fmt, &print_arr[idx].length, &print_arr[idx].flags);
    print_arr[idx].length--;
    DBUG_ASSERT(*fmt == '$' && print_arr[idx].length < MAX_ARGS);
    args_arr[print_arr[idx].length].arg_type= 'd';
    print_arr[idx].flags|= LENGTH_ARG;
    arg_count= max(arg_count, print_arr[idx].length + 1);
    fmt++;
  }
  else
    fmt= get_length(fmt, &print_arr[idx].length, &print_arr[idx].flags);

  if (*fmt == '.')
  {
    fmt++;
    /* Get print width */
    if (*fmt == '*')
    {
      fmt++;
      fmt= get_width(fmt, &print_arr[idx].width);
      print_arr[idx].width--;
      DBUG_ASSERT(*fmt == '$' && print_arr[idx].width < MAX_ARGS);
      args_arr[print_arr[idx].width].arg_type= 'd';
      print_arr[idx].flags|= WIDTH_ARG;
      arg_count= max(arg_count, print_arr[idx].width + 1);
      fmt++;
    }
    else
      fmt= get_width(fmt, &print_arr[idx].width);
  }
  else
    print_arr[idx].width= SIZE_T_MAX;

  fmt= check_longlong(fmt, &args_arr[arg_index].have_longlong);
  if (*fmt == 'p')
    args_arr[arg_index].have_longlong= (sizeof(void *) == sizeof(longlong));
  args_arr[arg_index].arg_type= print_arr[idx].arg_type= *fmt;

  print_arr[idx].arg_idx= arg_index;
  print_arr[idx].begin= ++fmt;

  while (*fmt && *fmt != '%')
    fmt++;

  if (!*fmt)                                  /* End of format string */
  {
    uint i;
    print_arr[idx].end= fmt;
    /* Obtain parameters from the list */
    for (i= 0 ; i < arg_count; i++)
    {
      switch (args_arr[i].arg_type) {
      case 's':
      case 'b':
        args_arr[i].str_arg= va_arg(ap, char *);
        break;
      case 'f':
      case 'g':
        args_arr[i].double_arg= va_arg(ap, double);
        break;
      case 'd':
      case 'i':
      case 'u':
      case 'x':
      case 'X':
      case 'o':
      case 'p':
        if (args_arr[i].have_longlong)
          args_arr[i].longlong_arg= va_arg(ap,longlong);
        else if (args_arr[i].arg_type == 'd' || args_arr[i].arg_type == 'i')
          args_arr[i].longlong_arg= va_arg(ap, int);
        else
          args_arr[i].longlong_arg= va_arg(ap, uint);
        break;
      case 'c':
        args_arr[i].longlong_arg= va_arg(ap, int);
        break;
      default:
        DBUG_ASSERT(0);
      }
    }
Example #8
0
	int Image::get_cols() const {		
		return get_width() * get_channels();
	}
Example #9
0
/* check addon delimiter using current 4 as character
 */
static inline signed char aux_mid (zbar_decoder_t *dcode)
{
    unsigned e = get_width(dcode, 4) + get_width(dcode, 5);
    return(decode_e(e, dcode->ean.s4, 7));
}
void KheperaView::print_targetInfo(){
	if (is_target_set()){
		Point targetCenter = get_target_position();
		View::print_targetInfo(_frame, get_height(), get_width(), targetCenter);
	}
}
Example #11
0
/**
 * \brief Returns the size of this surface.
 * \return the size of this surface
 */
Size Surface::get_size() const {
  return { get_width(), get_height() };
}
void MapDrawingArea::setup_surfaces()
{
    surface = Cairo::ImageSurface::create(Cairo::FORMAT_RGB24, get_width(), get_height());
}
Example #13
0
/** Initializes the swapchain object. */
bool Anvil::Swapchain::init()
{
    uint32_t                                              n_swapchain_images             = 0;
    auto                                                  parent_surface_ptr             = m_create_info_ptr->get_rendering_surface();
    VkResult                                              result                         = VK_ERROR_INITIALIZATION_FAILED;
    Anvil::StructChainUniquePtr<VkSwapchainCreateInfoKHR> struct_chain_ptr;
    std::vector<VkImage>                                  swapchain_images;
    const VkSurfaceTransformFlagBitsKHR                   swapchain_transformation       = VK_SURFACE_TRANSFORM_IDENTITY_BIT_KHR;
    const WindowPlatform                                  window_platform                = m_create_info_ptr->get_window()->get_platform();
    const bool                                            is_offscreen_rendering_enabled = (window_platform   == WINDOW_PLATFORM_DUMMY                     ||
                                                                                            window_platform   == WINDOW_PLATFORM_DUMMY_WITH_PNG_SNAPSHOTS);

    m_size.width  = parent_surface_ptr->get_width ();
    m_size.height = parent_surface_ptr->get_height();

    /* not doing offscreen rendering */
    if (!is_offscreen_rendering_enabled)
    {
        const auto&                                    khr_swapchain_entrypoints = m_device_ptr->get_extension_khr_swapchain_entrypoints();
        Anvil::StructChainer<VkSwapchainCreateInfoKHR> struct_chainer;

        #ifdef _DEBUG
        {
            const Anvil::SGPUDevice* sgpu_device_ptr(dynamic_cast<const Anvil::SGPUDevice*>(m_device_ptr) );

            const Anvil::DeviceType    device_type                     = m_device_ptr->get_type();
            uint32_t                   n_physical_devices              = 0;
            bool                       result_bool                     = false;
            const char*                required_surface_extension_name = nullptr;
            VkSurfaceCapabilitiesKHR   surface_caps;
            VkCompositeAlphaFlagsKHR   supported_composite_alpha_flags = static_cast<VkCompositeAlphaFlagsKHR>(0);
            VkSurfaceTransformFlagsKHR supported_surface_transform_flags;

            #ifdef _WIN32
                #if defined(ANVIL_INCLUDE_WIN3264_WINDOW_SYSTEM_SUPPORT)
                    required_surface_extension_name = VK_KHR_WIN32_SURFACE_EXTENSION_NAME;
                #endif
            #else
                #if defined(ANVIL_INCLUDE_XCB_WINDOW_SYSTEM_SUPPORT)
                    required_surface_extension_name = VK_KHR_XCB_SURFACE_EXTENSION_NAME;
                #endif
            #endif

            anvil_assert(required_surface_extension_name == nullptr                                                            ||
                         m_device_ptr->get_parent_instance()->is_instance_extension_supported(required_surface_extension_name) );

            switch (device_type)
            {
                case Anvil::DEVICE_TYPE_SINGLE_GPU: n_physical_devices = 1; break;

                default:
                {
                    anvil_assert_fail();
                }
            }

            for (uint32_t n_physical_device = 0;
                          n_physical_device < n_physical_devices;
                        ++n_physical_device)
            {
                const Anvil::PhysicalDevice* current_physical_device_ptr = nullptr;

                switch (device_type)
                {
                    case Anvil::DEVICE_TYPE_SINGLE_GPU: current_physical_device_ptr = sgpu_device_ptr->get_physical_device(); break;

                    default:
                    {
                        anvil_assert_fail();
                    }
                }

                /* Ensure opaque composite alpha mode is supported */
                anvil_assert(parent_surface_ptr->get_supported_composite_alpha_flags(&supported_composite_alpha_flags) );

                anvil_assert(supported_composite_alpha_flags & VK_COMPOSITE_ALPHA_OPAQUE_BIT_KHR);

                /* Ensure we can use the swapchain image format  */
                anvil_assert(parent_surface_ptr->is_compatible_with_image_format(m_create_info_ptr->get_format(),
                                                                                &result_bool) );
                anvil_assert(result_bool);

                /* Ensure the transformation we're about to request is supported by the rendering surface */
                anvil_assert(parent_surface_ptr->get_supported_transformations(&supported_surface_transform_flags) );

                anvil_assert(supported_surface_transform_flags & swapchain_transformation);

                /* Ensure the requested number of swapchain images is reasonable*/
                anvil_assert(parent_surface_ptr->get_capabilities(&surface_caps) );

                anvil_assert(surface_caps.maxImageCount == 0                                 ||
                             surface_caps.maxImageCount >= m_create_info_ptr->get_n_images() );
            }
        }
        #endif

        {
            VkSwapchainCreateInfoKHR create_info;

            create_info.clipped               = true; /* we won't be reading from the presentable images */
            create_info.compositeAlpha        = VK_COMPOSITE_ALPHA_OPAQUE_BIT_KHR;
            create_info.flags                 = m_create_info_ptr->get_flags();
            create_info.imageArrayLayers      = 1;
            create_info.imageColorSpace       = VK_COLORSPACE_SRGB_NONLINEAR_KHR;
            create_info.imageExtent.height    = parent_surface_ptr->get_height();
            create_info.imageExtent.width     = parent_surface_ptr->get_width ();
            create_info.imageFormat           = m_create_info_ptr->get_format ();
            create_info.imageSharingMode      = VK_SHARING_MODE_EXCLUSIVE;
            create_info.imageUsage            = m_create_info_ptr->get_usage_flags();
            create_info.minImageCount         = m_create_info_ptr->get_n_images   ();
            create_info.oldSwapchain          = VK_NULL_HANDLE;
            create_info.pNext                 = nullptr;
            create_info.pQueueFamilyIndices   = nullptr;
            create_info.presentMode           = m_create_info_ptr->get_present_mode();
            create_info.preTransform          = swapchain_transformation;
            create_info.queueFamilyIndexCount = 0;
            create_info.sType                 = VK_STRUCTURE_TYPE_SWAPCHAIN_CREATE_INFO_KHR;
            create_info.surface               = parent_surface_ptr->get_surface();

            struct_chainer.append_struct(create_info);
        }

        struct_chain_ptr = struct_chainer.create_chain();

        parent_surface_ptr->lock();
        {
            result = khr_swapchain_entrypoints.vkCreateSwapchainKHR(m_device_ptr->get_device_vk(),
                                                                    struct_chain_ptr->get_root_struct(),
                                                                    nullptr, /* pAllocator */
                                                                   &m_swapchain);
        }
        parent_surface_ptr->unlock();

        anvil_assert_vk_call_succeeded(result);
        if (is_vk_call_successful(result) )
        {
            set_vk_handle(m_swapchain);
        }

        /* Retrieve swap-chain images */
        result = khr_swapchain_entrypoints.vkGetSwapchainImagesKHR(m_device_ptr->get_device_vk(),
                                                                   m_swapchain,
                                                                  &n_swapchain_images,
                                                                   nullptr); /* pSwapchainImages */

        anvil_assert_vk_call_succeeded(result);
        anvil_assert                  (n_swapchain_images >  0);

        swapchain_images.resize(n_swapchain_images);

        result = khr_swapchain_entrypoints.vkGetSwapchainImagesKHR(m_device_ptr->get_device_vk(),
                                                                   m_swapchain,
                                                                  &n_swapchain_images,
                                                                  &swapchain_images[0]);

        anvil_assert_vk_call_succeeded(result);
    }
    else /* offscreen rendering */
    {
        m_create_info_ptr->set_usage_flags(m_create_info_ptr->get_usage_flags() | VK_IMAGE_USAGE_TRANSFER_SRC_BIT);

        n_swapchain_images = m_create_info_ptr->get_n_images();
    }

    for (uint32_t n_result_image = 0;
                  n_result_image < n_swapchain_images;
                ++n_result_image)
    {
        /* Spawn an Image wrapper class for the swap-chain image. */
        if (!is_offscreen_rendering_enabled)
        {
            auto create_info_ptr = Anvil::ImageCreateInfo::create_swapchain_wrapper(m_device_ptr,
                                                                                    this,
                                                                                    swapchain_images[n_result_image],
                                                                                    n_result_image);

            create_info_ptr->set_mt_safety(Anvil::Utils::convert_boolean_to_mt_safety_enum(is_mt_safe() ) );

            m_image_ptrs[n_result_image] = Anvil::Image::create(std::move(create_info_ptr) );
        }
        else
        {
            auto create_info_ptr = Anvil::ImageCreateInfo::create_nonsparse_alloc(m_device_ptr,
                                                                                  VK_IMAGE_TYPE_2D,
                                                                                  m_create_info_ptr->get_format(),
                                                                                  VK_IMAGE_TILING_OPTIMAL,
                                                                                  m_create_info_ptr->get_usage_flags(),
                                                                                  m_size.width,
                                                                                  m_size.height,
                                                                                  1, /* base_mipmap_depth */
                                                                                  1,
                                                                                  VK_SAMPLE_COUNT_1_BIT,
                                                                                  QUEUE_FAMILY_GRAPHICS_BIT,
                                                                                  VK_SHARING_MODE_EXCLUSIVE,
                                                                                  false, /* in_use_full_mipmap_chain */
                                                                                  0,     /* in_memory_features       */
                                                                                  0,     /* in_create_flags          */
                                                                                  VK_IMAGE_LAYOUT_GENERAL,
                                                                                  nullptr);

            create_info_ptr->set_mt_safety(Anvil::Utils::convert_boolean_to_mt_safety_enum(is_mt_safe() ) );

            m_image_ptrs[n_result_image] = Anvil::Image::create(std::move(create_info_ptr) );
        }

        /* For each swap-chain image, create a relevant view */
        {
            auto create_info_ptr = Anvil::ImageViewCreateInfo::create_2D(m_device_ptr,
                                                                         m_image_ptrs[n_result_image].get(),
                                                                         0, /* n_base_layer */
                                                                         0, /* n_base_mipmap_level */
                                                                         1, /* n_mipmaps           */
                                                                         VK_IMAGE_ASPECT_COLOR_BIT,
                                                                         m_create_info_ptr->get_format(),
                                                                         VK_COMPONENT_SWIZZLE_R,
                                                                         VK_COMPONENT_SWIZZLE_G,
                                                                         VK_COMPONENT_SWIZZLE_B,
                                                                         VK_COMPONENT_SWIZZLE_A);

            create_info_ptr->set_mt_safety(Anvil::Utils::convert_boolean_to_mt_safety_enum(is_mt_safe() ) );

            m_image_view_ptrs[n_result_image] = Anvil::ImageView::create(std::move(create_info_ptr) );
        }

        result = VK_SUCCESS;
    }

    /* Sign up for present submission notifications. This is needed to ensure that number of presented frames ==
     * number of acquired frames at destruction time.
     */
    {
        std::vector<Anvil::Queue*> queues;

        switch (m_device_ptr->get_type() )
        {
            case Anvil::DEVICE_TYPE_SINGLE_GPU:
            {
                const std::vector<uint32_t>* queue_fams_with_present_support_ptr(nullptr);
                const auto                   rendering_surface_ptr              (m_create_info_ptr->get_rendering_surface() );
                const Anvil::SGPUDevice*     sgpu_device_ptr                    (dynamic_cast<const Anvil::SGPUDevice*>(m_device_ptr) );

                if (!rendering_surface_ptr->get_queue_families_with_present_support(&queue_fams_with_present_support_ptr) )
                {
                    break;
                }

                if (queue_fams_with_present_support_ptr == nullptr)
                {
                    anvil_assert(queue_fams_with_present_support_ptr != nullptr);
                }
                else
                {
                    for (const auto queue_fam : *queue_fams_with_present_support_ptr)
                    {
                        const uint32_t n_queues = sgpu_device_ptr->get_n_queues(queue_fam);

                        for (uint32_t n_queue = 0;
                                      n_queue < n_queues;
                                    ++n_queue)
                        {
                            auto queue_ptr = sgpu_device_ptr->get_queue_for_queue_family_index(queue_fam,
                                                                                               n_queue);

                            anvil_assert(queue_ptr != nullptr);

                            if (std::find(queues.begin(),
                                          queues.end(),
                                          queue_ptr) == queues.end() )
                            {
                                queues.push_back(queue_ptr);
                            }
                        }
                    }
                }

                break;
            }
        }

        for (auto queue_ptr : queues)
        {
            queue_ptr->register_for_callbacks(
                QUEUE_CALLBACK_ID_PRESENT_REQUEST_ISSUED,
                std::bind(&Swapchain::on_present_request_issued,
                          this,
                          std::placeholders::_1),
                this
            );

            m_observed_queues.push_back(queue_ptr);
        }
    }

    /* Sign up for "about to close the parent window" notifications. Swapchain instance SHOULD be deinitialized
     * before the window is destroyed, so we're going to act as nice citizens.
     */
    m_create_info_ptr->get_window()->register_for_callbacks(
        WINDOW_CALLBACK_ID_ABOUT_TO_CLOSE,
        std::bind(&Swapchain::on_parent_window_about_to_close,
                  this),
        this
    );

    return is_vk_call_successful(result);
}
Example #14
0
bool
KeyboardControl::is_landscape() {
  return get_width() >= get_height();
}
Example #15
0
 /**
  * Returns whether the ScrollBar is defined or has to be set up first
  * @return True if the ScrollBar is defined,
  * False if it has to be set up first
  */
 bool defined() const {
   return get_width() > 0;
 }
Example #16
0
	/** Inherited from tscrollbar. */
	unsigned get_length() const { return get_width(); }
Example #17
0
bool test_new_piece()
{
    bool result = true;
    for (int x = 0; x < 5; x++) {
        for (int y = 0; y < 5; y++) {
            for (int compt_small = 0; compt_small < 2; ++compt_small) {
                for (int compt_horizontal = 0; compt_horizontal < 2; ++compt_horizontal) {
                    int size;
                    bool small;
                    bool horizontal;

                    if (compt_small == 0) {
                        small = true;
                        size = 2;
                    } else {
                        small = false;
                        size = 3;
                    }

                    if (compt_horizontal == 0)
                        horizontal = true;
                    else
                        horizontal = false;

                    piece p = new_piece_rh(x, y, small, horizontal);
                    result = result && test_equality_int(x, get_x(p), "get_x");
                    result = result && test_equality_int(y, get_y(p), "get_y");
                    if (horizontal) {
                        result = result && test_equality_int(1, get_height(p), "get_height");
                        result = result && test_equality_int(size, get_width(p), "get_width");
                        result = result && test_equality_bool(true, can_move_x(p), "can_move_x");
                        result = result && test_equality_bool(false, can_move_y(p), "can_move_y");
                    } else {
                        result = result && test_equality_int(size, get_height(p), "get_height");
                        result = result && test_equality_int(1, get_width(p), "get_width");
                        result = result && test_equality_bool(false, can_move_x(p), "can_move_x");
                        result = result && test_equality_bool(true, can_move_y(p), "can_move_y");
                    }
                    delete_piece(p);
                }
            }
            for (int width = 1; width < 4; width++) {
                for (int height = 1; height < 4; height++) {
                    for (int compt_move_x = 0; compt_move_x < 2; ++compt_move_x) {
                        for (int compt_move_y = 0; compt_move_y < 2; ++compt_move_y) {
                            bool move_x;
                            bool move_y;

                            if (compt_move_x == 0)
                                move_x = true;
                            else
                                move_x = false;

                            if (compt_move_y == 0)
                                move_y = true;
                            else
                                move_y = false;

                            piece p = new_piece(x, y, width, height, move_x, move_y);

                            result = result && test_equality_int(x, get_x(p), "get_x");
                            result = result && test_equality_int(y, get_y(p), "get_y");
                            result = result && test_equality_int(height, get_height(p), "get_height");
                            result = result && test_equality_int(width, get_width(p), "get_width");
                            if (move_x)
                                result = result && test_equality_bool(true, can_move_x(p), "can_move_x");
                            else
                                result = result && test_equality_bool(false, can_move_x(p), "not can_move_x");
                            if (move_y)
                                result = result && test_equality_bool(true, can_move_y(p), "can_move_y");
                            else
                                result = result && test_equality_bool(false, can_move_y(p), "not can_move_y");

                            delete_piece(p);
                        }
                    }
                }
            }
        }
    }
    return result;
}
Example #18
0
/**
 * Callback when canvas recieves an expose event.  The icon is entirely
 * redrawn for every expose event instead of checking and redrawing
 * just the dirty regions.  Since the icon is so small, the gain
 * probably isn't worth the extra overhead.
 */
gboolean
on_canvas_expose_event(GtkWidget *widget, GdkEventExpose *event,
	gpointer unused_udata)
{
    GdkRectangle panel, rect, bar;

	(void) unused_udata;

    /*   just draw once for all expose events   */
    if (event->count)
        return FALSE;

    /*   setup image column   */
    panel.x = ICON_INSET;
    panel.y = ICON_INSET;
    panel.height = (widget->allocation.height - ICON_INSET2) / 3;
    panel.width = XPM_WIDTH;

    /*   draw connection icon   */
    center_image(&rect, &panel, con_pixbuf);
    gdk_draw_pixbuf(canvas->window, NULL, con_pixbuf, 0, 0,
		rect.x, rect.y, rect.width, rect.height, GDK_RGB_DITHER_NONE, 0, 0);

    panel.y += panel.height;

    /*   paint download icon   */
    center_image(&rect, &panel, down_pixbuf);
    gdk_draw_pixbuf(canvas->window, NULL, down_pixbuf, 0, 0,
		rect.x, rect.y, rect.width, rect.height, GDK_RGB_DITHER_NONE, 0, 0);

    panel.y += panel.height;

    /*   paint upload icon   */
    center_image(&rect, &panel, up_pixbuf);
    gdk_draw_pixbuf(canvas->window, NULL, up_pixbuf, 0, 0,
		rect.x, rect.y, rect.width, rect.height, GDK_RGB_DITHER_NONE, 0, 0);

    /*   setup bar column   */
    panel.x = XPM_WIDTH + ICON_INSET;
    panel.y = ICON_INSET;
    panel.width = (ICON_WIDTH - ICON_INSET2) - XPM_WIDTH;
    panel.height = (widget->allocation.height - ICON_INSET2);

    /*   draw bar panel   */
    gtk_paint_box(widget->style, widget->window,
                  GTK_STATE_INSENSITIVE, GTK_SHADOW_OUT,
                  NULL, widget, NULL,
                  panel.x, panel.y, panel.width, panel.height);

    panel.height /= 3;
    rect.x = panel.x + ICON_INSET2;
    rect.y = panel.y + ICON_INSET2;
    rect.width = panel.width - ICON_INSET4;
    rect.height = panel.height - ICON_INSET4;
    bar.x = rect.x + ICON_INSET;
    bar.y = rect.y + ICON_INSET;
    bar.width = rect.width - ICON_INSET2;
    bar.height = rect.height - ICON_INSET2;

    /*   paint connection bar   */
    gtk_paint_shadow(widget->style, widget->window,
                     GTK_STATE_NORMAL, GTK_SHADOW_IN,
                     NULL, widget, NULL,
                     rect.x, rect.y, rect.width, rect.height);
    gdk_draw_rectangle(widget->window, widget->style->black_gc, TRUE,
                       bar.x, bar.y, bar.width, bar.height);
    bar.width = get_width(&bar, leaf_cnt + norm_cnt + ultra_cnt, con_max);
    gdk_draw_rectangle(widget->window, widget->style->white_gc, TRUE,
                       bar.x, bar.y, bar.width, bar.height);

    panel.y += panel.height;
    rect.y += panel.height;
    bar.y += panel.height;
    bar.width = rect.width - ICON_INSET2;

    /*   paint download bar   */
    gtk_paint_shadow(widget->style, widget->window,
                     GTK_STATE_NORMAL, GTK_SHADOW_IN,
                     NULL, widget, NULL,
                     rect.x, rect.y, rect.width, rect.height);
    gdk_draw_rectangle(widget->window, widget->style->black_gc, TRUE,
                       bar.x, bar.y, bar.width, bar.height);
    bar.width = get_width(&bar, down_cnt, down_max);
    gdk_draw_rectangle(widget->window, widget->style->white_gc, TRUE,
                       bar.x, bar.y, bar.width, bar.height);

    panel.y += panel.height;
    rect.y += panel.height;
    bar.y += panel.height;
    bar.width = rect.width - ICON_INSET2;

    /*   paint upload bar   */
    gtk_paint_shadow(widget->style, widget->window,
                     GTK_STATE_NORMAL, GTK_SHADOW_IN,
                     NULL, widget, NULL,
                     rect.x, rect.y, rect.width, rect.height);
    gdk_draw_rectangle(widget->window, widget->style->black_gc, TRUE,
                       bar.x, bar.y, bar.width, bar.height);
    bar.width = get_width(&bar, up_cnt, up_max);
    gdk_draw_rectangle(widget->window, widget->style->white_gc, TRUE,
                       bar.x, bar.y, bar.width, bar.height);

    /*   paint border   */
    gtk_paint_shadow(widget->style, widget->window,
                     GTK_STATE_NORMAL, GTK_SHADOW_OUT,
                     NULL, widget, NULL, 0, 0, -1, -1);

    return FALSE;
}
Example #19
0
    std::shared_ptr<pipeline_profile> pipeline_config::resolve(std::shared_ptr<pipeline> pipe)
    {
        std::lock_guard<std::mutex> lock(_mtx);
        _resolved_profile.reset();
        auto requested_device = resolve_device_requests(pipe);

        std::vector<stream_profile> resolved_profiles;

        //if the user requested all streams, or if the requested device is from file and the user did not request any stream
        if (_enable_all_streams || (!_device_request.filename.empty() && _stream_requests.empty()))
        {
            if (!requested_device)
            {
                requested_device = get_first_or_default_device(pipe);
            }

            util::config config;
            config.enable_all(util::best_quality);
            _resolved_profile = std::make_shared<pipeline_profile>(requested_device, config, _device_request.record_output);
            return _resolved_profile;
        }
        else
        {
            util::config config;

            //If the user did not request anything, give it the default
            if (_stream_requests.empty())
            {
                if (!requested_device)
                {
                    requested_device = get_first_or_default_device(pipe);
                }

                auto default_profiles = get_default_configuration(requested_device);
                for (auto prof : default_profiles)
                {
                    auto p = dynamic_cast<video_stream_profile*>(prof.get());
                    if (!p)
                    {
                        LOG_ERROR("prof is not video_stream_profile");
                        throw std::logic_error("Failed to resolve request. internal error");
                    }
                    config.enable_stream(p->get_stream_type(), p->get_stream_index(), p->get_width(), p->get_height(), p->get_format(), p->get_framerate());
                }

                _resolved_profile = std::make_shared<pipeline_profile>(requested_device, config, _device_request.record_output);
                return _resolved_profile;
            }
            else
            {
                //User enabled some stream, enable only them   
                for(auto&& req : _stream_requests)
                {
                    auto r = req.second;
                    config.enable_stream(r.stream, r.stream_index, r.width, r.height, r.format, r.fps);
                }

                auto devs = pipe->get_context()->query_devices();
                if (devs.empty())
                {
                    auto dev = get_first_or_default_device(pipe);
                    _resolved_profile = std::make_shared<pipeline_profile>(dev, config, _device_request.record_output);
                    return _resolved_profile;
                }
                else
                {
                    for (auto dev_info : devs)
                    {
                        try
                        {
                            auto dev = dev_info->create_device();
                            _resolved_profile = std::make_shared<pipeline_profile>(dev, config, _device_request.record_output);
                            return _resolved_profile;
                        }
                        catch (...) {}
                    }
                }

                throw std::runtime_error("Failed to resolve request. No device found that satisfies all requirements");
            }
        }

        assert(0); //Unreachable code
    }
Example #20
0
void
EditorInputCenter::fill() {

  auto tilemap = dynamic_cast<TileMap*>(Editor::current()->layerselect.selected_tilemap);
  if (! tilemap) {
    return;
  }

  // The tile that is going to be replaced:
  Uint32 replace_tile = tilemap->get_tile_id(hovered_tile.x, hovered_tile.y);

  if (Editor::current()->tileselect.tiles->pos(0, 0) == tilemap->get_tile_id(hovered_tile.x, hovered_tile.y)) {
    // Replacing by the same tiles shouldn't do anything.
    return;
  }

  std::vector<Vector> pos_stack;
  pos_stack.clear();
  pos_stack.push_back(hovered_tile);
  auto tiles = Editor::current()->tileselect.tiles.get();

  // Passing recursively trough all tiles to be replaced...
  while (pos_stack.size()) {

    if (pos_stack.size() > 1000000) {
      log_warning << "More than 1'000'000 tiles in stack to fill, STOP" << std::endl;
      return;
    }

    Vector pos = pos_stack[pos_stack.size() - 1];
    Vector tpos = pos - hovered_tile;

    // Tests for being inside tilemap:
    if ( pos.x < 0 || pos.y < 0 ||
         pos.x >= tilemap->get_width() || pos.y >= tilemap->get_height()) {
      pos_stack.pop_back();
      continue;
    }

    input_tile(pos, tiles->pos(tpos.x, tpos.y));
    Vector pos_;

    // Going left...
    pos_ = pos + Vector(-1, 0);
    if (pos_.x >= 0) {
      if (replace_tile == tilemap->get_tile_id(pos_.x, pos_.y) &&
          replace_tile != tiles->pos(tpos.x - 1, tpos.y)) {
        pos_stack.push_back( pos_ );
        continue;
      }
    }

    // Going right...
    pos_ = pos + Vector(1, 0);
    if (pos_.x < tilemap->get_width()) {
      if (replace_tile == tilemap->get_tile_id(pos_.x, pos_.y) &&
          replace_tile != tiles->pos(tpos.x + 1, tpos.y)) {
        pos_stack.push_back( pos_ );
        continue;
      }
    }

    // Going up...
    pos_ = pos + Vector(0, -1);
    if (pos_.y >= 0) {
      if (replace_tile == tilemap->get_tile_id(pos_.x, pos_.y) &&
          replace_tile != tiles->pos(tpos.x, tpos.y - 1)) {
        pos_stack.push_back( pos_ );
        continue;
      }
    }

    // Going down...
    pos_ = pos + Vector(0, 1);
    if (pos_.y < tilemap->get_height()) {
      if (replace_tile == tilemap->get_tile_id(pos_.x, pos_.y) &&
          replace_tile != tiles->pos(tpos.x, tpos.y + 1)) {
        pos_stack.push_back( pos_ );
        continue;
      }
    }

    // When tiles on each side are already filled or occupied by another tiles, it ends.
    pos_stack.pop_back();
  }
}
Example #21
0
File: main.c Project: mgist/ponyc
int main(int argc, char* argv[])
{
  stringtab_init();

  pass_opt_t opt;
  pass_opt_init(&opt);

  opt.release = true;
  opt.output = ".";

  ast_setwidth(get_width());
  bool print_program_ast = false;
  bool print_package_ast = false;

  opt_state_t s;
  opt_init(args, &s, &argc, argv);

  bool ok = true;
  bool print_usage = false;
  int id;

  while((id = opt_next(&s)) != -1)
  {
    switch(id)
    {
      case OPT_VERSION:
        printf("%s\n", PONY_VERSION);
        return 0;

      case OPT_DEBUG: opt.release = false; break;
      case OPT_BUILDFLAG: define_build_flag(s.arg_val); break;
      case OPT_STRIP: opt.strip_debug = true; break;
      case OPT_PATHS: package_add_paths(s.arg_val); break;
      case OPT_OUTPUT: opt.output = s.arg_val; break;
      case OPT_LIBRARY: opt.library = true; break;
      case OPT_DOCS: opt.docs = true; break;

      case OPT_SAFE:
        if(!package_add_safe(s.arg_val))
          ok = false;
        break;

      case OPT_IEEEMATH: opt.ieee_math = true; break;
      case OPT_CPU: opt.cpu = s.arg_val; break;
      case OPT_FEATURES: opt.features = s.arg_val; break;
      case OPT_TRIPLE: opt.triple = s.arg_val; break;
      case OPT_STATS: opt.print_stats = true; break;

      case OPT_AST: print_program_ast = true; break;
      case OPT_ASTPACKAGE: print_package_ast = true; break;
      case OPT_TRACE: parse_trace(true); break;
      case OPT_WIDTH: ast_setwidth(atoi(s.arg_val)); break;
      case OPT_IMMERR: error_set_immediate(true); break;
      case OPT_VERIFY: opt.verify = true; break;
      case OPT_FILENAMES: opt.print_filenames = true; break;
      case OPT_CHECKTREE: enable_check_tree(true); break;

      case OPT_BNF: print_grammar(false, true); return 0;
      case OPT_ANTLR: print_grammar(true, true); return 0;
      case OPT_ANTLRRAW: print_grammar(true, false); return 0;

      case OPT_PASSES:
        if(!limit_passes(&opt, s.arg_val))
        {
          ok = false;
          print_usage = true;
        }
        break;

      default: usage(); return -1;
    }
  }

  for(int i = 1; i < argc; i++)
  {
    if(argv[i][0] == '-')
    {
      printf("Unrecognised option: %s\n", argv[i]);
      ok = false;
      print_usage = true;
    }
  }

#ifdef PLATFORM_IS_WINDOWS
  opt.strip_debug = true;
#endif

  if(!ok)
  {
    print_errors();

    if(print_usage)
      usage();

    return -1;
  }

  if(package_init(&opt))
  {
    if(argc == 1)
    {
      ok &= compile_package(".", &opt, print_program_ast, print_package_ast);
    } else {
      for(int i = 1; i < argc; i++)
        ok &= compile_package(argv[i], &opt, print_program_ast,
          print_package_ast);
    }
  }

  if(!ok && get_error_count() == 0)
    printf("Error: internal failure not reported\n");

  package_done(&opt);
  pass_opt_done(&opt);
  stringtab_done();

  return ok ? 0 : -1;
}
Example #22
0
/**
 * \brief Tests whether a rectangle has overlaps the outside part of the map area.
 * \param collision_box the rectangle to check
 * \return true if a point of the rectangle is outside the map area
 */
bool Map::test_collision_with_border(const Rectangle& collision_box) const {

  return collision_box.get_x() < 0 || collision_box.get_x() + collision_box.get_width() >= get_width()
    || collision_box.get_y() < 0 || collision_box.get_y() + collision_box.get_height() >= get_height();
}
Example #23
0
 void clear() {
   rectangle(0, 0, get_width(), get_height());
 }
Example #24
0
 /**
  * Returns whether the given y-Coordinate is on the up arrow
  * @param y y-Coordinate to check
  * @return True if the given y-Coordinate is on the up arrow,
  * False otherwise
  */
 bool in_up_arrow(PixelScalar y) const {
   return y < rc.top + get_width();
 }
Example #25
0
 void clear(const Brush &brush) {
   fill_rectangle(0, 0, get_width(), get_height(), brush);
 }
Example #26
0
 /**
  * Returns whether the given y-Coordinate is on the down arrow
  * @param y y-Coordinate to check
  * @return True if the given y-Coordinate is on the down arrow,
  * False otherwise
  */
 bool in_down_arrow(PixelScalar y) const {
   return y >= rc.bottom - get_width();
 }
Example #27
0
 void copy_and(const Bitmap &src) {
   copy_and(0, 0, get_width(), get_height(), src, 0, 0);
 }
Example #28
0
 /** Returns the height of the scrollable area of the ScrollBar */
 PixelScalar get_netto_height() const {
   return get_height() - 2 * get_width() - 1;
 }
int main(){
	char s[1024];
	v.clear();	ans.clear();
	col = 0;	row = 0;	count = 0;
	while(true){
		while(gets(s)){
			if(s[0] == '%'){//finish
				break;
			} else {
				int nowi = 0;
				while(s[nowi] != '\0'){
					if(s[nowi] != ' ')
						v.push_back(s[nowi]);
					nowi++;
				}
				row++;
			}
		}
		col = v.size() / row;
		//printf("col = %d row = %d count = %d\n", col, row, count);
		ans.resize(row);
		for(int i = 0; i < row; i++)
			ans[i].resize(col);
		for(int i = 0; i < row; i++)
			for(int j = 0; j < col; j++)
				ans[i][j] = 0;
		//calculate
		count = 1;
		for(int i = 0; i < row; i++)
			for(int j = 0; j < col; j++)
				if(ans[i][j] == 0){
					//printf("v(%d, %d) = %c\n", i, j, v[i*col+j]);
					fill_count(i, j, &count, &v[i*col+j]);
					count++;
				}
		//print
		int* max_width = (int*)malloc(sizeof(int)*col);
		int maxnumincol;
		for(int j = 0; j < col; j++){
			maxnumincol = 0;
			for(int i = 0; i < row; i++)
				if(ans[i][j] > maxnumincol)
					maxnumincol = ans[i][j];
			max_width[j] = get_width(maxnumincol) + 1;
		}
		max_width[0]--;//no need ' '
		for(int i = 0; i < row; i++){
			for(int j = 0; j < col; j++)
				printf("%*d", max_width[j], ans[i][j]);
			puts("");
		}
		puts("%");
		free(max_width);
		//clear
		v.clear();
		col = 0;row = 0;count = 0;
		if(s[0] != '%')// so op!!
			break;
	}
	return 0;
}
Example #30
0
int main() {
  int message_space, x = 0, y = 0;

  key k;

  char *message;

  start_charm();

  message_space = 3;

  clear_screen();
  move_cursor(x, y);
  blot_char('@');

  k = get_key();

  while (k != KEY_ESCAPE && k != KEY_Q) {
    switch (k) {
    case KEY_UP:
      if (y > 0) {
        y--;
      }

      break;

    case KEY_DOWN:
      if (y < get_height() - message_space - 1) {
        y++;
      }

      break;

    case KEY_RIGHT:
      if (x < get_width() - 1) {
        x++;
      }

      break;

    case KEY_LEFT:
      if (x > 0) {
        x--;
      }

      break;

    default:
      ;
    }

    clear_screen();

    message = (char *) malloc(20 * sizeof(char));

    if (message != NULL) {
      (void) snprintf(message, 20, "Cursor: (%d, %d)", get_x(), get_y());
      move_cursor(0, get_height());
      hcenter_string(message);

      free(message);

      move_cursor(x, y);
      blot_char('@');
    }

    k = get_key();
  }

  end_charm();

  return 0;
}