correct way to work with system sprites
Pages: 1 2
Aleksey Murushkin (Cloverleaf) (8233) 41 posts |
Hi. I am trying to do the following. I have a sprite created at memory. And I want to put there a system sprite with file type icon. What is the correct steps to do that? |
Steffen Huber (91) 1953 posts |
Provide filetype icons always via Obey file and IconSprites command. Never use “System Sprite” area, that is I think deprecated since RISC OS 3 at least. Especially since it depends on the user reserving the memory for the “System Sprite” area. |
Aleksey Murushkin (Cloverleaf) (8233) 41 posts |
But I want to use in my program exact file icon types from system. I dont talk about icon for my program |
Rick Murray (539) 13840 posts |
Multitasking program? Icons supplied by the system? Then you’ll need to call the SpriteOp functions telling it to use the Wimp sprite area. |
Steve Drain (222) 1620 posts |
What is the class/gadget of the object you want the sprite to appear in, or are you plotting directly? In the former case you would pass the pointer to your user sprite area to Toolbox_Initialise. Then for a Button gadget, for example, you would specify ‘Use client sprite area’ in the Res file. The sprite can then be specified by its name as Value, or perhaps as an S field in Validation. For a Wimp sprite such as ‘file_XXX’ you would not have to do anything about a user sprite area. The ‘Use client sprite area’ flag can be changed at runtime if necessary. I cannot help with the latter case. ;-) |
Andy S (2979) 504 posts |
Never use “System Sprite” area, that is I think deprecated since RISC OS 3 at least. It’s a pity when they deprecated it that they didn’t provide some updated sprite star commands (SLOAD, SCHOOSE, etc.) and BASIC sprite plot commands (PLOT &ED) as I enjoyed their elegant simplicity (compared to the SWIs) when programming my Archie in my youth. |
Steffen Huber (91) 1953 posts |
What you call “file icon types from system” are not located in the system sprite area, but in the WIMP sprite area. Put there via te IconSprites command. Wimp_SpriteOp is your friend to use it inside your software. No idea how the Toolbox handles it. |
Rick Murray (539) 13840 posts |
I said that three hours ago. ;-)
I think it’s something that might have made sense on Arthur (maybe as an enhancement of the 6502 sprite routines – was it the Master Compact that did that?); but in a multitasking world it was… less useful. Indeed I’ve seen some really weird stuff “claiming” the system sprite area, like using it as an automatically resizing file buffer (yikes!). Didn’t something also try to make it look and feel like a RAMdisc where you could save the contents to restore them later?
I think the logical place for that would have been to add some sprite commands to BASIC. Like SINIT to initialise a sprite area (like DIM m% 12345678 then SINIT m%); with SCREATE, SPLOT, etc etc. m% is a pointer to the sprite area, obviously, so you could use the SWIs for the more esoteric things like flipping or inserting/deleting rows. Yeah, BASIC is where that should have ended up… |
John WILLIAMS (8368) 493 posts |
I suspect, M’lord, that the correspondent may be referring to MemFS, which I have loaded here, but which fails to auto-resize on many occasions! |
Steve Drain (222) 1620 posts |
Basalt has a |
Aleksey Murushkin (Cloverleaf) (8233) 41 posts |
At the moment i was able to render it with wimpspriteop_put_sprite_scaled but it has a problems with colours at the moment. I understand that i need to do the colour trans table but i cant get the info about sprite. wimpspriteop_select_sprite returns wrong data and wimpspriteop_get_sprite gives me error that wimp receives incorrect parameter at R0.
here is the result:
the value of spritename is "file_bf8" could someone help me to understand what is wrong? |
Andy S (2979) 504 posts |
That’s not good. It’s as if the sprite’s data (or your wimpsprheader) is misaligned by one word. Does your code write into the Wimp sprite area? |
Aleksey Murushkin (Cloverleaf) (8233) 41 posts |
No I don’t write to wimp sprite area |
Andy S (2979) 504 posts |
If you change the code to this, does it print the correct information?: osspriteop_header *wimpsprheader = wimpspriteop_select_sprite(spritename); wimpsprheader -= 4; debug_printf("wimpspriteop_select_sprite size = %d", wimpsprheader->size); debug_printf("wimpspriteop_select_sprite name = %s", wimpsprheader->name); debug_printf("wimpspriteop_select_sprite width = %d", wimpsprheader->width); debug_printf("wimpspriteop_select_sprite height = %d", wimpsprheader->height); debug_printf("wimpspriteop_select_sprite left_bit = %d", wimpsprheader->left_bit); debug_printf("wimpspriteop_select_sprite right_bit = %d", wimpsprheader->right_bit); debug_printf("wimpspriteop_select_sprite image = %d", wimpsprheader->image); debug_printf("wimpspriteop_select_sprite mask = %d", wimpsprheader->mask); debug_printf("wimpspriteop_select_sprite mode = %d", wimpsprheader->mode); I have no idea why it is 4 bytes out. I would also try selecting some different sprites. See if they all have that problem. |
Chris Hall (132) 3554 posts |
A sprite file omits the first word which specifies the length of the file (i.e. the length of the sprite area) as it is implied from the file length. |
Aleksey Murushkin (Cloverleaf) (8233) 41 posts |
when i made offset of 4 bytes and run same procedure 3 times i got these results:
is there any way to always get correct width, height and mode? do i need to get them from bytes offset? can i be sure it will work on other computers too? Thanks to everyone who is trying to help me |
Andy S (2979) 504 posts |
I think either something is corrupting your Wimp sprite area or wimpspriteop_select_sprite() is broken. :( The offset of 4 bytes is not a proper fix. I just wanted to get more information, in case someone else knows what’s going wrong. Try without the offset, with some other sprite file names. |
Andy S (2979) 504 posts |
is there any way to always get correct width, height and mode? I don’t know Toolbox, but I think you should use wimpspriteop_readspriteinfo(). It says here that you shouldn’t use WimpSprite_Op 24 to get the address (“using reason code 24 to read the address of a sprite is discouraged.”). That may be why wimpspriteop_select_sprite() is not working to get the information. |
Aleksey Murushkin (Cloverleaf) (8233) 41 posts |
I tried wimpspriteop_readspriteinfo and get width=34, height=34, mask=1, mode=21. looks correct I think. I am not sure only about mode. is it correct? |
Andy S (2979) 504 posts |
I am not sure only about mode. is it correct? I don’t know. I would have to open the sprite in !Paint to check. What should i do with mask? const char *sprite_name = "file_fff"; /* Set bit 3 to use the mask: */ os_action action = 4; os_factors scale; scale.xmul = 2; scale.ymul = 2; scale.xdiv = 1; scale.ydiv = 1; /* 0 for no colour trans table. You should make one. */ osspriteop_trans_tab const *trans_tab = 0; wimpspriteop_put_sprite_scaled( sprite_name, x, y, action, &scale, trans_tab); Does that do what you wanted? |
Aleksey Murushkin (Cloverleaf) (8233) 41 posts |
I have tried different things but cant do the correct colors. here my code:
some things that i was trying is commented. Basically i see the image but colors a wrong. but they are diffrent if i try USE_MASK or not |
Andy S (2979) 504 posts |
My code was wrong for the mask. It should have been: /* Set bit 3 to use the mask: */ os_action action = 8; |
Andy S (2979) 504 posts |
I think it should be something like this: int len = colourtrans_generate_table_for_sprite(wimpspriteop_AREA, (osspriteop_id)spritename, os_CURRENT_MODE, colourtrans_CURRENT_PALETTE, 0, colourtrans_RETURN_WIDE_ENTRIES, NULL, NULL); osspriteop_trans_tab * trans_tab = (osspriteop_trans_tab*)malloc(len); colourtrans_generate_table_for_sprite(wimpspriteop_AREA, (osspriteop_id)spritename, os_CURRENT_MODE, colourtrans_CURRENT_PALETTE, trans_tab, colourtrans_RETURN_WIDE_ENTRIES, NULL, NULL); wimpspriteop_put_sprite_scaled(spritename, 0, 0, osspriteop_GIVEN_WIDE_ENTRIES | osspriteop_USE_MASK, NULL, trans_tab); |
Aleksey Murushkin (Cloverleaf) (8233) 41 posts |
Andy, I have tried that too. unfortunately it still displayed with wrong colors. |
Aleksey Murushkin (Cloverleaf) (8233) 41 posts |
Finally I have found a working way. For those who is interested too:
|
Pages: 1 2