Lesson 05
Onwards and Upwards
More PSP Programming methods including overclocking, colors, and graphics based text.
This is the fourth part of Lesson 05; if you haven't completed the first,
second, or third part do that now.
So now we have code that allows us to select a color component to modify, and change the variable associated with that color. The next step is to actually display the program on the screen. Our user interface (UI) will consist of text, telling the user what the color components are, and the background.
Recall that the colors can only be from 0-255. We need to make sure that they don't exceed this when the user scrolls through them, so we'll
use a series of if/else statements to ensure that they stay within the target range.
Now we want to fill the background the color that our variables dictate.
Now we want to write the text over the background that we just drew:
We now need to do the same thing for the other two colors.
So now we have code that allows us to select a color component to modify, and change the variable associated with that color. The next step is to actually display the program on the screen. Our user interface (UI) will consist of text, telling the user what the color components are, and the background.
if(bgR < 0) {
bgR = 0;
} else if(bgR > 255) {
bgR = 255;
}
if(bgG < 0) {
bgG = 0;
} else if(bgG > 255) {
bgG = 255;
}
if(bgB < 0) {
bgB = 0;
} else if(bgB > 255) {
bgB = 255;
}
This should be pretty self explanatory. If the value of any of the components gets out of the range, we just set it to the lowest (or highest) place it should be able to be.bgR = 0;
} else if(bgR > 255) {
bgR = 255;
}
if(bgG < 0) {
bgG = 0;
} else if(bgG > 255) {
bgG = 255;
}
if(bgB < 0) {
bgB = 0;
} else if(bgB > 255) {
bgB = 255;
}
Now we want to fill the background the color that our variables dictate.
fillScreenRect(RGB(bgR, bgG, bgB), 0, 0, SCREEN_WIDTH, SCREEN_HEIGHT);
"fillScreenRect()" is a function that is defined in "graphics.c." It fills a rectangular portion of the screen a given color. It takes five parameters. The first is the color we want the rectangle
to be. The second is the x position of the rectangle. The third is the y position of the rectangle. The fourth is the width of the rectangle. And the fifth is the height of the rectangle.Now we want to write the text over the background that we just drew:
sprintf(filler, " RED: %i", bgR);
if(selComponent == 0) {
printTextScreen(11, 10, filler, shadowColorH);
printTextScreen(10, 10, filler, highlightColor);
} else {
printTextScreen(11, 10, filler, shadowColorD);
printTextScreen(10, 10, filler, dimmedColor);
}
You should remember the "sprintf()" function from Lesson 04. It is the one that parses a "printf()" into a string. This time,
though, we are using a variable. We want to display both the color (Red) and the value (bgR). We do this the same way that we outputted an integer in Lesson 03
(with the "%i" modifier). Then, if the component is selected, we use the "printTextScreen()" function from "graphics.c" to print our string to the screen. The function takes four parameters,
the first is the x position. The second is the y position. The third is the string. And the fourth is the color. The reason for the if/else statement is that we want to display the text in a
different color if it is supposed to be selected. We also outputted the shadow below the text.if(selComponent == 0) {
printTextScreen(11, 10, filler, shadowColorH);
printTextScreen(10, 10, filler, highlightColor);
} else {
printTextScreen(11, 10, filler, shadowColorD);
printTextScreen(10, 10, filler, dimmedColor);
}
We now need to do the same thing for the other two colors.
sprintf(filler, "GREEN: %i", bgG);
if(selComponent == 1) {
printTextScreen(11, 20, filler, shadowColorH);
printTextScreen(10, 20, filler, highlightColor);
} else {
printTextScreen(11, 20, filler, shadowColorD);
printTextScreen(10, 20, filler, dimmedColor);
}
sprintf(filler, " BLUE: %i", bgB);
if(selComponent == 2) {
printTextScreen(11, 30, filler, shadowColorH);
printTextScreen(10, 30, filler, highlightColor);
} else {
printTextScreen(11, 30, filler, shadowColorD);
printTextScreen(10, 30, filler, dimmedColor);
}
We're nearly done, I promise! In part five we'll put the finishing touches on our program and
create our Makefile.
if(selComponent == 1) {
printTextScreen(11, 20, filler, shadowColorH);
printTextScreen(10, 20, filler, highlightColor);
} else {
printTextScreen(11, 20, filler, shadowColorD);
printTextScreen(10, 20, filler, dimmedColor);
}
sprintf(filler, " BLUE: %i", bgB);
if(selComponent == 2) {
printTextScreen(11, 30, filler, shadowColorH);
printTextScreen(10, 30, filler, highlightColor);
} else {
printTextScreen(11, 30, filler, shadowColorD);
printTextScreen(10, 30, filler, dimmedColor);
}
