CrunchBang Linux Pastebin - collaborative debugging

pastebin is a collaborative debugging tool allowing you to share and modify code snippets while chatting on IRC, IM or a message board.

This site is developed to XHTML and CSS2 W3C standards. If you see this paragraph, your browser does not support those standards and you need to upgrade. Visit WaSP for a variety of options.

CrunchBang Linux Pastebin

Posted by johnraff on Fri 22nd Apr 19:01 (modification of post by view diff)
download | new post

  1. # This is a modified version of the example plymouth plugin script
  2.  
  3. screen_width = Window.GetWidth();
  4. screen_height = Window.GetHeight();
  5.  
  6. Window.SetBackgroundTopColor(0, 0, 0);
  7. Window.SetBackgroundBottomColor(0, 0, 0);
  8.  
  9. # screen width that logo image was made to look best on
  10. logo_image_original_screen_width = 1024; # just a guess
  11. logo_scale_factor = screen_width / logo_image_original_screen_width;
  12.  
  13. #logo.image = Image("special://logo");
  14. logo.original_image = Image ("crunchbang-logo.png");
  15. logo_width = logo.original_image.GetWidth() * logo_scale_factor;
  16. logo_height = logo.original_image.GetHeight() * logo_scale_factor;
  17. logo.image = logo.original_image.Scale(logo_width, logo_height);
  18. logo.sprite = Sprite(logo.image);
  19. logo.opacity_angle = 0;
  20.  
  21.  
  22. fun refresh_callback ()
  23.   {
  24.     if (status == "normal")
  25.       {
  26.         logo.opacity_angle += ((2 * 3.14) / 50) * 0.5# 0.5 HZ
  27.         min_opacity = 0.3;
  28.         opacity = (Math.Cos(logo.opacity_angle) + 1) / 2;
  29.         opacity *= 1 - min_opacity;
  30.         opacity += min_opacity;
  31.         logo.sprite.SetX (Window.GetX() + screen_width  / 2 - logo_width  / 2);
  32.         logo.sprite.SetY (Window.GetY() + screen_height / 2 - logo_height / 2);
  33.         logo.sprite.SetOpacity (opacity);
  34.       }
  35.     else
  36.       {
  37.         logo.sprite.SetX (0);
  38.         logo.sprite.SetY (0);
  39.         logo.sprite.SetOpacity (1);
  40.       }
  41.   }
  42.  
  43. Plymouth.SetRefreshFunction (refresh_callback);
  44.  
  45. status = "normal";
  46.  
  47. #----------------------------------------- Progress Bar --------------------------------
  48. progress_box_height = (logo_height * 0.1);
  49. progress_box_width = (screen_width * 0.4);
  50.  
  51. progress_box.original_image = Image("progress_box.png");
  52. progress_box.image = progress_box.original_image.Scale(progress_box_width, progress_box_height);
  53. progress_box.sprite = Sprite(progress_box.image);
  54.  
  55. progress_box.x = Window.GetX() + screen_width / 2 - progress_box_width / 2;
  56. progress_box.y = Window.GetY() + screen_height / 2 + logo_height / 2 + progress_box_height * 5;
  57. progress_box.sprite.SetPosition(progress_box.x, progress_box.y, 0);
  58.  
  59. progress_bar.original_image = Image("progress_bar.png");
  60. progress_bar.image = progress_bar.original_image.Scale(0, progress_box_height);
  61. progress_bar.sprite = Sprite();
  62.  
  63. progress_bar.x = progress_box.x;
  64. progress_bar.y = progress_box.y;
  65. progress_bar.sprite.SetPosition(progress_bar.x, progress_bar.y, 1);
  66.  
  67. # "progress * 2" for bar width is a hack which should be unnecessary
  68. fun progress_callback (duration, progress)
  69.   {
  70. # I don't understand the purpose of this line, but changed it anyway
  71. #    if (progress_bar.image.GetWidth () != Math.Int (progress_bar.original_image.GetWidth () * progress))
  72.     if (progress_bar.image.GetWidth () != Math.Int (progress_box_width * progress))
  73.       {
  74.         progress_bar.image = progress_bar.original_image.Scale(progress_box_width * progress * 2, progress_box_height);
  75.         progress_bar.sprite.SetImage (progress_bar.image);
  76.       }
  77.   }
  78.  
  79. Plymouth.SetBootProgressFunction(progress_callback);
  80.  
  81. #----------------------------------------- Display Messages --------------------------------
  82.  
  83. NUM_SCROLL_LINES = 5;
  84. LINE_WIDTH = 55;
  85. # width of one character
  86. CHAR_WIDTH = 7; # are we using a fixed-width font?
  87. # height of one character
  88. CHAR_HEIGHT = 10;
  89.  
  90. msg_color = [0.5,0.5,0.5]; # msg_color is array
  91.  
  92. fun update_status_callback(sta) {
  93.   if (sta == "failed") msg_color = [1,0,0];
  94.   if (sta == "warning") msg_color = [0.8,0.8,0];
  95.   if (sta == "normal") msg_color = [0.5,0.5,0.5];
  96. }
  97.  
  98. fun StringLength(string) {
  99.   index = 0;
  100.   str = String(string);
  101.   while(str.CharAt(index)) index++;
  102.   return index;
  103. }
  104.  
  105. // Initialising text images and their positions
  106. #  CHAR_HEIGHT * 2 is the height (including line spacing) of each line
  107. for (i=0; i < NUM_SCROLL_LINES; i++) {
  108.   lines[i]= Image.Text("");
  109.   message_sprite[i] = Sprite();
  110.   message_sprite[i].SetX (Window.GetX() + (screen_width / 2 ) - (LINE_WIDTH * CHAR_WIDTH / 2));
  111.   message_sprite[i].SetY (Window.GetY() + (screen_height / 2) + (logo_height /2) +(logo_height * 1.2)+ (i * CHAR_HEIGHT * 2) );
  112.   message_sprite[i].SetZ (10000);
  113. }
  114.  
  115.  
  116. pretext = String("");
  117.  
  118. fun scroll_message_callback(text) {
  119.  
  120.    nobreak = 0;
  121.    if (text.CharAt(0) == ">") {    # "no linebreak" flag, like "-n"
  122.        text = text.SubString(1, StringLength(text)); # remove ">" at front
  123.        nobreak = 1;
  124.    }
  125.  
  126.    if (pretext == "") {
  127.    
  128.        if (nobreak == 1) pretext = text;
  129.  
  130.           // Truncate the message if too long
  131.        if (StringLength(text) > LINE_WIDTH) {
  132.          text = text.SubString(0, LINE_WIDTH - 3);
  133.          text += "...";
  134.        }
  135.  
  136.        // Shift messages one up
  137.        for (i = 0; i < NUM_SCROLL_LINES - 1; i++) {
  138.          lines[i] = lines[i+1];
  139.        }
  140.    }
  141.    else {    # the previous message was flagged to have no linebreak
  142.  
  143.           // Truncate the message if too long
  144.        if (StringLength(text) > LINE_WIDTH - 5) { # leave min. 5 for pretext
  145.          text = text.SubString(0, LINE_WIDTH - 8);
  146.          text += "...";
  147.        }
  148.  
  149.           # Truncate the previous message if too long
  150.        if (StringLength(pretext) > (LINE_WIDTH - StringLength(text))) {
  151.          pretext = pretext.SubString(0, LINE_WIDTH - StringLength(text) - 3);
  152.          pretext += "...";
  153.        }
  154.  
  155.        text = pretext + text;
  156.  
  157.        if (nobreak == 1) pretext = text;
  158.        else pretext = "";
  159.        
  160.    }
  161.  
  162.    // Create the image for the latest message
  163.    lines[NUM_SCROLL_LINES - 1] = Image.Text( text, msg_color[0], msg_color[1], msg_color[2]);   
  164.  
  165.    // Re-allocate the text images to sprites
  166.    for (i = 0; i < NUM_SCROLL_LINES; i++) {
  167.      message_sprite[i].SetImage(lines[i]);
  168.    }
  169. }
  170.  
  171. Plymouth.SetUpdateStatusFunction(update_status_callback);
  172.  
  173. Plymouth.SetMessageFunction(scroll_message_callback);
  174.  
  175. #----------------------------------------- Quit --------------------------------
  176.  
  177. fun quit_callback ()
  178. {
  179.   logo.sprite.SetOpacity (1);
  180.   progress_bar.image = progress_bar.original_image.Scale(progress_box_width, progress_box_height);
  181.   progress_bar.sprite.SetImage(progress_bar.image);
  182. }
  183.  
  184. Plymouth.SetQuitFunction(quit_callback);

Submit a correction or amendment below (click here to make a fresh posting)
After submitting an amendment, you'll be able to view the differences between the old and new posts easily.

Syntax highlighting:

To highlight particular lines, prefix each line with @@


Remember me