Exemplo n.º 1
0
void
RPG_Graphics_Cursor_Manager::reset(const bool& update_in,
                                   const bool& lockedAccess_in,
                                   const bool& debug_in)
{
  RPG_TRACE(ACE_TEXT("RPG_Graphics_Cursor_Manager::reset"));

  if (update_in)
  {
    // sanity check(s)
    ACE_ASSERT(myHighlightWindow);

    SDL_Rect dirty_region = {0, 0, 0, 0};
    updateBG(dirty_region,
             NULL,
             lockedAccess_in,
             debug_in);

    myHighlightWindow->invalidate(dirty_region);
  } // end IF
	else
	  invalidateBG();
  resetHighlightBG(std::make_pair(std::numeric_limits<unsigned int>::max(),
                                  std::numeric_limits<unsigned int>::max()));
}
Exemplo n.º 2
0
void LCD::paintEvent(QPaintEvent* event) {

	Q_UNUSED(event);

	// nothing to draw?
	if (values.empty()) {return;}

	QPainter p(this);

	// update and draw the background ground grid
	updateBG();
	p.drawImage(0,0,bg);


	p.setPen(paint.pen);
	float h = float(height());

	// draw all bars
	for (unsigned int i = 0; i < values.size(); ++i) {

		unsigned int x = 2 + i*3;
		if ((int)x > width()) {break;}

		if (!centered) {
			int y1 = int(h - values[i] * h);
			p.drawLine(x-1, int(h), x-1, y1);

		} else if (centered == 1) {
			int y1 = int(h/2 - values[i] * h * 0.45);
			p.drawLine(x-1, int(h/2), x-1, y1);

		}

	}

}
Exemplo n.º 3
0
void
RPG_Graphics_Cursor_Manager::putHighlights(const RPG_Map_PositionList_t& mapPositions_in,
                                           const RPG_Graphics_Offsets_t& graphicsPositions_in,
                                           const RPG_Graphics_Position_t& viewPort_in,
                                           SDL_Rect& dirtyRegion_out,
																					 const bool& lockedAccess_in,
																					 const bool& debug_in)
{
  RPG_TRACE(ACE_TEXT("RPG_Graphics_Cursor_Manager::putHighlights"));

  // step0: init return value(s)
  ACE_OS::memset(&dirtyRegion_out, 0, sizeof(dirtyRegion_out));

  // sanity check
  ACE_ASSERT(myHighlightTile);
  ACE_ASSERT(myHighlightWindow);
  SDL_Surface* target_surface = myHighlightWindow->getScreen();
  ACE_ASSERT(target_surface);

  // step1: restore old backgrounds
	if (myScreenLock && lockedAccess_in)
    myScreenLock->lock();
  restoreHighlightBG(viewPort_in,
                     dirtyRegion_out,
                     NULL,
                     false,
										 debug_in);

  // step2: get new backgrounds
  SDL_Rect dirty_region;
  storeHighlightBG(mapPositions_in,
                   graphicsPositions_in,
                   dirty_region,
                   false);
  dirtyRegion_out = RPG_Graphics_SDL_Tools::boundingBox(dirty_region,
                                                        dirtyRegion_out);

  // step3: place highlights
	std::vector<SDL_Rect> clip_rectangles;
	SDL_Rect clip_rectangle = {static_cast<Sint16>(myBGPosition.first),
														 static_cast<Sint16>(myBGPosition.second),
														 static_cast<Uint16>(myBG->w),
														 static_cast<Uint16>(myBG->h)}, temp_rectangle;
  myHighlightWindow->clip();
  for (RPG_Graphics_OffsetsConstIterator_t iterator = graphicsPositions_in.begin();
       iterator != graphicsPositions_in.end();
       iterator++)
  {
    RPG_Graphics_Surface::put(*iterator,
                              *myHighlightTile,
                              target_surface,
                              dirty_region);
    dirtyRegion_out = RPG_Graphics_SDL_Tools::boundingBox(dirty_region,
                                                          dirtyRegion_out);
		temp_rectangle = RPG_Graphics_SDL_Tools::intersect(clip_rectangle,
																											 dirty_region);
		if (temp_rectangle.w || temp_rectangle.h)
			clip_rectangles.push_back(temp_rectangle);
  } // end FOR

  if (debug_in)
  {
    RPG_Graphics_Offset_t screen_position = graphicsPositions_in.front();

    // step1: show coordinates in top border
    std::ostringstream converter;
    std::string text = ACE_TEXT("[");
    converter << screen_position.first;
    text += converter.str();
    text += ACE_TEXT(",");
    converter.str(ACE_TEXT(""));
    converter.clear();
    converter << screen_position.second;
    text += converter.str();
    text += ACE_TEXT("]");
    RPG_Graphics_TextSize_t text_size =
        RPG_Graphics_Common_Tools::textSize(FONT_MAIN_SMALL,
                                            text);
    RPG_Graphics_IWindowBase* parent = myHighlightWindow->getParent();
    unsigned int border_top, dummy;
    parent->getBorders(border_top,
                       dummy,
                       dummy,
                       dummy);
    SDL_Rect window_area;
    myHighlightWindow->getArea(window_area, true);
    static RPG_Graphics_TextSize_t highlight_text_size_bg =
        std::make_pair(0, 0);
    static SDL_Surface* highlight_coordinates_bg = NULL;
    if (!highlight_coordinates_bg)
    {
      highlight_text_size_bg =
          RPG_Graphics_Common_Tools::textSize(FONT_MAIN_SMALL,
                                              std::string(ACE_TEXT_ALWAYS_CHAR("[0000,0000]")));
      highlight_coordinates_bg =
          RPG_Graphics_Surface::create(highlight_text_size_bg.first,
                                       highlight_text_size_bg.second);
      RPG_Graphics_Surface::get(std::make_pair((((window_area.w * 3) / 4) -
                                                (highlight_text_size_bg.first / 2)),
                                               ((border_top - highlight_text_size_bg.second) / 2)),
                                true,
                                *target_surface,
                                *highlight_coordinates_bg);
    } // end IF
    else
    {
      RPG_Graphics_Surface::put(std::make_pair((((window_area.w * 3) / 4) -
                                                (highlight_text_size_bg.first / 2)),
                                               ((border_top - highlight_text_size_bg.second) / 2)),
                                *highlight_coordinates_bg,
                                target_surface,
                                dirty_region);
      dirtyRegion_out = RPG_Graphics_SDL_Tools::boundingBox(dirty_region,
                                                            dirtyRegion_out);
    } // end ELSE
    RPG_Graphics_Surface::putText(FONT_MAIN_SMALL,
                                  text,
                                  RPG_Graphics_SDL_Tools::colorToSDLColor(RPG_Graphics_SDL_Tools::getColor(RPG_GRAPHICS_FONT_DEF_COLOR,
                                                                                                           *target_surface),
                                                                          *target_surface),
                                  true, // add shade
                                  RPG_Graphics_SDL_Tools::colorToSDLColor(RPG_Graphics_SDL_Tools::getColor(RPG_GRAPHICS_FONT_DEF_SHADECOLOR,
                                                                                                           *target_surface),
                                                                          *target_surface),
                                  std::make_pair((((window_area.w * 3) / 4) -
                                                  (text_size.first / 2)),
                                                 ((border_top - text_size.second) / 2)),
                                  target_surface,
                                  dirty_region);
    dirtyRegion_out = RPG_Graphics_SDL_Tools::boundingBox(dirty_region,
                                                          dirtyRegion_out);

    // step2: show highlight bg in top right corner
    SDL_Surface* highlight_bg = myHighlightBGCache.front().second;
    ACE_ASSERT(target_surface->w >= highlight_bg->w);
    ACE_ASSERT(target_surface->h >= highlight_bg->h);

    RPG_Graphics_Surface::unclip();
    RPG_Graphics_Surface::put(std::make_pair((target_surface->w - highlight_bg->w),
                                             0),
                              *highlight_bg,
                              target_surface,
                              dirty_region);
    RPG_Graphics_Surface::clip();

    dirtyRegion_out = RPG_Graphics_SDL_Tools::boundingBox(dirty_region,
                                                          dirtyRegion_out);
  } // end IF

	// step4: update (part(s) of) cursor bg
	for (std::vector<SDL_Rect>::const_iterator iterator = clip_rectangles.begin();
			 iterator != clip_rectangles.end();
			 iterator++)
	{
		updateBG(dirty_region,
						 &(*iterator),
						 false,
						 debug_in);
		dirtyRegion_out = RPG_Graphics_SDL_Tools::boundingBox(dirty_region,
																													dirtyRegion_out);
	} // end FOR
	if (myScreenLock && lockedAccess_in)
		myScreenLock->unlock();
	myHighlightWindow->unclip();
}
Exemplo n.º 4
0
void
RPG_Graphics_Cursor_Manager::restoreHighlightBG(const RPG_Graphics_Position_t& viewPort_in,
                                                SDL_Rect& dirtyRegion_out,
																								const SDL_Rect* clipRectangle_in,
                                                const bool& lockedAccess_in,
                                                const bool& debug_in)
{
  RPG_TRACE(ACE_TEXT("RPG_Graphics_Cursor_Manager::restoreHighlightBG"));

  // step0: init return value(s)
  ACE_OS::memset(&dirtyRegion_out, 0, sizeof(dirtyRegion_out));

  // sanity check(s)
  ACE_ASSERT(myHighlightWindow);
  SDL_Surface* target_surface = myHighlightWindow->getScreen();
  ACE_ASSERT(target_surface);
  ACE_ASSERT(!myHighlightBGCache.empty());
  if ((myHighlightBGCache.size() == 1) &&
      (myHighlightBGCache.front().first ==
       std::make_pair(std::numeric_limits<unsigned int>::max(),
                      std::numeric_limits<unsigned int>::max())))
    return; // nothing to do

	SDL_Rect window_area, clip_area, clip_rectangle, source_clip_rectangle;
	myHighlightWindow->getArea(window_area, true);
	myHighlightWindow->getArea(clip_area, false);
	if (clipRectangle_in)
		clip_area = *clipRectangle_in;
	RPG_Graphics_Position_t screen_position;
	SDL_Rect cursor_clip_rectangle = {static_cast<Sint16>(myBGPosition.first),
																		static_cast<Sint16>(myBGPosition.second),
																		static_cast<Uint16>(myBG->w),
																		static_cast<Uint16>(myBG->h)}, temp_rectangle;
	std::vector<SDL_Rect> cursor_relevant_clip_rectangles;
	myHighlightWindow->clip();
	if (lockedAccess_in && myScreenLock)
		myScreenLock->lock();
	for (RPG_Graphics_TileCacheConstIterator_t iterator = myHighlightBGCache.begin();
			 iterator != myHighlightBGCache.end();
			 iterator++)
	{
		screen_position =
			RPG_Graphics_Common_Tools::map2Screen((*iterator).first,
																						std::make_pair(window_area.w,
																													 window_area.h),
																						viewPort_in);

		source_clip_rectangle.x = screen_position.first;
		source_clip_rectangle.y = screen_position.second;
		source_clip_rectangle.w = (*iterator).second->w;
		source_clip_rectangle.h = (*iterator).second->h;
		clip_rectangle = RPG_Graphics_SDL_Tools::intersect(source_clip_rectangle,
																											 clip_area);
		dirtyRegion_out = RPG_Graphics_SDL_Tools::boundingBox(dirtyRegion_out,
																													clip_rectangle);
		source_clip_rectangle.x = clip_rectangle.x - screen_position.first;
		source_clip_rectangle.y = clip_rectangle.y - screen_position.second;
		if (!clip_rectangle.w || !clip_rectangle.h)
			continue; // nothing to do...

		temp_rectangle = clip_rectangle;
		// restore / clear background
		if (SDL_BlitSurface((*iterator).second,     // source
												&source_clip_rectangle, // aspect
												target_surface,         // target
												&clip_rectangle))       // aspect
			ACE_DEBUG((LM_ERROR,
									ACE_TEXT("failed to SDL_BlitSurface(): \"%s\", continuing\n"),
									ACE_TEXT(SDL_GetError())));

		temp_rectangle = RPG_Graphics_SDL_Tools::intersect(cursor_clip_rectangle,
																											 temp_rectangle);
		if (temp_rectangle.w || temp_rectangle.h)
			cursor_relevant_clip_rectangles.push_back(temp_rectangle);
	} // end FOR
	if (lockedAccess_in && myScreenLock)
		myScreenLock->unlock();
	myHighlightWindow->unclip();

  // *NOTE*: iff the highlight bg(s) intersected the cursor bg, an update is
  // needed of (that/those bit(s) of) the cursor bg...
	for (std::vector<SDL_Rect>::const_iterator iterator = cursor_relevant_clip_rectangles.begin();
			 iterator != cursor_relevant_clip_rectangles.end();
			 iterator++)
	{
		updateBG(temp_rectangle,
						 &(*iterator),
						 lockedAccess_in,
						 debug_in);
		if (debug_in)
			dirtyRegion_out = RPG_Graphics_SDL_Tools::boundingBox(temp_rectangle,
																  dirtyRegion_out);
	} // end FOR
}