Ejemplo n.º 1
0
//----------------------------------------------------------------------------//
void RenderedString::split(const size_t line, float split_point,
                           RenderedString& left)
{
    // FIXME: This function is big and nasty; it breaks all the rules for a
    // 'good' function and desperately needs some refactoring work done to it.
    // On the plus side, it does seem to work though ;)

    if (line >= getLineCount())
        CEGUI_THROW(InvalidRequestException("RenderedString::split: "
            "line number specified is invalid."));

    left.clearComponents();

    if (d_components.empty())
        return;

    // move all components in lines prior to the line being split to the left
    if (line > 0)
    {
        // calculate size of range
        const size_t sz = d_lines[line - 1].first + d_lines[line - 1].second;
        // range start
        ComponentList::iterator cb = d_components.begin();
        // range end (exclusive)
        ComponentList::iterator ce = cb + sz;
        // copy components to left side
        left.d_components.assign(cb, ce);
        // erase components from this side.
        d_components.erase(cb, ce);

        LineList::iterator lb = d_lines.begin();
        LineList::iterator le = lb + line;
        // copy lines to left side
        left.d_lines.assign(lb, le);
        // erase lines from this side
        d_lines.erase(lb, le);
    }

    // find the component where the requested split point lies.
    float partial_extent = 0;

    size_t idx = 0;
    const size_t last_component = d_lines[0].second;
    for (; idx < last_component; ++idx)
    {
        partial_extent += d_components[idx]->getPixelSize().d_width;

        if (split_point <= partial_extent)
            break;
    }

    // case where split point is past the end
    if (idx >= last_component)
    {
        // transfer this line's components to the 'left' string.
        //
        // calculate size of range
        const size_t sz = d_lines[0].second;
        // range start
        ComponentList::iterator cb = d_components.begin();
        // range end (exclusive)
        ComponentList::iterator ce = cb + sz;
        // copy components to left side
        left.d_components.insert(left.d_components.end(), cb, ce);
        // erase components from this side.
        d_components.erase(cb, ce);

        // copy line info to left side
        left.d_lines.push_back(d_lines[0]);
        // erase line from this side
        d_lines.erase(d_lines.begin());

        // fix up lines in this object
        for (size_t comp = 0, i = 0; i < d_lines.size(); ++i)
        {
            d_lines[i].first = comp;
            comp += d_lines[i].second;
        }

        return;
    }

    left.appendLineBreak();
    const size_t left_line = left.getLineCount() - 1;
    // Everything up to 'idx' is xfered to 'left'
    for (size_t i = 0; i < idx; ++i)
    {
        left.d_components.push_back(d_components[0]);
        d_components.erase(d_components.begin());
        ++left.d_lines[left_line].second;
        --d_lines[0].second;
    }

    // now to split item 'idx' putting half in left and leaving half in this.
    RenderedStringComponent* c = d_components[0];
    if (c->canSplit())
    {
        RenderedStringComponent* lc = 
            c->split(split_point - (partial_extent - c->getPixelSize().d_width),
                     idx == 0);

        if (lc)
        {
            left.d_components.push_back(lc);
            ++left.d_lines[left_line].second;
        }
    }
    // can't split, if component width is >= split_point xfer the whole
    // component to it's own line in the left part (FIX #306)
    else if (c->getPixelSize().d_width >= split_point)
    {
        left.appendLineBreak();
        left.d_components.push_back(d_components[0]);
        d_components.erase(d_components.begin());
        ++left.d_lines[left_line + 1].second;
        --d_lines[0].second;
    }

    // fix up lines in this object
    for (size_t comp = 0, i = 0; i < d_lines.size(); ++i)
    {
        d_lines[i].first = comp;
        comp += d_lines[i].second;
    }
}
Ejemplo n.º 2
0
CCMutableArray<StringLabel*>* TagString::parse( bool useTag )
{
    string cut = "";
    int start_idx = 0;
    
    float zen_width = 0;

    
    // 全角幅を取得
    {
        StringLabel* label_zen = StringLabel::init( "1", ccc3(0,0,0), baseFontSize );

#if (CC_TARGET_PLATFORM == CC_PLATFORM_IOS)
        zen_width = (int)(label_zen->getContentSize().width);
#else
        zen_width = label_zen->getContentSize().width;
#endif
    }
    

    
    /////////////////////////////////////////////
    // 変数タグの置換
    start_idx = 0;
    
    for( ;; )
    {
        int tag_start1 = tagStr.find( "<param=", start_idx );
        if( tag_start1 == string::npos ) break;
        
        int tag_start2 = tagStr.find( ">", tag_start1 );
        
        string param_str = tagStr.substr( tag_start1+7, tag_start2-(tag_start1+7) );
        
        // 変数の値取得
        string value = ParamList::shared()->getValue( param_str );
        
        if( !value.empty() )
        {
            // 文字列の置換
            tagStr.replace( tag_start1, tag_start2-tag_start1+1, value );
            start_idx = 0;
            continue;
        }
        
        start_idx = tag_start2 + 1;
    }
    
    //tagStr->getStringWidth()
      
    /////////////////////////////////////////////
    // 自動改行チェック
    if( autoKaigyouFlg )
    {
        vector< string > list = StringComparator::comparate( tagStr );
        
        bool tag_start = false;

        float total_size = 0;
        
        string conv_str = "";
        
        for( int i = 0; i < list.size(); i++ )
        {
            if (useTag)
            {
                if( list[i] == "<" )
                {
                    tag_start = true;
                }
                
                if( list[i] == ">" )
                {
                    tag_start = false;
                    conv_str.append( list[i] );
                    continue;
                }
            
                if( tag_start )
                {
                    // 改行チェック
                    if( list[i] == "b" )
                    {
                        if( list[i+1] == "r" )
                        {
                            total_size = 0;
                        }
                    }
                    
                    conv_str.append( list[i] );
                    continue;
                }
            }
            
            float strw = 0;

            // 半角
            if( list[i].length() == 1 )
            {
                StringLabel* label = StringLabel::init( list[i].c_str(), ccc3(0,0,0), baseFontSize );
                strw = label->getContentSize().width;
            }
            // 全角
            else
            {
                strw = zen_width;
            }
            
            
            total_size += strw;
            
            // 改行を挿入
            if( width > 0 && total_size > width )
            {
                //CCLog( "kaigyou2 total_size=%d", total_size );
                
                // 改行コードを入れる
                conv_str.append( "<br>" );
                total_size = strw;
            }

            else
            {
                if (list[i] == "\n")  total_size = 0;
            }
            conv_str.append( list[i] );
            
            
        }
        
        tagStr = conv_str;
    }
  
    
    /////////////////////////////////////////////
    // 改行、カラー、フォントサイズ、アンカー解析
   
    int line = 0;
    
    start_idx = 0;
    
    int active_anchor = 0;
    int active_font_size = baseFontSize;
    ccColor3B active_color = baseColor;
    
    //CCLog( "tag_str=%s", tagStr.c_str() );

    bool brflg = false;

    for( ;; )
    {
        
        // 開始タグ判定
        int tag_start = tagStr.find( "<", start_idx );
        

        if( tag_start != string::npos && useTag )
        {
            //  表示文字列を取得
            cut = tagStr.substr( start_idx, tag_start - (start_idx) );
            
            //CCLog( "cut=%s actuve=%d", cut.c_str(), active_anchor );
            
            if( !cut.empty() || brflg )
            {
                parseList->addObject( new ColorString( cut, active_color, active_font_size, line, active_anchor ) );
            }
            
                
            int tag_close = tagStr.find( ">", tag_start );
            
            // タグ文字列取得
            string param_str = tagStr.substr( tag_start+1, tag_close-(tag_start+1) );
            
            // アンカー
            if( param_str.find( "left" ) != string::npos )
            {
                active_anchor = ALIGN_LEFT;
            }
        
            if( param_str.find( "center" ) != string::npos )
            {
                active_anchor = ALIGN_CENTER;
            }
            
            if( param_str.find( "right" ) != string::npos )
            {
                active_anchor = ALIGN_RIGHT;
            }
            
            // 改行
            if( param_str.find( "br" ) != string::npos )
            {
                line += 1;
                brflg = true;
            }
                
            // カラー設定
            if( param_str.find( "color=" ) != string::npos )
            {
                // 色情報の切り出し
                string color_str = param_str.substr( 6, param_str.length()-6 );
                
                // 色成分に分解
                char *csv = const_cast<char*>( color_str.c_str() );
                int red   = CommonUtils::StrToInt( strtok(  csv, ":" ) );
                int green = CommonUtils::StrToInt( strtok( NULL, ":" ) );
                int blue  = CommonUtils::StrToInt( strtok( NULL, ":" ) );
                
                active_color = ccc3( red, green, blue );
                
            }
            
            // フォントサイズ
            if( param_str.find( "size=" ) != string::npos )
            {
                string size_str = param_str.substr( 5, param_str.length()-5 );
                
                active_font_size = CommonUtils::StrToInt( size_str );
            }
            
            // カラー 終了タグ
            if( param_str.find( "/color" ) != string::npos )
            {
                active_color = baseColor;
            }

            // アンカー 終了タグ
            if( param_str.find( "/center" ) != string::npos )
            {
                active_anchor = ALIGN_LEFT;
            }
            
            if( param_str.find( "/right" ) != string::npos )
            {
                active_anchor = ALIGN_LEFT;
            }
            
            // フォントサイズ 終了タグ
            if( param_str.find( "/size" ) != string::npos )
            {
                active_font_size = baseFontSize;
            }
            
            start_idx = tag_close + 1;
        }
        
        else
        {
            /*
            for( ;; )
            {
                // 改行コードがある場合
                tag_start = tagStr.find( "\n", start_idx );
                if (tag_start != string::npos)
                {
                    //  表示文字列を取得
                    cut = tagStr.substr( start_idx, tag_start - (start_idx) );
                    
                    if( !cut.empty() )
                    {
                        parseList->addObject( new ColorString( cut, active_color, active_font_size, line, active_anchor ) );
                        line += 1;
                    }
                    start_idx = tag_start + 1;
                }
                else
                {
                    break;
                }
            }
            */
            cut = tagStr.substr( start_idx, tagStr.length() - (start_idx) );
            
            if( !cut.empty() )
            {
                //CCLog( "cut=%s", cut.c_str() );
                
                parseList->addObject( new ColorString( cut, active_color, active_font_size, line, active_anchor ) );
            }
            
            break;
        }
        
    }
    

    
    int linecnt = getLineCount();
    
    float basex = 0;
    float basey = 0;
    
    
    
    // アライン設定
    if( baseAlign == TEXT_ALIGN_CENTER_TOP )
    {
        basex = ( ( width - getStringWidth() )/2 );
    }
    
    if( baseAlign == TEXT_ALIGN_RIGHT_TOP )
    {
        basex = width - getStringWidth();
    }
    
    if( baseAlign == TEXT_ALIGN_LEFT_MIDDLE )
    {
        basey = ( ( height - getStringHeight() )/2 );
    }
    
    if( baseAlign == TEXT_ALIGN_CENTER_MIDDLE )
    {
        basex = ( ( width  - getStringWidth()  )/2 );
        basey = ( ( height - getStringHeight() )/2 );
    }
    
    if( baseAlign == TEXT_ALIGN_RIGHT_MIDDLE )
    {
        basex = width - getStringWidth();
        basey = ( ( height - getStringHeight() )/2 );
    }
    
    if( baseAlign == TEXT_ALIGN_CENTER_BOTTOM )
    {
        basex = ( ( width  - getStringWidth()  )/2 );
        basey = height - getStringHeight();
    }
    
    if( baseAlign == TEXT_ALIGN_RIGHT_BOTTOM )
    {
        basex = width - getStringWidth();
        basey = height - getStringHeight();
    }
    
    if( baseAlign == TEXT_ALIGN_LEFT_BOTTOM )
    {
        basey = height - getStringHeight();
    }
    
    float dispx = basex;
    float dispy = basey;
    
    // 返却用のリスト
    CCMutableArray<StringLabel*>* ret = new CCMutableArray<StringLabel*>;
    ret->autorelease();
    
    // ラベルを生成
    for( int i = 0; i < linecnt; i++ )
    {
        CCMutableArray<ColorString*> *list = getStringList( i );
        
        float lh = getStringLineHeight( i );
        float lw = getStringLineWidth( i );
        
        // 下合わせ
        dispy += lh;
        
        for( int j = 0; j < list->count(); j++ )
        {
            ColorString* cstr = list->getObjectAtIndex( j );
            
            // アライン
            if( j == 0 )
            {
                if( cstr->getAlign() == ALIGN_LEFT   ) dispx = 0;
                if( cstr->getAlign() == ALIGN_CENTER ) dispx = ((width-lw)/2);
                if( cstr->getAlign() == ALIGN_RIGHT  ) dispx = width - lw;
            }    
            
            // テキストを設定
            StringLabel* label = cstr->getStrLabel();
            
            label->setAlign( TEXT_ALIGN_LEFT_BOTTOM );
            //label->setPosition( dispx, dispy );
            label->setOffsetX( dispx );
            label->setOffsetY( dispy );
            
            ret->addObject( label );
            
            // ラベルサイズ取得
            CCSize size = label->getContentSize();
            dispx += size.width;
        }
        
        dispx  = basex;
    }
    
    
    return ret;
    
    
    
    
}
Ejemplo n.º 3
0
int main(int argc, char** argv){
	struct ccn * ccn = NULL;
	//struct ccn_charbuf * name = NULL;
	struct ccn_closure * incoming = NULL;
	//const char * arg = NULL;
	int res;
	int micros;
	char ch;
	struct mydata * mydata = NULL;
	int allow_stale = 0;
	int use_decimal = 1;

	// TANG: comment out unused variables
	//int lineMarker = -1;
	int start = 0;
	int flying = -1;
	
	int i = 0;
	
	char* urlFile = NULL;
		
	//By default, we will send all the urls listed in the file starting from position 0
	while ((ch = getopt(argc, argv, "n:s:f:hd")) != -1) {
        switch (ch) {
            case 'f':
				urlFile = optarg;
				//printf("file name = %s \n", optarg);
                break;
			case 's':
				start = atoi(optarg);
				//printf("start = %d \n", start);
				break;
            case 'n':
                res = atoi(optarg);
                if (1 <= res)
                flying = res;
                else
                    usage(argv[0]);
				//printf("flying = %d \n", flying);
                break;
			case 'd':
				DEBUG = 1;
				break;
            case 'h':
            default:
                usage(argv[0]);
        }
    }

	//Initialize the URL list	
	char ** urlList = NULL;

	int lineCount = getLineCount(urlFile);
	// printf("There are %d URLs in the file %s\n", lineCount, urlFile);
	
	if(flying == -1)
		flying = lineCount; //By default, all the URLs in the urlFile will be queried

	urlList = malloc(lineCount * sizeof(char*));

	char line[2000];

	int idx = 0;
	int lineIdx = 0;

	FILE *file = fopen(urlFile, "r");
	if(file == NULL){
		printf("Cannot open file %s, exiting...\n", urlFile);
		exit(-1);
	}

	while(fgets(line, sizeof line, file) != NULL){	/* read a line */
		if(lineIdx >= start && lineIdx < start + flying){
			urlList[idx] = malloc((strlen(line)) * sizeof(char));
			strcpy(urlList[idx], line);	
			urlList[idx][strlen(line)-1] = '\0';

			if(DEBUG){
				printf("URL %d = %s \n", idx, line);
				printf("URL length = %zu \n", strlen(line));
			}
				
			idx++;
		}
		lineIdx++;
	}
	

	ccn = ccn_create();
    if (ccn_connect(ccn, NULL) == -1) {
        perror("Could not connect to ccnd");
        exit(1);
    }

	mydata = calloc(1, sizeof(*mydata));
    mydata->h = ccn;
    mydata->allow_stale = allow_stale;
    mydata->use_decimal = use_decimal;
    mydata->excl = NULL;
	//Initialize the ooo data
	mydata->ooo = malloc(sizeof(struct ooodata) * flying);

    for (i = 0; i < flying; i++) {
        incoming = &mydata->ooo[i].closure;
        incoming->p = &incoming_content;
        incoming->data = mydata;
        incoming->intdata = -1;
    }

	//Build and send out a group of interests
	ask_set(mydata, urlList, flying);
	
	/* Run a little while to see if there is anything there*/
	res = ccn_run(ccn, 500);
	
    /* We got something, run until end of data or somebody kills us */
    while (res >= 0) {
        micros = 50000000;
        res = ccn_run(ccn, micros / 1000);
    }
	
	printf("Exiting....");

	fclose(urlFile);
	//Release the dynamically allocated memory
	free(mydata->ooo);
	free(mydata);
	ccn_destroy(&ccn);
    exit(res < 0);
}
Ejemplo n.º 4
0
void DOHexEditor::draw()
{
	S32 left = 0;
	S32 top = getRect().getHeight();
	S32 right = getRect().getWidth();
	S32 bottom = 0;

	BOOL has_focus = gFocusMgr.getKeyboardFocus() == this;

	F32 line_height = mGLFont->getLineHeight();
	F32 char_width = mGLFont->getWidthF32(".");
	F32 data_column_width = char_width * 3; // " 00";
	F32 text_x = mTextRect.mLeft;
	F32 text_x_data = text_x + (char_width * 10.1f); // "00000000  ", dunno why it's a fraction off
#ifdef COLUMN_SPAN
	mColumns = (right - char_width * 2 - text_x_data - mScrollbar->getRect().getWidth()) / (char_width * 4); // touch this if you dare...
#endif
	F32 text_x_ascii = text_x_data + (data_column_width * mColumns) + (char_width * 2);
	F32 text_y = (F32)(mTextRect.mTop - line_height);

	U32 data_length = mValue.size();
	U32 line_count = getLineCount();
	U32 first_line = mScrollbar->getDocPos();
	U32 last_line = first_line + mScrollbar->getPageSize(); // don't -2 from scrollbar sizes

	LLRect clip(getRect());
	clip.mRight = mScrollbar->getRect().mRight;
	clip.mLeft -= 10;
	clip.mBottom -= 10;
	LLLocalClipRect bgclip(clip);

	// Background
	gl_rect_2d(left, top, right, bottom, LLColor4::white);

	// Let's try drawing some helpful guides
	LLColor4 guide_color_light = LLColor4(1.0f, 1.0f, 0.9f);
	LLColor4 guide_color_dark = LLColor4(1.0f, 1.0f, 0.8f);
	for(U32 col = 0; col < mColumns; col += 2)
	{
		// Behind hex
		F32 box_left = text_x_data + (col * data_column_width) + 2; // skew 2
		F32 box_right = box_left + data_column_width;
		gl_rect_2d(box_left, top, box_right, bottom, (col & 3) ? guide_color_light : guide_color_dark);
		// Behind ASCII
		//box_left = text_x_ascii + (col * char_width) - 1; // skew 1
		//box_right = box_left + char_width;
		//gl_rect_2d(box_left, top, box_right, bottom, guide_color);
	}

	
	// Scrollbar & border (drawn twice?)
	mBorder->setKeyboardFocusHighlight(has_focus);
	LLView::draw();


	LLLocalClipRect textrect_clip(mTextRect);


	// Selection stuff is reused
	U32 selection_start = getProperSelectionStart();
	U32 selection_end = getProperSelectionEnd();
	U32 selection_first_line = selection_start / mColumns;
	U32 selection_last_line = selection_end / mColumns;
	U32 selection_start_column = selection_start % mColumns;
	U32 selection_end_column = selection_end % mColumns;

	// Don't pretend a selection there is visible
	if(!selection_end_column)
	{
		selection_last_line--;
		selection_end_column = mColumns;
	}

	if(mHasSelection)
	{
		LLColor4 selection_color_context(LLColor4::black);
		LLColor4 selection_color_not_context(LLColor4::grey3);
		LLColor4 selection_color_data(selection_color_not_context);
		LLColor4 selection_color_ascii(selection_color_not_context);
		if(mInData) selection_color_data = selection_color_context;
		else selection_color_ascii = selection_color_context;


		// Setup for selection in data
		F32 selection_pixel_x_base = text_x_data + char_width - 3; // skew 3
		F32 selection_pixel_x_right_base = selection_pixel_x_base + (data_column_width * mColumns) - char_width + 4;
		F32 selection_pixel_x;
		F32 selection_pixel_x_right;
		F32 selection_pixel_y = (F32)(mTextRect.mTop - line_height) - 3; // skew 3;
		selection_pixel_y -= line_height * 2;
		selection_pixel_y -= line_height * (S32(selection_first_line) - S32(first_line));

		// Selection in data, First line
		if(selection_first_line >= first_line && selection_first_line <= last_line)
		{
			selection_pixel_x = selection_pixel_x_base;
			selection_pixel_x += (data_column_width * selection_start_column);
			if(selection_first_line == selection_last_line)
			{
				// Select to last character
				selection_pixel_x_right = selection_pixel_x_base + (data_column_width * selection_end_column);
				selection_pixel_x_right -= (char_width - 4);
			}
			else
			{
				// Select to end of line
				selection_pixel_x_right = selection_pixel_x_right_base;
			}
			gl_rect_2d(selection_pixel_x, selection_pixel_y + line_height, selection_pixel_x_right, selection_pixel_y, selection_color_data);
		}

		// Selection in data, Middle lines
		for(U32 line = selection_first_line + 1; line < selection_last_line; line++)
		{
			selection_pixel_y -= line_height;
			if(line >= first_line && line <= last_line)
			{
				gl_rect_2d(selection_pixel_x_base, selection_pixel_y + line_height, selection_pixel_x_right_base, selection_pixel_y, selection_color_data);
			}
		}
		
		// Selection in data, Last line
		if(selection_first_line != selection_last_line
			&& selection_last_line >= first_line && selection_last_line <= last_line)
		{
			selection_pixel_x_right = selection_pixel_x_base + (data_column_width * selection_end_column);
			selection_pixel_x_right -= (char_width - 4);
			selection_pixel_y -= line_height;
			gl_rect_2d(selection_pixel_x_base, selection_pixel_y + line_height, selection_pixel_x_right, selection_pixel_y, selection_color_data);
		}

		selection_pixel_y = (F32)(mTextRect.mTop - line_height) - 3; // skew 3;
		selection_pixel_y -= line_height * 2;
		selection_pixel_y -= line_height * (S32(selection_first_line) - S32(first_line));

		// Setup for selection in ASCII
		selection_pixel_x_base = text_x_ascii - 1;
		selection_pixel_x_right_base = selection_pixel_x_base + (char_width * mColumns);

		// Selection in ASCII, First line
		if(selection_first_line >= first_line && selection_first_line <= last_line)
		{
			selection_pixel_x = selection_pixel_x_base;
			selection_pixel_x += (char_width * selection_start_column);
			if(selection_first_line == selection_last_line)
			{
				// Select to last character
				selection_pixel_x_right = selection_pixel_x_base + (char_width * selection_end_column);
			}
			else
			{
				// Select to end of line
				selection_pixel_x_right = selection_pixel_x_right_base;
			}
			gl_rect_2d(selection_pixel_x, selection_pixel_y + line_height, selection_pixel_x_right, selection_pixel_y, selection_color_ascii);
		}

		// Selection in ASCII, Middle lines
		for(U32 line = selection_first_line + 1; line < selection_last_line; line++)
		{
			selection_pixel_y -= line_height;
			if(line >= first_line && line <= last_line)
			{
				gl_rect_2d(selection_pixel_x_base, selection_pixel_y + line_height, selection_pixel_x_right_base, selection_pixel_y, selection_color_ascii);
			}
		}
		
		// Selection in ASCII, Last line
		if(selection_first_line != selection_last_line
			&& selection_last_line >= first_line && selection_last_line <= last_line)
		{
			selection_pixel_x_right = selection_pixel_x_base + (char_width * selection_end_column);
			selection_pixel_y -= line_height;
			gl_rect_2d(selection_pixel_x_base, selection_pixel_y + line_height, selection_pixel_x_right, selection_pixel_y, selection_color_ascii);
		}
	}


	// Insert/Overwrite
	std::string text = (LL_KIM_OVERWRITE == gKeyboard->getInsertMode()) ? "OVERWRITE" : "INSERT";
	mGLFont->renderUTF8(text, 0, text_x, text_y, LLColor4::purple);
	// Offset on top
	text = "";
	for(U32 i = 0; i < mColumns; i++)
	{
		text.append(llformat(" %02X", i));
	}
	mGLFont->renderUTF8(text, 0, text_x_data, text_y, LLColor4::blue);
	// Size
	{
		S32 size = mValue.size();
		std::string size_desc;
		if(size < 1000) size_desc = llformat("%d bytes", size);
		else
		{
			if(size < 1000000)
			{
				size_desc = llformat("%f", F32(size) / 1000.0f);
				int i = size_desc.length() - 1;
				for(; i && size_desc.substr(i, 1) == "0"; i--);
				if(size_desc.substr(i, 1) == ".") i--;
				size_desc = size_desc.substr(0, i + 1);
				size_desc.append(" KB");
			}
			else
			{
				size_desc = llformat("%f", F32(size) / 1000000.0f);
				int i = size_desc.length() - 1;
				for(; i && size_desc.substr(i, 1) == "0"; i--);
				if(size_desc.substr(i, 1) == ".") i--;
				size_desc = size_desc.substr(0, i + 1);
				size_desc.append(" MB");
			}
		}
		F32 x = text_x_ascii;
		x += (char_width * (mColumns - size_desc.length()));
		mGLFont->renderUTF8(size_desc, 0, x, text_y, LLColor4::purple);
	}
	// Leave a blank line
	text_y -= (line_height * 2);

	// Everything below "header"
	for(U32 line = first_line; line <= last_line; line++)
	{
		if(line >= line_count) break;
		
		// Offset on left
		text = llformat("%08X", line * mColumns); // offset on left
		mGLFont->renderUTF8(text, 0, text_x, text_y, LLColor4::blue);

		// Setup for rendering hex and ascii
		U32 line_char_offset = mColumns * line;
		U32 colstart0 = 0;
		U32 colend0 = mColumns;
		U32 colstart1 = mColumns;
		U32 colend1 = mColumns;
		U32 colstart2 = mColumns;
		U32 colend2 = mColumns;
		if(mHasSelection)
		{
			if(line == selection_first_line)
			{
				colend0 = selection_start_column;
				colstart1 = selection_start_column;
				if(selection_first_line == selection_last_line)
				{
					colend1 = selection_end_column;
					colstart2 = selection_end_column;
					colend2 = mColumns;
				}
			}
			else if(line > selection_first_line && line < selection_last_line)
			{
				colend0 = 0;
				colstart1 = 0;
				colend1 = mColumns;
			}
			else if(line == selection_last_line)
			{
				colend0 = 0;
				colstart1 = 0;
				colend1 = selection_end_column;
				colstart2 = selection_end_column;
				colend2 = mColumns;
			}
		}

		// Data in hex
		text = "";
		for(U32 c = colstart0; c < colend0; c++)
		{
			U32 o = line_char_offset + c;
			if(o >= data_length) text.append("   ");
			else text.append(llformat(" %02X", mValue[o]));
		}
		mGLFont->renderUTF8(text, 0, text_x_data + (colstart0 * data_column_width), text_y, LLColor4::black);
		text = "";
		for(U32 c = colstart1; c < colend1; c++)
		{
			U32 o = line_char_offset + c;
			if(o >= data_length) text.append("   ");
			else text.append(llformat(" %02X", mValue[o]));
		}
		mGLFont->renderUTF8(text, 0, text_x_data + (colstart1 * data_column_width), text_y, LLColor4::white);
		text = "";
		for(U32 c = colstart2; c < colend2; c++)
		{
			U32 o = line_char_offset + c;
			if(o >= data_length) text.append("   ");
			else text.append(llformat(" %02X", mValue[o]));
		}
		mGLFont->renderUTF8(text, 0, text_x_data + (colstart2 * data_column_width), text_y, LLColor4::black);

		// ASCII
		text = "";
		for(U32 c = colstart0; c < colend0; c++)
		{
			U32 o = line_char_offset + c;
			if(o >= data_length) break;
			if((mValue[o] < 0x20) || (mValue[o] >= 0x7F)) text.append(".");
			else text.append(llformat("%c", mValue[o]));
		}
		mGLFont->renderUTF8(text, 0, text_x_ascii + (colstart0 * char_width), text_y, LLColor4::black);
		text = "";
		for(U32 c = colstart1; c < colend1; c++)
		{
			U32 o = line_char_offset + c;
			if(o >= data_length) break;
			if((mValue[o] < 0x20) || (mValue[o] >= 0x7F)) text.append(".");
			else text.append(llformat("%c", mValue[o]));
		}
		mGLFont->renderUTF8(text, 0, text_x_ascii + (colstart1 * char_width), text_y, LLColor4::white);
		text = "";
		for(U32 c = colstart2; c < colend2; c++)
		{
			U32 o = line_char_offset + c;
			if(o >= data_length) break;
			if((mValue[o] < 0x20) || (mValue[o] >= 0x7F)) text.append(".");
			else text.append(llformat("%c", mValue[o]));
		}
		mGLFont->renderUTF8(text, 0, text_x_ascii + (colstart2 * char_width), text_y, LLColor4::black);

		text_y -= line_height;
	}



	// Cursor
	if(has_focus && !mHasSelection && (U32(LLTimer::getElapsedSeconds() * 2.0f) & 0x1))
	{
		U32 cursor_line = mCursorPos / mColumns;
		if((cursor_line >= first_line) && (cursor_line <= last_line))
		{
			F32 pixel_y = (F32)(mTextRect.mTop - line_height);
			pixel_y -= line_height * (2 + (cursor_line - first_line));

			U32 cursor_offset = mCursorPos % mColumns; // bytes
			F32 pixel_x = mInData ? text_x_data : text_x_ascii;
			if(mInData)
			{
				pixel_x += data_column_width * cursor_offset;
				pixel_x += char_width;
				if(mSecondNibble) pixel_x += char_width;
			}
			else
			{
				pixel_x += char_width * cursor_offset;
			}
			pixel_x -= 2.0f;
			pixel_y -= 2.0f;
			gl_rect_2d(pixel_x, pixel_y + line_height, pixel_x + 2, pixel_y, LLColor4::black);
		}
	}
}
Ejemplo n.º 5
0
void CodeEditor::update(RenderWindow *window) {
	mTopbar.setSize(window->getWidth() - 8, mTopbar.getSize().y);
	if (mLineHighlightType != LineHighlightType::LineNumberArea) {
		mLineHighlightRect.setSize(window->getWidth() - 8, mLineHighlightRect.getSize().y);
	} else {
		mLineHighlightRect.setSize(mLineNumberAreaWidth, mLineHighlightRect.getSize().y);
	}

	//TODO: move the cursor when the text is scrolled.
	//TODO: make the above optional
	//TODO: make it so that when the cursor is moved outside the view, the view is back on the cursor.

	uint32 cursorY = mText[mCurrentLine].getPosition().y + 2;

	//Check to see if we scrolled to far in either direction.
	if (mText.size() > 1) {
		if (mText[0].getPosition().y > mPos.y) {
			uint32 deltaY = (mText[0].getPosition().y - mPos.y);
			for (uint32 i = 0; i < mText.size(); ++i) {
				mText[i].setPosition(mText[i].getPosition().x, mText[i].getPosition().y - deltaY);
				mLineNumbers[i].setPosition(mLineNumbers[i].getPosition().x, mLineNumbers[i].getPosition().y - deltaY);
			}
		}

		uint32 max = mText.size() - 1;
		if (mText[max].getPosition().y < mPos.y) {
			uint32 deltaY = (mPos.y - mText[max].getPosition().y);
			for (uint32 i = 0; i < mText.size(); ++i) {
				mText[i].setPosition(mText[i].getPosition().x, mText[i].getPosition().y + deltaY);
				mLineNumbers[i].setPosition(mLineNumbers[i].getPosition().x, mLineNumbers[i].getPosition().y + deltaY);
			}
		}

		cursorY = mText[mCurrentLine].getPosition().y + 2;

		if (mText[mCurrentLine].getPosition().y < mPos.y) {
			for (uint32 i = mCurrentLine; i < mText.size(); ++i) {
				if (mText[i].getPosition().y >(mPos.y - mFontSize)) {
					mCurrentLine = i;
					cursorY = mText[i].getPosition().y + 2;
					break;
				}
			}
		} else if (mText[mCurrentLine].getPosition().y > (mPos.y + mSize.y - (mFontSize * 2))) {
			for (int32 i = mCurrentLine; i >= 0; --i) {
				if (mText[i].getPosition().y < (mPos.y + mSize.y - (mFontSize * 2))) {
					mCurrentLine = i;
					cursorY = mText[i].getPosition().y + 2;
					break;
				}
			}
		}
	}

	if (mCursorType == CursorType::Underscore) {
		cursorY += Preferences::instance()->getFont()->getLineSpacing(mFontSize) - 2;
	}

	uint32 cursorX = 0;
	mUpperBound = 0;
	if (mLineIndex >= getLineLength(mCurrentLine)) {
		mUpperBound = getLineLength(mCurrentLine);
	} else {
		mUpperBound = mLineIndex;
	}

	for (int i = 0; i < mUpperBound; ++i) {
		uint32 c = getLine(mCurrentLine)[i];

		if (c == '\t') {
			cursorX += (getCharWidth(L'') * mTabWidth);
		} else {
			cursorX += getCharWidth(c);
		}
	}

	uint32 markX = 0;
	for (int i = 0; i < mMarkIndex; ++i) {
		uint32 c = getLine(mMarkLine)[i];

		if (c == '\t') {
			markX += (getCharWidth(L'') * mTabWidth);
		} else {
			markX += getCharWidth(c);
		}
	}

	uint32 markY = mText[mMarkLine].getPosition().y + 2;

	mCursorRect.setPosition(mPos.x + mLineNumberAreaWidth + cursorX /*offset*/, cursorY);
	mCurrentChar.setPosition(mCursorRect.getPosition().x, mCursorRect.getPosition().y - 2);
	mMarkRect.setPosition(mPos.x + mLineNumberAreaWidth + markX /*offset*/, markY);
	if (mLineHighlightType != LineHighlightType::CodeArea) {
		mLineHighlightRect.setPosition(mPos.x, cursorY);
	} else {
		mLineHighlightRect.setPosition(mPos.x + mLineNumberAreaWidth, cursorY);
	}

	if (mCursorType != CursorType::CursorLine) {
		mCursorRect.setWidth(getCharWidth(getCurrentChar()));
	}

	mMarkRect.setWidth(getCharWidth(getMarkChar()));

	if (!mFirstMarkSet) {
		setMark();
		mFirstMarkSet = true;
	}

	mCurrentChar.setString(getCurrentChar());

	bool useMilitaryTime = Preferences::instance()->useMilitaryTime();

	Clock clock(useMilitaryTime);

	int32 hour = clock.getCurrentHour();
	int32 minute = clock.getCurrentMinute();
	int32 second = clock.getCurrentSecond();

	String ampm = clock.isPm() ? "PM" : "AM";
	ampm = useMilitaryTime ? "" : ampm;

	String hourStr = String::number(hour);
	String minuteStr = String::number(minute);
	String secondStr = String::number(second);

	if (minuteStr.getLength() == 1) {
		minuteStr.prepend("0");
	}

	if (secondStr.getLength() == 1) {
		secondStr.prepend("0");
	}

	Date date = Date::currentDate();

	String time = Preferences::instance()->showClock() ? hourStr + ":" + minuteStr + ":" + secondStr + " " + ampm : "";
	String dateStr = date.getDayName() + " " + date.getMonthName() + " " + String::number(date.dayOfMonth()) + " " + String::number(date.getYear()) + " week of the year: " + String::number(date.weekNumber());

	if (mClock.getCurrentTimeInMilliseconds() >= (timeNow + 1000)) {
		timeNow = mClock.getCurrentTimeInMilliseconds();
		frameRate = frames;
		frames = 0;
	}
	
	uint32 p = (staticCastf(mCurrentLine + 1) / staticCastf(getLineCount())) * 100;
	mTopBarText.setString(mFilename + "\t" + String::number(p) + "% " + String::number(mCurrentLine + 1) + ":u" + String::number(mUpperBound) +
		", i" + String::number(mLineIndex) + "\t" + dateStr + " " + time + "\tfps: " + String::number(frameRate));

	//Draw/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

	if (mShowLineNumbers) {
		window->draw(mLineNumberArea);
	}

	if (mShowLineHighlight) {
		window->draw(mLineHighlightRect);
	}

	for (uint32 i = 0; i < mText.size(); ++i) {
		if ((mText[i].getPosition().y < (mPos.y - mFontSize)) || (mText[i].getPosition().y >= mPos.y + mSize.y)) {
			continue;
		}

		if (mShowLineHighlight && mLineHighlightType != LineHighlightType::LineNumberArea) {
			if (i == mCurrentLine) {
				mText[i].setColor(mLineHighlightTextColor);
			}

			if (i != mCurrentLine && mText[i].getColor() != mTextColor) {
				mText[i].setColor(mTextColor);
			}
		}

		if (mShowLineNumbers) {
			window->draw(mLineNumbers[i]);
		}

		window->draw(mText[i]);
	}
	
	if (mClock.getCurrentTimeInMilliseconds() >= (mLastBlinkTime + 500)) {
		mLastBlinkTime = mClock.getCurrentTimeInMilliseconds();
		mShowCursor = !mShowCursor;
	}

	if (!mBlinkCursor) {
		mShowCursor = true;
	}

	if (mShowCursor) {
		window->draw(mCursorRect);
	}

	if (mShowMark) {
		window->draw(mMarkRect);
	}

	String str = mCurrentChar.getString();
	if (mShowCursor && mCursorType == CursorType::Block && !str.isEmpty() && str != "\r") {
		window->draw(mCurrentChar);
	}

	mTopbar.setFillColor(Preferences::instance()->getTheme().barColor);
	window->draw(mTopbar);
	window->draw(mTopBarText);

	++frames;
}
Ejemplo n.º 6
0
const ChatLine& ChatBuffer::getLine(u32 index) const
{
	assert(index < getLineCount());	// pre-condition
	return m_unformatted[index];
}
Ejemplo n.º 7
0
int main(int argc, char *argv[]) {

  int i, j, k, countTopUsers;
  
  //file containing matrix of form CSR
  char *ipCSRAdjFileName;

  //list of users on which to apply page rank
  char *usersFileName;

  //number of cpus
  int cpucount;

  //to store graph adjacency matrix
  gk_csr_t *adjMat;

  int numUsers;

  //araay of user id
  int *users;

  gk_fkv_t **topUsers;
  int *topUserCount;

  int minSimUsers;

  char *opFile = "GraphRead.txt";
  
  if (argc < 4) {
    //not wnough arguments passed
    printf("\n Not enough arguments passed. \n");
    return -1;
  } 
  
  //parse commandline arguments
  ipCSRAdjFileName = argv[1];
  usersFileName = argv[2];
  minSimUsers = atoi(argv[3]);
  cpucount = atoi(argv[4]);

  //printf("\nBuilding adjacency matrix...\n");
  //read the adjacency matrix
  adjMat = gk_csr_Read(ipCSRAdjFileName, GK_CSR_FMT_CSR, 0, 0);
  //gk_csr_Write(adjMat, opFile, GK_CSR_FMT_CSR, 0, 0);
    
  fprintf(stderr, "\nMatrix building completed...\n");
  //get the number of users
  numUsers = getLineCount(usersFileName);
  users = getUsers(usersFileName, numUsers);
  
  //maintain storage of top similar users of cpucount users
  topUsers = (gk_fkv_t**) malloc(sizeof(gk_fkv_t*) * cpucount);
  for (i = 0; i < cpucount; i++) {
    topUsers[i] = (gk_fkv_t*) malloc(sizeof(gk_fkv_t) * minSimUsers);
  }

  //storage for top users count of chunk
  topUserCount = (int *) malloc(sizeof(int) * cpucount);
  
  //apply the personalized page rank for each user
  for (i = 0; i < numUsers; i+=cpucount) {

#pragma omp parallel default(none) private(j) shared(users, topUsers, topUserCount, adjMat) \
  firstprivate(i, minSimUsers, numUsers, cpucount)
    {
#pragma omp for
      for (j = 0; j < cpucount; j++) {
	if (i+j < numUsers) {
	  //find top users for users[i+j]
	  //get the top rank vertices from personalized page rank iteration	
	  topUserCount[j] = getTopSimUsers(adjMat, users[i+j], topUsers[j], minSimUsers);
	}
      }
    }

    //write the values for users chunks
    for (j = 0; j < cpucount; j++) {
      if (i+j < numUsers) {
	//user 
	printf("%d", users[i+j]);
	for (k = 0; k < topUserCount[j]; k ++) {
	  //print the top similar users with corresponding pr
	  printf("\t%d:%f", topUsers[j][k].val, topUsers[j][k].key);
	}
	printf("\n");
      }
    }
    

  }
    
  return 0;
}