Results 1 to 16 of 16

Thread: CL_LineEdit (Password Mode ?)

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Squire
    Join Date
    Aug 2009
    Posts
    16

    Default CL_LineEdit (Password Mode ?)

    Hey, im trying to set password mode in a LineEdit...

    But when i type the text here, i still see the 'plain text' i typed, shouldn't it hide the text w/ like some '*******' ? if so its not working on the 2.0.3, at least here... any tip ?

  2. #2
    ClanLib Developer
    Join Date
    May 2007
    Posts
    1,824

    Default

    It just needs implementing.

    I guess that
    Code:
    	CL_TempString get_visible_text_before_selection();
    	CL_TempString get_visible_text_after_selection();
    	CL_TempString get_visible_selected_text();
    All needs to check "password_mode" and return "****" instead

    We welcome patches

  3. #3
    Squire
    Join Date
    Aug 2009
    Posts
    16

    Default

    Quote Originally Posted by rombust View Post
    It just needs implementing.

    I guess that
    Code:
    	CL_TempString get_visible_text_before_selection();
    	CL_TempString get_visible_text_after_selection();
    	CL_TempString get_visible_selected_text();
    All needs to check "password_mode" and return "****" instead

    We welcome patches
    Ok so here we go w/ the implementation and the needed functions to be patched :

    Code:
    CL_TempString CL_LineEdit_Impl::get_visible_text_before_selection()
    {
    	int sel_start = cl_min(selection_start, selection_start+selection_length);
    	int start = cl_min(sel_start, clip_start_offset);
    	
    	if (start < clip_start_offset)
    		return CL_String();
    
    	int end = cl_min(sel_start, clip_end_offset);
    
    	CL_String sRet = text.substr(start, end-start);
    
    	// If we are in password mode, we gonna return the right characters
    	if ( password_mode ) { int nLen = sRet.size(); sRet.clear(); for ( int i = 0 ; i < nLen ; i++ ) { sRet += "*"; } }
    
    	return sRet;
    }
    
    CL_TempString CL_LineEdit_Impl::get_visible_selected_text()
    {
    	if (selection_length == 0)
    		return CL_TempString();
    
    	int sel_start = cl_min(selection_start, selection_start+selection_length);
    	int sel_end = cl_max(selection_start, selection_start + selection_length);
    	int end = cl_min(clip_end_offset, sel_end);
    	int start = cl_max(clip_start_offset, sel_start);
    
    	if (start > end)
    		return CL_TempString();
    
    	if (start == end)
    		return CL_TempString();
    
    	CL_String sRet = text.substr(start, end-start);
    
    	// If we are in password mode, we gonna return the right characters
    	if ( password_mode ) { int nLen = sRet.size(); sRet.clear(); for ( int i = 0 ; i < nLen ; i++ ) { sRet += "*"; } }
    
    	return sRet;
    }
    
    CL_TempString CL_LineEdit_Impl::get_visible_text_after_selection()
    {
    	// returns the whole visible string if there is no selection.
    
    	int sel_end = cl_max(selection_start, selection_start + selection_length);
    	int start = cl_max(clip_start_offset, sel_end);
    
    	int end = clip_end_offset;
    	if (start > end)
    		return CL_TempString();
    
    	if (clip_end_offset == sel_end)
    		return CL_TempString();
    
    	if (sel_end <= 0)
    		return CL_String();
    	else
    	{
    		CL_String sRet = text.substr(start, end-start);
    
    		// If we are in password mode, we gonna return the right characters
    		if ( password_mode ) { int nLen = sRet.size(); sRet.clear(); for ( int i = 0 ; i < nLen ; i++ ) { sRet += "*"; } }
    
    		return sRet;	
    	}
    }
    
    void CL_LineEdit_Impl::on_render(CL_GraphicContext &gc, const CL_Rect &update_rect)
    {
    	CL_Rect g = lineedit->get_geometry();
    	part_component.render_box(gc, g.get_size(), update_rect);
    
    	CL_Font font = part_component.get_font();
    
    	CL_TempString txt_before = get_visible_text_before_selection();
    	CL_TempString txt_selected = get_visible_selected_text();
    	CL_TempString txt_after = get_visible_text_after_selection();
    
    	if (txt_before.empty() && txt_selected.empty() && txt_after.empty())
    	{
    		txt_after = text.substr(clip_start_offset, clip_end_offset-clip_start_offset);
    
    		// If we are in password mode, we gonna return the right characters
    		if ( password_mode ) { int nLen = txt_after.size(); txt_after.clear(); for ( int i = 0 ; i < nLen ; i++ ) { txt_after += "*"; } }
    	}
    
    	CL_Size size_before = font.get_text_size(gc, txt_before);
    	CL_Size size_selected = font.get_text_size(gc, txt_selected);
    
    	// Draw text before selection
    	if (!txt_before.empty())
    	{
    		part_component.render_text(gc, txt_before, content_rect, update_rect);
    	}
    	if (!txt_selected.empty())
    	{
    		// Draw selection box.
    		CL_Rect selection_rect = get_selection_rect();
    		part_selection.render_box(gc, selection_rect, update_rect);
    		part_selection.render_text(gc, txt_selected, selection_rect, update_rect);
    	}
    	if (!txt_after.empty())
    	{
    		CL_Rect text_rect = content_rect;
    		text_rect.left += (size_before.width + size_selected.width);
    		part_component.render_text(gc, txt_after, text_rect, update_rect);
    	}
    
    	// draw cursor
    	if (lineedit->has_focus())
    	{
    		if (cursor_blink_visible)
    		{
    			CL_Rect cursor_rect = get_cursor_rect();
    			part_cursor.render_box(gc, cursor_rect, update_rect);
    		}
    	}
    }
    And

    Code:
    CL_Rect CL_LineEdit_Impl::get_cursor_rect()
    {
    	CL_GraphicContext &gc = lineedit->get_gc();
    	CL_Font font = part_component.get_font();
    
    	CL_Rect cursor_rect;
    
    	int substr_end = cursor_pos - clip_start_offset;
    	if (substr_end < 0)
    		substr_end = 0;
    
    	CL_String sText = text.substr(clip_start_offset, substr_end);
    
    	// If we are in password mode, we gonna return the right characters
    	if ( password_mode ) { int nLen = sText.size(); sText = ""; for ( int i = 0 ; i < nLen ; i++ ) { sText += "*"; } }
    
      	CL_Size text_size_before_cursor = font.get_text_size(gc, sText);
    
    	cursor_rect.left = content_rect.left + text_size_before_cursor.width;
    	cursor_rect.right = cursor_rect.left + part_cursor.get_preferred_width();
    
    	cursor_rect.top = vertical_text_align.bottom - text_size.height;
    	cursor_rect.bottom = vertical_text_align.bottom;
    
    	return cursor_rect;
    }
    All tested and 100% Working, My First Contribution ;P

  4. #4
    ClanLib Developer
    Join Date
    May 2007
    Posts
    1,824

    Default

    Many thanks.

    I modified it slightly, to conform with the coding style (see CODING_STYLE in the ClanLib source root directory).

    When creating patches, if possible, can you create the patch in the "Create Patch" format (if using TortoiseSVN etc) - it makes it easier to read. See attached.

    Currently there is a bug? with the patch. I'm not sure. You can select the password text, and press CTRL_C to copy the text. In internet explorer, CTRL_C is disabled on password lineedit's.

    (Patch committed to SVN)
    Attached Files Attached Files

  5. #5
    Squire
    Join Date
    Aug 2009
    Posts
    16

    Default

    Quote Originally Posted by rombust View Post
    Many thanks.

    I modified it slightly, to conform with the coding style (see CODING_STYLE in the ClanLib source root directory).

    When creating patches, if possible, can you create the patch in the "Create Patch" format (if using TortoiseSVN etc) - it makes it easier to read. See attached.

    Currently there is a bug? with the patch. I'm not sure. You can select the password text, and press CTRL_C to copy the text. In internet explorer, CTRL_C is disabled on password lineedit's.

    (Patch committed to SVN)
    this is propably a new condition for the component, like 'allow copy password', cause some applications in windows for example, allow you from copying/pasteing the password.... now this depends of the point of view ?

  6. #6
    Squire
    Join Date
    Jul 2009
    Posts
    21

    Default

    where i have to change this ?

    cause i use precompiled liberaries ..

    and i can only edit the lineedit.h ..

Similar Threads

  1. Windowed Mode
    By Eschar in forum Novashell Game Creation System
    Replies: 3
    Last Post: 09-21-2007, 11:22 PM
  2. Fix for Fullscreen mode
    By glorified_ameba in forum Official ClanLib SDK Forums
    Replies: 5
    Last Post: 07-27-2007, 04:22 PM
  3. Replies: 3
    Last Post: 07-17-2007, 12:55 AM
  4. My password
    By in forum Funeral Quest
    Replies: 1
    Last Post: 11-26-2006, 09:36 AM
  5. Password Retrieval
    By in forum Funeral Quest
    Replies: 2
    Last Post: 12-21-2002, 08:10 PM

Bookmarks

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •