This repository has been archived on 2023-10-09. You can view files and clone it. You cannot open issues or pull requests or push a commit.
Files
blender-archive/source/blender/blenlib/intern/rct.c
Ton Roosendaal ab407f6ac7 2.5
First version of region-scaling. WIP commit, so bear with me a while!

- All fixed sized regions have a small 'drag' widget, on the left or top.
  (not yet for free-sized regions, like 4-split).
- Mouse-over on widget changes cursor and allows drag.
- Click on widget hides/reveals.
- Fun for test; 3d view header, if high enough, draws more rows of
  buttons when width is too small.

The WIP stuff;
- It doesn't save yet in files, using the "minsize" variable of region
  definitions, also means other similar areas show same sizes now.
- Definitions for pref size, min/max will be added.
- Properties panel in Fcurve window draws widget on wrong place when
  hidden (subdiv system needs tweak)
- Widgets don't draw perfect yet, also needs further tweaks.

But, in general it's quite fun and usable. :) Many variatians are possible,
like for real tabs, or little icons, or just click-drag on edge.

The reason to first try the widget/tab variation:
- it re-uses the "Area Action Zone" code, widgets for layouting Screens
- it's visible, hotkey-only options for screen layouts are not preferred.
- distinguish clearly area-edges from region-edges this way. Having the
  cursor change shape on every edge (and block input) is probably annoying
  too... but that can be tested.

Later more!
2009-05-24 13:29:29 +00:00

203 lines
4.2 KiB
C

/*
*
* rct.c
*
* april 95
*
* $Id$
*
* A minimalist lib for functions doing stuff with rectangle structs.
*
* ***** BEGIN GPL LICENSE BLOCK *****
*
* 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.
*
* The Original Code is Copyright (C) 2001-2002 by NaN Holding BV.
* All rights reserved.
*
* The Original Code is: all of this file.
*
* Contributor(s): none yet.
*
* ***** END GPL LICENSE BLOCK *****
*
*/
#include "DNA_vec_types.h"
#include "BLI_blenlib.h"
#ifdef HAVE_CONFIG_H
#include <config.h>
#endif
int BLI_rcti_is_empty(rcti * rect)
{
return ((rect->xmax<=rect->xmin) ||
(rect->ymax<=rect->ymin));
}
int BLI_in_rcti(rcti * rect, int x, int y)
{
if(x<rect->xmin) return 0;
if(x>rect->xmax) return 0;
if(y<rect->ymin) return 0;
if(y>rect->ymax) return 0;
return 1;
}
int BLI_in_rctf(rctf *rect, float x, float y)
{
if(x<rect->xmin) return 0;
if(x>rect->xmax) return 0;
if(y<rect->ymin) return 0;
if(y>rect->ymax) return 0;
return 1;
}
void BLI_union_rctf(rctf *rct1, rctf *rct2)
{
if(rct1->xmin>rct2->xmin) rct1->xmin= rct2->xmin;
if(rct1->xmax<rct2->xmax) rct1->xmax= rct2->xmax;
if(rct1->ymin>rct2->ymin) rct1->ymin= rct2->ymin;
if(rct1->ymax<rct2->ymax) rct1->ymax= rct2->ymax;
}
void BLI_union_rcti(rcti *rct1, rcti *rct2)
{
if(rct1->xmin>rct2->xmin) rct1->xmin= rct2->xmin;
if(rct1->xmax<rct2->xmax) rct1->xmax= rct2->xmax;
if(rct1->ymin>rct2->ymin) rct1->ymin= rct2->ymin;
if(rct1->ymax<rct2->ymax) rct1->ymax= rct2->ymax;
}
void BLI_init_rctf(rctf *rect, float xmin, float xmax, float ymin, float ymax)
{
if(xmin <= xmax) {
rect->xmin= xmin;
rect->xmax= xmax;
}
else {
rect->xmax= xmin;
rect->xmin= xmax;
}
if(ymin <= ymax) {
rect->ymin= ymin;
rect->ymax= ymax;
}
else {
rect->ymax= ymin;
rect->ymin= ymax;
}
}
void BLI_init_rcti(rcti *rect, int xmin, int xmax, int ymin, int ymax)
{
if(xmin <= xmax) {
rect->xmin= xmin;
rect->xmax= xmax;
}
else {
rect->xmax= xmin;
rect->xmin= xmax;
}
if(ymin <= ymax) {
rect->ymin= ymin;
rect->ymax= ymax;
}
else {
rect->ymax= ymin;
rect->ymin= ymax;
}
}
void BLI_translate_rcti(rcti *rect, int x, int y)
{
rect->xmin += x;
rect->ymin += y;
rect->xmax += x;
rect->ymax += y;
}
void BLI_translate_rctf(rctf *rect, float x, float y)
{
rect->xmin += x;
rect->ymin += y;
rect->xmax += x;
rect->ymax += y;
}
int BLI_isect_rctf(rctf *src1, rctf *src2, rctf *dest)
{
float xmin, xmax;
float ymin, ymax;
xmin = (src1->xmin) > (src2->xmin) ? (src1->xmin) : (src2->xmin);
xmax = (src1->xmax) < (src2->xmax) ? (src1->xmax) : (src2->xmax);
ymin = (src1->ymin) > (src2->ymin) ? (src1->ymin) : (src2->ymin);
ymax = (src1->ymax) < (src2->ymax) ? (src1->ymax) : (src2->ymax);
if(xmax>=xmin && ymax>=ymin) {
if(dest) {
dest->xmin = xmin;
dest->xmax = xmax;
dest->ymin = ymin;
dest->ymax = ymax;
}
return 1;
}
else {
if(dest) {
dest->xmin = 0;
dest->xmax = 0;
dest->ymin = 0;
dest->ymax = 0;
}
return 0;
}
}
int BLI_isect_rcti(rcti *src1, rcti *src2, rcti *dest)
{
int xmin, xmax;
int ymin, ymax;
xmin = (src1->xmin) > (src2->xmin) ? (src1->xmin) : (src2->xmin);
xmax = (src1->xmax) < (src2->xmax) ? (src1->xmax) : (src2->xmax);
ymin = (src1->ymin) > (src2->ymin) ? (src1->ymin) : (src2->ymin);
ymax = (src1->ymax) < (src2->ymax) ? (src1->ymax) : (src2->ymax);
if(xmax>=xmin && ymax>=ymin) {
if(dest) {
dest->xmin = xmin;
dest->xmax = xmax;
dest->ymin = ymin;
dest->ymax = ymax;
}
return 1;
}
else {
if(dest) {
dest->xmin = 0;
dest->xmax = 0;
dest->ymin = 0;
dest->ymax = 0;
}
return 0;
}
}