Thank you JF I'll post more of my code then.
Code: Select all
#include <pspkernel.h>
#include <pspdebug.h>
#include <pspctrl.h>
#include <pspdisplay.h>
#include <psppower.h>
#include <psprtc.h>
#include <SDL/SDL.h>
#include <SDL/SDL_image.h>
#include <SDL/SDL_ttf.h>
#include <stdlib.h>
#include <stdio.h>
#include <time.h>
#include <string>
#include <list>
#include <iostream>
//#include "Calculator.h"
#include "alarm.h"
#include "alarmmanager.h"
using namespace std;
PSP_MODULE_INFO("iPDA", 0, 1, 1);
PSP_MAIN_THREAD_ATTR(THREAD_ATTR_USER | THREAD_ATTR_VFPU);
static bool isrunning = true;
static int curWindow = 1;
// Exit callback
int exit_callback(int arg1, int arg2, void *common) {
isrunning = false;
sceKernelExitGame();
return 0;
}
// Callback thread
int CallbackThread(SceSize args, void *argp) {
int cbid;
cbid = sceKernelCreateCallback("Exit Callback", exit_callback, NULL);
sceKernelRegisterExitCallback(cbid);
sceKernelSleepThreadCB();
return 0;
}
// Sets up the callback thread and returns its thread id
int SetupCallbacks(void) {
int thid = 0;
thid = sceKernelCreateThread("update_thread", CallbackThread, 0x11, 0xFA0, 0, 0);
if(thid >= 0)
{
sceKernelStartThread(thid, 0, 0);
}
return thid;
}
int main() {
//Initialize the controler and the PSP Speed
SceCtrlData pad;
scePowerSetClockFrequency(333, 333, 166);
sceCtrlSetSamplingCycle(0);
sceCtrlSetSamplingMode(PSP_CTRL_MODE_ANALOG);
char timeText[8];
int thread_id;
//Initialize the PSP Time
pspTime time;
//Initialize the SDL Library (audio and video)
if(SDL_Init(SDL_INIT_VIDEO) < 0)
cout << stderr << "Couldn't initialize SDL: " << SDL_GetError() << endl;
//Initialize the SDL True Type Font Library
if(TTF_Init() < 0)
cout << stderr << "Couldn't initialize TTF: " << SDL_GetError() << endl;
//Initialize the font color.
SDL_Color couleurblanc = {255, 255, 255};
SDL_Color couleurnoir = {0, 0, 0};
//Initialize the position of the text.
SDL_Rect txtcalendar_position;
txtcalendar_position.x = 130;
txtcalendar_position.y = 146;
SDL_Rect txtconfig_position;
txtconfig_position.x = 232;
txtconfig_position.y = 146;
SDL_Rect txtcalculator_position;
txtcalculator_position.x = 307;
txtcalculator_position.y = 146;
SDL_Rect txtweather_position;
txtweather_position.x = 119;
txtweather_position.y = 240;
SDL_Rect txtcontact_position;
txtcontact_position.x = 228;
txtcontact_position.y = 240;
SDL_Rect txtalarm_position;
txtalarm_position.x = 319;
txtalarm_position.y = 240;
SDL_Rect txttime_position;
txttime_position.x = 186;
txttime_position.y = 20;
//Calculatrice
SDL_Rect txtZero_position;
txtZero_position.x = 19;
txtZero_position.y = 236;
SDL_Rect txtDot_position;
txtDot_position.x = 66;
txtDot_position.y = 210;
SDL_Rect txtClear_position;
txtClear_position.x = 113;
txtClear_position.y = 231;
//Initialize the position of the images.
SDL_Rect background_position;
background_position.x = 0;
background_position.y = 0;
SDL_Rect calendar_position;
calendar_position.x = 125;
calendar_position.y = 80;
SDL_Rect tools_position;
tools_position.x = 218;
tools_position.y = 80;
SDL_Rect calculator_position;
calculator_position.x = 305;
calculator_position.y = 80;
SDL_Rect weather_position;
weather_position.x = 125;
weather_position.y = 170;
SDL_Rect contact_position;
contact_position.x = 218;
contact_position.y = 170;
SDL_Rect alarm_position;
alarm_position.x = 305;
alarm_position.y = 170;
SDL_Rect cal_position;
cal_position.x = 0;
cal_position.y = 0;
//Initialize the mouse.
SDL_Rect souris;
souris.x = 239;
souris.y = 134;
//Initialize the Joystick.
SDL_Rect posJoy;
posJoy.x = pad.Lx-128;
posJoy.y = pad.Ly-128;
//Chargement des images.
SDL_Surface *background, *mousePointer, *iconCalendar, *iconConfig, *iconWeather, *iconContact, *iconCalculator, *iconAlarm,
*Calculatrice;
SDL_Surface *ecran = SDL_SetVideoMode(480, 272, 32, SDL_HWSURFACE | SDL_DOUBLEBUF);
background = SDL_DisplayFormat(IMG_Load("data/gfx/blackbackground.png"));
mousePointer = SDL_DisplayFormatAlpha(IMG_Load("data/gfx/mouse.png"));
iconCalendar = SDL_DisplayFormatAlpha(IMG_Load("data/gfx/calendar.png"));
iconConfig = SDL_DisplayFormatAlpha(IMG_Load("data/gfx/tools.png"));
iconWeather = SDL_DisplayFormatAlpha(IMG_Load("data/gfx/weather.png"));
iconContact = SDL_DisplayFormatAlpha(IMG_Load("data/gfx/contact.png"));
iconCalculator = SDL_DisplayFormatAlpha(IMG_Load("data/gfx/calculator.png"));
iconAlarm = SDL_DisplayFormatAlpha(IMG_Load("data/gfx/clock.png"));
Calculatrice = SDL_DisplayFormatAlpha(IMG_Load("data/gfx/calculatrice.png"));
//Chargement des polices et du texte a afficher.
TTF_Font *font = TTF_OpenFont("data/font/Rippen.ttf", 15);
TTF_Font *timeFont = TTF_OpenFont("data/font/Rippen.ttf", 45);
TTF_Font *twentyFont = TTF_OpenFont("data/font/Rippen.ttf", 20);
TTF_Font *twenty5Font = TTF_OpenFont("data/font/Rippen.ttf", 25);
TTF_Font *thirtyFont = TTF_OpenFont("data/font/Rippen.ttf", 30);
TTF_Font *thirty5Font = TTF_OpenFont("data/font/Rippen.ttf", 35);
TTF_Font *fortyFont = TTF_OpenFont("data/font/Rippen.ttf", 40);
TTF_Font *fifthy5Font = TTF_OpenFont("data/font/Rippen.ttf", 55);
SDL_Surface *textCalendar = TTF_RenderText_Shaded(font, "Calendar", couleurblanc, couleurnoir);
SDL_Surface *textConfig = TTF_RenderText_Shaded(font, "Config", couleurblanc, couleurnoir);
SDL_Surface *textWeather = TTF_RenderText_Shaded(font, "Temperature", couleurblanc, couleurnoir);
SDL_Surface *textContact = TTF_RenderText_Shaded(font, "Contact", couleurblanc, couleurnoir);
SDL_Surface *textCalculator = TTF_RenderText_Shaded(font, "Calculator", couleurblanc, couleurnoir);
SDL_Surface *textAlarm = TTF_RenderText_Shaded(font, "Alarm", couleurblanc, couleurnoir);
SDL_Surface *textZero = TTF_RenderText_Blended(twentyFont, "0", couleurblanc);
SDL_Surface *textDot = TTF_RenderText_Blended(fifthy5Font, ".", couleurblanc);
SDL_Surface *textClear = TTF_RenderText_Blended(twenty5Font, "c", couleurblanc);
SDL_Surface *textTime = NULL;
//Initialisation du mode Debug de la PSP
pspDebugScreenInit();
SetupCallbacks();
//Declare alarm
/*pspTime alarmTime;
sceRtcGetCurrentClockLocalTime(&alarmTime);
alarmTime.minutes++;
AlarmManager Alarms;
Alarms.Add(new Alarm(false, "Marimba", false, "alarme 1", alarmTime));
alarmTime.minutes++;
Alarms.Add(new Alarm(false, "Marimba2", false, "alarme 2", alarmTime));*/
//Alarms.Save();
//list<Alarm*> alarms = Alarms.Check(time);
//Start the loop
while(isrunning)
{
sceCtrlReadBufferPositive(&pad, 1);
sceRtcGetCurrentClockLocalTime(&time);
if((pad.Lx < 35) && (souris.x > 0))
{
souris.x = souris.x-3;
}
else if((pad.Lx > 200) && (souris.x < 480))
{
souris.x = souris.x+3;
}
if((pad.Ly < 35) && (souris.y > 0))
{
souris.y = souris.y-3;
}
else if((pad.Ly > 200) && (souris.y < 480))
{
souris.y = souris.y+3;
}
if(souris.x >= 480)(souris.x = 480);
if(souris.y >= 272)(souris.y = 272);
SDL_BlitSurface(background, NULL, ecran, &background_position);
//if (textTime != NULL) SDL_FreeSurface(textTime);
snprintf(timeText, 8, "%02i : %02i", time.hour, time.minutes);
SDL_Surface *textTime = TTF_RenderText_Shaded(timeFont, timeText, couleurblanc, couleurnoir);
SDL_BlitSurface(textTime, NULL, ecran, &txttime_position);
if (curWindow == 1)
{
if (pad.Buttons & PSP_CTRL_CROSS)
{
if ((souris.x > calculator_position.x) && (souris.x < (calculator_position.x + 64)) &&
(souris.y > calculator_position.y) && (souris.y < (calculator_position.y + 64)))
{
curWindow = 2;
}
}
SDL_BlitSurface(iconCalendar, NULL, ecran, &calendar_position);
SDL_BlitSurface(textCalendar, NULL, ecran, &txtcalendar_position);
SDL_BlitSurface(iconConfig, NULL, ecran, &tools_position);
SDL_BlitSurface(textConfig, NULL, ecran, &txtconfig_position);
SDL_BlitSurface(iconWeather, NULL, ecran, &weather_position);
SDL_BlitSurface(textWeather, NULL, ecran, &txtweather_position);
SDL_BlitSurface(iconContact, NULL, ecran, &contact_position);
SDL_BlitSurface(textContact, NULL, ecran, &txtcontact_position);
SDL_BlitSurface(iconCalculator, NULL, ecran, &calculator_position);
SDL_BlitSurface(textCalculator, NULL, ecran, &txtcalculator_position);
SDL_BlitSurface(iconAlarm, NULL, ecran, &alarm_position);
SDL_BlitSurface(textAlarm, NULL, ecran, &txtalarm_position);
}
else if (curWindow == 2)
{
SDL_BlitSurface(Calculatrice, NULL, ecran, &cal_position);
SDL_BlitSurface(textZero, NULL, ecran, &txtZero_position);
SDL_BlitSurface(textDot, NULL, ecran, &txtDot_position);
SDL_BlitSurface(textClear, NULL, ecran, &txtClear_position);
if (pad.Buttons & PSP_CTRL_SELECT)(curWindow = 1);
}
SDL_BlitSurface(mousePointer, NULL, ecran, &souris);
SDL_Flip(ecran);
}
//Free the memory.
TTF_CloseFont(font);
TTF_CloseFont(timeFont);
TTF_CloseFont(twentyFont);
TTF_CloseFont(twenty5Font);
TTF_CloseFont(thirtyFont);
TTF_CloseFont(thirty5Font);
TTF_CloseFont(fortyFont);
TTF_CloseFont(fifthy5Font);
SDL_FreeSurface(background);
SDL_FreeSurface(mousePointer);
SDL_FreeSurface(iconCalendar);
SDL_FreeSurface(iconConfig);
SDL_FreeSurface(iconWeather);
SDL_FreeSurface(iconContact);
SDL_FreeSurface(iconCalculator);
SDL_FreeSurface(iconAlarm);
SDL_FreeSurface(textCalendar);
SDL_FreeSurface(textConfig);
SDL_FreeSurface(textWeather);
SDL_FreeSurface(textContact);
SDL_FreeSurface(textCalculator);
SDL_FreeSurface(textAlarm);
SDL_FreeSurface(textTime);
SDL_FreeSurface(textZero);
SDL_FreeSurface(Calculatrice);
TTF_Quit();
SDL_Quit();
sceKernelSleepThread();
return 0;
}