Chaos Project

RPG Maker => RPG Maker Scripts => RMXP Script Database => Topic started by: newold on April 26, 2011, 04:23:33 pm

Title: [XP][VX] Displacement Bar in Windows
Post by: newold on April 26, 2011, 04:23:33 pm
Displacement Bar in Windows
Authors: Newold
Version: 1.2
Type: Windows decoration
Key Term: Misc System



Introduction

This script is useful for adding a vertical scroll bar on the windows, as the windows in Windows SO


Features




Screenshots

(http://img854.imageshack.us/img854/8214/45303301.th.jpg) (http://img854.imageshack.us/i/45303301.jpg/)  (http://img822.imageshack.us/img822/7418/75361681.th.jpg) (http://img822.imageshack.us/i/75361681.jpg/)


Demo

none.


Script

Spoiler: ShowHide

=begin

 *****************************************************************************
 ESTE SCRIPT AÑADE UNA BARRA DE SCROLL VERTICAL A LAS VENTANAS EN CASO DE QUE
 SU CONTENDIO SEA MAYOR QUE LA VENTANA (COMO LAS VENTANAS DEL WINDOWS)
 
 CREADOR: NEWOLD
 FECHA: 15-04-2011
 VERSIÓN: 1.2, Compatible Con PRG Maker XP y VX
 
 Cambios versión 1.1: Ahora también pueden usar imágenes custom :D
 Cambios en la versión 1.2: Añadido unas cuantas sombras más y la  posibilidad
                            de ocultar el adorno de las barras
 
 *****************************************************************************
 
 *****************************************************************************
 INSTRUCCIONES
 *****************************************************************************
 
 - Las ventanas creadas tendrán por defecto la barra de scroll habilitada.
   Para cambiar esto, usar este comando:
       
       tuVentana.scroll_bar_visible = *valor*
     
     # *valor* = false  /  true  => DESACTIVAR /  ACTIVAR
 
 - La barra sale por defecto situada a la izquierda de la ventana.
   Para cambiar esto, usar este comando:
   
       tuVentana.scroll_bar_position = *valor*
     
     # *valor* = 0  /  1  => IZQUIERDA /  DERECHA
     
 - Las barras son creadas con unos colores por defecto.
   Para cambiar esto, usar estos comandos:
   
     # Cambiar el color del fondo de la barra
     
       tuVentana.scroll_bar_background_color = *color*
       
     # Cambiar el color del borde del fondo de la barra
     
       tuVentana.scroll_bar_background_borde_color = *color*
       
     # Cambiar el color de la barra de desplazamiento
     
       tuVentana.scroll_bar_top_color = *color*
       
     # Cambiar el color del borde de la barra de desplazamiento
     
       tuVentana.scroll_bar_top_borde_color = *color*
       
     # Cambiar el color del adorno encima de la barra de desplazamiento
     
       tuVentana.scroll_bar_decoration_color = *color*
       
     # Cambiar el color del sombreado de la barra de desplazamiento y adorno

       tuVentana.shadow_color = *color* # Sombreado 1
       
       tuVentana.shadow_color2 = *color* # Sombreado 2
       
       tuVentana.shadow_color3 = *color* # Sombreado 3
       
   # *color* = Color.new(*red*,*green*,*blue*,*alpha*)
   
       # *red*,*green*,*blue*,*alpha* = un valor entre 0 y 255
       
 - Si usas cualquier comando anterior usa también este comando para que
   se actualizen los cambios
   
      tuVentana.refresh_bars
     
 - Alternativamente, puedes usar una imagen para generar las barras.
   Para ello, usa este comando:
   
      tuVentana.use_custom_images = *image*
     
   *image* = El nombre de la imagen de la barra de desplazamiento.
             Esta imagen debe estar en la carpeta picture de tu juego.
             no te olvides de usar el comando
             
                 tuVentana.refresh_bars
                 
             para aplicar los cambios a tu ventana
             
 (Usa la imagen que acompaña al script para guiarte a la hora de crear
  tus propias barras :D.)
 
 - Por último, puedes usar este comando para que se dibuje o no el adorno
   en la barra de scroll (por defecto está activado que se vea)
   
       tuVentana.hide_decoration = *valor*
       
     # *valor* = false  /  true  => DESACTIVAR /  ACTIVAR
 
 *****************************************************************************
 
=end

#==============================================================================
class Window
 #--------------------------------------------------------------------------
 attr_accessor :scroll_bar_visible, :scroll_bar_background_color,
               :scroll_bar_background_borde_color,
               :scroll_bar_top_color, :scroll_bar_top_borde_color,
               :scroll_bar_decoration_color, :scroll_bar_position,
               :shadow_color,  :shadow_color2, :shadow_color3,
               :use_custom_images, :hide_decoration
 #--------------------------------------------------------------------------
 alias initialize_bynewold initialize
 def initialize
   initialize_bynewold
   @scroll_bar_visible = true
   @scroll_bar_background_color = Color.new(240,240,240,255)
   @scroll_bar_background_borde_color = Color.new(255,255,255,255)
   @scroll_bar_top_color = Color.new(205,205,209,255)
   @scroll_bar_top_borde_color = Color.new(0,0,0,255)
   @scroll_bar_decoration_color = Color.new(130,130,130,255)
   @shadow_color = Color.new(255,255,255,255)
   @shadow2_color = Color.new(255,255,255,255)
   @shadow3_color = Color.new(110,103,94,255)
   @scroll_bar_position = 0 # 0 = Izquierda  ||  1 = Derecha
   @use_custom_images = ''
   @hide_decoration = true
 end
 #--------------------------------------------------------------------------
 alias update_bynewold update
 def update
   update_bynewold
   if @background_bar != nil
     # Ocultar o mostrar la barra según sea pertinente
     if !self.visible
       @background_bar.visible = false
       @top_bar.visible = false
     else
       if @scroll_bar_visible
         @background_bar.visible = true
         @top_bar.visible = true
       else
         @background_bar.visible = false
         @top_bar.visible = false
       end
     end
     # Mover la barra de scroll a su lugar correspondiente
     # Comprobar si el maker es el xp o el vx y establecer unos valores
     if defined?(Cache)
       mod_height = 24
       mod_y = 10
       mody2 = 4
     else
       mod_height = 32
       mod_y = 8
       mody2 = 0
     end
     # Cálculos para saber donde debe estar la barra de escroll
     des_real_barra = @background_bar.bitmap.height -
       @top_bar.bitmap.height - mod_y
     des_real_barra = mod_height if des_real_barra < mod_height
     des_real_content = self.contents.height - self.height
     des_real_content = 1 if des_real_content < 1
     y_desplazamiento = (self.oy * des_real_barra / des_real_content)
     @top_bar.y = self.y + 5 + y_desplazamiento - ((mod_y-2)-6) + mody2
     if @top_bar.y + @top_bar.bitmap.height >
        @background_bar.y + @background_bar.bitmap.height - 2
       @top_bar.y = @background_bar.y + @background_bar.bitmap.height -
         2 - @top_bar.bitmap.height
     end
     # Otros datos a actualizar
     @background_bar.z = self.z + 1
     @top_bar.z = self.z + 2
   elsif self.visible and self.contents != nil and @background_bar == nil and
     @scroll_bar_visible == true
     create_vertical_bar
   end
 end
 #--------------------------------------------------------------------------
 def create_vertical_bar
   # ----------------------------------------------------------
   return if self.contents == nil or
     self.contents.height <= self.height - 32 or
     self.visible == false or
     @scroll_bar_visible == false
   # ----------------------------------------------------------
   
   # ----------------------------------------------------------
   # Comprobar si el maker es el xp o el vx y establecer unos valores
   if defined?(Cache)
     mod_height = 24
     mod_height2 = 2
     mod_y = 10
     mody2 = 4
     mod_x = 2
     mod_height_scroll_bar = 10
   else
     mod_height = 32
     mod_height2 = 0
     mod_y = 8
     mody2 = 0
     mod_x = 0
     mod_height_scroll_bar = 5
   end
   # ----------------------------------------------------------
   
   # ----------------------------------------------------------
   # Calcular el tamaño vertical que debería tener la barra de scroll
   vertical_size = self.height - mod_y - 2 # Tamaño completo
   # Ajustar el tamaño con respecto a la cantidad de datos disponibles
   data_size = (self.contents.height / mod_height) * 4
   vertical_size -= data_size - mod_height_scroll_bar
   # Comprobar si el tamaño de la barra es inferior a 8 y ajustarlo a 8
   vertical_size = 8 if vertical_size < 8
   # ----------------------------------------------------------
   
   # ----------------------------------------------------------
   if @background_bar == nil
     # background...........................................
     @background_bar = Sprite.new
     @background_bar.bitmap = Bitmap.new(11,self.height-mod_y-mod_height2)
     @background_bar.y = self.y + 4 + (mod_y-8)
     # .....................................................
     # top..................................................
     @top_bar = Sprite.new
     @top_bar.bitmap = Bitmap.new(9,vertical_size)
     @top_bar.y = self.y + 5 + (8-mod_y) + mody2
     # .....................................................
   else
     @background_bar.bitmap.clear
     @top_bar.bitmap.clear
   end
   # ----------------------------------------------------------
   
   # ----------------------------------------------------------
   # Posicionar las barras en el eje X
   if @scroll_bar_position == 0
     @background_bar.x = self.x + 4 + mod_x
     @top_bar.x = self.x + 5 + mod_x
   else
     @background_bar.x = self.x + self.width - 15 - mod_x
     @top_bar.x = self.x + self.width - 14 - mod_x
   end
   # ----------------------------------------------------------
   if @use_custom_images != ''
     rects = [
     # background
     Rect.new(1,1,11,4), # top
     Rect.new(1,17,11,4), # bottom
     Rect.new(1,4,11,12), # middle
     # top
     Rect.new(15,1,10,4), # top
     Rect.new(15,17,10,4), # bottom
     Rect.new(15,4,10,12), # middle
     # decoration
     Rect.new(27,7,5,8)
     ]
     # Aplicar la imagen a las barras
     if defined?(Cache)
       b = Cache.picture(@use_custom_images) # Para VX
     else
       b = RPG::Cache.picture(@use_custom_images) # Para XP
     end
     # Dibujar el background....
     h = @background_bar.bitmap.height
     w = @background_bar.bitmap.width
     @background_bar.bitmap.blt(0,0,b,rects[0]) # top
     @background_bar.bitmap.blt(0,h-rects[1].height,b,rects[1]) # bottom
     dest_rect = Rect.new(0,rects[0].height,w,h-rects[0].height-rects[1].height)
     @background_bar.bitmap.stretch_blt(dest_rect,b,rects[2]) # middle
     # Dibujar la barra de scroll...
     h = @top_bar.bitmap.height
     w = @top_bar.bitmap.width
     @top_bar.bitmap.blt(0,0,b,rects[3]) #top
     @top_bar.bitmap.blt(0,h-rects[4].height,b,rects[4]) # bottom
     dest_rect = Rect.new(0,rects[3].height,w,h-rects[3].height-rects[4].height)
     @top_bar.bitmap.stretch_blt(dest_rect,b,rects[5]) # middle
     # Dibujar el adorno en la barra de scroll centrado...
     if @hide_decoration == false
       x = (w / 2) - (rects[6].width / 2)
       y = (h / 2) - (rects[6].height / 2)
       @top_bar.bitmap.blt(x,y,b,rects[6]) # Adorno
     end
     return
   end
     

   # ----------------------------------------------------------
   # Creación del fondo de la barra
   @background_bar.bitmap.fill_rect(0,0,11,self.height-mod_y-mod_height2,
                                    @scroll_bar_background_borde_color)
   @background_bar.bitmap.fill_rect(1,1,9,self.height-mod_y-2-mod_height2,
                                    @scroll_bar_background_color)

   # Redondear la imagen:
   color = Color.new(0,0,0,0) # Color transparente
   # Borde Superior
   @background_bar.bitmap.fill_rect(0,0,2,1,color)
   @background_bar.bitmap.fill_rect(9,0,2,1,color)
   @background_bar.bitmap.fill_rect(0,1,1,1,color)
   @background_bar.bitmap.fill_rect(10,1,1,1,color)
   # añadir el borde faltante...
   @background_bar.bitmap.fill_rect(1,1,1,1,@scroll_bar_background_borde_color)
   @background_bar.bitmap.fill_rect(9,1,1,1,@scroll_bar_background_borde_color)
   # Borde Inferior
   h = @background_bar.bitmap.height
   @background_bar.bitmap.fill_rect(0,h-1,2,1,color)
   @background_bar.bitmap.fill_rect(9,h-1,2,1,color)
   @background_bar.bitmap.fill_rect(0,h-2,1,1,color)
   @background_bar.bitmap.fill_rect(10,h-2,1,1,color)
   # añadir el borde faltante...
   @background_bar.bitmap.fill_rect(1,h-2,1,1,@scroll_bar_background_borde_color)
   @background_bar.bitmap.fill_rect(9,h-2,1,1,@scroll_bar_background_borde_color)
   # ----------------------------------------------------------
   
   # ----------------------------------------------------------
   # Crear la barra de desplazamiento
   @top_bar.bitmap.fill_rect(0,0,9,vertical_size,
                                    @scroll_bar_top_borde_color)
   @top_bar.bitmap.fill_rect(1,1,7,vertical_size-2,
                                    @scroll_bar_top_color)
   # Redondear la imagen:
   color = Color.new(0,0,0,0) # Color transparente
   # Borde Superior
   @top_bar.bitmap.fill_rect(0,0,2,1,color)
   @top_bar.bitmap.fill_rect(7,0,2,1,color)
   @top_bar.bitmap.fill_rect(0,1,1,1,color)
   @top_bar.bitmap.fill_rect(8,1,1,1,color)
   # añadir el borde faltante...
   @top_bar.bitmap.fill_rect(1,1,1,1,@scroll_bar_top_borde_color)
   @top_bar.bitmap.fill_rect(7,1,1,1,@scroll_bar_top_borde_color)
   # Borde Inferior
   h = @top_bar.bitmap.height
   @top_bar.bitmap.fill_rect(0,h-1,2,1,color)
   @top_bar.bitmap.fill_rect(7,h-1,2,1,color)
   @top_bar.bitmap.fill_rect(0,h-2,1,1,color)
   @top_bar.bitmap.fill_rect(8,h-2,1,1,color)
   # añadir el borde faltante...
   @top_bar.bitmap.fill_rect(1,h-2,1,1,@scroll_bar_top_borde_color)
   @top_bar.bitmap.fill_rect(7,h-2,1,1,@scroll_bar_top_borde_color)
   # ----------------------------------------------------------
   
   # ----------------------------------------------------------
   # Crear el sombreado para la barra de scroll
   @top_bar.bitmap.fill_rect(1,2,2,h-4,@shadow_color)
   color = @shadow_color.dup
   
   color.alpha = @shadow_color.alpha / 2
   bitmap = Bitmap.new(1,h-4)
   bitmap.fill_rect(bitmap.rect,color)
   @top_bar.bitmap.blt(1,1,bitmap,bitmap.rect)
 
   color.alpha = @shadow_color.alpha / 2
   bitmap = Bitmap.new(1,h-4)
   bitmap.fill_rect(bitmap.rect,color)
   @top_bar.bitmap.blt(3,2,bitmap,bitmap.rect)
   
   color = @shadow2_color.dup
   
   color.alpha = @shadow2_color.alpha / 2
   bitmap = Bitmap.new(1,h-4)
   bitmap.fill_rect(bitmap.rect,color)
   @top_bar.bitmap.blt(2,2,bitmap,bitmap.rect)
   
   color = @shadow3_color.dup
   
   color.alpha = @shadow3_color.alpha / 2
   bitmap = Bitmap.new(1,h-4)
   bitmap.fill_rect(bitmap.rect,color)
   @top_bar.bitmap.blt(5,2,bitmap,bitmap.rect)
   
   color.alpha = @shadow3_color.alpha / 2
   bitmap = Bitmap.new(1,h-4)
   bitmap.fill_rect(bitmap.rect,color)
   @top_bar.bitmap.blt(7,2,bitmap,bitmap.rect)
   # ----------------------------------------------------------
   
   # ----------------------------------------------------------
   # Crear el adorno de la barra de scroll
   if vertical_size > 8 and @hide_decoration == false
     bitmap = Bitmap.new(5,8)
     bitmap.fill_rect(0,0,5,1,@scroll_bar_decoration_color)
     bitmap.fill_rect(0,1,5,1,@shadow_color)
     bitmap.fill_rect(0,2,5,1,@scroll_bar_decoration_color)
     bitmap.fill_rect(0,3,5,1,@shadow_color)
     bitmap.fill_rect(0,4,5,1,@scroll_bar_decoration_color)
     bitmap.fill_rect(0,5,5,1,@shadow_color)
     bitmap.fill_rect(0,6,5,1,@scroll_bar_decoration_color)
     bitmap.fill_rect(0,7,5,1,@shadow_color)
     # Dibujar este adorno en el centro de la barra
     x = (@top_bar.bitmap.width  / 2)  - (bitmap.width  / 2)
     y = (@top_bar.bitmap.height / 2)  - (bitmap.height / 2)
     @top_bar.bitmap.blt(x,y,bitmap,bitmap.rect)
   end
   # ----------------------------------------------------------
   
 end
 #--------------------------------------------------------------------------
 def refresh_bars
   if @background_bar != nil
     @background_bar.dispose
     @background_bar = nil
     @top_bar.dispose
     @top_bar = nil
   end
   create_vertical_bar
 end
 #--------------------------------------------------------------------------
 alias dispose_bynewold dispose
 def dispose
   dispose_bynewold
   if @background_bar != nil
     @background_bar.dispose
     @top_bar.dispose
   end
 end
 #--------------------------------------------------------------------------
end
#==============================================================================



Instructions

The instructions in the script are in spanish, here are translated for a program

Spoiler: ShowHide
- the created windows will have the bar of scroll habilitated by default.
   In order to change this, to use this command:

       YourWindow.scroll_visible_bar  = *valor*

     # *valor* = false / true  => DEACTIVATING / ACTIVATE

 - the bar comes out by default placed to the left of the window.
   In order to change this, to use this command:

       YourWindow.scroll_bar_position  = *valor *

     # *valor *  = 0 / 1 => LEFT / RIGHT

 - bars are made with some colors by default.
   In order to change this, to use these commands:

     # Changing the color of the bottom of the bar

       YourWindow.scroll_bar_background_color = *color*

     # Changing the color of the border of the bottom of the bar

       YourWindow.scroll_bar_background_borde_color = *color*

     # Changing the color of the scroll bar

       YourWindow.scroll_bar_top_color = *color*

     # Changing the color of the border of the scroll bar

       YourWindow.scroll_bar_top_borde_color = *color*

     # Changing the color of the adornment on the scroll bar

       YourWindow.scroll_bar_decoration_color = *color*

     # Changing the color of the shading of the scroll bar and adornment

       YourWindow.shadow_color = *color* # Shadow 1

       YourWindow.shadow_color2 = *color* # Shadow 2

       YourWindow.shadow_color3 = *color* # Shadow 3

   # *color* = Color.new(*red*,*green*,*blue*,*alpha*)

       # *red*,*green*,*blue*,*alpha* = val between 0 and 255

 - if you use any previous command you use also this command stops than
   Himself actualizen changes

      YourWindow.refresh_bars

 - alternatively, you can use an image to generate bars.
   For it, use this command:

      YourWindow.use_custom_images = *image*

   *image * = The name of the image of the scroll bar.
             This image must be in the folder picture of your game.
             Do not forget to use the command

                 YourWindow.refresh_bars

             In order to apply the changes to your window

 ( use the pattern image that goes with the script :d.)

 - finally, you can use this command in order that you appear vaguely or no the adornment
   In scroll's bar ( by default the fact that you see yourself is activated )

       YourWindow.hide_decoration = *valor*
       
     # *valor* = false  /  true  => DEACTIVATE /  ACTIVATE



Compatibility

none.


Credits and Thanks




Author's Notes

this is the pattern image for the scroll bars

(http://img832.imageshack.us/img832/6776/bars01.th.png) (http://img832.imageshack.us/i/bars01.png/)

or you can download from here :D (http://www.megaupload.com/?d=QUIJHFAV)

and this is my first script in the  forum  8), tomorrow more  :P
Title: Re: [XP][VX] Displacement Bar in Windows
Post by: ForeverZer0 on April 27, 2011, 09:26:20 pm
Looks nice.

Its also nice to see a new scripter around here.  :D