// ----------------------------------------------------------------------------- // Draws the image/background/etc // ----------------------------------------------------------------------------- void GfxCanvas::draw() { // Setup the viewport glViewport(0, 0, GetSize().x, GetSize().y); // Setup the screen projection glMatrixMode(GL_PROJECTION); glLoadIdentity(); glOrtho(0, GetSize().x, GetSize().y, 0, -1, 1); glMatrixMode(GL_MODELVIEW); glLoadIdentity(); // Clear glClearColor(0.0f, 0.0f, 0.0f, 1.0f); glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); // Translate to inside of pixel (otherwise inaccuracies can occur on certain gl implementations) if (OpenGL::accuracyTweak()) glTranslatef(0.375f, 0.375f, 0); // Draw the background drawCheckeredBackground(); // Pan by view offset if (allow_scroll_) glTranslated(offset_.x, offset_.y, 0); // Pan if offsets if (view_type_ == View::Centered || view_type_ == View::Sprite || view_type_ == View::HUD) { int mid_x = GetSize().x / 2; int mid_y = GetSize().y / 2; glTranslated(mid_x, mid_y, 0); } // Scale by UI scale // glScaled(UI::scaleFactor(), UI::scaleFactor(), 1.); // Draw offset lines if (view_type_ == View::Sprite || view_type_ == View::HUD) drawOffsetLines(); // Draw the image drawImage(); // Swap buffers (ie show what was drawn) SwapBuffers(); }
/* CTextureCanvas::drawTexture * Draws the currently opened composite texture *******************************************************************/ void CTextureCanvas::drawTexture() { // Push matrix glPushMatrix(); // Calculate top-left position of texture (for glScissor, since it ignores the current translation/scale) double left = offset.x + (GetSize().x * 0.5) - (texture->getWidth() * 0.5 * scale); double top = -offset.y + (GetSize().y * 0.5) - (texture->getHeight() * 0.5 * scale); // Translate to middle of the canvas glTranslated(GetSize().x * 0.5, GetSize().y * 0.5, 0); // Zoom double yscale = (tx_arc ? scale * 1.2 : scale); glScaled(scale, yscale, 1); // Draw offset guides if needed drawOffsetLines(); // Apply texture scale double tscalex = 1; double tscaley = 1; if (tex_scale) { tscalex = texture->getScaleX(); if (tscalex == 0) tscalex = 1; tscaley = texture->getScaleY(); if (tscaley == 0) tscaley = 1; glScaled(1.0 / tscalex, 1.0 / tscaley, 1); } // Translate by offsets if needed if (view_type == 0) glTranslated(texture->getWidth() * -0.5, texture->getHeight() * -0.5, 0); // No offsets if (view_type >= 1) glTranslated(-texture->getOffsetX(), -texture->getOffsetY(), 0); // Sprite offsets if (view_type == 2) glTranslated(-160*tscalex, -100*tscaley, 0); // HUD offsets // Draw the texture border //if (gfx_show_border) drawTextureBorder(); // Enable textures glEnable(GL_TEXTURE_2D); // First, draw patches semitransparently (for anything outside the texture) // But only if we are drawing stuff outside the texture area if (draw_outside) { for (uint32_t a = 0; a < texture->nPatches(); a++) drawPatch(a, true); } // Reset colouring OpenGL::setColour(COL_WHITE); // If we're currently dragging, draw a 'basic' preview of the texture using opengl if (dragging) { glEnable(GL_SCISSOR_TEST); glScissor(left, top, texture->getWidth() * scale, texture->getHeight() * scale); for (uint32_t a = 0; a < texture->nPatches(); a++) drawPatch(a); glDisable(GL_SCISSOR_TEST); } // Otherwise, draw the fully generated texture else { // Generate if needed if (!tex_preview.isLoaded()) { // Determine image type SIType type = PALMASK; if (blend_rgba) type = RGBA; // CTexture -> temp Image -> GLTexture SImage temp(type); texture->toImage(temp, parent, &palette, blend_rgba); tex_preview.loadImage(&temp, &palette); } // Draw it tex_preview.draw2d(); } // Disable textures glDisable(GL_TEXTURE_2D); // Now loop through selected patches and draw selection outlines OpenGL::setColour(70, 210, 220, 255, BLEND_NORMAL); glEnable(GL_LINE_SMOOTH); glLineWidth(1.5f); for (size_t a = 0; a < selected_patches.size(); a++) { // Skip if not selected if (!selected_patches[a]) continue; // Get patch CTPatch* patch = texture->getPatch(a); CTPatchEx* epatch = (CTPatchEx*)patch; // Check for rotation if (texture->isExtended() && (epatch->getRotation() == 90 || epatch->getRotation() == -90)) { // Draw outline, width/height swapped glBegin(GL_LINE_LOOP); glVertex2i(patch->xOffset(), patch->yOffset()); glVertex2i(patch->xOffset(), patch->yOffset() + (int)patch_textures[a]->getWidth()); glVertex2i(patch->xOffset() + (int)patch_textures[a]->getHeight(), patch->yOffset() + (int)patch_textures[a]->getWidth()); glVertex2i(patch->xOffset() + (int)patch_textures[a]->getHeight(), patch->yOffset()); glEnd(); } else { // Draw outline glBegin(GL_LINE_LOOP); glVertex2i(patch->xOffset(), patch->yOffset()); glVertex2i(patch->xOffset(), patch->yOffset() + (int)patch_textures[a]->getHeight()); glVertex2i(patch->xOffset() + (int)patch_textures[a]->getWidth(), patch->yOffset() + (int)patch_textures[a]->getHeight()); glVertex2i(patch->xOffset() + (int)patch_textures[a]->getWidth(), patch->yOffset()); glEnd(); } } // Finally, draw a hilight outline if anything is hilighted if (hilight_patch >= 0) { // Set colour OpenGL::setColour(255, 255, 255, 150, BLEND_ADDITIVE); // Get patch CTPatch* patch = texture->getPatch(hilight_patch); CTPatchEx* epatch = (CTPatchEx*)patch; GLTexture* patch_texture = patch_textures[hilight_patch]; // Check for rotation if (texture->isExtended() && (epatch->getRotation() == 90 || epatch->getRotation() == -90)) { // Draw outline, width/height swapped glBegin(GL_LINE_LOOP); glVertex2i(patch->xOffset(), patch->yOffset()); glVertex2i(patch->xOffset(), patch->yOffset() + (int)patch_texture->getWidth()); glVertex2i(patch->xOffset() + (int)patch_texture->getHeight(), patch->yOffset() + (int)patch_texture->getWidth()); glVertex2i(patch->xOffset() + (int)patch_texture->getHeight(), patch->yOffset()); glEnd(); } else { // Draw outline glBegin(GL_LINE_LOOP); glVertex2i(patch->xOffset(), patch->yOffset()); glVertex2i(patch->xOffset(), patch->yOffset() + (int)patch_texture->getHeight()); glVertex2i(patch->xOffset() + (int)patch_texture->getWidth(), patch->yOffset() + (int)patch_texture->getHeight()); glVertex2i(patch->xOffset() + (int)patch_texture->getWidth(), patch->yOffset()); glEnd(); } } glDisable(GL_LINE_SMOOTH); glLineWidth(1.0f); // Pop matrix glPopMatrix(); }