Chaos Project

RPG Maker => RPG Maker Scripts => Script Troubleshooting => Topic started by: bigace on November 24, 2013, 11:18:31 pm

Title: [RGSS]Issue with vertical text
Post by: bigace on November 24, 2013, 11:18:31 pm
Okay so I'm having an issue getting the text to be vertical. Here's the code:
#:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=
# ■ Bitmap
#:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=
class Bitmap
def gradient_fill_rect(*args)
if args[0].is_a?(Rect)
x, y, width, height = args[0].x, args[0].y, args[0].width, args[0].height
color1 = args[1].dup
color2 = args[2]
vertical = args[3]
else
x, y, width, height = args[0..3]
color1 = args[4].dup
color2 = args[5]
vertical = args[6]
end
dr = color2.red   - color1.red
dg = color2.green - color1.green
db = color2.blue  - color1.blue
da = color2.alpha - color1.alpha
start_rgba = [color1.red, color1.green, color1.blue, color1.alpha]
if vertical
dr, dg, db, da = dr / height, dg / height, db / height, da / height
(y...(y + height)).each do |i|
fill_rect(x, i, width, 1, color1)
start_rgba[0] = [start_rgba[0] + dr, 0].max
start_rgba[1] = [start_rgba[1] + dg, 0].max
start_rgba[2] = [start_rgba[2] + db, 0].max
start_rgba[3] = [start_rgba[3] + da, 0].max
color1.set(*start_rgba)
end
else
dr, dg, db, da = dr / width, dg / width, db / width, da / width
(x...(x + width)).each do |i|
fill_rect(i, y, 1, height, color1)
start_rgba[0] = [start_rgba[0] + dr, 0].max
start_rgba[1] = [start_rgba[1] + dg, 0].max
start_rgba[2] = [start_rgba[2] + db, 0].max
start_rgba[3] = [start_rgba[3] + da, 0].max
color1.set(*start_rgba)
end
end
end
def gradient_draw_text(*args)
is_rect = args[0].is_a?(Rect)
x        = is_rect ? args[0].x      : args[0]
y        = is_rect ? args[0].y      : args[1]
w        = is_rect ? args[0].width  : args[2]
h        = is_rect ? args[0].height : args[3]
text     = is_rect ? args[1].to_s   : args[4].to_s
color1   = is_rect ? args[2]        : args[5]
color2   = is_rect ? args[3]        : args[6]
align    = is_rect ? args[4]        : args[7]
vertical = is_rect ? args[5]        : args[8]
align = 0 if !align
vertical = false if !vertical
text_bmp = Bitmap.new(w, h)
text_bmp.font.name = font.name
text_bmp.font.size = font.size
text_bmp.font.bold = font.bold
text_bmp.font.italic = font.italic
text_bmp.font.outline = font.outline
text_bmp.font.shadow = font.shadow
text_bmp.font.out_color = font.out_color
text_bmp.draw_text(0, 0, w, h, text, align)
gradient_bmp = Bitmap.new(w, h)
gradient_bmp.gradient_fill_rect(0, 0, w, h, color1, color2, vertical)
w.times do |x2|
h.times do |y2|
alpha_txt = text_bmp.get_pixel(x2, y2).alpha
if alpha_txt > 0
c = gradient_bmp.get_pixel(x2, y2)
c.alpha = alpha_txt
text_bmp.set_pixel(x2, y2, c)
end
end
end     
draw_text(x, y, w, h, text.to_s, align)
blt(x, y, text_bmp, Rect.new(0, 0, w, h))
end 
end


So I was wondering if you guys could figure out where the issue is coming from.
Title: Re: [RGSS]Issue with vertical text
Post by: KK20 on November 24, 2013, 11:42:25 pm
What kind of vertical?
L
i
k
e

T
h
i
s

or rotated 90 degrees?
Either way, you have to change

        w.times do |x2|
            h.times do |y2|
                alpha_txt = text_bmp.get_pixel(x2, y2).alpha
                if alpha_txt > 0
                    c = gradient_bmp.get_pixel(x2, y2)
                    c.alpha = alpha_txt
                    text_bmp.set_pixel(x2, y2, c)
                end
            end
        end 

In its current state, it's only drawing horizontally. You have no check if it needs to be drawn horizontally or vertically.
Title: Re: [RGSS]Issue with vertical text
Post by: bigace on November 25, 2013, 02:02:24 am
The first vertical one, I'll take a look at that in a second thank you.
Title: Re: [RGSS]Issue with vertical text
Post by: KK20 on November 25, 2013, 01:17:31 pm
If this could be of any help to you, this draws text one char at a time vertically:

        chars = text.split('')
        y = 0
        while chars.size > 0
          text_bmp.draw_text(0, y, w, h, chars.shift, align)
          y += text_bmp.font.size
        end
Title: Re: [RGSS]Issue with vertical text
Post by: bigace on November 25, 2013, 01:59:21 pm
Nope this happens:
(https://db.tt/ilMIWbin)

I also tried this:
		if vertical
y_off = 0
text.each_char do |c|
rect = text_size(c)
rect.x = x
rect.y = y + y_off
draw_text(rect, c, align)
y_off += rect.height
end 
end

But this happenes:
(https://db.tt/yPGTiQCC)

Note: I've been trying to turn the word "Level"
Title: Re: [RGSS]Issue with vertical text
Post by: KK20 on November 25, 2013, 04:05:48 pm
Shouldn't you be drawing the vertical text to the text_bmp object? Because at the end of your method, you are calling a blt to copy the text_bmp object. Also, I have no idea why you have a draw_text immediately above that blt.