|
Text under an icon on the iconbar |
|
sinns (13:48 1/10/2014) nunfetishist (14:12 1/10/2014) sinns (14:34 1/10/2014) geraldholdsworth (14:43 1/10/2014) VincceH (15:56 1/10/2014) sinns (17:00 1/10/2014) VincceH (17:39 1/10/2014) sinns (17:42 1/10/2014) VincceH (18:16 1/10/2014) sinns (18:23 1/10/2014)
|
|
Simon Inns |
Message #123368, posted by sinns at 13:48, 1/10/2014 |
Member
Posts: 73
|
Hi
I've been poking around in the PRMs but I don't seem to be able to work out how to show text under an icon on the iconbar.
So far my code happily places the application icon (I'm using GCC, UnixLib and OSLib), but how do I create an Icon with text (like "!bigbadFS" under the !Sprite)?
Thanks in advance for any pointers! /Simon |
|
[ Log in to reply ] |
|
Rob Kendrick |
Message #123369, posted by nunfetishist at 14:12, 1/10/2014, in reply to message #123368 |
Today's phish is trout a la creme.
Posts: 524
|
Hi
I've been poking around in the PRMs but I don't seem to be able to work out how to show text under an icon on the iconbar.
So far my code happily places the application icon (I'm using GCC, UnixLib and OSLib), but how do I create an Icon with text (like "!bigbadFS" under the !Sprite)?
Thanks in advance for any pointers! /Simon It's been a long while, but don't you provide a normal icon data block for the iconbar? And thus it's just an icon with image and text? |
|
[ Log in to reply ] |
|
Simon Inns |
Message #123370, posted by sinns at 14:34, 1/10/2014, in reply to message #123369 |
Member
Posts: 73
|
That was what I was aiming for, but I couldn't see how to form the icon data block for a sprite with non-writable text. Looked to me like I would get a text entry icon; hence looking for an example. I guess I will give it a few attempts and see what happens, only an example code-block would be really nice
(I've done lots of ARM assembly, but very little WIMP which is why I am struggling a little, there is very little documentation). |
|
[ Log in to reply ] |
|
Gerald Holdsworth |
Message #123371, posted by geraldholdsworth at 14:43, 1/10/2014, in reply to message #123370 |
Member
Posts: 12
|
From what I can remember, it's remarkably easy. I'm sure it's covered in the PRMs, somewhere. I've done it, so it must be easy!! ;-) I'll see if I can find some of my old source code for you (I did write one application with an animated icon on the icon bar). |
|
[ Log in to reply ] |
|
VinceH |
Message #123372, posted by VincceH at 15:56, 1/10/2014, in reply to message #123370 |
Lowering the tone since the dawn of time
Posts: 1600
|
That was what I was aiming for, but I couldn't see how to form the icon data block for a sprite with non-writable text. Looked to me like I would get a text entry icon; hence looking for an example. Don't set the button type to one whereby the icon gains the caret - if it's not set as a writable icon, you won't get a writable icon.
(I suspect it isn't possible to put writable icons on the icon bar anyway).
<checks...>
Aha, yes. PRM 3, page 99 (under Wimp_CreateIcon):
"It is not possible to set the caret in the icon bar, so writable icons should not be used."
I've never put an icon + text on the bar, but since I have it open I may as look at how it's done...
As you've obviously already realised, it's the way the block of data pointed to in R1 that's important - in particular, the flags and 12 bytes of icon data.
(The 'icon block' is at R1+4, so offsets below are from there)
Icon Block + 16 is the icon flags - flag bits 0,1 and 8 need to be set so that the data is text + sprite + indirected
Flag bits 12-15 are the button type. You probably need it to be 2 (click notifies task, auto-repeat) or 3 (click notifies task, once only).
Icon block + 20 contain 12 bytes of icon data as follows:
Icon block + 20: Pointer to text buffer Icon block + 24: Pointer to sprite name Icon block + 28: Length of text buffer
Ah... I've just spotted that you will also need to put the sprite in the Wimp sprite area - if it was sprite only, that wouldn't be necessary because +20 would be a pointer to the sprite (or sprite name), and +24 would be a pointer to the sprite area - but since it's text + sprite, that option isn't available. |
|
[ Log in to reply ] |
|
Simon Inns |
Message #123373, posted by sinns at 17:00, 1/10/2014, in reply to message #123372 |
Member
Posts: 73
|
Hi Vince; I tried your suggestion but it still puts the text over the icon rather than under it (i.e. the text box is in the 68x68 extent of the icon).
Here's the code I came up with to follow your suggestion:
wimp_icon_create cicon; char *spriteText = "!DummyFS"; char *spriteName = "S!DummyFS"; // wimp_w cicon.w = wimp_ICON_BAR_LEFT; // Extent cicon.icon.extent.x0 = 0; cicon.icon.extent.y0 = 0; cicon.icon.extent.x1 = 68; cicon.icon.extent.y1 = 68; // Flags cicon.icon.flags = wimp_ICON_SPRITE | wimp_ICON_TEXT | wimp_ICON_INDIRECTED | wimp_ICON_HCENTRED | (wimp_BUTTON_CLICK << wimp_ICON_BUTTON_TYPE_SHIFT); // Data cicon.icon.data.indirected_text_and_sprite.text = spriteText; cicon.icon.data.indirected_text_and_sprite.validation = spriteName; cicon.icon.data.indirected_text_and_sprite.size = sizeof(spriteText); // Create the icon wimp_create_icon(&cicon);
Update: I added the sprite name into the validation string, but it still puts the text over the icon rather than under it
/Simon
[Edited by sinns at 17:40, 1/10/2014] |
|
[ Log in to reply ] |
|
VinceH |
Message #123374, posted by VincceH at 17:39, 1/10/2014, in reply to message #123373 |
Lowering the tone since the dawn of time
Posts: 1600
|
If the text is over the icon, is it over the bottom of the icon?
I'm thinking you might need to give it a greater height to allow for the text + sprite.
<checks style guide... probably easier to find in there...>
Yes, page 92:
"RISC OS uses the icon's width to position it horizontally, but it is your responsibility to position the icon vertically"
and
"Your application must position icons with text underneath them 16 OS units below the icon bar’s work area origin, and those without text level with it."
So I think you need to set y0 to -16 and (thanks to the handy diagram) y1 to 84 (that gives a gap between the text and icon of 4). |
|
[ Log in to reply ] |
|
Simon Inns |
Message #123375, posted by sinns at 17:42, 1/10/2014, in reply to message #123374 |
Member
Posts: 73
|
Ah, that helped But now my icon has disappeared... I will have a play to get it back again.
The text box is just a white rectangle though; I'm guessing I'm missing some code to specify what the text font and colour should be. |
|
[ Log in to reply ] |
|
VinceH |
Message #123376, posted by VincceH at 18:16, 1/10/2014, in reply to message #123375 |
Lowering the tone since the dawn of time
Posts: 1600
|
But now my icon has disappeared... I will have a play to get it back again. Was it in the wimp sprite pool?
The text box is just a white rectangle though; I'm guessing I'm missing some code to specify what the text font and colour should be. Oh yes. You don't appear to be setting bit 6 of the flags (text is an anti-aliased font) so you need to set the foreground colour in bits 24-27 of the flags, and the background colour in bits 28-31.
And while looking that up, I've just spotted some more info on the positioning of the text and sprite that the style guide obviously doesn't cover:
Bits 3 (Horizontal), 4 (Vertical) and 9 (Right justified) of the flags should be 1,0,0 respectively: That's text and sprite horizontally centred, with the text at the bottom and the sprite at the top. However, looking back at your code, you have set them that way, so it's not going to affect anything.
As a matter of interest, do you not have the PRMs and Style Guide (or the StrongHelp Wimp manual which should contain pretty much the same info)?
Grr... I was going to follow that with a link to download the PRMs - but the page I was going to link to at http://www.riscos.com/support/developers/prm_index/prmindex.htm is giving me a 404.
<looks further...>
Ah. A HTML version is now on the riscos.com site. |
|
[ Log in to reply ] |
|
Simon Inns |
Message #123378, posted by sinns at 18:23, 1/10/2014, in reply to message #123376 |
Member
Posts: 73
|
Hi Vince, I have a paper copy of the PRMs, but I don't have a copy of the style guide - I will grab one.
Anyway, with your help I was able to figure it out; most of my problems (apart from the obvious lack of practice) were in translating the PRM block descriptions to OSLib's way of doing things (although I feel I've got the hang of it now).
Just in case this pops up again, here is the working code:
// Add the task's icon to the icon bar void gui_initialiseIconBar(void) { wimp_icon_create cicon; char *spriteText = "DummyFS"; char *spriteName = "S!DummyFS"; // wimp_w cicon.w = wimp_ICON_BAR_LEFT; // Extent cicon.icon.extent.x0 = 0; cicon.icon.extent.y0 = -16; cicon.icon.extent.x1 = 68; cicon.icon.extent.y1 = 84; // Flags cicon.icon.flags = wimp_ICON_SPRITE | wimp_ICON_TEXT | wimp_ICON_INDIRECTED | wimp_ICON_HCENTRED | (wimp_BUTTON_CLICK << wimp_ICON_BUTTON_TYPE_SHIFT) | (wimp_COLOUR_BLACK << wimp_ICON_FG_COLOUR_SHIFT) | (wimp_COLOUR_VERY_LIGHT_GREY << wimp_ICON_BG_COLOUR_SHIFT); // Data cicon.icon.data.indirected_text_and_sprite.text = spriteText; cicon.icon.data.indirected_text_and_sprite.validation = spriteName; cicon.icon.data.indirected_text_and_sprite.size = sizeof(spriteText); // Create the icon wimp_create_icon(&cicon); }
Thanks again! |
|
[ Log in to reply ] |
|
|