Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- Textbox routine with unsigned int wrap for KickC by Scan/Desire
- Use KickC 0.8 or newer to compile
- */
- #include "c64.h"
- const char* screen = $0400;
- const char text[] = "this is a small test with word wrap, if a word is too long it moves it to the next line. isn't that supercalifragilisticexpialidocious? i think it's cool!@";
- const char text2[] = "textbox by scan of desire@";
- void main() {
- for (char x = 0; x < 15; x += 1) {
- textbox(x,x,x+x+1,x+10,text2);
- for (unsigned int wait = 0; wait < 15000; wait++) {}
- }
- textbox(30,8,39,24,text);
- textbox(1,3,38,9,text);
- textbox(0,12,20,24,text);
- do {} while (true);
- }
- void textbox(char x1, char y1, char x2, char y2, char* text) {
- draw_window(x1, y1, x2, y2);
- char y = y1+1;
- char x = x1+1;
- unsigned int z = y * 40;
- unsigned int i = 0;
- if (x == x2 || y == y2) {
- // no room to draw text, simply return
- return;
- }
- do {
- char character = text[i];
- screen[z+x] = character;
- if (character == $20) {
- // scan ahead to determine next unsigned int length
- char c = 0;
- unsigned int ls = i+1;
- while (text[ls] != $20 && text[ls] != $00) {
- ls++;
- c++;
- }
- // if it's too big to fit but not bigger than the whole box width, move to next line
- if (c+x >= x2 && c < x2-x1) {
- x = x1;
- y++;
- if (y == y2) {
- // text too long for textbox
- return;
- }
- z = y * 40;
- }
- }
- i++;
- // only move x if the the character was not a space and not at the beginning of a box
- if (character == $20 && x == x1+1) {} else {
- x++;
- }
- // this is in case the unsigned int is too long for one line and needs to be cut
- if (x == x2) {
- x = x1+1;
- y++;
- if (y == y2) {
- // text too long for textbox
- return;
- }
- z = y * 40;
- }
- } while (text[i] != 0);
- }
- void draw_window(char x1, char y1, char x2, char y2) {
- unsigned int z = y1 * 40;
- unsigned int q = y2 * 40;
- // draw horizontal lines
- for (char x = x1+1; x < x2; x++) {
- screen[z+x] = 64;
- screen[q+x] = 64;
- }
- // draw upper corners
- screen[z+x1] = 112;
- screen[z+x2] = 110;
- // draw vertical lines
- for (char y = y1+1; y < y2; y++) {
- z = y * 40;
- screen[z+x1] = 93;
- screen[z+x2] = 93;
- }
- // draw lower corners
- screen[q+x1] = 109;
- screen[q+x2] = 125;
- // window big enough to have an inside?
- if (x2-x1 > 1 && y2-y1 > 1) {
- // blank inside
- for(char y = y1+1; y < y2; y++) {
- z = y * 40;
- for(char x = x1+1; x < x2; x++) {
- screen[z+x] = $20;
- }
- }
- }
- }
Add Comment
Please, Sign In to add comment