… | |
… | |
514 | ); |
514 | ); |
515 | |
515 | |
516 | sub emit { |
516 | sub emit { |
517 | my ($self, $signal, @args) = @_; |
517 | my ($self, $signal, @args) = @_; |
518 | |
518 | |
519 | # I do not really like this solution, but I dislike duplication |
519 | # I do not really like this solution, but I do not like duplication |
520 | # and needlessly verbose code, too. |
520 | # and needlessly verbose code, either. |
521 | my @append |
521 | my @append |
522 | = $has_coords{$signal} |
522 | = $has_coords{$signal} |
523 | ? $args[0]->xy ($self) |
523 | ? $args[0]->xy ($self) |
524 | : (); |
524 | : (); |
525 | |
525 | |
… | |
… | |
898 | glClear GL_COLOR_BUFFER_BIT; |
898 | glClear GL_COLOR_BUFFER_BIT; |
899 | |
899 | |
900 | { |
900 | { |
901 | package CFPlus::UI::Base; |
901 | package CFPlus::UI::Base; |
902 | |
902 | |
903 | ($draw_x, $draw_y, $draw_w, $draw_h) = |
903 | local ($draw_x, $draw_y, $draw_w, $draw_h) = |
904 | (0, 0, $self->{w}, $self->{h}); |
904 | (0, 0, $self->{w}, $self->{h}); |
|
|
905 | |
|
|
906 | $self->_render; |
905 | } |
907 | } |
906 | |
|
|
907 | $self->_render; |
|
|
908 | }; |
908 | }; |
909 | } |
909 | } |
910 | |
910 | |
911 | sub _draw { |
911 | sub _draw { |
912 | my ($self) = @_; |
912 | my ($self) = @_; |
… | |
… | |
1900 | active_fg => [0, 0, 0], |
1900 | active_fg => [0, 0, 0], |
1901 | can_hover => 1, |
1901 | can_hover => 1, |
1902 | can_focus => 1, |
1902 | can_focus => 1, |
1903 | valign => 0, |
1903 | valign => 0, |
1904 | can_events => 1, |
1904 | can_events => 1, |
|
|
1905 | ellipsise => 0, |
1905 | #text => ... |
1906 | #text => ... |
1906 | #hidden => "*", |
1907 | #hidden => "*", |
1907 | @_ |
1908 | @_ |
1908 | ) |
1909 | ) |
1909 | } |
1910 | } |
… | |
… | |
1966 | ++$self->{cursor} if $self->{cursor} < length $self->{text}; |
1967 | ++$self->{cursor} if $self->{cursor} < length $self->{text}; |
1967 | } elsif ($sym == CFPlus::SDLK_HOME) { |
1968 | } elsif ($sym == CFPlus::SDLK_HOME) { |
1968 | $self->{cursor} = 0; |
1969 | $self->{cursor} = 0; |
1969 | } elsif ($sym == CFPlus::SDLK_END) { |
1970 | } elsif ($sym == CFPlus::SDLK_END) { |
1970 | $self->{cursor} = length $text; |
1971 | $self->{cursor} = length $text; |
|
|
1972 | } elsif ($uni == 21) { # ctrl-u |
|
|
1973 | $text = ""; |
|
|
1974 | $self->{cursor} = 0; |
1971 | } elsif ($uni == 27) { |
1975 | } elsif ($uni == 27) { |
1972 | $self->emit ('escape'); |
1976 | $self->emit ('escape'); |
1973 | } elsif ($uni) { |
1977 | } elsif ($uni >= 0x20 || $uni == 0x0d) { |
1974 | substr $text, $self->{cursor}++, 0, chr $uni; |
1978 | substr $text, $self->{cursor}++, 0, chr $uni; |
1975 | } else { |
1979 | } else { |
1976 | return 0; |
1980 | return 0; |
1977 | } |
1981 | } |
1978 | |
1982 | |
1979 | $self->_set_text ($text); |
1983 | $self->_set_text ($text); |
1980 | |
1984 | |
1981 | $self->realloc; |
1985 | $self->realloc; |
|
|
1986 | $self->update; |
1982 | |
1987 | |
1983 | 1 |
1988 | 1 |
1984 | } |
1989 | } |
1985 | |
1990 | |
1986 | sub invoke_focus_in { |
1991 | sub invoke_focus_in { |
… | |
… | |
2055 | glVertex 0.5 + $self->{cur_x} + $self->{ox}, $self->{cur_y} + $self->{oy} + $self->{cur_h}; |
2060 | glVertex 0.5 + $self->{cur_x} + $self->{ox}, $self->{cur_y} + $self->{oy} + $self->{cur_h}; |
2056 | glEnd; |
2061 | glEnd; |
2057 | } |
2062 | } |
2058 | } |
2063 | } |
2059 | |
2064 | |
|
|
2065 | ############################################################################# |
|
|
2066 | |
2060 | package CFPlus::UI::Entry; |
2067 | package CFPlus::UI::Entry; |
2061 | |
2068 | |
2062 | our @ISA = CFPlus::UI::EntryBase::; |
2069 | our @ISA = CFPlus::UI::EntryBase::; |
2063 | |
2070 | |
2064 | use CFPlus::OpenGL; |
2071 | use CFPlus::OpenGL; |
… | |
… | |
2066 | sub invoke_key_down { |
2073 | sub invoke_key_down { |
2067 | my ($self, $ev) = @_; |
2074 | my ($self, $ev) = @_; |
2068 | |
2075 | |
2069 | my $sym = $ev->{sym}; |
2076 | my $sym = $ev->{sym}; |
2070 | |
2077 | |
2071 | if ($sym == 13) { |
2078 | if ($ev->{uni} == 0x0d || $sym == 13) { |
2072 | unshift @{$self->{history}}, |
2079 | unshift @{$self->{history}}, |
2073 | my $txt = $self->get_text; |
2080 | my $txt = $self->get_text; |
2074 | |
2081 | |
2075 | $self->{history_pointer} = -1; |
2082 | $self->{history_pointer} = -1; |
2076 | $self->{history_saveback} = ''; |
2083 | $self->{history_saveback} = ''; |
… | |
… | |
2097 | $self->set_text ($self->{history}->[$self->{history_pointer}]); |
2104 | $self->set_text ($self->{history}->[$self->{history_pointer}]); |
2098 | } else { |
2105 | } else { |
2099 | $self->set_text ($self->{history_saveback}); |
2106 | $self->set_text ($self->{history_saveback}); |
2100 | } |
2107 | } |
2101 | |
2108 | |
|
|
2109 | } else { |
|
|
2110 | return $self->SUPER::invoke_key_down ($ev) |
|
|
2111 | } |
|
|
2112 | |
|
|
2113 | 1 |
|
|
2114 | } |
|
|
2115 | |
|
|
2116 | ############################################################################# |
|
|
2117 | |
|
|
2118 | package CFPlus::UI::TextEdit; |
|
|
2119 | |
|
|
2120 | our @ISA = CFPlus::UI::EntryBase::; |
|
|
2121 | |
|
|
2122 | use CFPlus::OpenGL; |
|
|
2123 | |
|
|
2124 | sub move_cursor_ver { |
|
|
2125 | my ($self, $dy) = @_; |
|
|
2126 | |
|
|
2127 | my ($y, $x) = $self->{layout}->index_to_line_x ($self->{cursor}); |
|
|
2128 | |
|
|
2129 | $y += $dy; |
|
|
2130 | |
|
|
2131 | if (defined (my $index = $self->{layout}->line_x_to_index ($y, $x))) { |
|
|
2132 | $self->{cursor} = $index; |
|
|
2133 | delete $self->{cur_h}; |
|
|
2134 | $self->update; |
|
|
2135 | return; |
|
|
2136 | } |
|
|
2137 | } |
|
|
2138 | |
|
|
2139 | sub invoke_key_down { |
|
|
2140 | my ($self, $ev) = @_; |
|
|
2141 | |
|
|
2142 | my $sym = $ev->{sym}; |
|
|
2143 | |
|
|
2144 | if ($sym == CFPlus::SDLK_UP) { |
|
|
2145 | $self->move_cursor_ver (-1); |
|
|
2146 | } elsif ($sym == CFPlus::SDLK_DOWN) { |
|
|
2147 | $self->move_cursor_ver (+1); |
2102 | } else { |
2148 | } else { |
2103 | return $self->SUPER::invoke_key_down ($ev) |
2149 | return $self->SUPER::invoke_key_down ($ev) |
2104 | } |
2150 | } |
2105 | |
2151 | |
2106 | 1 |
2152 | 1 |
… | |
… | |
2956 | |
3002 | |
2957 | $self->{texture} ||= new_from_opengl CFPlus::Texture $W, $H, sub { |
3003 | $self->{texture} ||= new_from_opengl CFPlus::Texture $W, $H, sub { |
2958 | glClearColor 0, 0, 0, 0; |
3004 | glClearColor 0, 0, 0, 0; |
2959 | glClear GL_COLOR_BUFFER_BIT; |
3005 | glClear GL_COLOR_BUFFER_BIT; |
2960 | |
3006 | |
|
|
3007 | package CFPlus::UI::Base; |
|
|
3008 | local ($draw_x, $draw_y, $draw_w, $draw_h) = |
|
|
3009 | (0, 0, $self->{w}, $self->{h}); |
|
|
3010 | |
2961 | my $top = int $self->{children}[1]{range}[0]; |
3011 | my $top = int $self->{children}[1]{range}[0]; |
2962 | |
3012 | |
2963 | my $paridx = 0; |
3013 | my $paridx = 0; |
2964 | my $top_paragraph; |
3014 | my $top_paragraph; |
2965 | my $top = int $self->{children}[1]{range}[0]; |
3015 | my $top = int $self->{children}[1]{range}[0]; |
… | |
… | |
3281 | |
3331 | |
3282 | package CFPlus::UI::Buttonbar; |
3332 | package CFPlus::UI::Buttonbar; |
3283 | |
3333 | |
3284 | our @ISA = CFPlus::UI::HBox::; |
3334 | our @ISA = CFPlus::UI::HBox::; |
3285 | |
3335 | |
3286 | # TODO: should actualyl wrap buttons and other goodies. |
3336 | # TODO: should actually wrap buttons and other goodies. |
3287 | |
3337 | |
3288 | ############################################################################# |
3338 | ############################################################################# |
3289 | |
3339 | |
3290 | package CFPlus::UI::Menu; |
3340 | package CFPlus::UI::Menu; |
3291 | |
3341 | |
… | |
… | |
3820 | if ($ev->{button} == 1) { |
3870 | if ($ev->{button} == 1) { |
3821 | $::CONN->user_send ("cast $spell->{name}"); |
3871 | $::CONN->user_send ("cast $spell->{name}"); |
3822 | } elsif ($ev->{button} == 2) { |
3872 | } elsif ($ev->{button} == 2) { |
3823 | $::CONN->user_send ("invoke $spell->{name}"); |
3873 | $::CONN->user_send ("invoke $spell->{name}"); |
3824 | } elsif ($ev->{button} == 3) { |
3874 | } elsif ($ev->{button} == 3) { |
|
|
3875 | my $shortname = CFPlus::shorten $spell->{name}, 14; |
3825 | (new CFPlus::UI::Menu |
3876 | (new CFPlus::UI::Menu |
3826 | items => [ |
3877 | items => [ |
3827 | ["bind <i>cast $spell->{name}</i> to a key" => sub { $::BIND_EDITOR->do_quick_binding (["cast $spell->{name}"]) }], |
3878 | ["bind <i>cast $shortname</i> to a key" => sub { $::BIND_EDITOR->do_quick_binding (["cast $spell->{name}"]) }], |
3828 | ["bind <i>invoke $spell->{name}</i> to a key" => sub { $::BIND_EDITOR->do_quick_binding (["invoke $spell->{name}"]) }], |
3879 | ["bind <i>invoke $shortname</i> to a key" => sub { $::BIND_EDITOR->do_quick_binding (["invoke $spell->{name}"]) }], |
3829 | ], |
3880 | ], |
3830 | )->popup ($ev); |
3881 | )->popup ($ev); |
3831 | } else { |
3882 | } else { |
3832 | return 0; |
3883 | return 0; |
3833 | } |
3884 | } |
3834 | |
3885 | |
3835 | 1 |
3886 | 1 |
3836 | }; |
3887 | }; |
3837 | |
3888 | |
3838 | my $tooltip = "$spell->{message}$TOOLTIP_ALL"; |
3889 | my $tooltip = (CFPlus::asxml $spell->{message}) . $TOOLTIP_ALL; |
3839 | |
3890 | |
3840 | #TODO: add path info to tooltip |
3891 | #TODO: add path info to tooltip |
3841 | #$self->add (6, $row, new CFPlus::UI::Label text => $spell->{path}); |
3892 | #$self->add (6, $row, new CFPlus::UI::Label text => $spell->{path}); |
3842 | |
3893 | |
3843 | $self->add (0, $row, new CFPlus::UI::Face |
3894 | $self->add (0, $row, new CFPlus::UI::Face |
… | |
… | |
4121 | glLoadIdentity; |
4172 | glLoadIdentity; |
4122 | |
4173 | |
4123 | { |
4174 | { |
4124 | package CFPlus::UI::Base; |
4175 | package CFPlus::UI::Base; |
4125 | |
4176 | |
4126 | ($draw_x, $draw_y, $draw_w, $draw_h) = |
4177 | local ($draw_x, $draw_y, $draw_w, $draw_h) = |
4127 | (0, 0, $self->{w}, $self->{h}); |
4178 | (0, 0, $self->{w}, $self->{h}); |
4128 | } |
|
|
4129 | |
4179 | |
4130 | $self->_draw; |
4180 | $self->_draw; |
|
|
4181 | } |
4131 | } |
4182 | } |
4132 | |
4183 | |
4133 | ############################################################################# |
4184 | ############################################################################# |
4134 | |
4185 | |
4135 | package CFPlus::UI; |
4186 | package CFPlus::UI; |