/*
* CINELERRA
* Copyright (C) 2011 Adam Williams <broadcast at earthling dot net>
- *
+ *
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
- *
+ *
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
- *
+ *
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
- *
+ *
*/
#include "bcpixmap.h"
#include "bcresources.h"
#include "bcscrollbar.h"
#include "clip.h"
-#include "colors.h"
+#include "bccolors.h"
#include "vframe.h"
#include <string.h>
-BC_ScrollBar::BC_ScrollBar(int x,
- int y,
- int orientation,
- int pixels,
- int64_t length,
- int64_t position,
- int64_t handlelength,
+BC_ScrollBar::BC_ScrollBar(int x, int y, int orientation, int pixels,
+ int64_t length, int64_t position, int64_t handlelength,
VFrame **data)
: BC_SubWindow(x, y, 0, 0, -1)
{
this->handlelength = handlelength;
this->selection_status = 0;
this->highlight_status = 0;
+ this->stretch = orientation & SCROLL_STRETCH ? 1 : 0;
+ orientation &= ~SCROLL_STRETCH;
this->orientation = orientation;
this->pixels = pixels;
- if(data)
- this->data = data;
- else
- if(orientation == SCROLL_HORIZ)
- this->data = BC_WindowBase::get_resources()->hscroll_data;
- else
- this->data = BC_WindowBase::get_resources()->vscroll_data;
+ if( !data ) data = orientation == SCROLL_HORIZ ?
+ BC_WindowBase::get_resources()->hscroll_data :
+ BC_WindowBase::get_resources()->vscroll_data ;
+ this->data = data;
handle_pixel = 0;
handle_pixels = 0;
calculate_dimensions(w, h);
}
-
-
void BC_ScrollBar::calculate_dimensions(int &w, int &h)
{
switch(orientation)
int BC_ScrollBar::get_span()
{
- switch(orientation)
- {
- case SCROLL_HORIZ:
- return data[SCROLL_HANDLE_UP]->get_h();
- break;
-
- case SCROLL_VERT:
- return data[SCROLL_HANDLE_UP]->get_w();
- break;
+ switch(orientation) {
+ case SCROLL_HORIZ: return data[SCROLL_HANDLE_UP]->get_h();
+ case SCROLL_VERT: return data[SCROLL_HANDLE_UP]->get_w();
}
return 0;
}
int BC_ScrollBar::get_arrow_pixels()
{
- switch(orientation)
- {
- case SCROLL_HORIZ:
- return data[SCROLL_BACKARROW_UP]->get_w();
- break;
-
- case SCROLL_VERT:
- return data[SCROLL_BACKARROW_UP]->get_h();
- break;
+ switch(orientation) {
+ case SCROLL_HORIZ: return data[SCROLL_BACKARROW_UP]->get_w();
+ case SCROLL_VERT: return data[SCROLL_BACKARROW_UP]->get_h();
}
return 0;
}
// Too small to draw anything
if(get_w() < get_arrow_pixels() * 2 + 5)
{
- draw_3segmenth(0,
- 0,
+ draw_3segmenth(0,
+ 0,
get_w(),
images[SCROLL_HANDLE_UP]);
}
// Too small to draw anything
if(get_h() < get_arrow_pixels() * 2 + 5)
{
- draw_3segmentv(0,
- 0,
+ draw_3segmentv(0,
+ 0,
get_w(),
images[SCROLL_HANDLE_UP]);
}
void BC_ScrollBar::get_handle_dimensions()
{
- int total_pixels = pixels -
+ int total_pixels = pixels -
get_arrow_pixels() * 2;
if(length > 0)
{
- handle_pixels = (int64_t)((double)handlelength /
- length *
- total_pixels +
+ handle_pixels = (int64_t)((double)handlelength /
+ length *
+ total_pixels +
.5);
if(handle_pixels < get_resources()->scroll_minhandle)
handle_pixels = get_resources()->scroll_minhandle;
- handle_pixel = (int64_t)((double)position /
- length *
- total_pixels + .5) +
+ handle_pixel = (int64_t)((double)position /
+ length *
+ total_pixels + .5) +
get_arrow_pixels();
// Handle pixels is beyond minimum right position. Clamp it.
CLAMP(handle_pixel, get_arrow_pixels(), (int)(pixels - get_arrow_pixels()));
CLAMP(handle_pixels, 0, total_pixels);
-// printf("BC_ScrollBar::get_handle_dimensions %d %d %d\n",
-// total_pixels,
+// printf("BC_ScrollBar::get_handle_dimensions %d %d %d\n",
+// total_pixels,
// handle_pixel,
// handle_pixels);
}
{
if(!highlight_status)
{
- highlight_status = get_cursor_zone(top_level->cursor_x,
+ highlight_status = get_cursor_zone(top_level->cursor_x,
top_level->cursor_y);
draw(1);
}
{
if(highlight_status && !selection_status)
{
- int new_highlight_status =
+ int new_highlight_status =
get_cursor_zone(top_level->cursor_x, top_level->cursor_y);
if(new_highlight_status != highlight_status)
{
{
//printf("BC_ScrollBar::cursor_motion_event 1\n");
double total_pixels = pixels - get_arrow_pixels() * 2;
- int64_t cursor_pixel = (orientation == SCROLL_HORIZ) ?
- top_level->cursor_x :
+ int64_t cursor_pixel = (orientation == SCROLL_HORIZ) ?
+ top_level->cursor_x :
top_level->cursor_y;
- int64_t new_position = (int64_t)((double)(cursor_pixel - min_pixel) /
+ int64_t new_position = (int64_t)((double)(cursor_pixel - min_pixel) /
total_pixels * length);
//printf("BC_ScrollBar::cursor_motion_event 2\n");
- if(new_position > length - handlelength)
+ if(new_position > length - handlelength)
new_position = length - handlelength;
if(new_position < 0) new_position = 0;
int BC_ScrollBar::repeat_event(int64_t duration)
{
- if(duration == top_level->get_resources()->scroll_repeat &&
+ if(duration == top_level->get_resources()->scroll_repeat &&
selection_status)
{
//printf("BC_ScrollBar::repeat_event %d %d\n", __LINE__, (int)repeat_count);
int BC_ScrollBar::update_length(int64_t length, int64_t position, int64_t handlelength, int flush)
{
+ if( stretch ) length += handlelength/4;
this->length = length;
this->position = position;
this->handlelength = handlelength;