void g2Controller::DrawComponentRect(const char* ElementName, int DestX, int DestY, int Width, int Height) { // Get the size of the source image int ImageWidth, ImageHeight; GetTheme()->GetComponentSize(ElementName, &ImageWidth, &ImageHeight); // Precompute the offsets and subset sizes int Y1 = DestY; int H1 = ImageHeight / 3; int Y3 = DestY + Height - H1; int H3 = H1; int Y2 = DestY + H1; int H2 = ImageHeight - H1 - H3; /*** Draw ***/ // Draw the top DrawComponentStretch(ElementName, DestX, Y1, Width, 0, H1 - 1); // Draw the bottom DrawComponentStretch(ElementName, DestX, Y3, Width, ImageHeight - H3, ImageHeight - 1); // Fill each row as best as possible int i; for(i = 0; i < (Height - H1 - H2) / H2; i++) DrawComponentStretch(ElementName, DestX, Y2 + i * H2, Width, H1, H1 + H2 - 1); DrawComponentStretch(ElementName, DestX, Y2 + H2 * i, Width, H1, H1 + Height - H1 - H2 * i - H3 - 1); }
void g2Panel::Render(int pX, int pY) { // Get the size of the source image int ImageWidth, ImageHeight; GetTheme()->GetComponentSize(g2Theme_Panel, &ImageWidth, &ImageHeight); // Precompute the offsets and subset sizes int Y1 = pY; int H1 = ImageHeight / 3; int Y3 = pY + Height - H1; int H3 = H1; int Y2 = pY + H1; int H2 = H1; /*** Draw ***/ // Draw the top DrawComponentStretch(g2Theme_Panel, pX, Y1, Width, 0, ImageHeight / 3); // Draw the bottom DrawComponentStretch(g2Theme_Panel, pX, Y3, Width, 2 * (ImageHeight / 3), ImageHeight); // Fill each row as best as possible for(int i = 0; i <= (Height - H1 - H3) / H2; i++) { if(i < (Height - H1 - H3) / H2) DrawComponentStretch(g2Theme_Panel, pX, Y2 + i * H2, Width, ImageHeight / 3 + 1, 2 * (ImageHeight / 3) + 1); else DrawComponentStretch(g2Theme_Panel, pX, Y2 + i * H2, Width, ImageHeight / 3 + 1, ImageHeight / 3 + Height % H2); } }
void g2Slider::Render(int pX, int pY) { // Center on the vertical the user's slider controller int SliderWidth, SliderHeight; int ControllerHeight; GetTheme()->GetComponentSize(g2Theme_SliderButton, &SliderWidth, &SliderHeight); GetTheme()->GetComponentSize(g2Theme_Slider, NULL, &ControllerHeight); // Which is the total height? We may need to shift the slider's background // since some slider buttons are taller than the bg int TotalHeight = SliderHeight; if(ControllerHeight > TotalHeight) TotalHeight = ControllerHeight; // Render the centered background DrawComponentStretch(g2Theme_Slider, pX, pY + TotalHeight / 2 - ControllerHeight / 2, Width); // Draw slider button g2ThemeElement ButtonStyle = g2Theme_SliderButton; if(GetDisabled()) ButtonStyle = g2Theme_SliderButton_Disabled; else if(IsDragging || GetControllerState() == g2ControllerState_Pressed) ButtonStyle = g2Theme_SliderButton_Pressed; // Computer offsets float ProgressRatio = Progress / fabs(MaxBound - MinBound); int OffsetX = g2Slider_SidePixelBuffer + int(float(Width - 2 * g2Slider_SidePixelBuffer) * ProgressRatio) - SliderWidth / 2; // Draw the slider button itself DrawComponent(ButtonStyle, pX + OffsetX, pY + TotalHeight / 2 - SliderHeight / 2); }
void g2TextField::Render(int pX, int pY) { /*** Draw Background (Text field) ***/ // What state is the component currently in? g2ThemeElement TextFieldState = g2Theme_TextField; if(GetDisabled()) TextFieldState = g2Theme_TextField_Disabled; // Render the background DrawComponentStretch(TextFieldState, pX, pY, Width); // The editable text field will draw itself }
void g2Controller::DrawComponentStretch(g2ThemeElement ElementType, int DestX, int DestY, int Width, int StartHeight, int EndHeight) { // Pass with name DrawComponentStretch(GetTheme()->GetElementName(ElementType), DestX, DestY, Width, StartHeight, EndHeight); }
void g2Controller::DrawComponentStretch(g2ThemeElement ElementType, int DestX, int DestY, int Width) { DrawComponentStretch(GetTheme()->GetElementName(ElementType), DestX, DestY, Width); }