nanogui: Changing display font in pushbutton control


Previous by date: 20 Feb 2007 16:15:33 +0000 Re: Errors while installing on Debian, His Majesty
Next by date: 20 Feb 2007 16:15:33 +0000 Re: rotate mouse movements 90 degree in nano-X, jasinski.utfpr.edu.br
Previous in thread: 20 Feb 2007 16:15:33 +0000 Re: Changing display font in pushbutton control, Greg Haerr
Next in thread: 20 Feb 2007 16:15:33 +0000 Re: Changing display font in pushbutton control, Uwe Klatt

Subject: RES: [nanogui] Changing display font in pushbutton control
From: ####@####.####
Date: 20 Feb 2007 16:15:33 +0000
Message-Id: <20070220125045.d6wgzutr6ecggccc@mail.utfpr.edu.br>

Hi Greg und Uwe,

I have followed your hints trying to make the pushbutton control able to display
fonts other than the DEFAULT_GUI_FONT. Guess what, it's working now, thanks!

Here's a short script of what I've done:

1) Create a copy of button.c in the winlib folder. Called it "fancybutton.c".

2) Just for the sake of organization, I changed all function names starting with
button_ to fancybutton_, and the class name from "BUTTON" to "FANCYBUTTON".

3) Changed line 514 from:
       hNewFont = GetStockObject( DEFAULT_GUI_FONT);
   to:
       hNewFont = (HFONT) GET_PBFONT(hwnd);

4) Now this was a little tricky; I had to change the SET_PBFONT and GET_PBFONT
macros from:
       #define SET_PBFONT(h,x)  (SetWindowWord(h, 8, x))
       #define GET_PBFONT(h)    (GetWindowWord(h, 8))
   to:
       #define SET_PBFONT(h,x)  (SetWindowLong(h, 8, x))
       #define GET_PBFONT(h)    (GetWindowLong(h, 8))

   since the pointers in my system are 32 bits long. As a consequence, I had to
change the number of extra bytes (wc.cbWndExtra) from 10 to 12. Hope there's no
problem with that. Actually, aren't most of them 32-bit nowadays?

5) In the message handler, I added the following:
       case WM_SETFONT:
          fancyButton_OnSetFont(hwnd, (HFONT)wParam, 0L);
          return 0;
   For some reason, I wasn't able to define the HANDLE_BM_SETFONT and
FORWARD_BM_SETFONT macros correctly. Honestly, I didn't understand their
reasoning quite enough, so I just added the case above.

6) Commented out the CheckRadioButton(...) function definition, since it is
already in button.c.

That would be all! But since I was already at it, I added an additional check
for the BS_FLAT style flag before drawing the 3d box surrounding the pushbutton
control.

Thanks for your hints and advice; I hope there's nothing fundamentally wrong
with the above changes.

Also, since it's starting to look so nice, I think I won't stop messing with the
controls yet. Next I'll add some code to change the text color for the control
(currently hardcoded as COLOR_BTNTEXT), so that each button can have its own
attribute. I see two immediate choices for that; one would be doing like Uwe
suggested (creating a new structure with all the newly added parameters for the
control), and the other would be increasing the number of extra bytes to hold
another 3 or 4 bytes for the color value. Does anyone have an advice for or
against one of these approaches? (or a better suggestion perhaps?)

Thanks a lot,

Ricardo Jasinski.
---------------------
####@####.####


-----Mensagem original-----
De: Greg Haerr ####@####.####
Assunto: Re: [nanogui] Changing display font in pushbutton control

: My first attempt was sending the WM_SETFONT message to the standard
: button control in microwindows, but it apparently doesn't handle this
: specific message. The code that should do it is commented out in the
: control's window procs (cenButtonWndFn) and in other places inside
: the button.c file (#if 0 static void WINAPI cenButton_OnSetFont()).

I commented out the SETFONT code when I brought in
this control from another library.  Uncomment it and add
code (after looking at the win32 documentation) to
implement a font change, and you should be in business.

Regards,

Greg



----------------------------------------------------------------
This message was sent using IMP, the Internet Messaging Program.

Previous by date: 20 Feb 2007 16:15:33 +0000 Re: Errors while installing on Debian, His Majesty
Next by date: 20 Feb 2007 16:15:33 +0000 Re: rotate mouse movements 90 degree in nano-X, jasinski.utfpr.edu.br
Previous in thread: 20 Feb 2007 16:15:33 +0000 Re: Changing display font in pushbutton control, Greg Haerr
Next in thread: 20 Feb 2007 16:15:33 +0000 Re: Changing display font in pushbutton control, Uwe Klatt


Powered by ezmlm-browse 0.20.