"Highlighting" a section of the screen
Posted: Sun Sep 21, 2014 10:44 pm
I'm working on a pseudo-GUI where my screen is split into panels. Each panel has its own 1MB buffer. Whenever a panel is selected, the drawing functions write to that buffer. Then whenever puts is called, all the buffers are copies to the primary video buffer, which is then copied to video mem. What I'm trying to achieve is whenever a panel is selected, it is drawn in a brighter color than the rest. However I'm having trouble formulating a way of doing this. Here's what I got so far:
inside puts:
The idea is to keep each panel's buffer unmodified and only copy the highlighted colors to video_buffer. Being bad with bit-wise manipulation, I think the "color |=" lines are incorrect, but if anybody could spot other issues, it would be appreciated.
Edit: fixed a bug. auto panelPtr = &panels[panelindex]; should be auto panelPtr = &panels;
Edit2: D'oh! That was the stupid bug. panelindex == getpanelindex() is redundant, it should've been i == getpanelindex()
inside puts:
Code: Select all
for (int i = 0; i < 3; ++i)
{
auto panelPtr = &panels[i];
uint32_t depth = vbeinfo->bpp / 8;
uint8_t* write_ptr = (uint8_t*) video_buffer;
uint8_t* read_ptr = (uint8_t*) panelPtr->video_buffer;
for (int y = panelPtr->ybase; y < panelPtr->endingline(); ++y)
{
for (int x = panelPtr->xbase; x < panelPtr->endingcolumn(); ++x)
{
unsigned where = x * depth + y * vbeinfo->pitch;
uint8_t color1 = read_ptr[where];
uint8_t color2 = read_ptr[where + 1];
uint8_t color3 = read_ptr[where + 2];
if (panelindex == getpanelindex())
{
// I suspect these lines might be the issue
color1 |= 0x555 & 255;
color2 |= (0x555 >> 8) & 255;
color3 |= (0x555 >> 16) & 255;
}
write_ptr[where] = color1;
write_ptr[where + 1] = color2;
write_ptr[where + 2] = color3;
}
}
}
uint8_t* writePtr = (uint8_t*) video_buffer_addr;
uint8_t* readPtr = (uint8_t*) video_buffer;
memcpy(writePtr, readPtr, vbeinfo->pitch * rows);
Edit: fixed a bug. auto panelPtr = &panels[panelindex]; should be auto panelPtr = &panels;
Edit2: D'oh! That was the stupid bug. panelindex == getpanelindex() is redundant, it should've been i == getpanelindex()