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 Wed 9th Mar 16:55 (modification of post by view diff)
View followups from johnraff | 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 logo image was made to look best on
  10. logo_image_original_screen_width = 1024;
  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 * 3" 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 * 3, progress_box_height);
  75.         progress_bar.sprite.SetImage (progress_bar.image);
  76.       }
  77.   }
  78.  
  79. Plymouth.SetBootProgressFunction(progress_callback);
  80.  
  81. #----------------------------------------- Status Update --------------------------------
  82.  
  83. NUM_SCROLL_LINES = 5;
  84. LINE_WIDTH = 55;
  85. # width of one character
  86. CHAR_WIDTH = 7;
  87. # height of one character
  88. CHAR_HEIGHT = 10;
  89.  
  90. fun StringLength(string) {
  91.   index = 0;
  92.   str = String(string);
  93.   while(str.CharAt(index)) index++;
  94.   return index;
  95. }
  96.  
  97. // Initialising text images and their positions
  98. // 20 is the height (including line spacing) of each line
  99. for (i=0; i < NUM_SCROLL_LINES; i++) {
  100.   lines[i]= Image.Text("");
  101.   message_sprite[i] = Sprite();
  102.   message_sprite[i].SetX (Window.GetX() + (screen_width / 2 ) - (LINE_WIDTH * CHAR_WIDTH / 2));
  103.   message_sprite[i].SetY (Window.GetY() + (screen_height / 2) + (logo_height /2) +(logo_height * 1.2)+ (i * CHAR_HEIGHT * 2) );
  104.   message_sprite[i].SetZ (10000);
  105. }
  106.  
  107.  
  108. fun scroll_message_callback(text) {
  109.  
  110.    // Truncate the message if too long
  111.    if (StringLength(text) > LINE_WIDTH) {
  112.      text = text.SubString(0, LINE_WIDTH - 3);
  113.      text += "...";
  114.    }
  115.  
  116.    // Shift messages one up
  117.    for (i = 0; i < NUM_SCROLL_LINES - 1; i++) {
  118.      lines[i] = lines[i+1];
  119.    }
  120.  
  121.    // Create the image for the latest message
  122. #  original script had "lines[i]"   
  123.    lines[4] = Image.Text( text, 0.5, 0.5, 0.5);
  124.  
  125.    // Re-allocate the text images to sprites
  126.    for (i = 0; i < NUM_SCROLL_LINES; i++) {
  127.      message_sprite[i].SetImage(lines[i]);
  128.    }
  129. }
  130.  
  131. Plymouth.SetUpdateStatusFunction(scroll_message_callback);
  132.  
  133. # messages get added to updates
  134. Plymouth.SetMessageFunction(scroll_message_callback);
  135.  
  136. #----------------------------------------- Quit --------------------------------
  137.  
  138. fun quit_callback ()
  139. {
  140.   logo.sprite.SetOpacity (1);
  141.   progress_bar.image = progress_bar.original_image.Scale(progress_box_width, progress_box_height);
  142.   progress_bar.sprite.SetImage(progress_bar.image);
  143. }
  144.  
  145. 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