Example #1
0
int mk_advance_one_code_point(const UTF16 **p, const UTF16 *end) {
  FQ_ASSERT(*p < end);

  // TODO_UTF16: FIXME: only support BMP here.
  *p = *p + 1;
  return get_str_width(**p);
}
Example #2
0
File: ui.c Project: JBarrada/fancy
void broadcast_msg(char *text, char big, unsigned char wait, unsigned char fg, unsigned char bg) {
	int text_width = (big)?get_str_width_big(text):get_str_width(text);
	int text_height = (big)?25:16;
	
	uint32_t absolute_x = (WIDTH_W/2) - (text_width/2) - 10;
	uint32_t absolute_y = (HEIGHT_W/2) - (text_height/2) - 10;
	
	ashes_palette_dim();
	
	rectangle_filled(absolute_x, absolute_y, text_width + (2*10), text_height + (2*10), bg);
	
	if (big)
		putstr_big(absolute_x + 10, absolute_y + 10, text, fg);
	else
		putstr(absolute_x + 10, absolute_y + 10, text, fg);
	
	swap_buffers();
	
	if (wait) {
		uint16_t key;
		while (1) {
			key = get_key();
			switch (key) {
				case ENTER_PRESSED:
				case ESC_PRESSED:
					ashes_palette();
					return;
			}
		}
	}
}
Example #3
0
File: ui.c Project: JBarrada/fancy
void draw_selection_prompt(char *text, char items[][100], int num_items, unsigned int selected) {
	uint32_t prompt_px_width = get_str_width(text);

	int i, item_width, selection_width = 0;
	for (i=0; i<num_items; i++) {
		item_width = get_str_width_big(items[i]);
		selection_width = (item_width+10>selection_width)?item_width+10:selection_width;
	}
	
	int box_height = 10 + 16 + 10 + 27 + 10;
	int box_width = ((prompt_px_width+20)>((selection_width*num_items)+10+(10*num_items)))?(prompt_px_width+20):((selection_width*num_items)+10+(10*num_items));
	
	uint32_t absolute_x = (WIDTH_W/2) - (box_width/2);
	uint32_t absolute_y = (HEIGHT_W/2) - (box_height/2);
	
	rectangle_filled(absolute_x, absolute_y, box_width, box_height, 4+8);

	putstr((WIDTH_W/2) - (prompt_px_width/2) , absolute_y + 10, text, 1+8);
	
	absolute_x += (box_width/2) - (((selection_width*num_items)+10+(10*num_items))/2) + 10;
	for (i=0; i<num_items; i++) {
		item_width = get_str_width_big(items[i]);
		if (i==selected)
			rectangle_filled(absolute_x, absolute_y + 26 + 10, selection_width, 27, 1+8);
		putstr_big(absolute_x + (selection_width/2) - (item_width/2), absolute_y + 26 + 10 + 1, items[i], (i==selected)?4+8:3+8);
		absolute_x += 10 + selection_width;
	}

	swap_buffers();
}
Example #4
0
File: ui.c Project: JBarrada/fancy
void draw_text_prompt(char *text, char *buffer, int max_char) {
	int buf_loc = strlen(buffer);
	
	char prompt[100];
	memset(prompt, 0 ,100);
	sstring(prompt, "%s (%d:%d)", text, buf_loc, max_char);
	
	uint32_t prompt_px_width = get_str_width(prompt);
	uint32_t buffer_px_width = get_str_width_big(buffer);
	
	int box_height = 10 + 16 + 10 + 27 + 10;
	int box_width = ((prompt_px_width+20)>(buffer_px_width+20+10+6))?(prompt_px_width+20):(buffer_px_width+20+10+6);
	
	uint32_t absolute_x = (WIDTH_W/2) - (box_width/2);
	uint32_t absolute_y = (HEIGHT_W/2) - (box_height/2);
	
	rectangle_filled(absolute_x, absolute_y, box_width, box_height, 3+8);
	rectangle_filled(absolute_x+10, absolute_y+26 + 10, box_width - 20, 27, 4+8);
		
	putstr((WIDTH_W/2) - (prompt_px_width/2) , absolute_y + 10, prompt, 1+8);
	
	putstr_big(absolute_x+14, absolute_y+26 + 10 + 1, buffer, 1+8);
	putstr_big(absolute_x+14 + buffer_px_width, absolute_y+26 + 10 + 1, "_", 2+8);
	
	swap_buffers();
}
Example #5
0
File: ui.c Project: JBarrada/fancy
int draw_text(TEXT *text_element, uint32_t a_x, uint32_t a_y) {
	int str1_width = get_str_width(text_element->text1);
	int str2_width = get_str_width(text_element->text2);
	
	int text1_x = (text_element->align==1)?(WIDTH_W-text_element->pos.x-str1_width):(a_x+text_element->pos.x);
	int text2_x = WIDTH_W-text_element->pos.x-str2_width;
	int text_y = a_y+text_element->pos.y;
	
	putstr(text1_x, text_y, text_element->text1, text_element->color);
	
	if (text_element->is_list_item) {
		putstr(text2_x, text_y, text_element->text2, text_element->color);
		line(text1_x+str1_width+4, text_y+9, text2_x-6, text_y+9, text_element->color);
	}

	return (text_element->pos.y + 16);
}
Example #6
0
int mk_advace_at_least_one_cell(const UTF16 **p, const UTF16 *end) {
  FQ_ASSERT(*p < end);

  // TODO_UTF16: FIXME: only support BMP here.
  int w = 0;
  int width = 0;
  do {
    w = get_str_width(**p);
    width += w;
    *p = *p + 1;
  } while (w == 0 && *p < end);

  if (w < 0) {
    return -1;
  }

  while (*p < end && get_str_width(**p) == 0) {
    *p = *p + 1;
  }
  
  return width;
}
Example #7
0
int get_column_widths(HWND hlistview,int *widths,int wcount)
{
	int i,count;
	count=lv_get_column_count(hlistview);
	for(i=0;i<count;i++){
		char str[255]={0};
		lv_get_col_text(hlistview,i,str,sizeof(str));
		if(str[0]!=0){
			if(i<wcount)
				widths[i]=get_str_width(hlistview,str);
		}
	}
	return count;
}
Example #8
0
static int resize_column(HWND hwnd,HWND hlistview,char *str,int col)
{
	int cw,sw;
	cw=ListView_GetColumnWidth(hlistview,col);
	sw=get_str_width(hlistview,str)+14;
	if(sw>cw){
		RECT rect={0};
		int diff=sw-cw;
		int w,h;
		GetWindowRect(hwnd,&rect);
		w=rect.right-rect.left;
		h=rect.bottom-rect.top;
		SetWindowPos(hwnd,NULL,0,0,w+diff,h,SWP_NOMOVE|SWP_NOZORDER);
		ListView_SetColumnWidth(hlistview,col,cw+diff);
	}
	return TRUE;
}
Example #9
0
int lv_add_column(HWND hlistview,char *str,int index)
{
	LV_COLUMN col;
	if(hlistview!=0 && str!=0){
		HWND header;
		int width=0;
		header=SendMessage(hlistview,LVM_GETHEADER,0,0);
		width=get_str_width(header,str);
		width+=14;
		if(width<40)
			width=40;
		col.mask = LVCF_WIDTH|LVCF_TEXT;
		col.cx = width;
		col.pszText = str;
		if(ListView_InsertColumn(hlistview,index,&col)>=0)
			return width;
	}
	return 0;
}
Example #10
0
void CUILines::ParseText() {
    if ( !fsimilar(m_oldWidth, m_wndSize.x) )
    {
        uFlags.set(flNeedReparse, TRUE);
        m_oldWidth = m_wndSize.x;
    }
    if (!uFlags.test(flComplexMode) || !uFlags.test(flNeedReparse))
        return;

    if(NULL == m_pFont)
        return;

    Reset();
    if (!m_text.empty() && NULL == m_pFont)
        R_ASSERT2(false, "can't parse text without font");


    CUILine* line = NULL;
    if (uFlags.test(flColoringMode))
        line = ParseTextToColoredLine(m_text.c_str());
    else
    {
        line = xr_new<CUILine>();
        CUISubLine subline;
        subline.m_text = m_text;
        subline.m_color = GetTextColor();
        line->AddSubLine(&subline);
    }

    BOOL bNewLines = FALSE;

    if (uFlags.test(flRecognizeNewLine))
        if ( m_pFont->IsMultibyte() ) {
            CUILine *ptmp_line = xr_new<CUILine>();
            int vsz = line->m_subLines.size();
            VERIFY( vsz );
            for ( int i = 0 ; i < vsz ; i++ ) {
                char *pszTemp = NULL;
                const u32 tcolor = line->m_subLines[i].m_color;
                char szTempLine[ MAX_MB_CHARS ] , *pszSearch = NULL;
                size_t llen = xr_strlen( line->m_subLines[i].m_text.c_str() );
                VERIFY( llen < MAX_MB_CHARS );
                strcpy( szTempLine , line->m_subLines[i].m_text.c_str() );
                pszSearch = szTempLine;
                while ( ( pszTemp = strstr( pszSearch , "\\n" ) ) != NULL ) {
                    bNewLines = TRUE;
                    *pszTemp = '\0';
                    ptmp_line->AddSubLine( pszSearch , tcolor );
                    pszSearch = pszTemp + 2;
                }
                ptmp_line->AddSubLine( pszSearch , tcolor );
            }
            line->Clear();
            xr_free( line );
            line=ptmp_line;
        } else
            line->ProcessNewLines(); // process "\n"

    if ( m_pFont->IsMultibyte() ) {
#define UBUFFER_SIZE 100
        u16	aMarkers[ UBUFFER_SIZE ];
        CUILine tmp_line;
        char szTempLine[ MAX_MB_CHARS ];
        float fTargetWidth = 1.0f;
        UI()->ClientToScreenScaledWidth( fTargetWidth );
        VERIFY( ( m_wndSize.x > 0 ) && ( fTargetWidth > 0 ) );
        fTargetWidth = m_wndSize.x / fTargetWidth;
        int vsz = line->m_subLines.size();
        VERIFY( vsz );
        if ( ( vsz > 1 ) && ( ! bNewLines ) ) { // only colored line, pizdets
            for ( int i = 0 ; i < vsz ; i++ ) {
                const char *pszText = line->m_subLines[i].m_text.c_str();
                const u32 tcolor = line->m_subLines[i].m_color;
                VERIFY( pszText );
                tmp_line.AddSubLine( pszText , tcolor );
            }
            m_lines.push_back( tmp_line );
            tmp_line.Clear();
        } else {
            for ( int i = 0 ; i < vsz ; i++ ) {
                const char *pszText = line->m_subLines[i].m_text.c_str();
                const u32 tcolor = line->m_subLines[i].m_color;
                u16 uFrom = 0 , uPartLen = 0;
                VERIFY( pszText );
                u16 nMarkers = m_pFont->SplitByWidth( aMarkers , UBUFFER_SIZE , fTargetWidth , pszText );
                for ( u16 j = 0 ; j < nMarkers ; j ++ ) {
                    uPartLen = aMarkers[ j ] - uFrom;
                    VERIFY( ( uPartLen > 0 ) && ( uPartLen < MAX_MB_CHARS ) );
                    strncpy( szTempLine , pszText + uFrom , uPartLen );
                    szTempLine[ uPartLen ] = '\0';
                    tmp_line.AddSubLine( szTempLine , tcolor );
                    m_lines.push_back( tmp_line );
                    tmp_line.Clear();
                    // Compiler bug :)
#pragma warning( disable : 4244 )
                    uFrom += uPartLen;
#pragma warning( default : 4244 )
                }
                strncpy( szTempLine , pszText + uFrom , MAX_MB_CHARS );
                tmp_line.AddSubLine( szTempLine , tcolor );
                m_lines.push_back( tmp_line );
                tmp_line.Clear();
            }
        }
    } else
    {
        float max_width							= m_wndSize.x;
        u32 sbl_cnt								= line->m_subLines.size();
        CUILine									tmp_line;
        string4096								buff;
        float curr_width						= 0.0f;
        bool bnew_line							= false;
        float __eps								= get_str_width(m_pFont,'o');//hack -(
        for(u32 sbl_idx=0; sbl_idx<sbl_cnt; ++sbl_idx)
        {
            bool b_last_subl					= (sbl_idx==sbl_cnt-1);
            CUISubLine& sbl						= line->m_subLines[sbl_idx];
//.			Msg("%s",sbl.m_text.c_str());
            u32 sub_len							= (u32)sbl.m_text.length();
            u32 curr_w_pos						= 0;

            u32 last_space_idx					= 0;
            for(u32 idx=0; idx<sub_len; ++idx)
            {
                bool b_last_ch	= (idx==sub_len-1);

                if(isspace(sbl.m_text[idx]))
                    last_space_idx = idx;

                float w1		= get_str_width(m_pFont, sbl.m_text[idx]);
                bool bOver		= (curr_width+w1+__eps > max_width);

                if(bOver || b_last_ch)
                {
                    if(last_space_idx && !b_last_ch)
                    {
                        idx = last_space_idx;
                        last_space_idx = 0;
                    }

                    strncpy_s			(buff, sizeof(buff), sbl.m_text.c_str()+curr_w_pos, idx-curr_w_pos+1);
//.					Msg					("-%s",buff);
                    tmp_line.AddSubLine	(buff , sbl.m_color);
                    curr_w_pos			= idx+1;
                } else
                    curr_width			+= w1;

                if(bOver || (b_last_ch&&sbl.m_last_in_line) )
                {
                    m_lines.push_back	(tmp_line);
                    tmp_line.Clear		();
                    curr_width			= 0.0f;
                    bnew_line			= false;
                }
            }
            if(b_last_subl && !tmp_line.IsEmpty())
            {
                m_lines.push_back	(tmp_line);
                tmp_line.Clear		();
                curr_width			= 0.0f;
                bnew_line			= false;
            }
        }
    }
//.		while (line->GetSize() > 0 )
//.			m_lines.push_back(*line->CutByLength(m_pFont, m_wndSize.x, uFlags.test(flCutWordsMode)));

    xr_delete(line);
    uFlags.set(flNeedReparse, FALSE);

}
Example #11
0
int populate_list(HWND hlistview,int resize_window)
{
	HKEY hkey=0;
	int total_width=0;
	ListView_DeleteAllItems(hlistview);
	set_columns(hlistview);
	RegOpenKeyEx(HKEY_LOCAL_MACHINE,"Software\\Microsoft\\Windows\\CurrentVersion\\Uninstall",0,KEY_READ,&hkey);
	if(hkey!=0){
		int i,count=0,widths[4];
		count=get_subkey_count(hkey);
		memset(widths,0,sizeof(widths));
		get_column_widths(hlistview,widths,sizeof(widths)/sizeof(int));
		for(i=0;i<count;i++){
			char str[512]={0};
			int len=sizeof(str);
			RegEnumKeyEx(hkey,i,str,&len,NULL,NULL,NULL,NULL);
			//RegEnumValue(hkey,i,str,&len,NULL,NULL,NULL,NULL);
			str[sizeof(str)-1]=0;
			if(str[0]!=0){
				int w;
				HKEY hsubkey=0;
				RegOpenKeyEx(hkey,str,0,KEY_READ,&hsubkey);
				if(hsubkey!=0){
					int type=REG_SZ;
					char dispstr[512]={0};
					len=sizeof(dispstr);
					RegQueryValueEx(hsubkey,"DisplayName",NULL,&type,dispstr,&len);
					lv_insert_data(hlistview,i,0,dispstr);
					w=get_str_width(hlistview,dispstr);
					if(widths[0]<w)
						widths[0]=w;
					RegCloseKey(hsubkey);

					lv_insert_data(hlistview,i,1,str);
					w=get_str_width(hlistview,str);
					if(widths[1]<w)
						widths[1]=w;

				}
			}			
		}
		for(i=0;i<4;i++){
			widths[i]+=12;
			ListView_SetColumnWidth(hlistview,i,widths[i]);
			total_width+=widths[i];
		}

		RegCloseKey(hkey);
		if(total_width>0){
			HWND hwnd,hdesk;
			hwnd=GetParent(hlistview);
			hdesk=GetDesktopWindow();
			if(hwnd!=0 && hdesk!=0){
				RECT rect={0};
				int wwin,wdesk,height;
				GetWindowRect(hwnd,&rect);
				wwin=rect.right-rect.left;
				GetWindowRect(hdesk,&rect);
				wdesk=rect.right-rect.left;
				height=rect.bottom-rect.top;
				height=height*2/3;;
				if(total_width>wdesk)
					total_width=wdesk;
				if((total_width>wwin) && resize_window)
					SetWindowPos(hwnd,NULL,0,0,total_width,height,SWP_NOMOVE);
			}
		}
	}
	return total_width;
}
Example #12
0
int populate_insert_dlg(HWND hwnd,HWND hlistview,TABLE_WINDOW *win)
{
	int i,count,widths[4]={0,0,0,0};
	int row_sel;
	char *cols[]={"field","data","type","size"};
	if(hlistview==0 || win==0)
		return FALSE;

	for(i=0;i<4;i++)
		widths[i]=lv_add_column(hlistview,cols[i],i);

	row_sel=ListView_GetSelectionMark(win->hlistview);

	count=lv_get_column_count(win->hlistview);

	for(i=0;i<count;i++){
		int w;
		char str[80]={0};
		lv_get_col_text(win->hlistview,i,str,sizeof(str));
		lv_insert_data(hlistview,i,FIELD_POS,str);
		w=get_str_width(hlistview,str);
		if(w>widths[FIELD_POS])
			widths[FIELD_POS]=w;
		if(row_sel>=0){
			str[0]=0;
			ListView_GetItemText(win->hlistview,row_sel,i,str,sizeof(str));
			lv_insert_data(hlistview,i,DATA_POS,str);
			w=get_str_width(hlistview,str);
			if(w>widths[DATA_POS])
				widths[DATA_POS]=w;
		}
		if(win->col_attr!=0){
			char *s="";
			if(!find_sql_type_str(win->col_attr[i].type,&s)){
				_snprintf(str,sizeof(str),"%i",win->col_attr[i].type);
				lv_insert_data(hlistview,i,TYPE_POS,str);
			}
			else
				lv_insert_data(hlistview,i,TYPE_POS,s);
			w=get_str_width(hlistview,s);
			if(w>widths[TYPE_POS])
				widths[TYPE_POS]=w;

			_snprintf(str,sizeof(str),"%i",win->col_attr[i].length);
			lv_insert_data(hlistview,i,SIZE_POS,str);
			w=get_str_width(hlistview,str);
			if(w>widths[SIZE_POS])
				widths[SIZE_POS]=w;
		}
	}
	{
		int total_width=0;
		for(i=0;i<4;i++){
			widths[i]+=12;
			ListView_SetColumnWidth(hlistview,i,widths[i]);
			total_width+=widths[i];
		}
		if(total_width>0){
			int width,height;
			RECT rect={0},irect={0},nrect={0};
			GetWindowRect(hwnd,&irect);
			get_nearest_monitor(irect.left,irect.top,total_width,100,&nrect);
			ListView_GetItemRect(hlistview,0,&rect,LVIR_BOUNDS);
			height=80+(count*(rect.bottom-rect.top+2));
			if((irect.top+height)>nrect.bottom){
				height=nrect.bottom-nrect.top-irect.top;
				if(height<320)
					height=320;
			}
			width=total_width+20;
			SetWindowPos(hwnd,NULL,0,0,width,height,SWP_NOMOVE|SWP_NOZORDER);
		}
	}

	return TRUE;
}