Page 1 of 1

Keyboard and background

Posted: Thu Mar 15, 2012 4:05 pm
by Leon
Not being able to find much info about the onscreen keyboard, I have some questions:

I'm trying to get a keyboard on top of a background image. Not sure if this is possible at all with the default keyboard. Can anyone point me to a good example/tutorial on how to use the keyboard in combination with backgrounds (either the default keyboard or a custom one)?

As a shortcut, after having used the keyboard with

Code: Select all

   consoleDemoInit();
	keyboardDemoInit();
	keyboardShow();
is there a way to reset (or re-init) the bottom screen so I can use

Code: Select all

	videoSetModeSub(MODE_5_2D);
	vramSetBankC(VRAM_C_SUB_BG_0x06200000);

	int bg3sub = bgInitSub(3, BgType_Bmp8, BgSize_B8_256x256, 0,0);		
	
   dmaCopy(mysubimg1Bitmap, bgGetGfxPtr(bg3sub), 256*256);
	dmaCopy(mysubimg1Pal, BG_PALETTE_SUB, 256*2);	
after having used the keyboard.

Both pieces of code separate work fine but not in the same app.... Reusing consoleDemoInit(); doesn't do the trick.
I'm sure it's my perception of the statements that causes the problem here. I still haven't quite figured out how the videomemory of the DS works.

Thanks for your time.

Re: Keyboard and background

Posted: Sat Mar 17, 2012 1:48 am
by WinterMute
Should just be a matter of clearing BG3 when you display keyboard again I think, something like this :-

Code: Select all

#include <nds.h>

#include "mysubimg1.h"

int bg3sub;

void displayBitmap() {
	videoSetModeSub(MODE_5_2D);
	vramSetBankC(VRAM_C_SUB_BG_0x06200000);

	bg3sub = bgInitSub(3, BgType_Bmp8, BgSize_B8_256x256, 0,0);      
   
	dmaCopy(mysubimg1Bitmap, bgGetGfxPtr(bg3sub), 256*256);
	dmaCopy(mysubimg1Pal, BG_PALETTE_SUB, 256*2);
}

void displayKeyboard() {
	consoleDemoInit();
	keyboardDemoInit();
	keyboardShow();
}

int showkeys = 0;

//---------------------------------------------------------------------------------
int main(void) {
//---------------------------------------------------------------------------------

	displayKeyboard();
	while(1) {
		swiWaitForVBlank();
		scanKeys();
		if(keysDown()&KEY_START){
			showkeys = !showkeys;
			if(showkeys) {
				displayBitmap();
			} else {
				dmaFillWords(0,bgGetGfxPtr(bg3sub), 256*256);
				displayKeyboard();
			}
		}
	}
	return 0;
}

Re: Keyboard and background

Posted: Sat Mar 17, 2012 10:28 am
by Leon
Ah.... right. I just didn't clear the background with

Code: Select all

dmaFillWords(0,bgGetGfxPtr(bg3sub), 256*256);
Works like a charm now... alternating that is.

No way of showing them both together? I'd thought that since the default keyboard is using layer 3, using layer 2 with the image and setting priority to layer 3 would do the trick but alas...

Like said, I still don't get the memory thing completely. If memory is set as default,

Code: Select all

vramSetBankC(VRAM_C_SUB_BG_0x06200000);
and the keyboard has the default settings

Code: Select all

keyboardInit(NULL, 3, BgType_Text4bpp, BgSize_T_256x512, 20, 0, false, true) 
where does bg2sub then fit in?

Code: Select all

bg2sub = bgInitSub(2, BgType_Bmp8, BgSize_B8_256x256, ?,0);   
Can you mix BgTypes at all? Is there a way to display an image on Text4bpp? You see.... I'm confused :oops:

Re: Keyboard and background

Posted: Mon Mar 19, 2012 2:27 am
by WinterMute
I'm not entirely clear on what you're trying to do here, if you display an image on top of the keyboard graphics then you won't see the keyboard any more. A more detailed explanation of how you want the display to appear might help.

Re: Keyboard and background

Posted: Mon Mar 19, 2012 1:18 pm
by Leon
The idea is to show a keyboard on top of a background image.

Re: Keyboard and background

Posted: Fri Mar 30, 2012 12:21 am
by mtheall
If you need help managing your VRAM, try http://mtheall.com/vram.php