[edit] I guess this probably belongs in Advanced Help, since it's defining a custom Window class [/edit]
Hi, I was looking for some direction on subclassing ListboxItem.
I want to create a ListboxImageItem, that contains a CEGUI::Texture* member and uses that in its draw() function.
So far I've got the class framework down, including:
- the constructor that sets the texture member, the pixelSize, and obviously calls the ListboxItem constructor.
- the overloaded getPixelSize() function to return my size (which is always 64x64)
Now I seem to be having trouble with the draw() function - mostly because it's a bit lower level in CEGUI than the other things i've been doing and haven't really seen it used much.
From my understand(ish)ing, I can just set my texture to be used by the geometrybuffer that's passed in, use the overlap of whatever target+clipping rects to figure out vertices, append those vertices to the geometrybuffer, and return?
Below is what I'm using right now.. I don't get errors, and if I print out the rects I see things like {2, 2, 108, 66}, then {2, 66, 108, 130} etc. which looks good (I'm assuming the listbox gives me the extra horizontal space to draw in). I even see my Listbox get a scrollbar after I've added a few of these image items. Yet I don't see anything in my Listbox on the screen. Is there anything else I should be checking, or that I'm obviously doing wrong?
Let me know if you'd like any other info, and thanks for reading-
[edit] I just looked and the GeometryBuffer for OpenGL appears to use triangles, not quads. Changed to pushing 6 vertices, but still have the same problem (obviously I would have expected to see 1 triangle anywho) [/edit]
[editedit] so I was using the Vertex::colour_val member wrong; I now use CEGUI::colours to set these. By doing so, using a non-white colour shows me that my triangles are indeed being drawn where I want them. I verified that the size and ID of the CEGUI::Texture *tex is correct; the ID is the same as this texture that I use / render elsewhere, outside of the GUI, in my program. [/editedit]
When I set my colour up to be blue, I can see the blue box if I don't bind the texture (setActiveTexture(0)). However, if I bind my texture, I see a white box, regardless of my colour's RGB.
Code: Select all
ListboxImageItem::ListboxImageItem(std::string name, int artList, int artIndex) : ListboxItem(String(name.c_str()))
{
tex = InterfaceManager::Get().GetCustomTexture(artList, artIndex);
pixelSize = tex->getSize();
setSelectionBrushImage("WindowsLook", "MultiListSelectionBrush");
}
CEGUI::Size ListboxImageItem::getPixelSize() const
{
return pixelSize;
}
void ListboxImageItem::draw(GeometryBuffer &buffer, const Rect &targetRect, float alpha, const Rect *clipper) const
{
if (d_selected && d_selectBrush != 0)
d_selectBrush->draw(buffer, targetRect, clipper, getModulateAlphaColourRect(d_selectCols, alpha));
// a simple opaque white
colour white(1.0f, 1.0f, 1.0f);
Vertex vbuffer[6];
// top-left
vbuffer[0].position = Vector3(targetRect.d_left, targetRect.d_top, 0.0f);
vbuffer[0].colour_val = white;
vbuffer[0].tex_coords = Vector2(0.0f, 0.0f);
// bottom-left
vbuffer[1].position = Vector3(targetRect.d_left, targetRect.d_bottom, 0.0f);
vbuffer[1].colour_val = white;
vbuffer[1].tex_coords = Vector2(0.0f, 1.0f);
// bottom-right
vbuffer[2].position = Vector3(targetRect.d_right, targetRect.d_bottom, 0.0f);
vbuffer[2].colour_val = white;
vbuffer[2].tex_coords = Vector2(1.0f, 1.0f);
// top-right
vbuffer[3].position = Vector3(targetRect.d_right, targetRect.d_top, 0.0f);
vbuffer[3].colour_val = white;
vbuffer[3].tex_coords = Vector2(1.0f, 0.0f);
// top-left
vbuffer[4].position = Vector3(targetRect.d_left, targetRect.d_top, 0.0f);
vbuffer[4].colour_val = white;
vbuffer[4].tex_coords = Vector2(0.0f, 0.0f);
// bottom-right
vbuffer[5].position = Vector3(targetRect.d_right, targetRect.d_bottom, 0.0f);
vbuffer[5].colour_val = white;
vbuffer[5].tex_coords = Vector2(1.0f, 1.0f);
// give our vertices to the buffer for drawing
buffer.setActiveTexture(tex);
buffer.appendGeometry(vbuffer, 6);
}
This is the code where I create my CEGUI::Texture, which is passed to the ListboxImageItem constructor - I've verified that the OpenGL textures themselves are loaded properly (I can render them to the screen just fine)
Code: Select all
CEGUI::Texture *VideoManager::GenCustomTexture(int artList, int artIndex)
{
Texture *targetTex = GraphicsManager::Get().GetaTextureDB(artList, artIndex);
CEGUI::Texture *newTex = &CEGUIRenderer->createTexture();
((CEGUI::OpenGLTexture *)newTex)->setOpenGLTexture(targetTex->ID, CEGUI::Size(targetTex->data.width,
targetTex->data.height));
return newTex;
}