From WiiBrew
< User:Thav
Jump to navigation Jump to search

Template:Infobox homebrewapp

libwsmenu is a brand new project with the intention of building a wrapper for libwiisprite to easily create menus for homebrew software. It will be hosted at Google Code. I would greatly appreciate any feedback on features that should be included, suggestions on implementation or if this even seems like a worthwhile project. Feel free to discuss on the talk page or to me privately at my gmail address, thavilden@..... I'm working out all the details here so the process can be open for feedback. I really hate when a "standard" sort of comes out without any community input and is lousy because the creator didn't think it through all the way. I fear I might be one of those creators.

Project Info

Proposed Features

  • Menu object that takes a one or two dimensional array of Button objects, which each contain a function pointer, default button image, hover button image, selected button image, foreground icon and foreground text.
  • Menu object will have methods to check if any of the Buttons are being hovered over or selected and then will return or call their pointed function.
  • Allow copying a menu object, so that one main menu can be created with other sub menus copied therefrom and modified.

Possible issues

  • The menu, buttons and all will have to sit in a LayerManager, but LayerManager has no visible option, so where do we put the Menu when not in use? Or is it better to discard the menu from memory and rebuild later? Will look into how this is done on other software. Each menu/function can sit in its own LayerManager and be shoved offscreen when needed. Maybe if the manager is not drawn before a flush it will not appear? Will look into this.
  • When allowing some other function to access video that does not use libwiisprite (say an emulator) then how do we make sure the path is clear, so to speak?

Class Member Function Outline


Inherit from wsp::LayerManager so I don't have to re-implement managing the list. Broke out the constructor in the same was as Button here.

 * libwsmenu - Menu
#include <gccore.h>
#include "layermanager.h"
//!libwsmenu namespace
namespace wsm{
	//!Generates a menu object for handling Button objects
	class Menu : public LayerManager {
			Menu(u32 boundary);
			void SetRows(u32 rows);
			void SetColumns(u32 cols);
			vold AddButtons(Button* buttons);
			void ArrangeMenu();
			bool AnyOver(u32 x, u32 y, bool select = 0);
			void RunSelected();
			u32 _rows, _cols;
			Button* _selected;
			Button** _layers;
			u32 _size, _boundary;


Inheriting from the Sprite class now so I wouldn't have to copy the code for zoom, stretch, transparency, reference etc. Did however want to exclude the collision and animation stuff for now. Though I guess it's actually probably fair game since if another sprite tries to crash with a button the "bool CollidesWith (const Sprite *sprite, bool complete=false) const;" should actually work out correctly. In fact, the animation stuff could work too with a little tweaking to the Set(State) functions. I have multiple options for constructors just in case people want to define a button individually (first), handle them outside the menu class (second) or as an array (third). The first and second constructors may not make it to the final cut. Need to throw in a few extra private variables that I don't have access to from the Sprite class (since they're set to private there, not protected).

For now, it looks like all the images will have to be the same size in the button so it can have a consistent collision rectangle and frame width/height.

 * libwsmenu - Button
#include <gccore.h>
#include "layer.h"
#include "image.h"
//!libwsmenu namespace
namespace wsm{
	//!Generates a button object for use with a menu
	class Button : public Sprite {
			Button(void (*f_ptr)(void), Image* img_up, Image* img_over, Image* img_down, Image* icon, char* btn_txt);
			Button(u32 x, u32 y, void (*f_ptr)(void), Image* img_up, Image* img_over, Image* img_down, Image* icon, char* btn_txt);
			void    SetUp(Image* img_up);
			void    SetDown(Image* img_down);
			void    SetOver(Image* img_over);
			void    SetIcon(Image* icon);
			void    setText(char* btn_txt);
			void    SetFunction(void (*f_ptr)(void));
			bool    IsPointerOver(u32 x, u32 y) const;
			bool    Select(u32 x, u32 y) const;
			void    Deselect();
			void    Draw();
			//These functions from sprite are protected so class users cannot use them.
			void 	DefineCollisionRectangle (f32 x, f32 y, f32 width, f32 height);
			const Rectangle * 	GetCollisionRectangle () const;
			bool 	CollidesWith (const Rectangle *rect, f32 x=0, f32 y=0) const;
			bool 	CollidesWith (const Sprite *sprite, bool complete=false) const;
			bool 	CollidesWith (const TiledLayer *tiledlayer) const;
			u32 	GetFrame () const;
			u32 	GetFrameSequencePos () const;
			u32 	GetFrameSequenceLength () const;
			u32 	GetRawFrameCount () const;
			void 	SetFrame (u32 sequenceIndex);
			void 	NextFrame ();
			void 	PrevFrame ();
			void 	SetFrameSequence (u32 *sequence, u32 length);
			bool _hovered;
			bool _selected;
			Image*  _img_up;
			Image*  _img_over;
			Image*  _img_down;
			Image*  _icon;
			char*   _btn_txt;
			void    (*_f_ptr)(void);

Development information

Borrowing heavily from