// inhered interfaces void CTfWin::_DisplayFunc() { assert(iNrOfEntries); glClear(GL_COLOR_BUFFER_BIT); pcTransFunc->_ExportColorMap(&pfColorMap[0], iNrOfEntries); glMatrixMode(GL_PROJECTION); glPushMatrix(); glLoadIdentity(); glMatrixMode(GL_MODELVIEW); glPushMatrix(); glLoadIdentity(); if( cHistogram.pfBins.BIsAllocated() ) { // normalize the coordinate glTranslatef(-1.0f, -1.0f, -1.0f); glScalef(2.0f, 2.0f, 2.0f); float fDomainMin = pcTransFunc->cDomainMin.FGetValue(); float fDomainMax = pcTransFunc->cDomainMax.FGetValue(); float fHistogramMin = cHistogram.cMin.FGetValue(); float fHistogramMax = cHistogram.cMax.FGetValue(); glPushMatrix(); glScalef(1.0f / (float)(fHistogramMax - fHistogramMin), 1.0f, 1.0f); glTranslatef(-fHistogramMin, 0.0f, 0.0f); glTranslatef(fDomainMin, 0.0f, 0.0f); glScalef((fDomainMax - fDomainMin)/(float)iNrOfEntries, 1.0f, 1.0f); glBegin(GL_QUADS); for(int i = 0; i < iNrOfEntries; i++) { float l, r, b, t; l = (float)i; r = (float)i + 1; b = 0.0f; t = pfColorMap[i*4 + 3]; // use the alpha channel as the height glColor3fv(&pfColorMap[i*4]); // setup the color glVertex2f(l, b); glVertex2f(r, b); glVertex2f(r, t); glVertex2f(l, t); } glEnd(); glColor4f(1.0, 1.0, 1.0, 1.0); _DrawString3D(SZSprintf("%.2e", fDomainMin), 0.0f, 0.5f, 0.0f); _DrawString3D(SZSprintf("%.2e", fDomainMax), (float)iNrOfEntries, 0.5f, 0.0f); glPopMatrix(); ///////////////////////////////////////////////////// glPushMatrix(); glScalef(1.0f / (float)(float)cHistogram.pfBins.USize(), 1.0f, 1.0f); glPushAttrib(GL_LINE_BIT); glLineWidth(4.0); glBegin(GL_LINE_STRIP); glColor4f(1.0, 1.0, 1.0, 1.0); for(int i = 0; i < (int)cHistogram.pfBins.USize(); i++) { glVertex2f((float)i, cHistogram.pfBins[i]); glVertex2f((float)i + 1.0f, cHistogram.pfBins[i]); } glEnd(); glPopAttrib(); // glPushAttrib(GL_LINE_BIT); glPopMatrix(); _DrawString(SZSprintf("%.2e", fHistogramMin), 0, 2, false); _DrawString(SZSprintf("%.2e", fHistogramMax), -1, 2, true); _DrawString(SZSprintf("%.2e", cHistogram.fMaxCount), 0, -16, false); } else { // normalize the coordinate glTranslatef(-1.0f, -1.0f, -1.0f); glScalef(2.0f, 2.0f, 2.0f); glScalef(1.0f/(float)iNrOfEntries, 1.0f, 1.0f); // plot the transfer func. as bar chart // each entry in the TR is a bar // the height of each bar represents the corresponding alpha // the color of each bar represents the corresponding color glBegin(GL_QUADS); for(int i = 0; i < iNrOfEntries; i++) { float l, r, b, t; l = (float)i; r = (float)i + 1; b = 0.0f; t = pfColorMap[i*4 + 3]; // use the alpha channel as the height glColor3fv(&pfColorMap[i*4]); // setup the color glVertex2f(l, b); glVertex2f(r, b); glVertex2f(r, t); glVertex2f(l, t); } glEnd(); // plot the transfer func. as lines for(int c = 0; c < 3; c++) // only plot the RGB channels { switch(c) { case 0: glColor4f(1.0, 0.0f, 0.0f, 1.0f); break; case 1: glColor4f(0.0, 1.0f, 0.0f, 1.0f); break; case 2: glColor4f(0.0, 0.0f, 1.0f, 1.0f); break; } glBegin(GL_LINE_STRIP); for(int i = 0; i < iNrOfEntries; i++) glVertex2f((float)i, pfColorMap[i*4 + c]); glEnd(); } glColor4f(0.0f, 1.0f, 1.0f, 1.0f); _DrawString(SZSprintf("%.2e", pcTransFunc->cDomainMin.FGetValue()), 0, 0, false); _DrawString(SZSprintf("%.2e", pcTransFunc->cDomainMax.FGetValue()), -1, 0, true); } glMatrixMode(GL_PROJECTION); glPopMatrix(); glMatrixMode(GL_MODELVIEW); glPopMatrix(); }
void CTfUi::_DisplayFunc() { glClear(GL_COLOR_BUFFER_BIT); glMatrixMode(GL_PROJECTION); glPushMatrix(); glLoadIdentity(); glMatrixMode(GL_MODELVIEW); glPushMatrix(); glLoadIdentity(); // normalize the coordinate glTranslatef(-1.0f, -1.0f, -1.0f); glScalef(2.0f, 2.0f, 2.0f); // plot the histogram as backgroun glPushMatrix(); float fDomainMin = pcTransFunc->cDomainMin.FGetValue(); float fDomainMax = pcTransFunc->cDomainMax.FGetValue(); float fHistogramMin = cHistogramMin.FGetValue(); float fHistogramMax = cHistogramMax.FGetValue(); glScalef(1.0f / (float)(fDomainMax - fDomainMin), 1.0f, 1.0f); glTranslatef(-fDomainMin, 0.0f, 0.0f); glBegin(GL_QUADS); glColor4f(1.0f, 1.0f, 1.0f, 1.0f); for(int i = 0; i < pfHistogram.num; i++) { float l, r, b, t; l = (float) i / (float) pfHistogram.num * (float)(fHistogramMax - fHistogramMin) + fHistogramMin; r = (float) (i + 1) / (float) pfHistogram.num * (float)(fHistogramMax - fHistogramMin) + fHistogramMin; b = 0.0f; t = pfHistogram[i]; glVertex2f(l, b); glVertex2f(r, b); glVertex2f(r, t); glVertex2f(l, t); } glEnd(); glPopMatrix(); glColor4f(0.0f, 1.0f, 1.0f, 1.0f); _DrawString(SZSprintf("%.2e", pcTransFunc->cDomainMin.FGetValue()), 0, 0, false); _DrawString(SZSprintf("%.2e", pcTransFunc->cDomainMax.FGetValue()), -1, 0, true); // plot the transfer func. as lines for(int c = 0; c < CTransFunc::NR_OF_COLORS; c++) { // plot the spline _PlotSpline(c); } // plot the editing spline in thicker line _PlotSpline(iEditingChannel, true); // plot the select region if the left mouse is being pressed if( false == vcMouseEvents.empty() && GLUT_LEFT_BUTTON == vcMouseEvents.begin()->iButton ) { vector<CMouseEvent>::iterator vcFirstEvevt = vcMouseEvents.begin(); vector<CMouseEvent>::iterator vcLastEvevt = vcMouseEvents.end() - 1; if( GLUT_LEFT_BUTTON == vcFirstEvevt->iButton ) { glColor4f(1.0f, 1.0f, 0.0f, 1.0f); glBegin(GL_LINE_LOOP); float l, b, r, t; l = (float)vcFirstEvevt->iX / (float)piViewport[2]; r = (float)vcLastEvevt->iX / (float)piViewport[2]; b = (float)vcFirstEvevt->iY / (float)piViewport[3]; t = (float)vcLastEvevt->iY / (float)piViewport[3]; glVertex2f(l, b); glVertex2f(r, b); glVertex2f(r, t); glVertex2f(l, t); glEnd(); } } glMatrixMode(GL_PROJECTION); glPopMatrix(); glMatrixMode(GL_MODELVIEW); glPopMatrix(); }
void ETextEditable::Draw(ERect updateRect) { if(!IsVisible()) return; ERect rect = Frame().OffsetToSelf(E_ORIGIN); rect.left += fMargins.left; rect.top += fMargins.top; rect.right -= fMargins.right; rect.bottom -= fMargins.bottom; if(!rect.IsValid()) return; ERegion clipping; GetClippingRegion(&clipping); if(clipping.CountRects() > 0) clipping &= (rect & updateRect); else clipping = (rect & updateRect); if(clipping.CountRects() <= 0) return; e_rgb_color bkColor = e_ui_color(E_DOCUMENT_BACKGROUND_COLOR); e_rgb_color fgColor = e_ui_color(E_DOCUMENT_TEXT_COLOR); if(!IsEnabled()) { bkColor.disable(ViewColor()); fgColor.disable(ViewColor()); } if(!IsFocusChanging()) { PushState(); ConstrainClippingRegion(&clipping); SetDrawingMode(E_OP_COPY); SetPenSize(0); SetHighColor(bkColor); FillRect(rect & updateRect, E_SOLID_HIGH); PopState(); } EFont font; e_font_height fontHeight; GetFont(&font); font.GetHeight(&fontHeight); if(fCount > 0 && !IsFocusChanging()) { PushState(); ConstrainClippingRegion(&clipping); float x = 0, y = 0; if(GetCharLocation(0, &x, &y, &font)) { SetDrawingMode(E_OP_COPY); SetPenSize(0); SetHighColor(fgColor); SetLowColor(bkColor); _DrawString(fText, EPoint(x, y)); if(IsEnabled() && IsSelected()) { char *selectedText = DuplicateText(fSelectStart, fSelectEnd); if(selectedText != NULL) { x = 0; y = 0; if(GetCharLocation(fSelectStart, &x, &y, &font)) { DrawSelectedBackground(updateRect); SetLowColor(e_ui_color(E_DOCUMENT_HIGHLIGHT_COLOR)); _DrawString(selectedText, EPoint(x, y)); } free(selectedText); } } } PopState(); } if(IsEnabled() && IsEditable() && (IsFocus() || IsFocusChanging())) { PushState(); ConstrainClippingRegion(&clipping); DrawCursor(); PopState(); } if((IsFocus() || IsFocusChanging()) && Window()->IsActivate() && IsEnabled() && (Flags() & E_NAVIGABLE)) { e_rgb_color color = e_ui_color(E_NAVIGATION_BASE_COLOR); if(IsFocusChanging() && !IsFocus()) color = e_ui_color(E_DOCUMENT_BACKGROUND_COLOR); PushState(); ConstrainClippingRegion(&clipping); SetDrawingMode(E_OP_COPY); SetPenSize(0); SetHighColor(color); StrokeRect(rect, E_SOLID_HIGH); PopState(); } }