textextend ... very confused

Hi,

I have a few classes that derive from a scrolling-lcd class ... which then
draws text on a bitmap and if need be highlights a line of text.

I check the children, and they all make roughly the same calls to the parent
draw class. Only one object gets each line highlighted to have double heights
(see p_bug flag here)

If I call draw from that object the parent with the flag on, then my line is
highlighted properly ... in all cases, the highlighting takes the correct
width ... I'm quite puzzled.. any clue ?

Thanks,

Philippe

    def Draw(self, p_pdc, p_f_info, p_text_color, p_highlight = True, p_bug =
False):
        if -1 == self.m_pos:
            return

        l_line_row = self.m_gui_conf.LCD_LINE_1_ROW
        if len(self.m_lcd) > self.M_NUM_LINES:
            l_to_display = self.M_NUM_LINES
            
            if len(self.m_lcd) - self.m_pos < self.M_NUM_LINES:
                l_pos = len(self.m_lcd) - self.M_NUM_LINES
            else:
                l_pos = self.m_pos
        else:
            l_pos = 0
            l_to_display = len(self.m_lcd)

        for l_num_lines_to_display in range(l_to_display):
            
            l_text = self.m_lcd[l_num_lines_to_display + l_pos]

            l_coord = (self.m_gui_conf.LCD_LINE_COL,l_line_row)
            p_pdc.SetFont(p_f_info)
            
            if False == p_highlight or l_num_lines_to_display !=
self.m_to_highlight:
                p_pdc.DrawText(l_text,l_coord[0],l_coord[1])
            else:
                l_textExtent = self.m_parent.GetFullTextExtent(l_text,
p_f_info)

                # create a bitmap the same size as our text
                if False == p_bug:
                    l_bmp = wx.EmptyBitmap(l_textExtent[0] , l_textExtent[1] )
                else:
                   l_bmp = wx.EmptyBitmap(l_textExtent[0] , l_textExtent[1] /
2 )
                l_dc = wx.MemoryDC()
                l_dc.SelectObject(l_bmp)
                
l_dc.SetBackground(wx.Brush(self.m_gui_conf.LCD_BG_HIGHLIGHT_TEXT_COLOR,
wx.SOLID))
                l_dc.Clear()
                
l_dc.SetTextForeground(self.m_gui_conf.LCD_HIGHLIGHT_TEXT_COLOR)
                l_dc.SetFont(p_f_info)
                l_dc.DrawText(l_text, 0, 0)
                l_dc.SelectObject(wx.NullBitmap)
                p_pdc.DrawBitmap(l_bmp,l_coord[0],l_coord[1])
            
            l_line_row += self.m_gui_conf.LCD_LINE_SPACING

···

--
_________________________
Philippe C. Martin
+1 405 562 7005
www.snakecard.com
_________________________

PS: when the "bug" flag in on, I divide the height by two and get what seems
to be the correct height.

···

On Monday 12 February 2007 13:53, Philippe C. Martin wrote:

Hi,

I have a few classes that derive from a scrolling-lcd class ... which then
draws text on a bitmap and if need be highlights a line of text.

I check the children, and they all make roughly the same calls to the
parent draw class. Only one object gets each line highlighted to have
double heights (see p_bug flag here)

If I call draw from that object the parent with the flag on, then my line
is highlighted properly ... in all cases, the highlighting takes the
correct width ... I'm quite puzzled.. any clue ?

Thanks,

Philippe

    def Draw(self, p_pdc, p_f_info, p_text_color, p_highlight = True, p_bug
= False):
        if -1 == self.m_pos:
            return

        l_line_row = self.m_gui_conf.LCD_LINE_1_ROW
        if len(self.m_lcd) > self.M_NUM_LINES:
            l_to_display = self.M_NUM_LINES

            if len(self.m_lcd) - self.m_pos < self.M_NUM_LINES:
                l_pos = len(self.m_lcd) - self.M_NUM_LINES
            else:
                l_pos = self.m_pos
        else:
            l_pos = 0
            l_to_display = len(self.m_lcd)

        for l_num_lines_to_display in range(l_to_display):

            l_text = self.m_lcd[l_num_lines_to_display + l_pos]

            l_coord = (self.m_gui_conf.LCD_LINE_COL,l_line_row)
            p_pdc.SetFont(p_f_info)

            if False == p_highlight or l_num_lines_to_display !=
self.m_to_highlight:
                p_pdc.DrawText(l_text,l_coord[0],l_coord[1])
            else:
                l_textExtent = self.m_parent.GetFullTextExtent(l_text,
p_f_info)

                # create a bitmap the same size as our text
                if False == p_bug:
                    l_bmp = wx.EmptyBitmap(l_textExtent[0] ,
l_textExtent[1] ) else:
                   l_bmp = wx.EmptyBitmap(l_textExtent[0] , l_textExtent[1]
/ 2 )
                l_dc = wx.MemoryDC()
                l_dc.SelectObject(l_bmp)

l_dc.SetBackground(wx.Brush(self.m_gui_conf.LCD_BG_HIGHLIGHT_TEXT_COLOR,
wx.SOLID))
                l_dc.Clear()

l_dc.SetTextForeground(self.m_gui_conf.LCD_HIGHLIGHT_TEXT_COLOR)
                l_dc.SetFont(p_f_info)
                l_dc.DrawText(l_text, 0, 0)
                l_dc.SelectObject(wx.NullBitmap)
                p_pdc.DrawBitmap(l_bmp,l_coord[0],l_coord[1])

            l_line_row += self.m_gui_conf.LCD_LINE_SPACING

--
_________________________
Philippe C. Martin
+1 405 562 7005
www.snakecard.com
_________________________

Philippe C. Martin wrote:

Hi,

I have a few classes that derive from a scrolling-lcd class ... which then draws text on a bitmap and if need be highlights a line of text.

I check the children, and they all make roughly the same calls to the parent draw class. Only one object gets each line highlighted to have double heights (see p_bug flag here)

If I call draw from that object the parent with the flag on, then my line is highlighted properly ... in all cases, the highlighting takes the correct width ... I'm quite puzzled.. any clue ?

                l_textExtent = self.m_parent.GetFullTextExtent(l_text, p_f_info)

You probably have a different font set for the m_parent window than for the dc. Try using p_pdc.GetFullTextExtent instead.

···

--
Robin Dunn
Software Craftsman
http://wxPython.org Java give you jitters? Relax with wxPython!