示例#1
0
bool MgRoundRect::isCurve() const
{
    return fabsf(_rx) > getWidth() / 6 || fabsf(_ry) > getHeight() / 6;
}
示例#2
0
//----------------------------------------------------------------------------------------------------
void UIEditView::drawRect (CDrawContext *pContext, const CRect& updateRect)
{
	// disable focus drawing
	bool focusDrawing = getFrame ()->focusDrawingEnabled ();
	if (!editing && focusDrawing)
		getFrame ()->setFocusDrawingEnabled (false);

	CViewContainer::drawRect (pContext, updateRect);

	if (!editing && focusDrawing)
		getFrame ()->setFocusDrawingEnabled (focusDrawing);

	CRect oldClip = pContext->getClipRect (oldClip);
	CRect newClip (updateRect);
	newClip.offset (-getViewSize ().left, -getViewSize ().top);
	pContext->setClipRect (updateRect);

	CCoord save[4];
	modifyDrawContext (save, pContext);

	const CCoord dashLength[] = {5, 5};
	const CLineStyle lineDash (CLineStyle::kLineCapButt, CLineStyle::kLineJoinMiter, 0, 2, dashLength);
	pContext->setLineStyle (lineDash);
	pContext->setLineWidth (1);
	pContext->setDrawMode (kAliasing);
	pContext->setFrameColor (kBlueCColor);
	pContext->drawRect (CRect (0, 0, getWidth(), getHeight()), kDrawStroked);

	if (editing)
	{
		if (lines)
			lines->draw (pContext);
		pContext->setDrawMode (kAntiAliasing);
		if (highlightView)
		{
			CRect r = UISelection::getGlobalViewCoordinates (highlightView);
			CPoint p;
			frameToLocal (p);
			r.offset (p.x, p.y);
			r.inset (2, 2);
			pContext->setFrameColor (viewHighlightColor);
			pContext->setLineStyle (kLineSolid);
			pContext->setLineWidth (3);
			pContext->drawRect (r);
		}
		if (getSelection ()->total () > 0)
		{
			pContext->setDrawMode (kAliasing);
			pContext->setFrameColor (viewSelectionColor);
			pContext->setLineStyle (kLineSolid);
			pContext->setLineWidth (1);

			FOREACH_IN_SELECTION(getSelection (), view)
				CRect vs = getSelection ()->getGlobalViewCoordinates (view);
				CPoint p;
				frameToLocal (p);
				vs.offset (p.x, p.y);
				pContext->drawRect (vs);
			FOREACH_IN_SELECTION_END

		}
	}
示例#3
0
文件: table.cpp 项目: Ablu/mana
// -- widget ops
void GuiTable::draw(gcn::Graphics* graphics)
{
    if (!mModel)
        return;

    if (config.getFloatValue("guialpha") != mAlpha)
        mAlpha = config.getFloatValue("guialpha");

    if (mOpaque)
    {
        graphics->setColor(Theme::getThemeColor(Theme::BACKGROUND,
                (int)(mAlpha * 255.0f)));
        graphics->fillRectangle(gcn::Rectangle(0, 0, getWidth(), getHeight()));
    }

    // First, determine how many rows we need to draw, and where we should start.
    int first_row = -(getY() / getRowHeight());

    if (first_row < 0)
        first_row = 0;

    int rows_nr = 1 + (getHeight() / getRowHeight()); // May overestimate by one.

    int max_rows_nr = mModel->getRows() - first_row; // clip if neccessary:
    if (max_rows_nr < rows_nr)
        rows_nr = max_rows_nr;

    // Now determine the first and last column
    // Take the easy way out; these are usually bounded and all visible.
    int first_column = 0;
    int last_column = mModel->getColumns() - 1;

    // Set up everything for drawing
    int height = getRowHeight();
    int y_offset = first_row * height;

    for (int r = first_row; r < first_row + rows_nr; ++r)
    {
        int x_offset = 0;

        for (int c = first_column; c <= last_column; ++c)
        {
            gcn::Widget *widget = mModel->getElementAt(r, c);
            int width = getColumnWidth(c);
            if (widget)
            {
                gcn::Rectangle bounds(x_offset, y_offset, width, height);

                if (widget == mTopWidget)
                {
                    bounds.height = widget->getHeight();
                    bounds.width = widget->getWidth();
                }

                widget->setDimension(bounds);

                graphics->setColor(Theme::getThemeColor(Theme::HIGHLIGHT,
                                                      (int)(mAlpha * 255.0f)));

                if (mLinewiseMode && r == mSelectedRow && c == 0)
                {
                    graphics->fillRectangle(gcn::Rectangle(0, y_offset,
                                                           getWidth(), height));
                }
                else if (!mLinewiseMode &&
                          c == mSelectedColumn && r == mSelectedRow)
                {
                    graphics->fillRectangle(gcn::Rectangle(x_offset, y_offset,
                                                           width, height));
                }

                graphics->pushClipArea(bounds);
                widget->draw(graphics);
                graphics->popClipArea();
            }

            x_offset += width;
        }

        y_offset += height;
    }

    if (mTopWidget)
    {
        gcn::Rectangle bounds = mTopWidget->getDimension();
        graphics->pushClipArea(bounds);
        mTopWidget->draw(graphics);
        graphics->popClipArea();
    }
}
示例#4
0
 void Gaming::InsufficientDimensionsEx::__print_args(std::ostream &os) const {
     os << "minWidth: " << getExpHeight() << " minHeight: " << getExpHeight() << std::endl;
     os << "width " << getWidth() << " height " << getHeight();
 }
    void TextAreaOverlayElement::updatePositionGeometry()
    {
        float *pVert;

        if (mFont.isNull())
        {
            // not initialised yet, probably due to the order of creation in a template
            return;
        }

        size_t charlen = mCaption.size();
        checkMemoryAllocation( charlen );

        mRenderOp.vertexData->vertexCount = charlen * 6;
        // Get position / texcoord buffer
        const HardwareVertexBufferSharedPtr& vbuf = 
            mRenderOp.vertexData->vertexBufferBinding->getBuffer(POS_TEX_BINDING);
        pVert = static_cast<float*>(
            vbuf->lock(HardwareBuffer::HBL_DISCARD, Root::getSingleton().getFreqUpdatedBuffersUploadOption()) );

        float largestWidth = 0;
        float left = _getDerivedLeft() * 2.0f - 1.0f;
        float top = -( (_getDerivedTop() * 2.0f ) - 1.0f );

        // Derive space with from a number 0
        if(!mSpaceWidthOverridden)
        {
            mSpaceWidth = mFont->getGlyphAspectRatio(UNICODE_ZERO) * mCharHeight;
        }

        // Use iterator
        DisplayString::iterator i, iend;
        iend = mCaption.end();
        bool newLine = true;
        for( i = mCaption.begin(); i != iend; ++i )
        {
            if( newLine )
            {
                Real len = 0.0f;
                for( DisplayString::iterator j = i; j != iend; j++ )
                {
                    Font::CodePoint character = OGRE_DEREF_DISPLAYSTRING_ITERATOR(j);
                    if (character == UNICODE_CR
                        || character == UNICODE_NEL
                        || character == UNICODE_LF) 
                    {
                        break;
                    }
                    else if (character == UNICODE_SPACE) // space
                    {
                        len += mSpaceWidth * 2.0f * mViewportAspectCoef;
                    }
                    else 
                    {
                        len += mFont->getGlyphAspectRatio(character) * mCharHeight * 2.0f * mViewportAspectCoef;
                    }
                }

                if( mAlignment == Right )
                    left -= len;
                else if( mAlignment == Center )
                    left -= len * 0.5f;

                newLine = false;
            }

            Font::CodePoint character = OGRE_DEREF_DISPLAYSTRING_ITERATOR(i);
            if (character == UNICODE_CR
                || character == UNICODE_NEL
                || character == UNICODE_LF)
            {
                left = _getDerivedLeft() * 2.0f - 1.0f;
                top -= mCharHeight * 2.0f;
                newLine = true;
                // Also reduce tri count
                mRenderOp.vertexData->vertexCount -= 6;

                // consume CR/LF in one
                if (character == UNICODE_CR)
                {
                    DisplayString::iterator peeki = i;
                    peeki++;
                    if (peeki != iend && OGRE_DEREF_DISPLAYSTRING_ITERATOR(peeki) == UNICODE_LF)
                    {
                        i = peeki; // skip both as one newline
                        // Also reduce tri count
                        mRenderOp.vertexData->vertexCount -= 6;
                    }

                }
                continue;
            }
            else if (character == UNICODE_SPACE) // space
            {
                // Just leave a gap, no tris
                left += mSpaceWidth * 2.0f * mViewportAspectCoef;
                // Also reduce tri count
                mRenderOp.vertexData->vertexCount -= 6;
                continue;
            }

            Real horiz_height = mFont->getGlyphAspectRatio(character) * mViewportAspectCoef ;
            const Font::UVRect& uvRect = mFont->getGlyphTexCoords(character);

            // each vert is (x, y, z, u, v)
            //-------------------------------------------------------------------------------------
            // First tri
            //
            // Upper left
            *pVert++ = left;
            *pVert++ = top;
            *pVert++ = -1.0;
            *pVert++ = uvRect.left;
            *pVert++ = uvRect.top;

            top -= mCharHeight * 2.0f;

            // Bottom left
            *pVert++ = left;
            *pVert++ = top;
            *pVert++ = -1.0;
            *pVert++ = uvRect.left;
            *pVert++ = uvRect.bottom;

            top += mCharHeight * 2.0f;
            left += horiz_height * mCharHeight * 2.0f;

            // Top right
            *pVert++ = left;
            *pVert++ = top;
            *pVert++ = -1.0;
            *pVert++ = uvRect.right;
            *pVert++ = uvRect.top;
            //-------------------------------------------------------------------------------------

            //-------------------------------------------------------------------------------------
            // Second tri
            //
            // Top right (again)
            *pVert++ = left;
            *pVert++ = top;
            *pVert++ = -1.0;
            *pVert++ = uvRect.right;
            *pVert++ = uvRect.top;

            top -= mCharHeight * 2.0f;
            left -= horiz_height  * mCharHeight * 2.0f;

            // Bottom left (again)
            *pVert++ = left;
            *pVert++ = top;
            *pVert++ = -1.0;
            *pVert++ = uvRect.left;
            *pVert++ = uvRect.bottom;

            left += horiz_height  * mCharHeight * 2.0f;

            // Bottom right
            *pVert++ = left;
            *pVert++ = top;
            *pVert++ = -1.0;
            *pVert++ = uvRect.right;
            *pVert++ = uvRect.bottom;
            //-------------------------------------------------------------------------------------

            // Go back up with top
            top += mCharHeight * 2.0f;

            float currentWidth = (left + 1)/2 - _getDerivedLeft();
            if (currentWidth > largestWidth)
            {
                largestWidth = currentWidth;

            }
        }
        // Unlock vertex buffer
        vbuf->unlock();

        if (mMetricsMode == GMM_PIXELS)
        {
            // Derive parametric version of dimensions
            Real vpWidth;
            vpWidth = (Real) (OverlayManager::getSingleton().getViewportWidth());

            largestWidth *= vpWidth;
        };

        if (getWidth() < largestWidth)
            setWidth(largestWidth);
    }
示例#6
0
int main(void)
{
    // seed pseudorandom number generator
    srand48(time(NULL));

    // instantiate window
    GWindow window = newGWindow(WIDTH, HEIGHT);

    // instantiate bricks
    initBricks(window);
    
    // instantiate ball, centered in middle of window
    GOval ball = initBall(window);

    // instantiate paddle, centered at bottom of window
    GRect paddle = initPaddle(window);

    // instantiate scoreboard, centered in middle of window, just above ball
    GLabel label = initScoreboard(window);

    // number of bricks initially
    int bricks = COLS * ROWS;

    // number of lives initially
    int lives = LIVES;

    // number of points initially
    int points = 0;

    // keep playing until game over
     double velocity= 2.0 + drand48() ;
     double vely = 2.0;
     updateScoreboard(window, label, points);
     waitForClick();
    while (lives > 0 && bricks > 0)
    {
        
        updateScoreboard(window, label, points);
        GEvent event = getNextEvent(MOUSE_EVENT);
        if (event != NULL)
            {
            
                
                if (getEventType(event) == MOUSE_MOVED)
                {
                    double x = getX(event) - getWidth(paddle) / 2;
                    setLocation(paddle, x, getY(paddle));                                              
                }
            }
                 
        move(ball, velocity, vely);
        
        if (getX(ball) + getWidth(ball) >= getWidth(window))
        {
            velocity = -velocity;
        }
        else if (getX(ball) <= 0)
        {
            velocity = -velocity;
          
        }
        if( getY(ball) <= 0)
        {
            vely = -vely;
        }
        else if (getY(ball)+getWidth(ball) >= HEIGHT)
        {      
           
            lives--;
            setLocation(ball, (WIDTH/2)-10, HEIGHT/2);
            waitForClick();
           
            
        }   
        
        GObject obj = detectCollision(window, ball);
        if(obj != NULL)
        {
            if(strcmp(getType(obj), "GRect")==0)
            {
                vely = -vely;
                if(obj != paddle)
                {
                    removeGWindow(window, obj);
                    bricks--;
                    points++;
                    
                    
                }
            }
        }
        pause(10);   
    }
         
    

    // wait for click before exiting
    waitForClick();

    // game over
    closeGWindow(window);
    return 0;
}
示例#7
0
void Rectangle2< T >::setOrigin( T x, T y )
{
    setBounds( x, y, getWidth(), getHeight() );
}
 void updateMarker()
 {
     marker.setBounds (roundToInt ((getWidth() - edge * 2) * s),
                       roundToInt ((getHeight() - edge * 2) * (1.0f - v)),
                       edge * 2, edge * 2);
 }
 void resized()
 {
     marker.setBounds (0, roundToInt ((getHeight() - edge * 2) * h),
                       getWidth(), edge * 2);
 }
void GifPixRect::copyImage(const PixRect *src) {
  rop(CRect(0,0,getWidth(),getHeight()), SRCCOPY, src, src->getRect());
}
示例#11
0
void ofFbo::begin() {
	bind();
	ofPushView();
	ofViewport(0, 0, getWidth(), getHeight());
	ofSetupScreenPerspective(getWidth(), getHeight(), false);
}
示例#12
0
 void resized()
 {
     editor->setBounds (10, 45, getWidth() - 20, getHeight() - 55);
     fileChooser.setBounds (10, 10, getWidth() - 20, 25);
 }
void ofxTimeMeasurements::draw(float x, float y) {

	if (!enabled) return;
	
	drawLines.clear();
	float percentTotal = 0.0f;
	float timePerFrame = 1000.0f / desiredFrameRate;

	mutex.lock();

	vector<TimeMeasurement*> toResetUpdatedLastFrameFlag;

	//update time stuff, build draw lists
	for( unordered_map<string,TimeMeasurement*>::iterator ii = times.begin(); ii != times.end(); ++ii ){
		TimeMeasurement* t = ii->second;
		string key = ii->first;
		if(!t->measuring){
			if (t->life > 0.01){
				t->life *= idleTimeColorDecay; //decrease life
			}else{ //life decays very slow when very low
				t->life *= deadThreadExtendedLifeDecSpeed; //decrease life very slowly
			}
		}
		if (!t->updatedLastFrame && timeAveragePercent < 1.0f){ // if we didnt update that time, make it tend to zero slowly
			t->avgDuration = (1.0f - timeAveragePercent) * t->avgDuration;
		}
		toResetUpdatedLastFrameFlag.push_back(t);
	}

	unordered_map<Poco::Thread*, ThreadInfo>::iterator ii;
	vector<Poco::Thread*> expiredThreads;

	//lets make sure the Main Thread is always on top
	vector< pair<Poco::Thread*, ThreadInfo> > sortedThreadList;

	for( ii = threadInfo.begin(); ii != threadInfo.end(); ++ii ){ //walk all thread trees
		if (ii->first == NULL){ //main thread is NULL!
			sortedThreadList.insert(sortedThreadList.begin(), *ii);
		}else{
			sortedThreadList.push_back(*ii);
		}
	}
	std::sort(sortedThreadList.begin(), sortedThreadList.end(), compareThreadPairs);

	#if defined(USE_OFX_HISTORYPLOT)
	vector<ofxHistoryPlot*> plotsToDraw;
	#endif

	for( int k = 0; k < sortedThreadList.size(); k++ ){ //walk all thread trees

		Poco::Thread* thread = sortedThreadList[k].first;
		core::tree<string> &tr = sortedThreadList[k].second.tree;

		PrintedLine header;
		header.formattedKey = "+" + *tr;
		header.color = threadInfo[thread].color;
		header.key = *tr; //key for selection, is thread name
		drawLines.push_back(header); //add header to drawLines

		int numAlive = 0;
		int numAdded = 0;

		core::tree<string>::iterator wholeTreeWalker = tr.in();
		bool finishedWalking = false;

		while( !finishedWalking ){

			string key = *wholeTreeWalker;
			TimeMeasurement * t = times[*wholeTreeWalker];

			#if defined(USE_OFX_HISTORYPLOT)
			bool plotActive = false;
			if(plots[key]){
				if(t->settings.plotting){
					if(t->updatedLastFrame){
						if (t->accumulating){
							plots[key]->update(t->microsecondsAccum / 1000.0f);
						}else{
							plots[key]->update(t->avgDuration / 1000.0f);
						}
					}
					plotsToDraw.push_back(plots[key]);
					plotActive = true;
				}
			}
			#endif

			bool visible = t->settings.visible;
			bool alive = t->life > 0.0001;
			if(alive){
				numAlive++;
			}

			if (visible){
				PrintedLine l;
				l.key = key;
				l.tm = t;

				int depth = wholeTreeWalker.level();
				for(int i = 0; i < depth; ++i) l.formattedKey += " ";

				if (wholeTreeWalker.size() == 0){
					l.formattedKey += "-";
				}else{
					l.formattedKey += "+";
				}
				l.formattedKey += key;
				#if defined(USE_OFX_HISTORYPLOT)
				if(plotActive) l.formattedKey += " [p]";
				#endif

				l.time = getTimeStringForTM(t);

				l.color = threadInfo[thread].color * ((1.0 - idleTimeColorFadePercent) + idleTimeColorFadePercent * t->life);
				if (!t->settings.enabled){
					l.color = disabledTextColor;
				}
				if (t->key == selection && menuActive){
					if(ofGetFrameNum()%5 < 4){
						l.color.invert();
					}
				}
				drawLines.push_back(l);
				numAdded++;
			}

			//only update() and draw() count to the final %
			if(key == TIME_MEASUREMENTS_DRAW_KEY || key == TIME_MEASUREMENTS_UPDATE_KEY){
				percentTotal += (t->avgDuration * 0.1f) / timePerFrame;
			}
			t->accumulating = false;
			t->microsecondsAccum = 0;

			//control the iterator to walk the tree "recursivelly" without doing so.
			if(wholeTreeWalker.size()){
				wholeTreeWalker = wholeTreeWalker.in();
			}else{
				if ( wholeTreeWalker.next() == wholeTreeWalker.end() ){
					wholeTreeWalker = wholeTreeWalker.out();
					while( wholeTreeWalker.next() == wholeTreeWalker.end() && wholeTreeWalker != tr){
						wholeTreeWalker = wholeTreeWalker.out();
					}
					if(wholeTreeWalker == tr){
						finishedWalking = true;
					}else{
						wholeTreeWalker++;
					}
				}else{
					++wholeTreeWalker;
				}
			}
		}

		if (numAlive == 0 && removeExpiredThreads){
			//drop that whole section if all entries in it are not alive
			for(int i = 0; i < numAdded + 1; i++){
				if(drawLines.size() > 0){
					int delID = drawLines.size() - 1;
					//clear selection if needed
					if (selection == drawLines[delID].key){
						selection = TIME_MEASUREMENTS_UPDATE_KEY;
					}
					drawLines.erase(drawLines.begin() + delID);
				}
			}
			expiredThreads.push_back(thread);
		}
	}

	//delete expired threads
	for(int i = 0; i < expiredThreads.size(); i++){
		unordered_map<Poco::Thread*, ThreadInfo>::iterator treeIt = threadInfo.find(expiredThreads[i]);
		if (treeIt != threadInfo.end()) threadInfo.erase(treeIt);
	}

	mutex.unlock();

	updateLongestLabel();

	//update max width, find headers
	int tempMaxW = -1;
	vector<int> headerLocations;
	for( int i = 0; i < drawLines.size(); i++ ){
		if (drawLines[i].tm){ //its a measurement
			//add padding to draw in columns
			for(int j = drawLines[i].formattedKey.length(); j < longestLabel; j++){
				drawLines[i].formattedKey += " ";
			}
			if (!drawLines[i].tm->error){
				drawLines[i].fullLine = drawLines[i].formattedKey + " " + drawLines[i].time;
			}else{
				drawLines[i].fullLine = drawLines[i].formattedKey + "    Error!" ;
			}
			int len = drawLines[i].fullLine.length();
			if(len > tempMaxW) tempMaxW = len;
		}else{ //its a header
			drawLines[i].fullLine = drawLines[i].formattedKey;
			headerLocations.push_back(i);
		}
	}
	maxW = tempMaxW;

	ofSetupScreen(); //mmmm----
	ofPushStyle();
	ofPushMatrix();
	ofScale(uiScale,uiScale);
	ofSetDrawBitmapMode(OF_BITMAPMODE_SIMPLE);

	ofFill();
	ofEnableAlphaBlending();

	#if defined(USE_OFX_HISTORYPLOT)
	//int numCols = plotsToDraw.size()
	for(int i = 0; i < plotsToDraw.size(); i++){
		int y = ofGetHeight() / uiScale - plotHeight * (i + 1);
		plotsToDraw[i]->draw(0, y, ofGetWidth() / uiScale, plotHeight);
		ofSetColor(99);
		if(i != plotsToDraw.size() -1){
			ofLine(0, y, ofGetWidth() / uiScale, y );
		}
	}
	#endif

	float totalW = getWidth();
	float totalH = getHeight();

	ofSetColor(bgColor, 245);
	int barH = 1;
	ofRect(x, y + 1, totalW, totalH);

	//thread header bg highlight
	for(int i = 0; i < headerLocations.size(); i++){
		int loc = headerLocations[i];
		//whole section
		ofSetColor(drawLines[loc].color, 40);
		int h = charH * ((i < headerLocations.size() - 1) ? headerLocations[i+1] - headerLocations[i] : drawLines.size() - loc );
		ofRect(x, y + 2 + loc * charH, totalW, h);
		//thread header
		ofSetColor(drawLines[loc].color, 40);
		ofRect(x, y + 2 + loc * charH, totalW, charH + 1);
	}

	ofSetColor(hilightColor);
	ofRect(x, y + 1, totalW, barH);
	ofRect(x, y + totalH - charH - 4 , totalW, barH);
	ofRect(x, y + totalH, totalW - barH, barH);

	for(int i = 0; i < drawLines.size(); i++){
		ofSetColor(drawLines[i].color);
		drawString(drawLines[i].fullLine, x , y + (i + 1) * charH);
	}

	//print bottom line, fps and stuff
	bool missingFrames = ( ofGetFrameRate() < desiredFrameRate - 1.0 ); // tolerance of 1 fps TODO!
	static char msg[128];

	sprintf(msg, "%2.1f fps % 5.1f%%", ofGetFrameRate(), percentTotal );
	if(missingFrames){
		ofSetColor(170,33,33);
	}else{
		ofSetColor(hilightColor);
	}
	int len = strlen(msg);
	string pad = " ";
	int diff = (maxW - len) - 1;
	for(int i = 0; i < diff; i++) pad += " ";
	int lastLine = ( drawLines.size() + 1 ) * charH + 2;
	drawString( pad + msg, x, y + lastLine );
	ofSetColor(hilightColor);
	drawString( " '" + ofToString(char(activateKey)) + "'" + string(timeAveragePercent < 1.0 ? " avgd!" : ""),
					   x, y + lastLine );

	for(int i = 0; i < toResetUpdatedLastFrameFlag.size(); i++){
		toResetUpdatedLastFrameFlag[i]->updatedLastFrame = false;
	}
	ofPopMatrix();
	ofPopStyle();
}
示例#14
0
BOOL LLImageRaw::scale( S32 new_width, S32 new_height, BOOL scale_image_data )
{
	LLMemType mt1((LLMemType::EMemType)mMemType);
	llassert((1 == getComponents()) || (3 == getComponents()) || (4 == getComponents()) );

	S32 old_width = getWidth();
	S32 old_height = getHeight();
	
	if( (old_width == new_width) && (old_height == new_height) )
	{
		return TRUE;  // Nothing to do.
	}

	// Reallocate the data buffer.

	if (scale_image_data)
	{
		// Vertical
		S32 temp_data_size = old_width * new_height * getComponents();
		U8* temp_buffer = new U8[ temp_data_size ];
		for( S32 col = 0; col < old_width; col++ )
		{
			copyLineScaled( getData() + (getComponents() * col), temp_buffer + (getComponents() * col), old_height, new_height, old_width, old_width );
		}

		deleteData();

		U8* new_buffer = allocateDataSize(new_width, new_height, getComponents());

		// Horizontal
		for( S32 row = 0; row < new_height; row++ )
		{
			copyLineScaled( temp_buffer + (getComponents() * old_width * row), new_buffer + (getComponents() * new_width * row), old_width, new_width, 1, 1 );
		}

		// Clean up
		delete[] temp_buffer;
	}
	else
	{
		// copy	out	existing image data
		S32	temp_data_size = old_width * old_height	* getComponents();
		U8*	temp_buffer	= new U8[ temp_data_size ];
		if (!temp_buffer)
		{
			llwarns << "Out of memory in LLImageRaw::scale: old (w, h, c) = (" << old_width << ", " << old_height << ", " << (S32)getComponents() << 
				") ; new (w, h, c) = (" << new_width << ", " << new_height << ", " << (S32)getComponents() << ")" << llendl;			

			return FALSE ;
		}
		memcpy(temp_buffer,	getData(), temp_data_size);	/* Flawfinder: ignore */

		// allocate	new	image data,	will delete	old	data
		U8*	new_buffer = allocateDataSize(new_width, new_height, getComponents());

		for( S32 row = 0; row <	new_height;	row++ )
		{
			if (row	< old_height)
			{
				memcpy(new_buffer +	(new_width * row * getComponents()), temp_buffer + (old_width *	row	* getComponents()),	getComponents()	* llmin(old_width, new_width));	/* Flawfinder: ignore */
				if (old_width <	new_width)
				{
					// pad out rest	of row with	black
					memset(new_buffer +	(getComponents() * ((new_width * row) +	old_width)), 0,	getComponents()	* (new_width - old_width));
				}
			}
			else
			{
				// pad remaining rows with black
				memset(new_buffer +	(new_width * row * getComponents()), 0,	new_width *	getComponents());
			}
		}

		// Clean up
		delete[] temp_buffer;
	}

	return TRUE ;
}
示例#15
0
ItemMakerBox::ItemMakerBox() :
    filenameLbl(new gcn::Label("Filename: ")),
    filenameFld(new gcn::TextField("data/items/")),
    nameLbl(new gcn::Label("Name: ")),
    nameFld(new gcn::TextField("")),
    //------------------------
    typeLbl(new gcn::Label("Type")),
    typeLst(new StringList),
    typeDropDown(new gcn::DropDown),

    genderLbl(new gcn::Label("Gender")),
    genderLst(new StringList),
    genderDropDown(new gcn::DropDown),

    dropableLbl(new gcn::Label("Dropable: ")),
    dropableCheckBox(new gcn::CheckBox("", false)),
    stackableLbl(new gcn::Label("Stackable")),
    stackableCheckBox(new gcn::CheckBox("", false)),
    duraLbl(new gcn::Label("Durability: ")),
    duraFld(new NumberField("1")),
    //------------------------
    thumbLbl(new gcn::Label("Image: ")),
    thumbFld(new gcn::TextField("tsprites/")),
    spriteLbl(new gcn::Label("Sprite: ")),
    spriteFld(new gcn::TextField("tsprites/")),
    animLbl(new gcn::Label("Animation: ")),
    animFld(new gcn::TextField("anim/")),
    //------------------------
    augLbl(new gcn::Label("Auguments:")),
    augArea(new gcn::Container),        //placeholder
    //------------------------
    actionsLbl(new gcn::Label("Actions: ")),
    actionsArea(new gcn::Container),      //placeholder
    //------------------------
    descLbl(new gcn::Label("Description: ")),
    descFld(new gcn::TextBox("")),
    descScroller(new gcn::ScrollArea(descFld)),
    //------------------------
    loadBtn(new gcn::Button("Load")),
    saveBtn(new gcn::Button("Save"))
{
    setCaption(caption_);


    //initialise drop down lists
    typeLst->addElement("Food");
    typeLst->addElement("Weapon");
    typeLst->addElement("Amour");
    typeLst->addElement("Quest");
    typeLst->addElement("Misc");
    typeDropDown->setListModel(typeLst);

    genderLst->addElement("Asexual");
    genderLst->addElement("Female");
    genderLst->addElement("Male");
    genderDropDown->setListModel(genderLst);


    //confif widget appearance
    descScroller->setFrameSize(1);
    loadBtn->setFrameSize(0);
    saveBtn->setFrameSize(0);
    loadBtn->setFocusable(false);
    saveBtn->setFocusable(false);

    //set sizes of widgets
    filenameFld->setWidth(150);
    nameFld->setWidth(150);
    //------------------------
    typeDropDown->setWidth(150);
    genderDropDown->setWidth(150);
    stackableLbl->setWidth(150);
    duraFld->setWidth(150);
    //------------------------
    thumbFld->setWidth(150);
    spriteFld->setWidth(150);
    animFld->setWidth(150);
    //------------------------
    augArea->setWidth(240);        //placeholder
    augArea->setHeight(100);        //placeholder
    //------------------------
    actionsArea->setWidth(240);    //placeholder
    actionsArea->setHeight(100);    //placeholder
    //------------------------
    descScroller->setWidth(240);
    descScroller->setHeight(75);


    //position widgets
    filenameLbl->setPosition(10, 10);
    filenameFld->setPosition(100, 10);
    nameLbl->setPosition(10, 35);
    nameFld->setPosition(100, 35);
    //------------------------
    typeLbl->setPosition(10, 60);
    typeDropDown->setPosition(100, 60);
    genderLbl->setPosition(10, 85);
    genderDropDown->setPosition(100, 85);
    dropableLbl->setPosition(10, 110);
    dropableCheckBox->setPosition(100, 110);
    stackableLbl->setPosition(10, 135);
    stackableCheckBox->setPosition(100, 135);
    duraLbl->setPosition(10, 160);
    duraFld->setPosition(100, 160);
    //------------------------
    thumbLbl->setPosition(10, 185);
    thumbFld->setPosition(100, 185);
    spriteLbl->setPosition(10, 210);
    spriteFld->setPosition(100, 210);
    animLbl->setPosition(10, 235);
    animFld->setPosition(100, 235);
    //------------------------
    augLbl->setPosition(10, 265);
    augArea->setPosition(10, 280);       //placeholder
    //------------------------
    actionsLbl->setPosition(10, 400);
    actionsArea->setPosition(10, 430);    //placeholder
    //------------------------
    descLbl->setPosition(10, 550);
    descScroller->setPosition(10, 570);
    //------------------------
    loadBtn->setPosition(10, 652);
    saveBtn->setPosition(50, 652);


    //add widgets to window
    add(filenameLbl);
    add(filenameFld);
    add(nameLbl);
    add(nameFld);
    //------------------------
    add(typeLbl);
    add(typeDropDown);
    add(genderLbl);
    add(genderDropDown);
    add(dropableLbl);
    add(dropableCheckBox);
    add(stackableLbl);
    add(stackableCheckBox);
    add(duraLbl);
    add(duraFld);
    //------------------------
    add(augLbl);
    add(augArea);        //placeholder
    //------------------------
    add(actionsLbl);
    add(actionsArea);    //placeholder
    //------------------------
    add(thumbLbl);
    add(thumbFld);
    add(spriteLbl);
    add(spriteFld);
    add(animLbl);
    add(animFld);
    //------------------------
    add(descLbl);
    add(descScroller);
    //------------------------
    add(saveBtn);
    add(loadBtn);


    // set size of window
    resizeToContent();
    setWidth(getWidth()+10);
    setHeight(getHeight()+10);
}
示例#16
0
void ColourSelector::resized()
{
    const int swatchesPerRow = 8;
    const int swatchHeight = 22;

    const int numSliders = ((flags & showAlphaChannel) != 0) ? 4 : 3;
    const int numSwatches = getNumSwatches();

    const int swatchSpace = numSwatches > 0 ? edgeGap + swatchHeight * ((numSwatches + 7) / swatchesPerRow) : 0;
    const int sliderSpace = ((flags & showSliders) != 0)  ? jmin (22 * numSliders + edgeGap, proportionOfHeight (0.3f)) : 0;
    const int topSpace = ((flags & showColourAtTop) != 0) ? jmin (30 + edgeGap * 2, proportionOfHeight (0.2f)) : edgeGap;

    previewArea.setBounds (edgeGap, edgeGap, getWidth() - edgeGap * 2, topSpace - edgeGap * 2);

    int y = topSpace;

    if ((flags & showColourspace) != 0)
    {
        const int hueWidth = jmin (50, proportionOfWidth (0.15f));

        colourSpace->setBounds (edgeGap, y,
                                getWidth() - hueWidth - edgeGap - 4,
                                getHeight() - topSpace - sliderSpace - swatchSpace - edgeGap);

        hueSelector->setBounds (colourSpace->getRight() + 4, y,
                                getWidth() - edgeGap - (colourSpace->getRight() + 4),
                                colourSpace->getHeight());

        y = getHeight() - sliderSpace - swatchSpace - edgeGap;
    }

    if ((flags & showSliders) != 0)
    {
        const int sliderHeight = jmax (4, sliderSpace / numSliders);

        for (int i = 0; i < numSliders; ++i)
        {
            sliders[i]->setBounds (proportionOfWidth (0.2f), y,
                                   proportionOfWidth (0.72f), sliderHeight - 2);

            y += sliderHeight;
        }
    }

    if (numSwatches > 0)
    {
        const int startX = 8;
        const int xGap = 4;
        const int yGap = 4;
        const int swatchWidth = (getWidth() - startX * 2) / swatchesPerRow;
        y += edgeGap;

        if (swatchComponents.size() != numSwatches)
        {
            swatchComponents.clear();

            for (int i = 0; i < numSwatches; ++i)
            {
                SwatchComponent* const sc = new SwatchComponent (*this, i);
                swatchComponents.add (sc);
                addAndMakeVisible (sc);
            }
        }

        int x = startX;

        for (int i = 0; i < swatchComponents.size(); ++i)
        {
            SwatchComponent* const sc = swatchComponents.getUnchecked(i);

            sc->setBounds (x + xGap / 2,
                           y + yGap / 2,
                           swatchWidth - xGap,
                           swatchHeight - yGap);

            if (((i + 1) % swatchesPerRow) == 0)
            {
                x = startX;
                y += swatchHeight;
            }
            else
            {
                x += swatchWidth;
            }
        }
    }
}
/**
 * Called whenever an action occurs, and processes it to
 * check if it's relevant to the surface and convert it
 * into a meaningful interaction like a "click", calling
 * the respective handlers.
 * @param action Pointer to an action.
 * @param state State that the action handlers belong to.
 */
void InteractiveSurface::handle(Action *action, State *state)
{
	if (!_visible || _hidden)
		return;

	action->setSender(this);

	if (action->getDetails()->type == SDL_MOUSEBUTTONUP || action->getDetails()->type == SDL_MOUSEBUTTONDOWN)
	{
		action->setMouseAction(action->getDetails()->button.x, action->getDetails()->button.y, getX(), getY());
	}
	else if (action->getDetails()->type == SDL_MOUSEMOTION)
	{
		action->setMouseAction(action->getDetails()->motion.x, action->getDetails()->motion.y, getX(), getY());
	}

	if (action->isMouseAction())
	{
		if ((action->getAbsoluteXMouse() >= getX() && action->getAbsoluteXMouse() < getX() + getWidth()) &&
			(action->getAbsoluteYMouse() >= getY() && action->getAbsoluteYMouse() < getY() + getHeight()))
		{
			if (!_isHovered)
			{
				_isHovered = true;
				mouseIn(action, state);
			}
			if (_listButton && action->getDetails()->type == SDL_MOUSEMOTION)
			{
				_buttonsPressed = SDL_GetMouseState(0, 0);
				for (Uint8 i = 1; i <= NUM_BUTTONS; ++i)
				{
					if (isButtonPressed(i))
					{
						action->getDetails()->button.button = i;
						mousePress(action, state);
					}
				}
			}
			mouseOver(action, state);
		}
		else
		{
			if (_isHovered)
			{
				_isHovered = false;
				mouseOut(action, state);
				if (_listButton && action->getDetails()->type == SDL_MOUSEMOTION)
				{
					for (Uint8 i = 1; i <= NUM_BUTTONS; ++i)
					{
						if (isButtonPressed(i))
						{
							setButtonPressed(i, false);
						}
						action->getDetails()->button.button = i;
						mouseRelease(action, state);
					}
				}
			}
		}
	}

	if (action->getDetails()->type == SDL_MOUSEBUTTONDOWN)
	{
		if (_isHovered && !isButtonPressed(action->getDetails()->button.button))
		{
			setButtonPressed(action->getDetails()->button.button, true);
			mousePress(action, state);
		}
	}
	else if (action->getDetails()->type == SDL_MOUSEBUTTONUP)
	{
		if (isButtonPressed(action->getDetails()->button.button))
		{
			setButtonPressed(action->getDetails()->button.button, false);
			mouseRelease(action, state);
			if (_isHovered)
			{
				mouseClick(action, state);
			}
		}
	}

	if (_isFocused)
	{
		if (action->getDetails()->type == SDL_KEYDOWN)
		{
			keyboardPress(action, state);
		}
		else if (action->getDetails()->type == SDL_KEYUP)
		{
			keyboardRelease(action, state);
		}
	}
}
 Rectangle BasicContainer::getChildrenArea()
 {
     return Rectangle(0, 0, getWidth(), getHeight());
 }
示例#19
0
 void resized()
 {
     int pw = jmin (getWidth() / 2 - 20, 350);
     panel1.setBounds (10, 6, pw, getHeight() - 12);
     panel2.setBounds (panel1.getRight() + 20, panel1.getY(), pw, panel1.getHeight());
 }
int main(void)
{
  // seed pseudorandom number generator
  srand48(time(NULL));

  // instantiate window
  GWindow window = newGWindow(WIDTH, HEIGHT);

  // instantiate bricks
  initBricks(window);
  
  // deal out the powerUps
  //initPowerUps(window);

  // instantiate ball, centered in middle of window
  GOval ball = initBall(window);

  // instantiate paddle, centered at bottom of window
  GRect paddle = initPaddle(window);

  // instantiate scoreboard, centered in middle of window, just above ball
  GLabel label = initScoreboard(window);

  // number of bricks initially
  int bricks = COLS * ROWS;

  // number of lives initially
  int lives = LIVES;

  // number of points initially
  int points = 0;

  // how long to wait
  int wait = 9;

  // Velocity for ball
  double velocity = 3.0;
  double xvelocity = 0;

  add(window, label);
  add(window, paddle);
  add(window, ball);
  // keep playing until game over
  waitForClick();
  while (lives > 0 && bricks > 0)
  {
    GEvent event = getNextEvent(MOUSE_EVENT);
    if (event != NULL)
    {
      // if the event was movement
      if (getEventType(event) == MOUSE_MOVED)
      {
        // ensure ball follows top cursor
        double x = getX(event) - getWidth(paddle) / 2;
        setLocation(paddle, x, getY(paddle));
      }
    }
    // move ball along x-axis
    xvelocity = xvelocity <= 0? -drand48() : drand48();
    move(ball, xvelocity, velocity);

    // bounce off right edge of window
    if (getX(ball) + RADIUS*2 >= getWidth(window))
    {
      setLocation(ball, getWidth(window) - RADIUS*2, getY(ball));
      xvelocity = -xvelocity;
    }
    // bounce off left edge of window
    else if (getX(ball) <= 0)
    {
      setLocation(ball, 1, getY(ball));
      xvelocity = -xvelocity;
    }

    // die off bottom of window
    if (getY(ball) + RADIUS*2 >= getHeight(window))
    {
      lives--;
      setLocation(ball, WIDTH/2, HEIGHT/2);
      waitForClick();
      velocity = -velocity;
      xvelocity = -xvelocity;
    }
    // bounce off top of window
    else if (getY(ball) <= 0)
    {
      velocity = -velocity;
    }
    GObject collision = detectCollision(window, ball);
    if (collision != NULL && collision != label)
    {
      /*if (strcmp(getType(collision), "GOval") == 0)
      {
        setVisible(collision, false);
        if (strcmp(getColorGObject(collision), "#FFCC00") == 0)
        {
          points+=2;
        } else if (strcmp(getColorGObject(collision), "#000000") == 0)
        {
          setSize(paddle, getWidth(paddle)+20, getHeight(paddle));
          points++;
          if (getWidth(paddle) >= 120)
          {
            setColor(paddle, "#000000");
            setColor(ball, "#000000");
            wait = 3;
          }
        }
      }*/
      /*else*/ if (strcmp(getType(collision), "GRect") == 0 && collision != paddle)
      {
        setVisible(collision, false);
        bricks--;
        velocity = -velocity;
        if (strcmp(getColorGObject(collision), "#FF0000") == 0)
        {
          if (!(wait < 5))
          {
            wait = 5;
            setColor(ball, "#FF0000");
            setColor(paddle, "#FF0000");
          }
          else
          {
            // leave wait alone!
          }
          
          points += 5;
        }
        else if (strcmp(getColorGObject(collision), "#FF9933") == 0)
        {
          if (!(wait < 7))
          {
            wait = 7;
            setColor(ball, "#FF9933");
            setColor(paddle, "#FF9933");
          }
          else
          {
            // leave wait alone...
          }
          points += 3;
        }
        else if (strcmp(getColorGObject(collision), "#FFCC00") == 0)
        {
          points += 2;
        }
        else
        {
          points++;
        }
      } else {
        velocity = -velocity;
        if (getX(ball) < getWidth(paddle)/2)
        {
          xvelocity = -xvelocity;
        }
        else if (getX(ball) > getWidth(paddle)/2)
        {
          // leave xvelocity alone.
        }
      }
    }
    // linger before moving again
    pause(wait);
    updateScoreboard(window, label, points);
  }

  if (lives > 0)
  {
    char s[12];
    sprintf(s, "WIN: %i!", points);
    setLabel(label, s);
  } else {
    setLabel(label, "LOOSE!");
  }
  // wait for click before exiting
  waitForClick();

  // game over
  closeGWindow(window);
  return 0;
}
示例#21
0
typename Rectangle2< T >::PointType Rectangle2< T >::getSize() const
{
    return PointType( getWidth(), getHeight() );
}
示例#22
0
文件: window.cpp 项目: blue112/jlug
/**
* \brief get width and height of the window
*/
jlug::Rect jlug::Window::getSize(void)
 {
     jlug::Rect rect(0, 0, getWidth(), getHeight());
     return rect;
 }
示例#23
0
 void OutOfBoundsEx::__print_args(std::ostream &os) const {
     os << getWidth() << ' ' << getHeight() << " is out of bounds of " << getExpWidth() <<  ' '  << getExpHeight();
 }
示例#24
0
 float timeToX (const double time) const
 {
     return getWidth() * (float) ((time - visibleRange.getStart()) / (visibleRange.getLength()));
 }
void WebBrowserComponent::resized()
{
    browser->setSize (getWidth(), getHeight());
}
示例#26
0
 double xToTime (const float x) const
 {
     return (x / getWidth()) * (visibleRange.getLength()) + visibleRange.getStart();
 }
示例#27
0
/**
 * Changes the height of the surface.
 * @warning This is not a trivial setter!
 * It will force the surface to be recreated for the new size.
 * @param height New height in pixels.
 */
void Surface::setHeight(int height)
{
	resize(getWidth(), height);
	_redraw = true;
}
void TooltipWindow::paint (Graphics& g)
{
    getLookAndFeel().drawTooltip (g, tipShowing, getWidth(), getHeight());
}
示例#29
0
文件: table.cpp 项目: Ablu/mana
gcn::Rectangle GuiTable::getChildrenArea() const
{
    return gcn::Rectangle(0, 0, getWidth(), getHeight());
}
示例#30
0
bool ofPixels_<PixelType>::blendInto(ofPixels_<PixelType> &dst, size_t xTo, size_t yTo) const{
	if (!(isAllocated()) || !(dst.isAllocated()) || getBytesPerPixel() != dst.getBytesPerPixel() || xTo + getWidth()>dst.getWidth() || yTo + getHeight()>dst.getHeight() || getNumChannels()==0) return false;

	std::function<void(const ConstPixel&,Pixel&)> blendFunc;
	switch(getNumChannels()){
	case 1:
		blendFunc = [](const ConstPixel&src, Pixel&dst){
			dst[0] = clampedAdd(src[0], dst[0]);
		};
		break;
	case 2:
		blendFunc = [](const ConstPixel&src, Pixel&dst){
			dst[0] = clampedAdd(src[0], dst[0] / ofColor_<PixelType>::limit() * (ofColor_<PixelType>::limit() - src[1]));
			dst[1] = clampedAdd(src[1], dst[1] / ofColor_<PixelType>::limit() * (ofColor_<PixelType>::limit() - src[1]));
		};
		break;
	case 3:
		blendFunc = [](const ConstPixel&src, Pixel&dst){
			dst[0] = clampedAdd(src[0], dst[0]);
			dst[1] = clampedAdd(src[1], dst[1]);
			dst[2] = clampedAdd(src[2], dst[2]);
		};
		break;
	case 4:
		blendFunc = [](const ConstPixel&src, Pixel&dst){
			dst[0] = clampedAdd(src[0], dst[0] / ofColor_<PixelType>::limit() * (ofColor_<PixelType>::limit() - src[3]));
			dst[1] = clampedAdd(src[1], dst[1] / ofColor_<PixelType>::limit() * (ofColor_<PixelType>::limit() - src[3]));
			dst[2] = clampedAdd(src[2], dst[2] / ofColor_<PixelType>::limit() * (ofColor_<PixelType>::limit() - src[3]));
			dst[3] = clampedAdd(src[3], dst[3] / ofColor_<PixelType>::limit() * (ofColor_<PixelType>::limit() - src[3]));
		};
		break;
	}
	auto dstLine = dst.getLine(yTo);
	for(auto line: getConstLines()){
		auto dstPixel = dstLine.getPixels().begin() + xTo;
		for(auto p: line.getPixels()){
			blendFunc(p,dstPixel);
			dstPixel++;
		}
		dstLine++;
	}

	return true;
}