Example #1
0
static int SDL_line(SDL_Surface* dst, int16_t x1, int16_t y1, int16_t x2, int16_t y2,
                    uint8_t r, uint8_t g, uint8_t b, uint8_t a)
{
    if(x1 == x2) return vlineRGBA(dst, x1, y1, y2, r, g, b, a);
    if(y1 == y2) return hlineRGBA(dst, x1, x2, y1, r, g, b, a);
    return lineRGBA(dst, x1, y1, x2, y2, r, g, b, a);
}
Example #2
0
void graph_render(graph_state_t* state, struct background * bg, SDL_Color line_color)
{
    rect_t r;
    if(!state->history) return;

    r.x = 0;
    r.y = 0;
    r.w = state->width;
    r.h = state->height;

    fill_background(graph_surface, &r, bg);

    int prevX = x_to_pixel(state, state->history[0]);
    for(int i = 1; i < state->width; i++)
    {
        int x = x_to_pixel(state, state->history[i]);
        int delta = 0;
        if(x > prevX) delta = 1;
        if(x < prevX) delta = -1;
        //surf, x, y1, y2, r,g,b,a
        vlineRGBA(graph_surface, state->width - i, prevX + delta, x, line_color.r, line_color.g, line_color.b, 255);
        //surf, x1, y1, x2, y2, r,g,b,a
        prevX = x;
    }
}
Example #3
0
void ui_waveform_render(){
    rect_t r;
    rect_origin(&layout.waveform.rect, &r);

    SDL_FillRect(waveform_surface, &r, SDL_MapRGB(waveform_surface->format, 30, 30, 30));
#define MAX(a, b) ((a > b) ? a : b)
    int h;
    SDL_Color c;
    if(skip < 1) skip = 1;

    for(int j = 0; j < N_WF_BINS; j++){
        float * history = waveform_bins[j].history;
        int hptr = waveform_bins[j].hptr; 
        hptr -= hptr % skip;
        c = waveform_bins[j].color;

        for(int i = 0; i < layout.waveform.w; i++)
        {
            float x = 0.;
            for(int k = 0; k < skip; k++){
                hptr--;
                if(hptr < 0)
                    hptr = WAVEFORM_HISTORY_SIZE;
                x = MAX(x, history[hptr]);
            }
            h = x * layout.waveform.h;
            vlineRGBA(waveform_surface, layout.waveform.w - i, (layout.waveform.h + h) / 2, (layout.waveform.h - h) / 2, c.r, c.g, c.b, 255);
        }
    }
    for(int i = 0; i < layout.waveform.w; i++){
        char l = 0;
        for(int k = 0; k < skip; k++){
            l = l | beat_lines[i * skip + k];
        }
        if(l & 1)
            vlineRGBA(waveform_surface, layout.waveform.w - i, layout.waveform.y, layout.waveform.h, 128, 255, 0, 200);
        if(l & 2)
            vlineRGBA(waveform_surface, layout.waveform.w - i, layout.waveform.y, layout.waveform.h, 255, 128, 0, 200);
        if(l & 4)
            vlineRGBA(waveform_surface, layout.waveform.w - i, layout.waveform.y, layout.waveform.h, 255, 0, 0, 200);
         
    }
}
Example #4
0
void TriangleTool::draw(SDL_Renderer *r)
{
	int x, y;
	SDL_GetMouseState(&x, &y);

	if (active && draw_bounds.collide_point(x, y))
	{
		SDL_ShowCursor(SDL_DISABLE);
		hlineRGBA(r, x - pointer_width, x + pointer_width, y, 0, 0, 0, 255);
		vlineRGBA(r, x, y - pointer_width, y + pointer_width, 0, 0, 0, 255);
	}
	else 
		SDL_ShowCursor(SDL_ENABLE);
}
Example #5
0
void GameDrawer::Draw()
{
   boxRGBA(m_pSurface, m_pBoardMetrics->GetBoardLeft(), m_pBoardMetrics->GetBoardTop(), m_pBoardMetrics->GetBoardRight(), m_pBoardMetrics->GetBoardBottom(), GAME_BACKGROUND_R, GAME_BACKGROUND_G, GAME_BACKGROUND_B, 230);

   for(int nX=0; nX<=m_pBoardMetrics->GetWidth(); nX++) {
       vlineRGBA(m_pSurface, m_pBoardMetrics->GetLeftSpots() + nX*m_pBoardMetrics->GetPieceSize(), m_pBoardMetrics->GetTopSpots(), m_pBoardMetrics->GetBottomSpots(), 0, 0, 0, 255);
   }

   for(int nY=0; nY<=m_pBoardMetrics->GetHeight(); nY++) {
       hlineRGBA(m_pSurface, m_pBoardMetrics->GetLeftSpots(), m_pBoardMetrics->GetRightSpots(), m_pBoardMetrics->GetTopSpots() + nY*m_pBoardMetrics->GetPieceSize(), 0, 0, 0, 255);
   }

   for(int nX=0; nX<m_pBoardMetrics->GetWidth(); nX++)
      if( IsBinaryColDuplicate(m_Binary, nX) != BINARYLIB_ROW_UNIQUE ) {
         SDL_Rect rect;
         rect.w = m_pBoardMetrics->GetPieceSize();
         rect.h = m_pBoardMetrics->GetBottomSpots() - m_pBoardMetrics->GetTopSpots();
         rect.x = m_pBoardMetrics->GetXPos(nX);
         rect.y = m_pBoardMetrics->GetTopSpots();
         SDL_FillRect(m_pSurface, &rect, SDL_MapRGB(m_pSurface->format, 255, 255, 0));
      }

   for(int nY=0; nY<m_pBoardMetrics->GetHeight(); nY++)
      if( IsBinaryRowDuplicate(m_Binary, nY) != BINARYLIB_ROW_UNIQUE ) {
         SDL_Rect rect;
         rect.w = m_pBoardMetrics->GetRightSpots() - m_pBoardMetrics->GetLeftSpots();
         rect.h = m_pBoardMetrics->GetPieceSize();
         rect.x = m_pBoardMetrics->GetLeftSpots();
         rect.y = m_pBoardMetrics->GetYPos(nY);
         SDL_FillRect(m_pSurface, &rect, SDL_MapRGB(m_pSurface->format, 255, 255, 0));
      }

   for(int nX=0; nX<m_pBoardMetrics->GetWidth(); nX++) {
       for(int nY=0; nY<m_pBoardMetrics->GetHeight(); nY++) {
           DrawCell(nX, nY);
       }
   }
}
Example #6
0
void hc_menu::draw(void)
{
	if(active)
	{
		active->draw();
		return;
	}

	hc_box *tmp = nullptr;
	for(int i = 0; i < counter; i++)
	{
		if(is_in_rect(mouse_x, mouse_y, x, y + i * 64, max_width + 32, 48))
		{
			tmp = box_active;
			if(mouse->get_state() == 1)
			{
				if(entries[i]->type == HC_MENU_ENTRY_SLIDER)
				{
					entries[i]->value = mouse_x - (x + entries[i]->width - 255 + 16);
					if(entries[i]->value > 255)
					{
						entries[i]->value = 255;
					}
					else if(entries[i]->value < 0)
					{
						entries[i]->value = 0;
					}
				}

			}
		}
		else
		{
			tmp = box_normal;
		}
		tmp->draw(x, y + i * 64, max_width + 32, 48);
		string label = entries[i]->label;

		if(entries[i]->type == HC_MENU_ENTRY_TEXT)
		{
			label += ": " + entries[i]->text_value;
		}
		else if(entries[i]->type == HC_MENU_ENTRY_TOOGLE)
		{
			vector<string> toogle = explode(entries[i]->text_value, '|');
			label += ": " + toogle[entries[i]->value];
		}
		else if(entries[i]->type == HC_MENU_ENTRY_PASSWORD)
		{
			label += ": ";
			for(uint8_t j = 0; j < entries[i]->text_value.length(); j++) // hide the password
			{
				label += "*";
			}
		}
		else if(entries[i]->type == HC_MENU_ENTRY_SLIDER)
		{
			hlineRGBA(renderer, x + entries[i]->width - 255 + 16, x + entries[i]->width + 16, y + 24 + 64 * i, 0, 0, 0, 255);
			vlineRGBA(renderer, x + entries[i]->width - 255 + 16 + entries[i]->value, y + 24 + 64 * i - 5, y + 24 + 64 * i + 5, 0, 0, 0, 255);
		}
		text->print(x + width() / 2 - entries[i]->width / 2, y + 16 + 64 * i, 0, 0, label.c_str());
	}
}
Example #7
0
void Game::UpdateDisplay()
{
	m_ColorIntensity.Animate();

	//Draw background
	if( !is_classic ) {
		SDL_BlitSurface(m_pBackground, NULL, m_pScreen, NULL);
	} else {
		SDL_FillRect(m_pScreen, NULL, SDL_MapRGB(m_pScreen->format, 255, 255, 255));
	}

	int nWidth = GetHitoriBoardWidth(m_Hitori);
	int nHeight = GetHitoriBoardHeight(m_Hitori);

	int nPieceWidth = (SCREEN_WIDTH-1)/nWidth;//The -1 is just so range of pixels is 0->Dimension-1; instead of 0->Dimension
	int nPieceHeight = (SCREEN_HEIGHT-1)/nHeight;

        int nPieceSize = nPieceWidth < nPieceHeight ? nPieceWidth : nPieceHeight;

	int nBoardWidth = nPieceSize * nWidth;
	int nBoardHeight = nPieceSize * nHeight;

	int nTop = (SCREEN_HEIGHT - nBoardHeight) / 2;
	int nLeft = (SCREEN_WIDTH - nBoardWidth) / 2;

	/*SDL_Rect rectBoard;
	rectBoard.x = nLeft;
	rectBoard.y = nTop;
	rectBoard.w = nBoardWidth;
	rectBoard.h = nBoardHeight;
	SDL_FillRect(m_pScreen, &rectBoard, SDL_MapRGB(m_pScreen->format, GAME_BACKGROUND_R, GAME_BACKGROUND_G, GAME_BACKGROUND_B));*/
	boxRGBA(m_pScreen, nLeft, nTop, nLeft + nBoardWidth, nTop + nBoardHeight,  GAME_BACKGROUND_R, GAME_BACKGROUND_G, GAME_BACKGROUND_B, 180);

	for(int nX=0; nX<=nWidth; nX++) {
		vlineRGBA(m_pScreen, nLeft + nX*nPieceSize, nTop, nTop + nBoardHeight, 0, 0, 0, 255);
	}

	for(int nY=0; nY<=nHeight; nY++) {
		hlineRGBA(m_pScreen, nLeft, nLeft + nBoardWidth, nTop + nY*nPieceSize, 0, 0, 0, 255);
	}

	for(int nX=0; nX<nWidth; nX++) {
                for(int nY=0; nY<nHeight; nY++) {
			DrawCell(nX, nY, nLeft, nTop, nPieceSize);
                }
        }

        DrawSelector(nLeft, nTop, nPieceSize);

#ifdef USE_GRAPHIC_YOU_WIN
	if( m_bGameOver ) {
		if( m_pWinGraphic == NULL ) {
		m_pWinGraphic = nSDL_LoadImage(image_HitoriYouWin);
                SDL_SetColorKey(m_pWinGraphic, SDL_SRCCOLORKEY, SDL_MapRGB(m_pWinGraphic->format, 255, 255, 255));
		}

		SDL_Rect rectWin;
		rectWin.x = (SCREEN_WIDTH - m_pWinGraphic->w)/2;
		rectWin.y = (SCREEN_HEIGHT - m_pWinGraphic->h)/2;
		rectWin.w = m_pWinGraphic->w;
		rectWin.h = m_pWinGraphic->h;
	
		SDL_BlitSurface(m_pWinGraphic, NULL, m_pScreen, &rectWin);	
	}
#else
	if( !m_YouWinMessage.Animate() )
#endif
        {
                SDL_UpdateRect(m_pScreen, 0, 0, SCREEN_WIDTH, SCREEN_HEIGHT);
        }
}