Permalink
Browse files

Added msgdialog sample

  • Loading branch information...
1 parent 4a0ee0b commit 269b14e2e13e598930fabcad7d66b24bcdc9f591 @Estwald Estwald committed Dec 24, 2010
View
@@ -0,0 +1,80 @@
+.SUFFIXES:
+ifeq ($(strip $(PSL1GHT)),)
+$(error "PSL1GHT must be set in the environment.")
+endif
+
+include $(PSL1GHT)/Makefile.base
+
+TARGET := $(notdir $(CURDIR))
+BUILD := build
+SOURCE := source
+INCLUDE := include
+DATA := data
+LIBS := -lgcm_sys -lreality -lsysutil -lio -lm
+
+TITLE := Template - PSL1GHT
+APPID := TEST00003
+CONTENTID := UP0001-$(APPID)_00-0000000000000000
+
+CFLAGS += -g -O2 -Wall --std=gnu99
+CXXFLAGS += -g -O2 -Wall
+
+ifneq ($(BUILD),$(notdir $(CURDIR)))
+
+export OUTPUT := $(CURDIR)/$(TARGET)
+export VPATH := $(foreach dir,$(SOURCE),$(CURDIR)/$(dir)) \
+ $(foreach dir,$(DATA),$(CURDIR)/$(dir))
+export BUILDDIR := $(CURDIR)/$(BUILD)
+export DEPSDIR := $(BUILDDIR)
+
+CFILES := $(foreach dir,$(SOURCE),$(notdir $(wildcard $(dir)/*.c)))
+CXXFILES := $(foreach dir,$(SOURCE),$(notdir $(wildcard $(dir)/*.cpp)))
+SFILES := $(foreach dir,$(SOURCE),$(notdir $(wildcard $(dir)/*.S)))
+BINFILES := $(foreach dir,$(DATA),$(notdir $(wildcard $(dir)/*.bin)))
+VCGFILES := $(foreach dir,$(SOURCE),$(notdir $(wildcard $(dir)/*.vcg)))
+
+export OFILES := $(CFILES:.c=.o) \
+ $(CXXFILES:.cpp=.o) \
+ $(SFILES:.S=.o) \
+ $(BINFILES:.bin=.bin.o) \
+ $(VCGFILES:.vcg=.vcg.o)
+
+export BINFILES := $(BINFILES:.bin=.bin.h)
+export VCGFILES := $(VCGFILES:.vcg=.vcg.h)
+
+export INCLUDES := $(foreach dir,$(INCLUDE),-I$(CURDIR)/$(dir)) \
+ -I$(CURDIR)/$(BUILD)
+
+.PHONY: $(BUILD) clean
+
+$(BUILD):
+ @[ -d $@ ] || mkdir -p $@
+ @make --no-print-directory -C $(BUILD) -f $(CURDIR)/Makefile
+
+clean:
+ @echo Clean...
+ @rm -rf $(BUILD) $(OUTPUT).elf $(OUTPUT).self $(OUTPUT).a $(OUTPUT).pkg
+
+pkg: $(BUILD)
+ @echo Creating PKG...
+ @mkdir -p $(BUILD)/pkg
+ @mkdir -p $(BUILD)/pkg/USRDIR
+ @cp $(ICON0) $(BUILD)/pkg/
+ @$(FSELF) -n $(BUILD)/$(TARGET).elf $(BUILD)/pkg/USRDIR/EBOOT.BIN
+ @$(SFO) --title "$(TITLE)" --appid "$(APPID)" -f $(SFOXML) $(BUILD)/pkg/PARAM.SFO
+ @$(PKG) --contentid $(CONTENTID) $(BUILD)/pkg/ $(OUTPUT).pkg
+
+run: $(BUILD)
+ @$(PS3LOADAPP) $(OUTPUT).self
+
+else
+
+DEPENDS := $(OFILES:.o=.d)
+
+$(OUTPUT).self: $(OUTPUT).elf
+$(OUTPUT).elf: $(OFILES)
+$(OFILES): $(BINFILES) $(VCGFILES)
+
+-include $(DEPENDS)
+
+endif
@@ -0,0 +1,19 @@
+#pragma once
+
+#include <sysutil/video.h>
+#include <rsx/gcm.h>
+
+extern u32 *buffer[2];
+extern gcmContextData *context;
+extern VideoResolution res;
+
+// Initilize the screen and rsx
+void init_screen();
+
+// Block the PPU thread untill the previous flip operation has finished.
+void waitFlip();
+
+void flip(s32 buffer);
+
+// Needs to be called each frame to map the buffers and setup render target
+void setupRenderTarget(u32 currentBuffer);
@@ -0,0 +1,197 @@
+
+#include <stdio.h>
+#include <malloc.h>
+#include <string.h>
+#include <assert.h>
+#include <unistd.h>
+#include <math.h>
+
+#include <rsx/commands.h>
+#include <rsx/nv40.h>
+#include <rsx/reality.h>
+
+#include <io/pad.h>
+
+#include <sysmodule/sysmodule.h>
+
+#include "rsxutil.h"
+
+// for msgdialogs
+#include "sysutil/events.h"
+#include "sysutil/msgdialog.h"
+
+int currentBuffer = 0;
+
+void my_flip()
+{
+ //tiny3d_Flip();
+
+ flip(currentBuffer); // Flip buffer onto screen
+ waitFlip(); // Wait for the last flip to finish, so we can draw to the old buffer
+ currentBuffer = !currentBuffer;
+}
+
+
+
+
+volatile int dialog_action = 0;
+
+void my_dialog(msgbutton button, void *userdata)
+{
+ switch(button) {
+
+ case MSGDIALOG_BUTTON_OK:
+ dialog_action = 1;
+ break;
+ case MSGDIALOG_BUTTON_NO:
+ case MSGDIALOG_BUTTON_ESCAPE:
+ dialog_action = 2;
+ break;
+ case MSGDIALOG_BUTTON_NONE:
+ dialog_action = -1;
+ break;
+ default:
+ break;
+ }
+}
+
+
+void dialog()
+{
+ int response;
+ u32 happypercent;
+ u32 moneypercent;
+
+// error code message
+
+ MsgDialogErrorCode(0xBEBACAFE, my_dialog, (void *) 0xEEEE0001, NULL);
+ MsgDialogDelayedClose(3000.0f); // 3 seconds
+
+ dialog_action = 0;
+ while(dialog_action!=-1)
+ {
+ sysCheckCallback();my_flip();
+ }
+
+ MsgDialogClose();
+
+// yes/no message
+
+ msgtype mdialogyesno = MSGDIALOG_NORMAL | MSGDIALOG_BUTTON_TYPE_YESNO | MSGDIALOG_DISABLE_CANCEL_ON | MSGDIALOG_DEFAULT_CURSOR_NO;
+
+ MsgDialogOpen(mdialogyesno, "Hey!!\nYou are Happy?", my_dialog, (void *) 0x11110001, NULL);
+
+ dialog_action = 0;
+ while(!dialog_action)
+ {
+ sysCheckCallback();my_flip();
+ }
+
+ MsgDialogClose();
+
+ response = dialog_action;
+
+// OK message
+
+ msgtype mdialogok = MSGDIALOG_NORMAL | MSGDIALOG_BUTTON_TYPE_OK;
+
+ if(response == 1)
+ MsgDialogOpen(mdialogok, "I'm glad you're happy :)\nMerry Christmas!!!", my_dialog, (void *) 0x22220001, NULL);
+ else
+ MsgDialogOpen(mdialogok, "Ok, but removes your vinegar face :p\nIt's Christmas!!!", my_dialog, (void *) 0x22220002, NULL);
+
+ dialog_action = 0;
+ while(!dialog_action)
+ {
+ sysCheckCallback();my_flip();
+ }
+
+ MsgDialogClose();
+
+// Single Progress bar
+
+ msgtype mdialogprogress = MSGDIALOG_SINGLE_PROGRESSBAR;
+
+ happypercent = 0;
+
+ MsgDialogOpen(mdialogprogress, "Recharging happiness batteries...", my_dialog, (void *) 0x33330001, NULL);
+ MsgDialogProgressBarMessage(PROGRESSBAR_INDEX0, "You're Happy");
+ MsgDialogResetProgressBar(PROGRESSBAR_INDEX0);
+
+ dialog_action = 0;
+ while(!dialog_action)
+ {
+ MsgDialogIncProgressBar(PROGRESSBAR_INDEX0, happypercent);
+ sysCheckCallback();my_flip();
+ if(happypercent < 100) happypercent++;
+ usleep(100*1000);
+ }
+
+ MsgDialogClose();
+
+// Double Progress bar
+
+ mdialogprogress = MSGDIALOG_DOUBLE_PROGRESSBAR;
+
+ moneypercent = 0;
+
+ MsgDialogOpen(mdialogprogress, "Recharging Virtual money...", my_dialog, (void *) 0x33330002, NULL);
+ MsgDialogProgressBarMessage(PROGRESSBAR_INDEX0, "You're Happy");
+ MsgDialogResetProgressBar(PROGRESSBAR_INDEX0);
+ MsgDialogProgressBarMessage(PROGRESSBAR_INDEX1, "Virtual money");
+ MsgDialogResetProgressBar(PROGRESSBAR_INDEX1);
+
+ dialog_action = 0;
+ while(!dialog_action)
+ {
+ MsgDialogIncProgressBar(PROGRESSBAR_INDEX0, happypercent);
+ MsgDialogIncProgressBar(PROGRESSBAR_INDEX1, moneypercent);
+ sysCheckCallback();my_flip();
+ if(happypercent < 100) happypercent++;
+ if(moneypercent < 100) moneypercent++;
+ usleep(100*1000);
+ }
+
+ MsgDialogClose();
+
+// OK with delay time
+
+ MsgDialogOpen(mdialogok, "Congratulations!!!\nYou are now happy and you have virtual money :p", my_dialog, (void *) 0x22220003, NULL);
+ MsgDialogDelayedClose(3000.0f); // 3 seconds
+
+ dialog_action = 0;
+ while(!dialog_action)
+ {
+ sysCheckCallback();my_flip();
+ }
+
+ MsgDialogClose();
+
+// OK with delay time
+
+ MsgDialogOpen(mdialogok, "Good bye!!", my_dialog, (void *) 0x22220004, NULL);
+ MsgDialogDelayedClose(2000.0f); // 2 seconds
+
+ dialog_action = 0;
+ while(!dialog_action)
+ {
+ sysCheckCallback();my_flip();
+ }
+
+ MsgDialogClose();
+
+}
+
+s32 main(s32 argc, const char* argv[])
+{
+
+ init_screen();
+ ioPadInit(7);
+
+ waitFlip();
+
+ dialog();
+
+ return 0;
+}
+
Oops, something went wrong.

0 comments on commit 269b14e

Please sign in to comment.