///scr_Book_DrawEvent
//Place this script within the obj_Book's (or equivalent) Draw Event.
//This script takes no arguments.

draw_background_stretched(Background,0,0,room_width,room_height,c_white,1);
draw_set_font(Font);

var hh = 0;
var hhh = 0;

if (p = -1){
    draw_background_stretched(TitleSketch,0,0,room_width,room_height,c_white,1);
    draw_set_halign(fa_center); //Places origin of the text at the center of the string
    draw_text_ext_color(x+(room_width*0.75),y+TopMargin+(ParagraphSpacing*1),Title,-1,WordWrapWidth,TextColor,TextColor,TextColor,TextColor,1);
    //If Book INI file exists...
    if ( file_exists(Book) ){
        draw_text_ext_color(x+(room_width*0.75),y+TopMargin+(ParagraphSpacing*2),Author,-1,WordWrapWidth,TextColor,TextColor,TextColor,TextColor,1);
        draw_text_ext_color(x+(room_width*0.75),y+TopMargin+(ParagraphSpacing*3),Date,-1,WordWrapWidth,TextColor,TextColor,TextColor,TextColor,1);
    }
    //If Book INI does not exist, add extra ParagraphSpacing due to multi-line title
    else{
        draw_text_ext_color(x+(room_width*0.75),y+TopMargin+(ParagraphSpacing*3),Author,-1,WordWrapWidth,TextColor,TextColor,TextColor,TextColor,1);
        draw_text_ext_color(x+(room_width*0.75),y+TopMargin+(ParagraphSpacing*4),Date,-1,WordWrapWidth,TextColor,TextColor,TextColor,TextColor,1);
    }
    
    //Draw the close book button on title page...
    if (mouse_x >= CloseBook_X) and (mouse_y >= CloseBook_Y) and (mouse_x <= CloseBook_XX) and (mouse_y <= CloseBook_YY){
    draw_sprite(CloseBookSprite_Highlighted,1,10,10,c_white,1);
    }
    else{ draw_sprite(CloseBookSprite,1,CloseBook_X,CloseBook_Y,c_white,1); }
    
    //Draw the page forward button on title page...
    if (mouse_x >= PageForward_X) and (mouse_y >= PageForward_Y) and (mouse_x <= PageForward_XX) and (mouse_y <= PageForward_YY){
        draw_sprite(PageForwardSprite_Highlighted,1,PageForward_X,PageForward_Y,c_white,1);
    }
    else{ draw_sprite(PageForwardSprite,1,PageForward_X,PageForward_Y,c_white,1); }
}
else{
    draw_background_stretched(Sketch[p],0,0,room_width,room_height,c_white,1);
    draw_set_halign(fa_left); //Places origin of the text at the left of the string.
    //FOR-LOOP goes through up-to 30 Paragraph#'s on the current left and right pages
    //and draws the text with word-wrap and hh (left-side) or hhh (right-side) spacing
    //plus the ParagraphSpacing. You need to know the height of the paragraphs so that
    //the next drawn paragraph text does not over-lap the previous, hince hh and hhh.
    // Page[p,t] is a 2D array in which = Page[page number,paragraph number]
    for (t=1; t < 30; t+=1){
        draw_text_ext_color(x+LeftOuterMargins,y+TopMargin+hh,Page[p,t],-1,WordWrapWidth,TextColor,TextColor,TextColor,TextColor,1); 
        draw_text_ext_color(x+(room_width/2)+RightInnerMargins,y+TopMargin+hhh,Page[p+1,t],-1,WordWrapWidth,TextColor,TextColor,TextColor,TextColor,1);
        hh += string_height_ext(Page[p,t],-1,WordWrapWidth)+ParagraphSpacing;
        hhh += string_height_ext(Page[p+1,t],-1,WordWrapWidth)+ParagraphSpacing;
    }
    
    //Draw page backward button...
    if (mouse_x >= PageBackward_X) and (mouse_y >= PageBackward_Y) and (mouse_x <= PageBackward_XX) and (mouse_y <= PageBackward_YY){
        draw_sprite(PageBackwardSprite_Highlighted,1,PageBackward_X,PageBackward_Y,c_white,1);
    }
    else{ draw_sprite(PageBackwardSprite,1,PageBackward_X,PageBackward_Y,c_white,1); }
    
    //Draw the page forward button if applicable...
    if (p <= (TotalPages-2)){
        
        if (mouse_x >= CloseBook_X) and (mouse_y >= CloseBook_Y) and (mouse_x <= CloseBook_XX) and (mouse_y <= CloseBook_YY){
            draw_sprite(CloseBookSprite_Highlighted,1,10,10,c_white,1);
        }
        else{ draw_sprite(CloseBookSprite,1,10,10,c_white,1); }
        
        if (mouse_x >= PageForward_X) and (mouse_y >= PageForward_Y) and (mouse_x <= PageForward_XX) and (mouse_y <= PageForward_YY){
            draw_sprite(PageForwardSprite_Highlighted,1,PageForward_X,PageForward_Y,c_white,1);
        }
        else{ draw_sprite(PageForwardSprite,1,PageForward_X,PageForward_Y,c_white,1); }
    }
    //Replace the page forward button with the close book button if on last page...
    else{
        if (mouse_x >= CloseBook_LastPageX) and (mouse_y >= CloseBook_LastPageY) and (mouse_x <= CloseBook_LastPageXX) and (mouse_y <= CloseBook_LastPageYY){
            draw_sprite(CloseBookSprite_Highlighted,1,CloseBook_LastPageX,CloseBook_LastPageY,c_white,1);
        }
        else{ draw_sprite(CloseBookSprite,1,CloseBook_LastPageX,CloseBook_LastPageY,c_white,1)}
    }
}

//Always draw the bookmark image...
if (Bookmark == p) or (mouse_x >= Bookmark_X) and (mouse_y >= Bookmark_Y) and (mouse_x <= Bookmark_XX) and (mouse_y <= Bookmark_YY){
    draw_sprite(BookmarkSprite_Highlighted,1,Bookmark_X,Bookmark_Y,c_white,1);
}
else{ draw_sprite(BookmarkSprite,1,Bookmark_X,Bookmark_Y,c_white,1); }

//Always draw the background audio on/off image...
if (BackgroundAudioOn = "false"){
    draw_sprite(BgAudioOffSprite,1,BgAudioOff_X,BgAudioOff_Y,c_white,1);
}
else{ draw_sprite(BgAudioOnSprite,1,BgAudioOn_X,BgAudioOn_Y,c_white,1); }

//Always draw the narration audio on/off image...
if (NarrationOn = "false"){
    draw_sprite(NarrationOffSprite,1,NarrationOff_X,NarrationOff_Y,c_white,1);
}
else{ draw_sprite(NarrationOnSprite,1,NarrationOn_X,NarrationOn_Y,c_white,1); }

//Draws the custom mouse cursor; draw this last so it stays on top of everything
//Make sure to turn display mouse off in the settings; there is a "cursor_sprite"
//function, but I am not sure if it works in LateralGM+ENIGMA.
if mouse_check_button_pressed(mb_left){
    draw_sprite(CursorSprite_Clicked,1,mouse_x,mouse_y);
}
else{
    draw_sprite(CursorSprite,1,mouse_x,mouse_y);
}
