BlackBerry Forums Support Community
              

Closed Thread
 
Thread Tools
Old 05-21-2008, 12:24 AM   #1
Pan_magically
Knows Where the Search Button Is
 
Join Date: Apr 2008
Model: 8100
PIN: N/A
Carrier: Hong Kong CSL
Posts: 18
Wink Alpha value of color not working in paint()

Please Login to Remove!

Trying to display a hovering label on top of my ListField. The Label should be a round-rect and has a semi-transparent black bgcolor. I got the label and text to display and everything, but the bgcolor is solid black. The idea is that the hovering label will appear on top of the items in ListField.


here is my code
Code:
public class MyListField extends ListField {


    protected void paint(Graphics g){
        super.paint(g);
        if(this.getSize() > 0)        
            this.paintFloatingText(g);
    }

    protected int getVerticalScroll(){
        Manager manager = this.getManager();
        int scrollPos = -1;
        if(manager != null)
            scrollPos = manager.getVerticalScroll();

             
        return scrollPos;                
    }
    
    private void paintFloatingText(Graphics g){

	XYRect floatingRect = new XYRect(100,100,70,30);
        
        // since the Field is scrollable, a y offset is need to make sure the label     always displays on the same position on the screen
        int offset_x = 0;
        int offset_y = this.getVerticalScroll();
        
  
        Font fnt = this.floatingLabelFont;
        
        //g.setColor(UIParameters.floating_label_bgColor);
        // set the color as black semi-transparent fror background 
        g.setColor(0xCC000000);
        
        int arc = Math.min(floatingRect.width,floatingRect.height)/2;        
        g.fillRoundRect(offset_x + floatingRect.x ,offset_y + floatingRect.y, floatingRect.width,floatingRect.height,arc,arc);

        //g.setColor(UIParameters.floating_label_fgColor);
        // set the color as white for text 
        g.setColor(0x00FFFFFF);
        
        g.setFont(fnt);

        // Calculate the left-top margins to center the text display
        int margin_x = (int)((floatingRect.width - fnt.getAdvance(this.label))/2);           
        int margin_y = (int)((floatingRect.height - fnt.getHeight())/2);        
        g.drawText(this.label, offset_x + floatingRect.x+margin_x, offset_y + floatingRect.y + margin_y, Graphics.TOP | Graphics.LEFT); 
    }    
}

Last edited by Pan_magically; 05-21-2008 at 12:29 AM..
Offline  
Old 05-21-2008, 12:58 AM   #2
richard.puckett
Talking BlackBerry Encyclopedia
 
richard.puckett's Avatar
 
Join Date: Oct 2007
Location: Seattle, WA
Model: 9020
PIN: N/A
Carrier: T-Mobile
Posts: 212
Default

Use the get/setGlobalAlpha methods to handle transparency. So in your example you'd do something like:

graphics.setGlobalAlpha(0xCC);
graphics.setColor(0x000000);
// do stuff
// restore global alpha and color
__________________
Do your homework and know how to ask a good question.
Offline  
Old 05-21-2008, 02:01 AM   #3
Pan_magically
Knows Where the Search Button Is
 
Join Date: Apr 2008
Model: 8100
PIN: N/A
Carrier: Hong Kong CSL
Posts: 18
Default

Tyvm. It is working nicely now.

I am more used to using the j2me original Graphics object to draw stuff, and I didn't think a separate method was needed.
Offline  
Old 05-21-2008, 07:57 AM   #4
CELITE
Thumbs Must Hurt
 
Join Date: Dec 2005
Model: 8310
Carrier: Rogers
Posts: 138
Default

The setColor methods of the RIM graphics object do not take the first 8 bits (alpha) into account.
Offline  
Closed Thread



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


10X 2N3055 TO-3 NPN Amplifier Switch Transistor Audio Power Metal Case 15A/60V picture

10X 2N3055 TO-3 NPN Amplifier Switch Transistor Audio Power Metal Case 15A/60V

$9.99



TO-92 Assortment NPN PNP DIY kit 15 value 600pcs Transistor  picture

TO-92 Assortment NPN PNP DIY kit 15 value 600pcs Transistor

$14.40



Mitsubishi 2SC2166C NPN Epitaxial Planar Type RF Power Transistor Ships from USA picture

Mitsubishi 2SC2166C NPN Epitaxial Planar Type RF Power Transistor Ships from USA

$55.50



Portable 600pc 15Value NPN PNP Transistor TO-92 Assortment Kit Set /Box Hot picture

Portable 600pc 15Value NPN PNP Transistor TO-92 Assortment Kit Set /Box Hot

$12.66



2N3416 Original New -Old stock GE Transistor picture

2N3416 Original New -Old stock GE Transistor

$10.95



US Stock 10pcs J201 JFET N-Channel Transistor 50mA 40V TO-92 New picture

US Stock 10pcs J201 JFET N-Channel Transistor 50mA 40V TO-92 New

$11.87







Copyright © 2004-2016 BlackBerryForums.com.
The names RIM © and BlackBerry © are registered Trademarks of BlackBerry Inc.